Skip to content

Commit

Permalink
CMake improvements
Browse files Browse the repository at this point in the history
 * Bump required version to 3.12 (we were already implicitly requiring this by using cxx_std_20)
 * Rename the top-level project to "flux" rather than "libflux"
 * Rename the test executable to "test-flux" rather than "test-libflux"
 * Add a flux-internal interface library target which we use to set compile options (mostly warning settings) which will be re-used between the tests and examples
 * Make the tests and examples use the flux-internal library rather than the flux target itself
 * Add various extra conformance flags for MSVC
 * Enable various warnings for Clang
  • Loading branch information
tcbrindle committed Jan 8, 2024
1 parent a45d844 commit af46246
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
31 changes: 26 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0076 NEW) # remove warning for target_sources(flux...) for < 3.13
cmake_policy(SET CMP0092 NEW) # remove warning for CMAKE_LANG_FLAG MSVC for < 3.15

project(libflux CXX)
project(flux CXX)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)


set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

add_library(flux INTERFACE)
Expand All @@ -21,6 +20,7 @@ if (MSVC)
else()
target_compile_features(flux INTERFACE cxx_std_20)
endif()
set_target_properties(flux PROPERTIES cxx_standard_required On)

target_include_directories(
flux
Expand All @@ -29,7 +29,28 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set(CMAKE_CXX_EXTENSIONS Off)
add_library(flux-internal INTERFACE)
target_link_libraries(flux-internal INTERFACE flux)
set_target_properties(flux-internal PROPERTIES cxx_extensions Off)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(flux-internal INTERFACE -Wall -Wextra -Wconversion -pedantic
-fno-omit-frame-pointer
-ftemplate-backtrace-limit=0)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(flux-internal INTERFACE -Wall -Wextra -Wconversion -pedantic
-fno-omit-frame-pointer
-ftemplate-backtrace-limit=0
-fconcepts-diagnostics-depth=2)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(flux-internal INTERFACE /W4
# Various options for closer standard conformance
/utf-8 /Zc:__cplusplus /Zc:throwingNew /Zc:inline /Zc:externConstexpr
/Zc:templateScope /Zc:checkGwOdr /Zc:enumTypes
/wd4459 # local variable name hides global variable
/wd4702 # unreachable code
)
endif()

option(FLUX_BUILD_DOCS "Build Flux documentation (requires Sphinx)" Off)
option(FLUX_BUILD_EXAMPLES "Build Flux examples" On)
Expand Down Expand Up @@ -118,4 +139,4 @@ install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/.."
PATTERN "build2file" EXCLUDE
)
)
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function(ADD_EXAMPLE NAME SOURCE)
add_executable(${NAME} ${SOURCE})
target_link_libraries(${NAME} flux)
target_link_libraries(${NAME} flux-internal)
if(${${NAME}_SKIP_TEST})
#pass
else()
Expand Down
32 changes: 9 additions & 23 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_library(catch-main catch_main.cpp)
target_compile_features(catch-main PUBLIC cxx_std_20)
target_compile_definitions(catch-main PUBLIC -DCATCH_CONFIG_NO_POSIX_SIGNALS)

add_executable(test-libflux
add_executable(test-flux

test_concepts.cpp
test_overflow.cpp
Expand Down Expand Up @@ -76,39 +76,25 @@ add_executable(test-libflux
test_single.cpp
test_unfold.cpp
)
target_link_libraries(test-libflux flux catch-main)
target_compile_definitions(test-libflux PUBLIC
target_link_libraries(test-flux flux-internal catch-main)
target_compile_definitions(test-flux PUBLIC
FLUX_UNWIND_ON_ERROR
FLUX_ERROR_ON_OVERFLOW
FLUX_DISABLE_STATIC_BOUNDS_CHECKING
)

if(${FLUX_ENABLE_ASAN})
target_compile_options(test-libflux PRIVATE -fsanitize=address)
target_link_options(test-libflux PRIVATE -fsanitize=address)
target_compile_options(test-flux PRIVATE -fsanitize=address)
target_link_options(test-flux PRIVATE -fsanitize=address)
endif()

if(${FLUX_ENABLE_UBSAN})
target_compile_options(test-libflux PRIVATE -fsanitize=undefined)
target_link_options(test-libflux PRIVATE -fsanitize=undefined)
target_compile_options(test-flux PRIVATE -fsanitize=undefined)
target_link_options(test-flux PRIVATE -fsanitize=undefined)
endif()

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
target_precompile_headers(test-libflux PRIVATE "catch.hpp")
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(test-libflux PRIVATE -Wall -Wextra -pedantic
-fno-omit-frame-pointer
-ftemplate-backtrace-limit=0
-fconcepts-diagnostics-depth=2)
endif()

if(MSVC)
target_compile_options(test-libflux PRIVATE /W4
/wd4459 # local variable name hides global variable
/wd4702 # unreachable code
)
target_precompile_headers(test-flux PRIVATE "catch.hpp")
endif()

if(${FLUX_BUILD_MODULE})
Expand All @@ -117,4 +103,4 @@ if(${FLUX_BUILD_MODULE})
endif()

include(Catch)
catch_discover_tests(test-libflux)
catch_discover_tests(test-flux)

0 comments on commit af46246

Please sign in to comment.