Skip to content

Commit

Permalink
Merge pull request #1613 from DARMA-tasking/1602-refactor-cmake-compi…
Browse files Browse the repository at this point in the history
…ler-flags

#1602: stop using CMAKE_CXX_FLAGS for setting compile options
  • Loading branch information
cz4rs authored Nov 24, 2021
2 parents 6166b78 + e851266 commit a4da5db
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 171 deletions.
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ cmake_policy(SET CMP0082 NEW)

get_directory_property(hasParent PARENT_DIRECTORY)

include(cmake/turn_on_warnings.cmake)

include(cmake/check_system_functions.cmake)

set(VIRTUAL_TRANSPORT_LIBRARY vt CACHE INTERNAL "" FORCE )
set(FCONTEXT_LIBRARY fcontext)

# Set the local module path so custom cmake scripts can be located automatically
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/")
set(
CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
)

# Try to find ccache to speed up compilation
find_program(ccache_binary ccache)
Expand All @@ -31,15 +33,14 @@ if (ccache_binary)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${ccache_binary}")
endif()

set(CMAKE_CXX_EXTENSIONS OFF)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
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 Expand Up @@ -90,11 +91,7 @@ option(vt_mimalloc_enabled "Build VT with mimalloc" OFF)
option(vt_mimalloc_static "Build VT with mimalloc using static linking" ON)
option(vt_asan_enabled "Build VT with address sanitizer" OFF)
option(vt_ubsan_enabled "Build VT with undefined behavior sanitizer" OFF)

option(vt_werror_enabled "Build VT with -Werror enabled" OFF)
if (vt_werror_enabled)
enable_cxx_compiler_flag_if_supported("-Werror")
endif()

include(cmake/nvcc_no_deprecated_gpu_targets.cmake)
include(cmake/load_bundled_libraries.cmake)
Expand Down
42 changes: 19 additions & 23 deletions cmake-modules/SetCXXCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
# 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)

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
# 4.9.3 complains about std::min not being constexpr
if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 5))
if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5))
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")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=900")
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
list(APPEND TARGET_PUBLIC_CXX_FLAGS -ftemplate-depth=900)
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -DCLI11_EXPERIMENTAL_OPTIONAL=0")
list(APPEND TARGET_PUBLIC_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")
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -DCLI11_EXPERIMENTAL_OPTIONAL=0)
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")
elseif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
list(APPEND TARGET_PRIVATE_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_PUBLIC_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_PUBLIC_CXX_FLAGS -fsanitize=undefined -fno-omit-frame-pointer)
endif()

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

message(DEBUG "Target ${vt_target} private compile options: ${TARGET_CXX_FLAGS}")
target_compile_options(${vt_target} PRIVATE ${TARGET_PRIVATE_CXX_FLAGS})

endmacro()
80 changes: 42 additions & 38 deletions cmake/configure_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ else()
endif()
list(REMOVE_DUPLICATES VT_CONFIG_TYPES)

list(APPEND CMAKE_MESSAGE_INDENT "Building VT with ")

option(vt_lb_enabled "Build VT with load balancing enabled" ON)
option(vt_trace_enabled "Build VT with trace enabled" OFF)
option(vt_priorities_enabled "Build VT with message priorities enabled" ON)
Expand All @@ -34,65 +36,65 @@ set(
)

if (${vt_test_trace_runtime_enabled})
message(STATUS "Building VT with runtime tracing enabled (for testing)")
message(STATUS "runtime tracing enabled (for testing)")
set(vt_feature_cmake_test_trace_on "1")
else()
set(vt_feature_cmake_test_trace_on "0")
endif()

if (${vt_lb_enabled})
message(STATUS "Building VT with load balancing enabled")
message(STATUS "load balancing enabled")
set(vt_feature_cmake_lblite "1")
else()
message(STATUS "Building VT with load balancing disabled")
message(STATUS "load balancing disabled")
set(vt_feature_cmake_lblite "0")
endif()

