Skip to content

Commit

Permalink
Tweak address sanitizer setup
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Dec 9, 2023
1 parent 7628138 commit e8d143b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ message(DEBUG "CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}")
option(TACTILE_BUILD_APP_BUNDLE "Build the editor as a macOS application bundle (.app)" OFF)
option(TACTILE_BUILD_TESTS "Build the test suite" OFF)
option(TACTILE_BUILD_LEGACY "Build the legacy targets" OFF)
option(TACTILE_USE_SANITIZERS "Enable runtime sanitizers" OFF)
option(TACTILE_USE_ADDRESS_SANITIZER "Build with AddressSanitizer enabled" OFF)
option(TACTILE_USE_LTO "Enable link-time optimizations" OFF)

message(DEBUG "TACTILE_BUILD_APP_BUNDLE: ${TACTILE_BUILD_APP_BUNDLE}")
message(DEBUG "TACTILE_BUILD_TESTS: ${TACTILE_BUILD_TESTS}")
message(DEBUG "TACTILE_BUILD_LEGACY: ${TACTILE_BUILD_LEGACY}")
message(DEBUG "TACTILE_USE_SANITIZERS: ${TACTILE_USE_SANITIZERS}")
message(DEBUG "TACTILE_USE_ADDRESS_SANITIZER: ${TACTILE_USE_ADDRESS_SANITIZER}")
message(DEBUG "TACTILE_USE_LTO: ${TACTILE_USE_LTO}")

# Determine build type, e.g. "debug" or "release".
Expand Down
86 changes: 47 additions & 39 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
project(tactile-modules CXX)

set(TACTILE_COMPILE_OPTIONS)
set(TACTILE_LINK_OPTIONS)

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(TACTILE_COMPILE_OPTIONS
/EHsc
/MP
/W4
/bigobj
/permissive-
/Zc:preprocessor
/Zc:__cplusplus
/wd4251
/wd4275
)
list(APPEND TACTILE_COMPILE_OPTIONS
/EHsc
/MP
/W4
/bigobj
/permissive-
/Zc:preprocessor
/Zc:__cplusplus
/wd4251
/wd4275
)
else ()
set(TACTILE_COMPILE_OPTIONS
-fvisibility=hidden
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wsign-conversion
-Wswitch-enum
)
list(APPEND TACTILE_COMPILE_OPTIONS
-fvisibility=hidden
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wsign-conversion
-Wswitch-enum
)

if (TACTILE_USE_SANITIZERS MATCHES ON)
list(APPEND TACTILE_COMPILE_OPTIONS
-fno-omit-frame-pointer
-fsanitize=address
)
list(APPEND TACTILE_COMPILE_OPTIONS
-fno-omit-frame-pointer
-fsanitize=address
)
if (TACTILE_USE_ADDRESS_SANITIZER MATCHES ON)
if (NOT MSVC)
list(APPEND TACTILE_COMPILE_OPTIONS
-fsanitize=address
-fno-sanitize-recover
-fno-omit-frame-pointer
)
list(APPEND TACTILE_LINK_OPTIONS
-fsanitize=address
-fno-sanitize-recover
-fno-omit-frame-pointer
)
endif ()
endif ()
endif ()

Expand Down Expand Up @@ -90,15 +91,22 @@ function(tactile_prepare_target target)
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERPROCEDURAL_OPTIMIZATION ${TACTILE_USE_LTO}
RUNTIME_OUTPUT_DIRECTORY ${TACTILE_BUILD_DIR}
ARCHIVE_OUTPUT_DIRECTORY ${TACTILE_BUILD_DIR}
LIBRARY_OUTPUT_DIRECTORY ${TACTILE_BUILD_DIR}
INTERPROCEDURAL_OPTIMIZATION "${TACTILE_USE_LTO}"
RUNTIME_OUTPUT_DIRECTORY "${TACTILE_BUILD_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${TACTILE_BUILD_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${TACTILE_BUILD_DIR}"
)

target_compile_options(${target} PRIVATE ${TACTILE_COMPILE_OPTIONS})
target_link_options(${target} PRIVATE ${TACTILE_LINK_OPTIONS})
target_precompile_headers(${target} PRIVATE ${TACTILE_PRECOMPILED_HEADERS})
target_compile_options(${target} PRIVATE "${TACTILE_COMPILE_OPTIONS}")
target_link_options(${target} PRIVATE "${TACTILE_LINK_OPTIONS}")

target_precompile_headers(${target} PRIVATE "${TACTILE_PRECOMPILED_HEADERS}")

if (TACTILE_USE_ADDRESS_SANITIZER MATCHES ON)
if (NOT MSVC)
target_link_libraries(${target} PRIVATE -fsanitize=address)
endif ()
endif ()
endfunction()

function(tactile_set_output_dir target directory)
Expand Down

0 comments on commit e8d143b

Please sign in to comment.