diff --git a/.gitignore b/.gitignore index 0cb4a662..f37d5079 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /compile_commands.json -/build +/CMakeFiles +/stagedir +**/build/ # ignore emacs temp files *~ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe6d2cf7..cb8dc908 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,14 +13,14 @@ repos: # This brings in a portable version of clang-format. # See also: https://github.com/ssciwr/clang-format-wheel - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.8 + rev: v20.1.7 hooks: - id: clang-format types_or: [c++, c] # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi - rev: 0.15.1 + rev: 0.20.0 hooks: - id: gersemi name: CMake linting @@ -34,7 +34,7 @@ repos: # - id: markdownlint - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell diff --git a/CMakeLists.txt b/CMakeLists.txt index fe1bce03..816d8a19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.25...4.1) project( beman.exemplar # CMake Project Name, which is also the name of the top-level diff --git a/CMakePresets.json b/CMakePresets.json index 483e1a34..ca9dca2e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,10 +6,16 @@ "hidden": true, "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/stagedir", "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceDir}/stagedir" + }, "CMAKE_CXX_STANDARD": "20", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", - "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "./infra/cmake/use-fetch-content.cmake" + "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "./infra/cmake/use-fetch-content.cmake", + "CMAKE_SKIP_TEST_ALL_DEPENDENCY": false } }, { @@ -120,6 +126,9 @@ { "name": "_root-build", "hidden": true, + "targets": [ + "all_verify_interface_header_sets", "all" + ], "jobs": 0 }, { diff --git a/cookiecutter/{{cookiecutter.project_name}}/.gitignore b/cookiecutter/{{cookiecutter.project_name}}/.gitignore index 0cb4a662..f37d5079 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/.gitignore +++ b/cookiecutter/{{cookiecutter.project_name}}/.gitignore @@ -1,5 +1,7 @@ /compile_commands.json -/build +/CMakeFiles +/stagedir +**/build/ # ignore emacs temp files *~ diff --git a/cookiecutter/{{cookiecutter.project_name}}/.pre-commit-config.yaml b/cookiecutter/{{cookiecutter.project_name}}/.pre-commit-config.yaml index fe6d2cf7..cb8dc908 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/.pre-commit-config.yaml +++ b/cookiecutter/{{cookiecutter.project_name}}/.pre-commit-config.yaml @@ -13,14 +13,14 @@ repos: # This brings in a portable version of clang-format. # See also: https://github.com/ssciwr/clang-format-wheel - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.8 + rev: v20.1.7 hooks: - id: clang-format types_or: [c++, c] # CMake linting and formatting - repo: https://github.com/BlankSpruce/gersemi - rev: 0.15.1 + rev: 0.20.0 hooks: - id: gersemi name: CMake linting @@ -34,7 +34,7 @@ repos: # - id: markdownlint - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell diff --git a/cookiecutter/{{cookiecutter.project_name}}/CMakeLists.txt b/cookiecutter/{{cookiecutter.project_name}}/CMakeLists.txt index ea17bede..f0377075 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/CMakeLists.txt +++ b/cookiecutter/{{cookiecutter.project_name}}/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.25...4.1) project( beman.{{cookiecutter.project_name}} # CMake Project Name, which is also the name of the top-level diff --git a/cookiecutter/{{cookiecutter.project_name}}/CMakePresets.json b/cookiecutter/{{cookiecutter.project_name}}/CMakePresets.json index 483e1a34..ca9dca2e 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/CMakePresets.json +++ b/cookiecutter/{{cookiecutter.project_name}}/CMakePresets.json @@ -6,10 +6,16 @@ "hidden": true, "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/stagedir", "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceDir}/stagedir" + }, "CMAKE_CXX_STANDARD": "20", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", - "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "./infra/cmake/use-fetch-content.cmake" + "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "./infra/cmake/use-fetch-content.cmake", + "CMAKE_SKIP_TEST_ALL_DEPENDENCY": false } }, { @@ -120,6 +126,9 @@ { "name": "_root-build", "hidden": true, + "targets": [ + "all_verify_interface_header_sets", "all" + ], "jobs": 0 }, { diff --git a/cookiecutter/{{cookiecutter.project_name}}/examples/CMakeLists.txt b/cookiecutter/{{cookiecutter.project_name}}/examples/CMakeLists.txt index 0c1d3854..542a8520 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/examples/CMakeLists.txt +++ b/cookiecutter/{{cookiecutter.project_name}}/examples/CMakeLists.txt @@ -1,5 +1,31 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +cmake_minimum_required(VERSION 3.25...4.1) + +project( + beman.{{cookiecutter.project_name}}.examples + DESCRIPTION "Examaples for Beman implementation of {{cookiecutter.project_name}}" + LANGUAGES CXX + VERSION 2.1.1 +) + +if(PROJECT_IS_TOP_LEVEL) + set(_find_package_option REQUIRED) + + # see Professional CMake Chapter 40. Making Projects Consumable + option(CHECK_PROJECT_IS_CONSUMABLE NO) + if(CHECK_PROJECT_IS_CONSUMABLE) + set(_find_package_option) + endif() + + find_package(beman.{{cookiecutter.project_name}} 2.1.1 EXACT ${_find_package_option}) + if(NOT TARGET beman::{{cookiecutter.project_name}}) + add_subdirectory(.. {{cookiecutter.project_name}}_src) + endif() + + enable_testing() +endif() + set(ALL_EXAMPLES identity_direct_usage) # Example `identity_as_default_projection` need ranges support: @@ -15,7 +41,7 @@ else() ) endif() -message("Examples to be built: ${ALL_EXAMPLES}") +message(STATUS "Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) add_executable(beman.{{cookiecutter.project_name}}.examples.${example}) @@ -24,4 +50,8 @@ foreach(example ${ALL_EXAMPLES}) beman.{{cookiecutter.project_name}}.examples.${example} PRIVATE beman::{{cookiecutter.project_name}} ) + add_test( + NAME beman.{{cookiecutter.project_name}}.examples.${example} + COMMAND $ + ) endforeach() diff --git a/cookiecutter/{{cookiecutter.project_name}}/src/beman/{{cookiecutter.project_name}}/CMakeLists.txt b/cookiecutter/{{cookiecutter.project_name}}/src/beman/{{cookiecutter.project_name}}/CMakeLists.txt index 008e1883..edd5f2f7 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/src/beman/{{cookiecutter.project_name}}/CMakeLists.txt +++ b/cookiecutter/{{cookiecutter.project_name}}/src/beman/{{cookiecutter.project_name}}/CMakeLists.txt @@ -11,9 +11,9 @@ target_sources( beman.{{cookiecutter.project_name}} PUBLIC FILE_SET HEADERS - BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include - FILES - ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/beman/{{cookiecutter.project_name}}/identity.hpp + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/beman/{{cookiecutter.project_name}}/identity.hpp ) set_target_properties( @@ -22,10 +22,10 @@ set_target_properties( ) install( - TARGETS beman.{{cookiecutter.project_name}} COMPONENT beman.{{cookiecutter.project_name}} + TARGETS beman.{{cookiecutter.project_name}} + COMPONENT beman.{{cookiecutter.project_name}} EXPORT beman.{{cookiecutter.project_name}} - DESTINATION - ${CMAKE_INSTALL_LIBDIR}$<$:/debug> + DESTINATION ${CMAKE_INSTALL_LIBDIR}$<$:/debug> RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}$<$:/debug> FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) diff --git a/cookiecutter/{{cookiecutter.project_name}}/tests/beman/{{cookiecutter.project_name}}/CMakeLists.txt b/cookiecutter/{{cookiecutter.project_name}}/tests/beman/{{cookiecutter.project_name}}/CMakeLists.txt index 75c9dfd1..a3a4a229 100644 --- a/cookiecutter/{{cookiecutter.project_name}}/tests/beman/{{cookiecutter.project_name}}/CMakeLists.txt +++ b/cookiecutter/{{cookiecutter.project_name}}/tests/beman/{{cookiecutter.project_name}}/CMakeLists.txt @@ -11,3 +11,27 @@ target_link_libraries( include(GoogleTest) gtest_discover_tests(beman.{{cookiecutter.project_name}}.tests.identity) + +if(BEMAN_{{cookiecutter.project_name.upper()}}_INSTALL_CONFIG_FILE_PACKAGE) + # test if the targets are usable from the install directory + add_test( + NAME install-to-stagedir + COMMAND + ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix + ${CMAKE_BINARY_DIR}/stagedir --config $ + ) + add_test( + NAME find-package-test + COMMAND + ${CMAKE_CTEST_COMMAND} + # --verbose + --output-on-failure -C $ --build-and-test + "${CMAKE_SOURCE_DIR}/examples" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator + ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_BUILD_TYPE=$" + "-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/stagedir" + ) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 49aaf251..a479dd12 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,31 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +cmake_minimum_required(VERSION 3.25...4.1) + +project( + beman.exemplar.examples + DESCRIPTION "Examaples for Beman implementation of exemplar" + LANGUAGES CXX + VERSION 2.1.1 +) + +if(PROJECT_IS_TOP_LEVEL) + set(_find_package_option REQUIRED) + + # see Professional CMake Chapter 40. Making Projects Consumable + option(CHECK_PROJECT_IS_CONSUMABLE NO) + if(CHECK_PROJECT_IS_CONSUMABLE) + set(_find_package_option) + endif() + + find_package(beman.exemplar 2.1.1 EXACT ${_find_package_option}) + if(NOT TARGET beman::exemplar) + add_subdirectory(.. exemplar_src) + endif() + + enable_testing() +endif() + set(ALL_EXAMPLES identity_direct_usage) # Example `identity_as_default_projection` need ranges support: @@ -15,7 +41,7 @@ else() ) endif() -message("Examples to be built: ${ALL_EXAMPLES}") +message(STATUS "Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) add_executable(beman.exemplar.examples.${example}) @@ -24,4 +50,8 @@ foreach(example ${ALL_EXAMPLES}) beman.exemplar.examples.${example} PRIVATE beman::exemplar ) + add_test( + NAME beman.exemplar.examples.${example} + COMMAND $ + ) endforeach() diff --git a/src/beman/exemplar/CMakeLists.txt b/src/beman/exemplar/CMakeLists.txt index cbed5ce1..0153bbb2 100644 --- a/src/beman/exemplar/CMakeLists.txt +++ b/src/beman/exemplar/CMakeLists.txt @@ -11,9 +11,9 @@ target_sources( beman.exemplar PUBLIC FILE_SET HEADERS - BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include - FILES - ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/beman/exemplar/identity.hpp + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../../include + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/beman/exemplar/identity.hpp ) set_target_properties( @@ -22,10 +22,10 @@ set_target_properties( ) install( - TARGETS beman.exemplar COMPONENT beman.exemplar + TARGETS beman.exemplar + COMPONENT beman.exemplar EXPORT beman.exemplar - DESTINATION - ${CMAKE_INSTALL_LIBDIR}$<$:/debug> + DESTINATION ${CMAKE_INSTALL_LIBDIR}$<$:/debug> RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}$<$:/debug> FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) diff --git a/tests/beman/exemplar/CMakeLists.txt b/tests/beman/exemplar/CMakeLists.txt index 153cdb8e..7f91dabb 100644 --- a/tests/beman/exemplar/CMakeLists.txt +++ b/tests/beman/exemplar/CMakeLists.txt @@ -11,3 +11,27 @@ target_link_libraries( include(GoogleTest) gtest_discover_tests(beman.exemplar.tests.identity) + +if(BEMAN_EXEMPLAR_INSTALL_CONFIG_FILE_PACKAGE) + # test if the targets are usable from the install directory + add_test( + NAME install-to-stagedir + COMMAND + ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix + ${CMAKE_BINARY_DIR}/stagedir --config $ + ) + add_test( + NAME find-package-test + COMMAND + ${CMAKE_CTEST_COMMAND} + # --verbose + --output-on-failure -C $ --build-and-test + "${CMAKE_SOURCE_DIR}/examples" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator + ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_BUILD_TYPE=$" + "-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/stagedir" + ) +endif()