Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1765: use vt compilation flags for bundled libraries as well #1776

Merged
merged 10 commits into from
May 16, 2022
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ get_directory_property(hasParent PARENT_DIRECTORY)
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(
Expand All @@ -38,18 +37,7 @@ 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()

# Code coverage option of VT
option(CODE_COVERAGE "Enable coverage reporting" OFF)
# OPTION(CODE_COVERAGE_ENABLED FALSE)
# if(CODE_COVERAGE_ENABLED)
# include(cmake/code_coverage.cmake)
# endif(CODE_COVERAGE_ENABLED)

set(MPI_EXTRA_FLAGS "" CACHE STRING "Flags to pass to mpirun/mpiexec")
string(REPLACE " " ";" MPI_EXTRA_FLAGS_LIST "${MPI_EXTRA_FLAGS}")
Expand Down
64 changes: 29 additions & 35 deletions cmake-modules/SetCXXCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
# Call this from all CMakeLists.txt files that can be built independently.

macro(set_darma_compiler_flags vt_target)

set(CMAKE_CXX_EXTENSIONS OFF)
Copy link
Contributor Author

@cz4rs cz4rs May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed: CMAKE_CXX_EXTENSIONS is already disabled in the main CMakeLists.txt

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_EQUAL 5))
message("${PROJECT_NAME} currently requires g++ 5 or greater. If you need it to work with 4.9, please complain.")
endif ()
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
list(APPEND TARGET_PUBLIC_CXX_FLAGS -ftemplate-depth=900)
if (APPLE)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -stdlib=libc++ -DCLI11_EXPERIMENTAL_OPTIONAL=0)
function(set_darma_compiler_flags vt_target)
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_EQUAL 5))
message("${PROJECT_NAME} currently requires g++ 5 or greater. If you need it to work with 4.9, please complain.")
endif ()
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
list(APPEND TARGET_PUBLIC_CXX_FLAGS -ftemplate-depth=900)
if (APPLE)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -stdlib=libc++)
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 2021.3.0)
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 (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -DCLI11_EXPERIMENTAL_OPTIONAL=0)
Copy link
Contributor Author

@cz4rs cz4rs May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed: CLI11_EXPERIMENTAL_OPTIONAL is no longer present in CLI11

endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 2021.3.0)
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)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
endif()

if (vt_ubsan_enabled)
add_definitions(-DVT_UBSAN_ENABLED)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -fsanitize=undefined -fno-omit-frame-pointer)
endif()
if ("${vt_target}" STREQUAL "${VIRTUAL_TRANSPORT_LIBRARY}")
if (vt_asan_enabled)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
endif()

message(DEBUG "Target ${vt_target} public compile options: ${TARGET_CXX_FLAGS}")
target_compile_options(${vt_target} PUBLIC ${TARGET_PUBLIC_CXX_FLAGS})
if (vt_ubsan_enabled)
add_definitions(-DVT_UBSAN_ENABLED)
list(APPEND TARGET_PUBLIC_CXX_FLAGS -fsanitize=undefined -fno-omit-frame-pointer)
endif()
endif()

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

endmacro()
message(DEBUG "Target ${vt_target} private compile options: ${TARGET_PRIVATE_CXX_FLAGS}")
target_compile_options(${vt_target} PRIVATE ${TARGET_PRIVATE_CXX_FLAGS})
endfunction()
17 changes: 0 additions & 17 deletions cmake/code_coverage.cmake

This file was deleted.

10 changes: 9 additions & 1 deletion cmake/load_bundled_libraries.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Bundled dependencies

include(SetCXXCompilerFlags)

# Export a minimum version flag for any bundled libraries that don't set their own
set(CMAKE_CXX_STANDARD 14)

Expand All @@ -9,11 +10,14 @@ if (vt_libfort_enabled)
set(FORT_ENABLE_TESTING OFF CACHE INTERNAL "")
add_subdirectory(${PROJECT_LIB_DIR}/libfort)
set(FORT_LIBRARY fort)
set_darma_compiler_flags(${FORT_LIBRARY})
endif()

# Optionally include fcontext
if (vt_fcontext_enabled)
set(FCONTEXT_LIBRARY fcontext)
add_subdirectory(${PROJECT_LIB_DIR}/context)
set_darma_compiler_flags(${FCONTEXT_LIBRARY})
endif()

