build: removed unused cmake code + minor renaming
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
light7734 2026-02-13 13:24:35 +03:30
parent c6b99b7933
commit 01f20c325a
Signed by: light7734
GPG key ID: E7CE6145374F0B5F
7 changed files with 121 additions and 261 deletions

14
.gitignore vendored
View file

@ -1,11 +1,9 @@
# Temp directories
.vs/ .vs/
bin/ bin/
bin-obj/ bin-obj/
build/ build/
.cache/ .cache/
# VS Files
**.vcxproj** **.vcxproj**
**.sln **.sln
@ -17,21 +15,9 @@ build/
Makefile Makefile
**/**.mk **/**.mk
**/**.project **/**.project
**/Engine.txt
**/GLAD.txt
**/Sandbox.txt
**/Logs/**
**/logs/**
**.ini
!**/default_gui_layout.ini
CMake/
CMakeUserPresets.json CMakeUserPresets.json
compile_commands.json compile_commands.json

View file

@ -7,7 +7,7 @@ set(CMAKE_CXX_MODULE_STD 1)
cmake_minimum_required(VERSION 4.1) cmake_minimum_required(VERSION 4.1)
project(Light) project(Light)
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/functions.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/module.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/options.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/options.cmake)

View file

@ -5,7 +5,7 @@
* Why did I do this? * Why did I do this?
* To reduce as much complexity from the API, * To reduce as much complexity from the API,
* Which should make the Renderer code simpler. * Which should make the Renderer code simpler.
* In the long run, it should pay off... * In the long run, it should pay off... or so I hope it does.
*/ */
module; module;

View file

@ -1,7 +1,10 @@
if(WIN32) if(WIN32)
add_compile_definitions(LIGHT_PLATFORM_WINDOWS) add_compile_definitions(LIGHT_PLATFORM_WINDOWS)
elseif(UNIX) elseif(UNIX)
add_compile_definitions(LIGHT_PLATFORM_LINUX) add_compile_definitions(LIGHT_PLATFORM_LINUX)
else() else()
message(FATAL "Failed to generate cmake: unsupported platform") message(FATAL "Failed to generate cmake: unsupported platform")
endif() endif()

View file