if (${vt_trace_enabled})
message(STATUS "Building VT with tracing enabled")
message(STATUS "tracing enabled")
set(vt_feature_cmake_trace_enabled "1")
else()
message(STATUS "Building VT with tracing disabled")
message(STATUS "tracing disabled")
set(vt_feature_cmake_trace_enabled "0")
endif()

# This will be set to 1 during generation of cmake config for vt-trace target
set(vt_feature_cmake_trace_only "0")

if (${vt_priorities_enabled})
message(STATUS "Building VT with priorities enabled")
message(STATUS "priorities enabled")
message(
STATUS
"Building VT with priority bits per level: ${vt_priority_bits_per_level}"
"priority bits per level: ${vt_priority_bits_per_level}"
)
set(vt_feature_cmake_priorities "1")
else()
message(STATUS "Building VT with priorities disabled")
message(STATUS "priorities disabled")
set(vt_feature_cmake_priorities "0")
endif()

set(vt_feature_cmake_priority_bits_level "${vt_priority_bits_per_level}")

if (${vt_bit_check_overflow})
message(STATUS "Building VT with bit check overflow")
message(STATUS "bit check overflow")
set(vt_feature_cmake_bit_check_overflow "1")
else()
set(vt_feature_cmake_bit_check_overflow "0")
endif()

if (${vt_fcontext_enabled})
message(STATUS "Building VT with fcontext (ULT) enabled")
message(STATUS "fcontext (ULT) enabled")
set(vt_feature_cmake_fcontext "1")
else()
message(STATUS "Building VT with fcontext (ULT) disabled")
message(STATUS "fcontext (ULT) disabled")
set(vt_feature_cmake_fcontext "0")
endif()

if (${vt_mimalloc_enabled})
message(STATUS "Building VT with mimalloc enabled")
message(STATUS "mimalloc enabled")
set(vt_feature_cmake_mimalloc "1")
else()
message(STATUS "Building VT with mimalloc disabled")
message(STATUS "mimalloc disabled")
set(vt_feature_cmake_mimalloc "0")
endif()

Expand All @@ -104,76 +106,67 @@ else()
endif()

if ((vt_mpi_guards OR vt_trace_only) AND PERL_FOUND)
message(STATUS "Building VT with user MPI prevention guards enabled")
message(STATUS "user MPI prevention guards enabled")
set(vt_feature_cmake_mpi_access_guards "1")
elseif ((vt_mpi_guards OR vt_trace_only) AND NOT PERL_FOUND)
# No perl? Can't generate wrapper source file.
message(STATUS "Building VT with user MPI prevention guards disabled (requested, but perl not found)")
message(STATUS "user MPI prevention guards disabled (requested, but perl not found)")
set(vt_feature_cmake_mpi_access_guards "0")
else()
message(STATUS "Building VT with user MPI prevention guards disabled")
message(STATUS "user MPI prevention guards disabled")
set(vt_feature_cmake_mpi_access_guards "0")
endif()

option(vt_zoltan_enabled "Build VT with Zoltan" OFF)
if (vt_zoltan_enabled AND vt_zoltan_found)
message(STATUS "Building VT with zoltan enabled")
message(STATUS "zoltan enabled")
set(vt_feature_cmake_zoltan "1")
elseif (vt_zoltan_enabled AND NOT vt_zoltan_found)
message(STATUS "Building VT with zoltan disabled (requested, but Zoltan not found)")
message(STATUS "zoltan disabled (requested, but Zoltan not found)")
set(vt_feature_cmake_zoltan "0")
else()
message(STATUS "Building VT with zoltan disabled")
message(STATUS "zoltan disabled")
set(vt_feature_cmake_zoltan "0")
endif()

option(vt_ci_build "Build VT with CI mode on" OFF)
if(${vt_ci_build})
set(vt_feature_cmake_ci_build "1")
else()
set(vt_feature_cmake_ci_build "0")
endif()

if (LOWERCASE_CMAKE_BUILD_TYPE STREQUAL "release")
option(vt_debug_verbose "Build VT with verbose debug printing enabled" OFF)
else()
option(vt_debug_verbose "Build VT with verbose debug printing enabled" ON)
endif()

