Skip to content

Commit

Permalink
Fixed compile options
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele A. Ron committed Aug 21, 2022
1 parent 4a2b146 commit 2ffc4f9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ target_include_directories(${PROJECT_NAME}
# Set optimization flags #
##########################

set(SANITIZE "OFF" CACHE STRING "Set the sanitizer to pass (the value provided will be passed directly to -fsanitize)")
if (NOT CMAKE_CXX_FLAGS)
if (NOT ${SANITIZE} STREQUAL "OFF")
target_compile_options(${PROJECT_NAME} INTERFACE -fsanitize=${SANITIZE})
target_compile_options(${PROJECT_NAME} INTERFACE -g)
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (MSVC)
list(APPEND CMAKE_CXX_FLAGS "/O0")
target_compile_options(${PROJECT_NAME} INTERFACE /O0)
else ()
list(APPEND CMAKE_CXX_FLAGS "-O0")
target_compile_options(${PROJECT_NAME} INTERFACE -O0)
endif ()
else ()
if (MSVC)
list(APPEND CMAKE_CXX_FLAGS "/O3")
target_compile_options(${PROJECT_NAME} INTERFACE /O3)
else ()
list(APPEND CMAKE_CXX_FLAGS "-O3")
target_compile_options(${PROJECT_NAME} INTERFACE -O3)
endif ()
endif ()
message("Setting CXX flags to default for ${CMAKE_BUILD_TYPE} mode (${CMAKE_CXX_FLAGS})")
Expand Down

0 comments on commit 2ffc4f9

Please sign in to comment.