@ -1,221 +0,0 @@
function(add_module)
cmake_parse_arguments(
ARGS
""
"NAME"
"INTERFACES;ROOT_DIR;SOURCES;DEPENDENCIES;PRIVATE_DEPENDENCIES;TESTS;TEST_INTERFACES;ENTRYPOINT;"
${ARGN}
)
if(NOT ARGS_NAME)
message(FATAL_ERROR "You must provide a name")
endif()
set(target_library_name ${ARGS_NAME})
set(target_executable_name ${ARGS_NAME})
set(module_directory "${CMAKE_CURRENT_SOURCE_DIR}/${target_library_name}")
if(ARGS_ROOT_DIR)
set(module_directory "${ARGS_ROOT_DIR}")
endif()
# In this case, the module is an executable, so we prepend "lib" to the
# target name. And set the "executable_target" name to ARGS_NAME. The
# rationale here is to easily be able to write tests for an executable
# modules's interfaces... by splitting it into two targets:
# lib"executable_name" for the interface and "executable_name" for the "int
# main()" defining file (the entrypoint). the lib"executable_name" should
# not be disruptive since an executable module's library will not be
# dependent upon (except by the tests within the same module)
if(ARGS_ENTRYPOINT)
set(target_library_name "lib_${ARGS_NAME}")
add_executable(
${target_executable_name} ${module_directory}/${ARGS_ENTRYPOINT}
)
endif()
add_library(${target_library_name})
if(ARGS_SOURCES)
set(files)
foreach(file ${ARGS_SOURCES})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(${target_library_name} PRIVATE ${files})
endif()
if(ARGS_PUBLIC_SOURECS)
set(files)
foreach(file ${ARGS_PUBLIC_SOURECS})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(${target_library_name} PUBLIC ${files})
endif()
if(ARGS_INTERFACES)
set(files)
foreach(file ${ARGS_INTERFACES})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(
${target_library_name} PUBLIC FILE_SET public_cxx_modules TYPE
CXX_MODULES FILES ${files}
)
endif()
target_link_libraries(${target_library_name} PUBLIC ${ARGS_DEPENDENCIES})
target_link_libraries(
${target_library_name} PRIVATE ${ARGS_PRIVATE_DEPENDENCIES}
)
if(ARGS_TESTS)
message("ADDING TESTS ${target_library_name}!!!")
set(test_files)
foreach(test_file ${ARGS_TESTS})
list(APPEND test_files "${module_directory}/${test_file}")
endforeach()
add_executable("${target_library_name}_tests" ${test_files})
target_link_libraries(
"${target_library_name}_tests"
PRIVATE ${target_library_name}
#
test
)
if(ARGS_TEST_INTERFACES)
set(test_interface_files)
foreach(file ${ARGS_TEST_INTERFACES})
list(APPEND test_interface_files "${module_directory}/${file}")
endforeach()
message("TEST INTERFACE FILES: ${test_interface_files}")
target_sources(
"${target_library_name}_tests"
PRIVATE FILE_SET test_cxx_modules TYPE CXX_MODULES FILES
${test_interface_files}
)
endif()
endif()
if(ARGS_ENTRYPOINT)
target_link_libraries(
${target_executable_name} PRIVATE ${target_library_name}
)
endif()
endfunction()
function(add_executable_module exename)
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/private")
foreach(source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach()
message("Adding executable ${exename} with source files: ${source_files}")
set(PUBLIC_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/public_includes")
file(MAKE_DIRECTORY "${PUBLIC_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/public/"
"${PUBLIC_INCLUDE_DIR}/${exename}" SYMBOLIC
)
set(PRIVATE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/private_includes")
file(MAKE_DIRECTORY "${PRIVATE_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/private/"
"${PRIVATE_INCLUDE_DIR}${exename}" SYMBOLIC
)
endfunction()
function(add_test_module target_lib_name)
# if(NOT ${ENABLE_UNIT_TESTS}) return() endif()
add_executable(${target_lib_name}_tests ${ARGN})
target_link_libraries(
${target_lib_name}_tests
PRIVATE ${target_lib_name}
#
test
)
return()
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/private")
foreach(source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach()
message(
"Adding test executable ${target_lib_name}_tests with source files: ${source_files}"
)
set(PUBLIC_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/public_includes")
file(MAKE_DIRECTORY "${PUBLIC_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/public/"
"${PUBLIC_INCLUDE_DIR}/${target_lib_name}" SYMBOLIC
)
set(PRIVATE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/private_includes")
file(MAKE_DIRECTORY "${PRIVATE_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/private/"
"${PRIVATE_INCLUDE_DIR}/${target_lib_name}" SYMBOLIC
)
add_executable(${target_lib_name}_tests ${source_files})
target_link_libraries(
${target_lib_name}_tests PRIVATE ${target_lib_name} std test
)
target_include_directories(
${target_lib_name}_tests
PRIVATE ${PUBLIC_INCLUDE_DIR}
PRIVATE ${PRIVATE_INCLUDE_DIR}
)
endfunction()
function(add_fuzz_module target_lib_name)
if(NOT ${ENABLE_FUZZ_TESTS})
return()
endif()
set(source_files)
set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/private")
foreach(source_file ${ARGN})
list(APPEND source_files "${source_directory}/${source_file}")
endforeach()
message(
"Adding fuzz executable ${target_lib_name}_fuzz with source files: ${source_files}"
)
set(PUBLIC_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/public_includes")
file(MAKE_DIRECTORY "${PUBLIC_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/public/"
"${PUBLIC_INCLUDE_DIR}/${target_lib_name}" SYMBOLIC
)
set(PRIVATE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/private_includes")
file(MAKE_DIRECTORY "${PRIVATE_INCLUDE_DIR}")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/private/"
"${PRIVATE_INCLUDE_DIR}/${target_lib_name}" SYMBOLIC
)
add_executable(${target_lib_name}_fuzz ${source_files})
target_link_libraries(
${target_lib_name}_fuzz PRIVATE ${target_lib_name} std fuzz_test
)
target_link_options(${target_lib_name}_fuzz PRIVATE -fsanitize=fuzzer)
target_compile_options(${target_lib_name}_fuzz PRIVATE -fsanitize=fuzzer)
target_include_directories(
${target_lib_name}_fuzz
PRIVATE ${PUBLIC_INCLUDE_DIR}
PRIVATE ${PRIVATE_INCLUDE_DIR}
)
endfunction()
function(add_option option help)
option(${option} ${help})
if(${option})
message(STATUS "${option}: ON")
add_compile_definitions(${option}=1)
else()
message(STATUS "${option}: OFF")
endif()
endfunction()

104
tools/cmake/module.cmake Normal file
View file

@ -0,0 +1,104 @@
function(add_module)
cmake_parse_arguments(
ARGS
""
"NAME"
"INTERFACES;ROOT_DIR;SOURCES;DEPENDENCIES;PRIVATE_DEPENDENCIES;TESTS;TEST_INTERFACES;ENTRYPOINT;"
${ARGN}
)
if(NOT ARGS_NAME)
message(FATAL_ERROR "You must provide a name")
endif()
set(target_library_name ${ARGS_NAME})
set(target_executable_name ${ARGS_NAME})
set(module_directory "${CMAKE_CURRENT_SOURCE_DIR}/${target_library_name}")
if(ARGS_ROOT_DIR)
set(module_directory "${ARGS_ROOT_DIR}")
endif()
# In this case, the module is an executable, so we prepend "lib" to the
# target name. And set the "executable_target" name to ARGS_NAME. The
# rationale here is to easily be able to write tests for an executable
# modules's interfaces... by splitting it into two targets:
# lib"executable_name" for the interface and "executable_name" for the "int
# main()" defining file (the entrypoint). the lib"executable_name" should
# not be disruptive since an executable module's library will not be
# dependent upon (except by the tests within the same module)
if(ARGS_ENTRYPOINT)
set(target_library_name "lib_${ARGS_NAME}")
add_executable(
${target_executable_name} ${module_directory}/${ARGS_ENTRYPOINT}
)
endif()
add_library(${target_library_name})
if(ARGS_SOURCES)
set(files)
foreach(file ${ARGS_SOURCES})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(${target_library_name} PRIVATE ${files})
endif()
if(ARGS_PUBLIC_SOURECS)
set(files)
foreach(file ${ARGS_PUBLIC_SOURECS})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(${target_library_name} PUBLIC ${files})
endif()
if(ARGS_INTERFACES)
set(files)
foreach(file ${ARGS_INTERFACES})
list(APPEND files "${module_directory}/${file}")
endforeach()
target_sources(
${target_library_name} PUBLIC FILE_SET public_cxx_modules TYPE
CXX_MODULES FILES ${files}
)
endif()
target_link_libraries(${target_library_name} PUBLIC ${ARGS_DEPENDENCIES})
target_link_libraries(
${target_library_name} PRIVATE ${ARGS_PRIVATE_DEPENDENCIES}
)
if(ARGS_TESTS)
message("ADDING TESTS ${target_library_name}!!!")
set(test_files)
foreach(test_file ${ARGS_TESTS})
list(APPEND test_files "${module_directory}/${test_file}")
endforeach()
add_executable("${target_library_name}_tests" ${test_files})
target_link_libraries(
"${target_library_name}_tests"
PRIVATE ${target_library_name}
#
test
)
if(ARGS_TEST_INTERFACES)
set(test_interface_files)
foreach(file ${ARGS_TEST_INTERFACES})
list(APPEND test_interface_files "${module_directory}/${file}")
endforeach()
message("TEST INTERFACE FILES: ${test_interface_files}")
target_sources(
"${target_library_name}_tests"
PRIVATE FILE_SET test_cxx_modules TYPE CXX_MODULES FILES
${test_interface_files}
)
endif()
endif()
if(ARGS_ENTRYPOINT)
target_link_libraries(
${target_executable_name} PRIVATE ${target_library_name}
)
endif()
endfunction()

View file

@ -1,3 +1,14 @@
function(add_option option help)
option(${option} ${help})
if(${option})
message(STATUS "${option}: ON")
add_compile_definitions(${option}=1)
else()
message(STATUS "${option}: OFF")
endif()
endfunction()
add_option(ENABLE_SANDBOX "Enables the building of the sandbox module for experimentation") add_option(ENABLE_SANDBOX "Enables the building of the sandbox module for experimentation")
add_option(ENABLE_UNIT_TESTS "Enables the building of the unit test modules") add_option(ENABLE_UNIT_TESTS "Enables the building of the unit test modules")
add_option(ENABLE_FUZZ_TESTS "Enables the building of the fuzz test modules") add_option(ENABLE_FUZZ_TESTS "Enables the building of the fuzz test modules")
@ -10,39 +21,16 @@ add_option(
) )
if(ENABLE_STATIC_ANALYSIS) if(ENABLE_STATIC_ANALYSIS)
set(CMAKE_CXX_CLANG_TIDY set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks")
"clang-tidy;--warnings-as-errors=*;--allow-no-checks"
)
endif() endif()
if(ENABLE_LLVM_COVERAGE) if(ENABLE_LLVM_COVERAGE)
include(CheckCXXSourceCompiles)
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message( message(
FATAL_ERROR "ENABLE_LLVM_COVERAGE only supports the clang compiler" FATAL_ERROR "ENABLE_LLVM_COVERAGE only supports the clang compiler"
) )
endif() endif()
# Check for libc++
check_cxx_source_compiles(
"
#include <string>
#ifdef _LIBCPP_VERSION
int main() { return 0; }
#else
#error Not using libc++
#endif
"
USING_LIBCXX
)
if(NOT USING_LIBCXX)
message(
FATAL_ERROR
"ENABLE_LLVM_COVERAGE requires libc++, please compile with -stdlib=libc++"
)
endif()
add_compile_options(-fprofile-instr-generate -fcoverage-mapping) add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping) add_link_options(-fprofile-instr-generate -fcoverage-mapping)
endif() endif()