From 426ca3513d07ab29c6b07d99efba30cb246b56b1 Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 14:05:54 -0500 Subject: [PATCH 1/7] Convert to INTERFACE and verify headers Convert to an interface library and use verify headers to test that headers are self-contained and compile correctly by themselves. Test install at end of CI and run both Asan and RWDI builds. --- .github/workflows/ci.yml | 20 ++++++++++++++++--- CMakeLists.txt | 4 +++- Makefile | 1 + src/beman/optional26/CMakeLists.txt | 3 --- src/beman/optional26/detail/iterator.cpp | 4 ---- src/beman/optional26/optional.cpp | 4 ---- src/beman/optional26/tests/CMakeLists.txt | 2 -- src/beman/optional26/tests/test_types.cpp | 4 ---- src/beman/optional26/tests/test_utilities.cpp | 4 ---- 9 files changed, 21 insertions(+), 25 deletions(-) delete mode 100644 src/beman/optional26/detail/iterator.cpp delete mode 100644 src/beman/optional26/optional.cpp delete mode 100644 src/beman/optional26/tests/test_types.cpp delete mode 100644 src/beman/optional26/tests/test_utilities.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a41d1c..0257d91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,13 +82,27 @@ jobs: echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} rm -rf .build - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B .build -S . - - name: CMake Build + cmake ${{ matrix.config.cmake_args }} -DCMAKE_INSTALL_PREFIX=.install -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B .build -S . + - name: CMake ASAN Build run: | set -x + cmake --build .build --config Asan --target all_verify_interface_header_sets -- -k 0 cmake --build .build --config Asan --target all -- -k 0 - - name: CMake Test + - name: CMake ASAN Test run: | set -x [[ ! -z "${{ matrix.config.asan_options }}" ]] && export ASAN_OPTIONS="${{ matrix.config.asan_options }}" ctest --build-config Asan --output-on-failure --test-dir .build + - name: CMake RWDI Build + run: | + set -x + cmake --build .build --config RelWithDebInfo --target all_verify_interface_header_sets -- -k 0 + cmake --build .build --config RelWithDebInfo --target all -- -k 0 + - name: CMake RWDI Test + run: | + set -x + ctest --build-config RelWithDebInfo --output-on-failure --test-dir .build + - name: Install + run: | + set -x + cmake --install .build --config RelWithDebInfo --component beman_optional26_development --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f012e3..b3aa944 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,10 @@ if(OPTIONAL26_ENABLE_TESTING) FetchContent_MakeAvailable(googletest) endif() +set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON) + # Create the library target and named header set for beman_optional26 -add_library(beman_optional26 STATIC) +add_library(beman_optional26 INTERFACE) target_sources( beman_optional26 PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS src include diff --git a/Makefile b/Makefile index 90e9175..c98ab60 100755 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ $(_build_path)/CMakeCache.txt: | $(_build_path) .gitmodules TARGET:=all compile: $(_build_path)/CMakeCache.txt ## Compile the project + cmake --build $(_build_path) --config $(CONFIG) --target all_verify_interface_header_sets -- -k 0 cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0 install: $(_build_path)/CMakeCache.txt compile ## Install the project diff --git a/src/beman/optional26/CMakeLists.txt b/src/beman/optional26/CMakeLists.txt index 1bd7439..10a7fc9 100644 --- a/src/beman/optional26/CMakeLists.txt +++ b/src/beman/optional26/CMakeLists.txt @@ -1,9 +1,6 @@ # src/beman/optional26/CMakeLists.txt -*-cmake-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Ensure that optional and iterator get compiled at least once -target_sources(beman_optional26 PUBLIC optional.cpp detail/iterator.cpp) - # The library is empty -- exclude it install( TARGETS beman_optional26 diff --git a/src/beman/optional26/detail/iterator.cpp b/src/beman/optional26/detail/iterator.cpp deleted file mode 100644 index c01fe5d..0000000 --- a/src/beman/optional26/detail/iterator.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// src/beman/optional26/detail/iterator.cpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include diff --git a/src/beman/optional26/optional.cpp b/src/beman/optional26/optional.cpp deleted file mode 100644 index f5b151c..0000000 --- a/src/beman/optional26/optional.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// src/beman/optional26/optional.cpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include diff --git a/src/beman/optional26/tests/CMakeLists.txt b/src/beman/optional26/tests/CMakeLists.txt index a35e019..5a2c1ad 100644 --- a/src/beman/optional26/tests/CMakeLists.txt +++ b/src/beman/optional26/tests/CMakeLists.txt @@ -17,8 +17,6 @@ target_sources( optional_range_support.t.cpp optional_ref.t.cpp optional_ref_monadic.t.cpp - test_types.cpp - test_utilities.cpp ) target_sources( diff --git a/src/beman/optional26/tests/test_types.cpp b/src/beman/optional26/tests/test_types.cpp deleted file mode 100644 index a851377..0000000 --- a/src/beman/optional26/tests/test_types.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// src/beman/optional26/test/test_types.cpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include diff --git a/src/beman/optional26/tests/test_utilities.cpp b/src/beman/optional26/tests/test_utilities.cpp deleted file mode 100644 index 0c48cce..0000000 --- a/src/beman/optional26/tests/test_utilities.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// src/beman/optional26/test/test_utilities.cpp -*-C++-*- -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include From 5919e9a8d4315519899ff0e747e602e68152e44e Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 14:57:48 -0500 Subject: [PATCH 2/7] Add verify to build presets Add the verify headers target to the build presets for each compiler. --- CMakePresets.json | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index eb05f0c..6ee0372 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -64,37 +64,65 @@ { "name": "common", "hidden": true, - "configuration": "Asan" + "configuration": "Asan", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "system", "inherits": "common", - "configurePreset": "system" + "configurePreset": "system", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "gcc-14", "inherits": "common", - "configurePreset": "gcc-14" + "configurePreset": "gcc-14", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "gcc-13", "inherits": "common", - "configurePreset": "gcc-13" + "configurePreset": "gcc-13", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "clang-19", "inherits": "common", - "configurePreset": "clang-19" + "configurePreset": "clang-19", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "clang-18", "inherits": "common", - "configurePreset": "clang-18" + "configurePreset": "clang-18", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "clang-17", "inherits": "common", - "configurePreset": "clang-17" + "configurePreset": "clang-17", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] } ], "testPresets": [ From 74bd833c640d96ac6db035db8de959bac35b5d8d Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 15:23:11 -0500 Subject: [PATCH 3/7] Clean up empty CML.txt files --- CMakeLists.txt | 3 ++- include/beman/optional26/CMakeLists.txt | 7 +++++++ src/beman/optional26/CMakeLists.txt | 23 ----------------------- 3 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 src/beman/optional26/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b3aa944..538bef4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,9 +51,10 @@ if(OPTIONAL26_ENABLE_TESTING) TYPE HEADERS BASE_DIRS src ) + + add_subdirectory(src/beman/optional26/tests) endif() -add_subdirectory(src/beman/optional26) add_subdirectory(include/beman/optional26) add_subdirectory(examples) diff --git a/include/beman/optional26/CMakeLists.txt b/include/beman/optional26/CMakeLists.txt index 2915023..3cbb347 100644 --- a/include/beman/optional26/CMakeLists.txt +++ b/include/beman/optional26/CMakeLists.txt @@ -13,3 +13,10 @@ target_sources( detail/stl_interfaces/fwd.hpp detail/stl_interfaces/iterator_interface.hpp ) + +install( + TARGETS beman_optional26 + FILE_SET beman_optional26_headers + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT beman_optional26_development +) diff --git a/src/beman/optional26/CMakeLists.txt b/src/beman/optional26/CMakeLists.txt deleted file mode 100644 index 10a7fc9..0000000 --- a/src/beman/optional26/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# src/beman/optional26/CMakeLists.txt -*-cmake-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# The library is empty -- exclude it -install( - TARGETS beman_optional26 - ARCHIVE - DESTINATION ${CMAKE_INSTALL_LIBDIR} - COMPONENT beman_optional26_library - EXCLUDE_FROM_ALL -) - -install( - TARGETS beman_optional26 - FILE_SET beman_optional26_headers - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - COMPONENT beman_optional26_development -) - -# Tests -if(OPTIONAL26_ENABLE_TESTING) - add_subdirectory(tests) -endif() From b337a9c9d0175534eed3a08cdc47366ea73726c4 Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 15:30:47 -0500 Subject: [PATCH 4/7] Reformat CML.txt to pass lint --- CMakeLists.txt | 2 +- include/beman/optional26/CMakeLists.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 538bef4..7548916 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ if(OPTIONAL26_ENABLE_TESTING) BASE_DIRS src ) - add_subdirectory(src/beman/optional26/tests) + add_subdirectory(src/beman/optional26/tests) endif() add_subdirectory(include/beman/optional26) diff --git a/include/beman/optional26/CMakeLists.txt b/include/beman/optional26/CMakeLists.txt index 3cbb347..6015d59 100644 --- a/include/beman/optional26/CMakeLists.txt +++ b/include/beman/optional26/CMakeLists.txt @@ -15,8 +15,8 @@ target_sources( ) install( - TARGETS beman_optional26 - FILE_SET beman_optional26_headers - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - COMPONENT beman_optional26_development + TARGETS beman_optional26 + FILE_SET beman_optional26_headers + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT beman_optional26_development ) From b7cb3327fed3b285fd0268242c69e6f65ca672dc Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 18:09:50 -0500 Subject: [PATCH 5/7] Add back cmake export file Add the EXPORT component for the header install components. --- CMakeLists.txt | 2 +- include/beman/optional26/CMakeLists.txt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7548916..7924eb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ON) add_library(beman_optional26 INTERFACE) target_sources( beman_optional26 - PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS src include + PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS include ) if(OPTIONAL26_ENABLE_TESTING) diff --git a/include/beman/optional26/CMakeLists.txt b/include/beman/optional26/CMakeLists.txt index 6015d59..e43fc93 100644 --- a/include/beman/optional26/CMakeLists.txt +++ b/include/beman/optional26/CMakeLists.txt @@ -20,3 +20,22 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT beman_optional26_development ) + +install( + TARGETS beman_optional26 + EXPORT beman_optional26_export + DESTINATION + ${CMAKE_INSTALL_LIBDIR} + FILE_SET beman_optional26_headers + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT beman_optional26_development +) + +install( + EXPORT beman_optional26_export + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ + NAMESPACE Beman::Optional26:: + FILE beman_optional26.cmake + EXPORT_LINK_INTERFACE_LIBRARIES + COMPONENT beman_optional26_development +) From 35f363a5bd98bf081677b6c9e55919d80973e674 Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 20:35:08 -0500 Subject: [PATCH 6/7] Export a Config.cmake file for FindPackage Add back FindPackage support. --- CMakeLists.txt | 18 ++++++++++++++++++ cmake/Config.cmake.in | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7924eb1..3b91b8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,24 @@ add_subdirectory(include/beman/optional26) add_subdirectory(examples) + +include(CMakePackageConfigHelpers) + +# This will be used to replace @PACKAGE_cmakeModulesDir@ +set(cmakeModulesDir cmake/beman) +configure_package_config_file( + cmake/Config.cmake.in BemanOptional26Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ + PATH_VARS cmakeModulesDir + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/BemanOptional26Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ + COMPONENT beman_optional26_development +) + # Coverage configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 050aedb..4c786be 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1,4 +1,4 @@ -# cmake/Config.cmake.in -*-makefile-*- +# cmake/Config.cmake.in -*-cmake-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception @PACKAGE_INIT@ From 5691c2da52b5ae0963391191f5a9d66807370a8c Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Sun, 10 Nov 2024 20:46:42 -0500 Subject: [PATCH 7/7] Reformat CML.txt Lint failed. Fixed indentation. --- CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b91b8c..5b4897d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,22 +59,23 @@ add_subdirectory(include/beman/optional26) add_subdirectory(examples) - include(CMakePackageConfigHelpers) # This will be used to replace @PACKAGE_cmakeModulesDir@ set(cmakeModulesDir cmake/beman) configure_package_config_file( - cmake/Config.cmake.in BemanOptional26Config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ - PATH_VARS cmakeModulesDir - NO_SET_AND_CHECK_MACRO - NO_CHECK_REQUIRED_COMPONENTS_MACRO + cmake/Config.cmake.in + BemanOptional26Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ + PATH_VARS cmakeModulesDir + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO ) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/BemanOptional26Config.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ - COMPONENT beman_optional26_development +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/BemanOptional26Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman/optional26/ + COMPONENT beman_optional26_development ) # Coverage