if(vt_debug_verbose)
message(STATUS "Building VT with verbose debug printing enabled")
message(STATUS "verbose debug printing enabled")
set(vt_feature_cmake_debug_verbose "1")
else()
message(STATUS "Building VT with verbose debug printing disabled")
message(STATUS "verbose debug printing disabled")
set(vt_feature_cmake_debug_verbose "0")
endif()

message(STATUS "CI_BUILD = ${vt_feature_cmake_ci_build}")

option(
vt_diagnostics_runtime_enabled
"Build VT with performance metrics/stats enabled at runtime by default" OFF
)
if (vt_diagnostics_enabled)
message(STATUS "Building VT with diagnostics (performance stats) enabled")
message(STATUS "diagnostics (performance stats) enabled")
set(vt_feature_cmake_diagnostics "1")

if (vt_diagnostics_runtime_enabled)
message(
STATUS
"Building VT with diagnostics (performance stats) enabled at runtime by default"
"diagnostics (performance stats) enabled at runtime by default"
)
set(vt_feature_cmake_diagnostics_runtime "1")
else()
message(
STATUS
"Building VT with diagnostics (performance stats) disabled at runtime by default"
"diagnostics (performance stats) disabled at runtime by default"
)
set(vt_feature_cmake_diagnostics_runtime "0")
endif()

else()
message(STATUS "Building VT with diagnostics (performance stats) disabled")
message(STATUS "diagnostics (performance stats) disabled")
set(vt_feature_cmake_diagnostics "0")
set(vt_feature_cmake_diagnostics_runtime "0")
endif()
Expand All @@ -183,10 +176,10 @@ option(
"Build VT with assertions and debug prints disabled" OFF
)
if (${vt_production_build_enabled})
message(STATUS "Building VT with assertions and debug prints disabled")
message(STATUS "assertions and debug prints disabled")
set(vt_feature_cmake_production_build "1")
else()
message(STATUS "Building VT with assertions and debug prints enabled")
message(STATUS "assertions and debug prints enabled")
set(vt_feature_cmake_production_build "0")
endif()

Expand All @@ -203,9 +196,20 @@ set (vt_feature_cmake_print_term_msgs "0")
set (vt_feature_cmake_no_pool_alloc_env "0")

if (${vt_pool_enabled})
message(STATUS "Building VT with memory pool enabled")
message(STATUS "memory pool enabled")
set (vt_feature_cmake_memory_pool "1")
else()
message(STATUS "Building VT with memory pool disabled")
message(STATUS "memory pool disabled")
set (vt_feature_cmake_memory_pool "0")
endif()

option(vt_ci_build "Build VT with CI mode on" OFF)
if(${vt_ci_build})
set(vt_feature_cmake_ci_build "1")
else()
set(vt_feature_cmake_ci_build "0")
endif()

list(POP_BACK CMAKE_MESSAGE_INDENT)

message(STATUS "CI_BUILD = ${vt_feature_cmake_ci_build}")
9 changes: 0 additions & 9 deletions cmake/threading_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ function(config_for_openmp)
set(vt_fcontext_enabled "0" PARENT_SCOPE)

set(LOCAL_THREADS_DEPENDENCY "find_dependency(OpenMP REQUIRED)" PARENT_SCOPE)

#
# The OpenMP compiler and linker flags are handled through the target instead
# of manually setting the flags for VT:
#
# string(APPEND VT_TARGET_CXX_FLAGS ${OpenMP_CXX_FLAGS})
# set(VT_TARGET_CXX_FLAGS "${VT_TARGET_CXX_FLAGS}" PARENT_SCOPE)
# string(APPEND VT_TARGET_LINKER_FLAGS ${OpenMP_EXE_LINKER_FLAGS})
# set(VT_TARGET_LINKER_FLAGS "${VT_TARGET_LINKER_FLAGS}" PARENT_SCOPE)
endfunction(config_for_openmp)

function(config_for_std_thread)
Expand Down
Loading

0 comments on commit a4da5db

Please sign in to comment.