cmake: add flags to enable sanitizers on linux (#1284)

Sanitizers added: address, undefined behaviour, thread

also rename WICKED_USE_{IPO,SYMLINKS} to WICKED_ENABLE_{IPO,SYMLINKS}
for consistency with the other options.
This commit is contained in:
Dennis Brakhane
2025-11-04 17:17:59 +01:00
committed by GitHub
parent 88f9d899ad
commit d7e9cc90cd
10 changed files with 50 additions and 22 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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: |
+40 -12
View File
@@ -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($<$<CONFIG:Debug>:${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 "$<IF:$<BOOL:${WICKED_USE_SYMLINKS}>,Symlinking,Copying> Content directory"
COMMENT "$<IF:$<BOOL:${WICKED_ENABLE_SYMLINKS}>,Symlinking,Copying> Content directory"
VERBATIM
)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -27,7 +27,7 @@ target_link_libraries(Template_Linux PUBLIC
$<$<BOOL:${INSTALLED_ENGINE}>:WickedEngine::WickedEngine>
)
if(WICKED_USE_IPO)
if(WICKED_ENABLE_IPO)
set_target_properties(Template_Linux PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ON
INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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 "$<IF:$<BOOL:${WICKED_USE_SYMLINKS}>,Symlinking,Copying> Tests resources"
COMMENT "$<IF:$<BOOL:${WICKED_ENABLE_SYMLINKS}>,Symlinking,Copying> Tests resources"
VERBATIM
)
+1 -1
View File
@@ -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