diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ad803aaa..65367731a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,7 @@ install(FILES if(HIGHFIVE_EXAMPLES OR HIGHFIVE_UNIT_TESTS) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveWarnings.cmake) + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveFlags.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HighFiveOptionalDependencies.cmake) endif() diff --git a/cmake/HighFiveFlags.cmake b/cmake/HighFiveFlags.cmake new file mode 100644 index 000000000..33be65e9c --- /dev/null +++ b/cmake/HighFiveFlags.cmake @@ -0,0 +1,30 @@ +if(TARGET HighFiveFlags) + # Allow multiple `include(HighFiveWarnings)`, which would + # attempt to redefine `HighFiveWarnings` and fail without + # this check. + return() +endif() + +add_library(HighFiveFlags INTERFACE) + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if(HIGHFIVE_MAX_ERRORS) + target_compile_options(HighFiveFlags + INTERFACE + -fmax-errors=${HIGHFIVE_MAX_ERRORS} + ) + endif() +endif() + +if(HIGHFIVE_GLIBCXX_ASSERTIONS) + target_compile_definitions(HighFiveFlags INTERFACE -D_GLIBCXX_ASSERTIONS) +endif() + +if(HIGHFIVE_HAS_FRIEND_DECLARATIONS) + target_compile_definitions(HighFiveFlags INTERFACE -DHIGHFIVE_HAS_FRIEND_DECLARATIONS=1) +endif() + +if(HIGHFIVE_SANITIZER) + target_compile_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER}) + target_link_options(HighFiveFlags INTERFACE -fsanitize=${HIGHFIVE_SANITIZER}) +endif() diff --git a/cmake/HighFiveWarnings.cmake b/cmake/HighFiveWarnings.cmake index a1dee19dc..2357a97ca 100644 --- a/cmake/HighFiveWarnings.cmake +++ b/cmake/HighFiveWarnings.cmake @@ -6,7 +6,6 @@ if(TARGET HighFiveWarnings) endif() add_library(HighFiveWarnings INTERFACE) -add_library(HighFiveFlags INTERFACE) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" @@ -48,11 +47,3 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") endif() endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - if(HIGHFIVE_MAX_ERRORS) - target_compile_options(HighFiveFlags - INTERFACE - -fmax-errors=${HIGHFIVE_MAX_ERRORS} - ) - endif() -endif()