# CLI11 always included in the build
Expand All @@ -22,10 +26,12 @@ add_subdirectory(${PROJECT_LIB_DIR}/CLI)
# fmt always included in the build
set(FMT_LIBRARY fmt)
add_subdirectory(${PROJECT_LIB_DIR}/fmt)
set_darma_compiler_flags(${FMT_LIBRARY})

# EngFormat-Cpp always included in the build
set(ENG_FORMAT_LIBRARY EngFormat-Cpp)
add_subdirectory(${PROJECT_LIB_DIR}/EngFormat-Cpp)
set_darma_compiler_flags(${ENG_FORMAT_LIBRARY})

# json library always included in the build
set(JSON_BuildTests OFF)
Expand All @@ -40,6 +46,7 @@ set(BROTLI_BUNDLED_MODE OFF)
set(BROTLI_BUILD_PORTABLE ON)
set(BROTLI_LIBRARY brotlicommon-static brotlienc-static brotlidec-static)
add_subdirectory(${PROJECT_LIB_DIR}/brotli)
set_darma_compiler_flags(${BROTLI_LIBRARY})

# Optionally include mimalloc (alternative memory allocator)
if (vt_mimalloc_enabled)
Expand All @@ -49,6 +56,7 @@ if (vt_mimalloc_enabled)
else()
set(MIMALLOC_LIBRARY mimalloc)
endif()
set_darma_compiler_flags(${MIMALLOC_LIBRARY})
endif()

# Check if sanitizers can be enabled
Expand Down
6 changes: 6 additions & 0 deletions cmake/turn_on_warnings.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
include(CheckCXXCompilerFlag)

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()

macro(add_cxx_compiler_flag_if_supported flag)
check_cxx_compiler_flag(${flag} flag_supported)
if(flag_supported)
Expand Down
6 changes: 1 addition & 5 deletions lib/brotli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Ubuntu 12.04 LTS has CMake 2.8.7, and is an important target since
# several CI services, such as Travis and Drone, use it. Solaris 11
# has 2.8.6, and it's not difficult to support if you already have to
# support 2.8.7.
cmake_minimum_required(VERSION 2.8.6)
cmake_minimum_required(VERSION 3.17)

cmake_policy(SET CMP0048 NEW)
project(brotli VERSION 1.0.9)
Expand Down
23 changes: 6 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,33 +317,22 @@ install(
COMPONENT runtime
)

set(FMT_LIBRARY_EXPORT ${FMT_LIBRARY})
install(TARGETS ${FMT_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
install(TARGETS ${BROTLI_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
install(TARGETS ${ENG_FORMAT_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})

install(TARGETS ${FMT_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
install(TARGETS ${JSON_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
install(TARGETS ${BROTLI_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})

if (vt_mimalloc_enabled)
set(MIMALLOC_LIBRARY_EXPORT ${MIMALLOC_LIBRARY})
endif()

if (vt_libfort_enabled)
set(FORT_LIBRARY_EXPORT ${FORT_LIBRARY})
install(TARGETS ${FORT_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
endif()

if (vt_fcontext_enabled)
set(FCONTEXT_LIBRARY_EXPORT ${FCONTEXT_LIBRARY})
endif()

# Export to build directory
export(
TARGETS ${VIRTUAL_TRANSPORT_LIBRARY}
${FCONTEXT_LIBRARY_EXPORT}
${MIMALLOC_LIBRARY_EXPORT}
${FORT_LIBRARY_EXPORT}
${FMT_LIBRARY_EXPORT}
${FCONTEXT_LIBRARY}
${MIMALLOC_LIBRARY}
${FORT_LIBRARY}
${FMT_LIBRARY}
${ENG_FORMAT_LIBRARY}
${JSON_LIBRARY}
${BROTLI_LIBRARY}
Expand Down
2 changes: 1 addition & 1 deletion tests/extern/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.

cmake_minimum_required(VERSION 2.8.8)
cmake_minimum_required(VERSION 3.17)

if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
Expand Down
2 changes: 1 addition & 1 deletion tests/extern/googletest/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ else()
cmake_policy(SET CMP0048 NEW)
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
endif()
cmake_minimum_required(VERSION 2.6.4)
cmake_minimum_required(VERSION 3.17)

if (POLICY CMP0063) # Visibility
cmake_policy(SET CMP0063 NEW)
Expand Down