diff --git a/.gitignore b/.gitignore index dac37fd..2e3b44d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,9 @@ -# Temp directories .vs/ bin/ bin-obj/ build/ .cache/ -# VS Files **.vcxproj** **.sln @@ -17,21 +15,9 @@ build/ Makefile **/**.mk - **/**.project -**/Engine.txt -**/GLAD.txt -**/Sandbox.txt - -**/Logs/** -**/logs/** -**.ini -!**/default_gui_layout.ini - -CMake/ CMakeUserPresets.json - compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c6d5b0..66fd275 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_MODULE_STD 1) cmake_minimum_required(VERSION 4.1) 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/options.cmake) diff --git a/modules/renderer/vk/api_wrapper.cppm b/modules/renderer/vk/api_wrapper.cppm index 524788d..294bbe3 100644 --- a/modules/renderer/vk/api_wrapper.cppm +++ b/modules/renderer/vk/api_wrapper.cppm @@ -5,7 +5,7 @@ * Why did I do this? * To reduce as much complexity from the API, * 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; diff --git a/tools/cmake/definitions.cmake b/tools/cmake/definitions.cmake index 3bbb44d..5c74548 100644 --- a/tools/cmake/definitions.cmake +++ b/tools/cmake/definitions.cmake @@ -1,7 +1,10 @@ if(WIN32) add_compile_definitions(LIGHT_PLATFORM_WINDOWS) + elseif(UNIX) add_compile_definitions(LIGHT_PLATFORM_LINUX) + else() message(FATAL "Failed to generate cmake: unsupported platform") + endif() diff --git a/tools/cmake/functions.cmake b/tools/cmake/functions.cmake deleted file mode 100644 index 80cbcb0..0000000 --- a/tools/cmake/functions.cmake +++ /dev/null @@ -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() diff --git a/tools/cmake/module.cmake b/tools/cmake/module.cmake new file mode 100644 index 0000000..c206fd2 --- /dev/null +++ b/tools/cmake/module.cmake @@ -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() diff --git a/tools/cmake/options.cmake b/tools/cmake/options.cmake index 991795a..2045c83 100644 --- a/tools/cmake/options.cmake +++ b/tools/cmake/options.cmake @@ -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_UNIT_TESTS "Enables the building of the unit 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) - set(CMAKE_CXX_CLANG_TIDY - "clang-tidy;--warnings-as-errors=*;--allow-no-checks" - ) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks") endif() if(ENABLE_LLVM_COVERAGE) - include(CheckCXXSourceCompiles) - if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") message( FATAL_ERROR "ENABLE_LLVM_COVERAGE only supports the clang compiler" ) endif() - # Check for libc++ - check_cxx_source_compiles( - " - #include - #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_link_options(-fprofile-instr-generate -fcoverage-mapping) endif()