Skip to content

Commit

Permalink
#1602: use target_compile_options to set compilation flags
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 23, 2021
1 parent 300760f commit 6c8d891
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()

include(SetCXXCompilerFlags)
set_darma_compiler_flags()

# Code coverage option of VT
option(CODE_COVERAGE "Enable coverage reporting" OFF)
# OPTION(CODE_COVERAGE_ENABLED FALSE)
Expand Down
26 changes: 13 additions & 13 deletions cmake-modules/SetCXXCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Compiler-specific C++14 activation.
# Call this from all CMakeLists.txt files that can be built independently.

macro(set_darma_compiler_flags)
macro(set_darma_compiler_flags vt_target)

set(CMAKE_CXX_EXTENSIONS OFF)

Expand All @@ -11,34 +10,35 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
message("${PROJECT_NAME} currently requires g++ 5 or greater. If you need it to work with 4.9, please complain.")
endif ()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
list(APPEND TARGET_CXX_FLAGS -Wno-unused-variable)
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=900")
list(APPEND TARGET_CXX_FLAGS -ftemplate-depth=900)
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -DCLI11_EXPERIMENTAL_OPTIONAL=0")
list(APPEND TARGET_CXX_FLAGS -stdlib=libc++ -DCLI11_EXPERIMENTAL_OPTIONAL=0)
endif ()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCLI11_EXPERIMENTAL_OPTIONAL=0")
list(APPEND TARGET_CXX_FLAGS -DCLI11_EXPERIMENTAL_OPTIONAL=0)
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
list(APPEND TARGET_CXX_FLAGS -Wno-missing-braces)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 2021.3.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fhonor-infinites")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fhonor-nans")
list(APPEND TARGET_CXX_FLAGS -fhonor-infinites -fhonor-nans)
elseif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
message(FATAL_ERROR "Your C++ compiler may not support C++14.")
endif ()

if (vt_asan_enabled)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
list(APPEND TARGET_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer)
endif()

if (vt_ubsan_enabled)
add_definitions(-DVT_UBSAN_ENABLED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
list(APPEND TARGET_CXX_FLAGS -fsanitize=undefined -fno-omit-frame-pointer)
endif()

message(DEBUG "Target ${vt_target} compile options: ${TARGET_CXX_FLAGS}")
target_compile_options(${vt_target} PUBLIC ${TARGET_CXX_FLAGS})

endmacro()
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ target_compile_features(
cxx_alias_templates
)

include(SetCXXCompilerFlags)
set_darma_compiler_flags(${VIRTUAL_TRANSPORT_LIBRARY})

if (vt_gold_linker_enabled)
if (UNIX AND NOT APPLE)
execute_process(
Expand Down

0 comments on commit 6c8d891

Please sign in to comment.