Skip to content

Commit

Permalink
Only add warning flags for tests and examples.
Browse files Browse the repository at this point in the history
The CMake code uses an interface target `HighFiveWarnings` which
collects all warnings we want when building the examples and tests.
However, we no longer set these warnings for users of HighFive, since
they might have different preferences w.r.t. which flags should be set.
  • Loading branch information
1uc committed Aug 3, 2023
1 parent 3449d3d commit b06fa2c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 125 deletions.
36 changes: 36 additions & 0 deletions CMake/HighFiveWarnings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
if(TARGET HighFiveWarnings)
# Allow multiple `include(HighFiveWarnings)`, which would
# attempt to redefine `HighFiveWarnings` and fail without
# this check.
return()
endif()

add_library(HighFiveWarnings INTERFACE)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")

target_compile_options(HighFiveWarnings
INTERFACE
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-Wunused
-Woverloaded-virtual
-Wformat=2
-Wconversion
-Wsign-conversion
-Wno-error=deprecated-declarations
)

if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Intel")
target_compile_options(HighFiveWarnings
INTERFACE
-Wpedantic
-Wcast-align
-Wdouble-promotion
)
endif()
endif()
57 changes: 0 additions & 57 deletions CMake/config/CompilerFlagsHelpers.cmake

This file was deleted.

45 changes: 0 additions & 45 deletions CMake/config/ReleaseDebugAutoFlags.cmake

This file was deleted.

14 changes: 2 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/highfive/H5Version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/highfive/H5Version.hpp)
# INCLUDES
list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/CMake
${PROJECT_SOURCE_DIR}/CMake/portability
${PROJECT_SOURCE_DIR}/CMake/config)
${CMAKE_CURRENT_SOURCE_DIR}/CMake
${CMAKE_CURRENT_SOURCE_DIR}/CMake/config)

# OPTIONS
# Compatibility within Highfive 2.x series
Expand Down Expand Up @@ -135,15 +134,6 @@ if(HIGHFIVE_UNIT_TESTS)
endif()
endif()


if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# ICC gets mad if we shorten "int"s
add_definitions("-wd1682")
endif()

# Set compile time flags _after_ including required dependencies
include(ReleaseDebugAutoFlags)

if(HIGHFIVE_EXAMPLES)
add_subdirectory(src/examples)
endif()
Expand Down
18 changes: 10 additions & 8 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include_directories(${HDF5_INCLUDE_DIRS})
include(HighFiveWarnings)

function(compile_example exemple_source)
function(compile_example example_source)

get_filename_component(example_filename ${exemple_source} NAME)
get_filename_component(example_filename ${example_source} NAME)
string(REPLACE ".cpp" "_bin" example_name ${example_filename})

if(${example_filename} MATCHES ".*eigen.*")
Expand Down Expand Up @@ -32,14 +32,16 @@ function(compile_example exemple_source)
if(${example_name} MATCHES ".*hl_hdf5.*")
find_package(HDF5 QUIET COMPONENTS HL NAMES HDF5_HL)
if(${HDF5_HL_FOUND})
add_executable(${example_name} ${exemple_source})
target_link_libraries(${example_name} HighFive ${HDF5_HL_LIBRARIES})
message("HDF5 HL: ${HDF5_HL_LIBRARIES}")
add_executable(${example_name} ${example_source})
target_link_libraries(${example_name} HighFive HighFiveWarnings ${HDF5_HL_LIBRARIES})
endif()
else()
add_executable(${example_name} ${exemple_source})
target_link_libraries(${example_name} HighFive)
return()
endif()

add_executable(${example_name} ${example_source})
target_link_libraries(${example_name} HighFive HighFiveWarnings)

endfunction()

file(GLOB list_example "*.cpp")
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include(CTest)
include(Catch)
include(HighFiveWarnings)

if(MSVC)
add_definitions(/bigobj)
Expand All @@ -8,7 +9,7 @@ endif()
## Base tests
foreach(test_name tests_high_five_base tests_high_five_multi_dims tests_high_five_easy test_all_types)
add_executable(${test_name} "${test_name}.cpp")
target_link_libraries(${test_name} HighFive Catch2::Catch2WithMain)
target_link_libraries(${test_name} HighFive HighFiveWarnings Catch2::Catch2WithMain)
catch_discover_tests(${test_name})
endforeach()

Expand All @@ -18,7 +19,7 @@ if(HIGHFIVE_PARALLEL_HDF5)

## parallel MPI tests
add_executable(tests_parallel_bin ${tests_parallel_src})
target_link_libraries(tests_parallel_bin HighFive Catch2::Catch2)
target_link_libraries(tests_parallel_bin HighFive HighFiveWarnings Catch2::Catch2)

# We need to patch in a call to `mpirun` or equivalent when using
# parallel tests. Somehow, this is not foreseen in Catch2, modify the
Expand Down Expand Up @@ -48,6 +49,6 @@ if(HIGHFIVE_TEST_SINGLE_INCLUDES)
get_filename_component(CLASS_NAME ${PUBLIC_HEADER} NAME_WE)
configure_file(tests_import_public_headers.cpp "tests_${CLASS_NAME}.cpp" @ONLY)
add_executable("tests_include_${CLASS_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/tests_${CLASS_NAME}.cpp")
target_link_libraries("tests_include_${CLASS_NAME}" HighFive)
target_link_libraries("tests_include_${CLASS_NAME}" HighFive HighFiveWarnings)
endforeach()
endif()

0 comments on commit b06fa2c

Please sign in to comment.