diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 2e36fb5e1..edb09855d 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -114,7 +114,7 @@ jobs: - name: Initial compile run: | - CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DWICKED_USE_IPO=NO + CC=${{ matrix.cc }} CXX=${{ matrix.cxx }} cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DWICKED_ENABLE_IPO=NO make -C build -j$(nproc) - name: Generate shader dump diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3f7d5634..8e34a5c4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -118,7 +118,7 @@ jobs: run: | mkdir build cd build - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DWICKED_USE_IPO=NO + cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DWICKED_ENABLE_IPO=NO make -j$(nproc) - name: Generate shader dump run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 772cd2c78..f7c2924b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,21 +22,32 @@ option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available wit option(WICKED_EDITOR "Build WickedEngine editor" ON) option(WICKED_TESTS "Build WickedEngine tests" ON) option(WICKED_IMGUI_EXAMPLE "Build WickedEngine imgui example" ON) -option(WICKED_USE_IPO "Enable IPO/LTO in non-debug builds" ${ipo_supported}) +option(WICKED_ENABLE_IPO "Enable IPO/LTO in non-debug builds" ${ipo_supported}) +if(UNIX) + option(WICKED_ENABLE_ASAN "Enable AddressSanitizer in debug builds" OFF) + option(WICKED_ENABLE_UBSAN "Enable UndefinedBehaviourSanitizer in debug builds" OFF) + option(WICKED_ENABLE_TSAN "Enable ThreadSanitizer in debug builds" OFF) + option(WICKED_ENABLE_SAN_ALWAYS "Enable the selected sanitizers in all builds, not just debug" OFF) +endif() +if(UNIX) + option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON) +elseif(WIN32) + option(WICKED_WINDOWS_TEMPLATE "Build WickedEngine Windows template" ON) +endif() if (CMAKE_HOST_WIN32) set(symlink_default OFF) else() set(symlink_default ON) endif() -option(WICKED_USE_SYMLINKS "Prefer symlinking over copying directories" ${symlink_default}) +option(WICKED_ENABLE_SYMLINKS "Prefer symlinking over copying directories" ${symlink_default}) # check that IPO is supported when turned on -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) check_ipo_supported() endif() -if(WICKED_USE_SYMLINKS) +if(WICKED_ENABLE_SYMLINKS) # check for symlink support (on windows it requires admin or developer mode) execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink CMakeLists.txt ${CMAKE_CURRENT_BINARY_DIR}/symlink-test @@ -47,7 +58,7 @@ if(WICKED_USE_SYMLINKS) file(REMOVE ${CMAKE_BINARY_DIR}/symlink-test) set(COPY_OR_SYMLINK_DIR_CMD create_symlink) else() - message(FATAL_ERROR "Symlinks are not supported. Either disable them using -DWICKED_USE_SYMLINKS=OFF or enable Windows' developer mode") + message(FATAL_ERROR "Symlinks are not supported. Either disable them using -DWICKED_ENABLE_SYMLINKS=OFF or enable Windows' developer mode") endif() else() if(CMAKE_VERSION VERSION_LESS "3.26.0") @@ -57,11 +68,6 @@ else() endif() endif() -if(UNIX) - option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON) -elseif(WIN32) - option(WICKED_WINDOWS_TEMPLATE "Build WickedEngine Windows template" ON) -endif() # Configure CMake global variables set(CMAKE_CXX_STANDARD 17) @@ -72,7 +78,29 @@ set(CMAKE_POSITION_INDEPENDENT_CODE WICKED_PIC) # Use solution folders to organize projects set_property(GLOBAL PROPERTY USE_FOLDERS ON) +if(WICKED_ENABLE_ASAN AND WICKED_ENABLE_TSAN) + message(FATAL_ERROR "WICKED_ENABLE_ASAN and WICKED_ENABLE_TSAN are mutually exclusive!") +endif() +if(WICKED_ENABLE_ASAN) + set(SANITIZE_OPTIONS "-fsanitize=address") +endif() + +if(WICKED_ENABLE_TSAN) + set(SANITIZE_OPTIONS "${SANITIZE_OPTIONS} -fsanitize=thread") +endif() + +if(WICKED_ENABLE_UBSAN) + set(SANITIZE_OPTIONS "${SANITIZE_OPTIONS} -fsanitize=undefined") +endif() + +if(WICKED_ENABLE_SAN_ALWAYS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_OPTIONS}") + add_link_options(${SANITIZE_LINK_OPTIONS) +else() + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZE_OPTIONS}") + add_link_options($<$:${SANITIZE_LINK_OPTIONS}>) +endif() if (WIN32) set(PLATFORM "Windows") @@ -82,7 +110,7 @@ if (WIN32) /W3 /MP ) - endif() + endif() # add_compile_definitions(_WIN32=1) this is a given from the compiler elseif(UNIX) @@ -132,7 +160,7 @@ endif() add_subdirectory(WickedEngine) add_custom_target(Content COMMAND ${CMAKE_COMMAND} -E ${COPY_OR_SYMLINK_DIR_CMD} ${WICKED_ROOT_DIR}/Content ${CMAKE_CURRENT_BINARY_DIR}/Content - COMMENT "$,Symlinking,Copying> Content directory" + COMMENT "$,Symlinking,Copying> Content directory" VERBATIM ) diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 08032f48d..6069fbcf5 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -46,7 +46,7 @@ else () endif () -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(Editor PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF diff --git a/Samples/Example_ImGui/CMakeLists.txt b/Samples/Example_ImGui/CMakeLists.txt index af742f672..52a8cd823 100644 --- a/Samples/Example_ImGui/CMakeLists.txt +++ b/Samples/Example_ImGui/CMakeLists.txt @@ -75,7 +75,7 @@ else() set(LIB_DXCOMPILER "libdxcompiler.so") endif () -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(Example_ImGui PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF diff --git a/Samples/Example_ImGui_Docking/CMakeLists.txt b/Samples/Example_ImGui_Docking/CMakeLists.txt index a8526ad99..255b696a9 100644 --- a/Samples/Example_ImGui_Docking/CMakeLists.txt +++ b/Samples/Example_ImGui_Docking/CMakeLists.txt @@ -81,7 +81,7 @@ else() set(LIB_DXCOMPILER "libdxcompiler.so") endif () -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(Example_ImGui_Docking PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF diff --git a/Samples/Template_Linux/CMakeLists.txt b/Samples/Template_Linux/CMakeLists.txt index b828a6ffb..b27efc8d4 100644 --- a/Samples/Template_Linux/CMakeLists.txt +++ b/Samples/Template_Linux/CMakeLists.txt @@ -27,7 +27,7 @@ target_link_libraries(Template_Linux PUBLIC $<$:WickedEngine::WickedEngine> ) -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(Template_Linux PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF diff --git a/Samples/Template_Windows/CMakeLists.txt b/Samples/Template_Windows/CMakeLists.txt index b02c36cec..3e9416e29 100644 --- a/Samples/Template_Windows/CMakeLists.txt +++ b/Samples/Template_Windows/CMakeLists.txt @@ -21,7 +21,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE YES ) -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(${PROJEC_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF diff --git a/Samples/Tests/CMakeLists.txt b/Samples/Tests/CMakeLists.txt index 8d01d3944..c9254ff6f 100644 --- a/Samples/Tests/CMakeLists.txt +++ b/Samples/Tests/CMakeLists.txt @@ -32,7 +32,7 @@ else() set(LIB_DXCOMPILER "libdxcompiler.so") endif () -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(Tests PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF @@ -59,6 +59,6 @@ add_custom_command( # Copy font test resources COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/yumin.ttf ${CMAKE_CURRENT_BINARY_DIR}/ - COMMENT "$,Symlinking,Copying> Tests resources" + COMMENT "$,Symlinking,Copying> Tests resources" VERBATIM ) diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index 7ab800eac..f52017704 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -247,7 +247,7 @@ add_executable(offlineshadercompiler offlineshadercompiler.cpp ) -if(WICKED_USE_IPO) +if(WICKED_ENABLE_IPO) set_target_properties(${WICKEDENGINE_STATIC_LIBRARIES} ${TARGET_NAME} offlineshadercompiler PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF