Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/compile_commands.json
/build
/CMakeFiles
/stagedir
Copy link
Member

Choose a reason for hiding this comment

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

These shouldn't exist outside the build directory anyway, no need to add them here

Copy link
Author

Choose a reason for hiding this comment

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

see #217

**/build/

# ignore emacs temp files
*~
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
{
Expand Down Expand Up @@ -120,6 +126,9 @@
{
"name": "_root-build",
"hidden": true,
"targets": [
"all_verify_interface_header_sets", "all"
],
"jobs": 0
},
{
Expand Down
4 changes: 3 additions & 1 deletion cookiecutter/{{cookiecutter.project_name}}/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/compile_commands.json
/build
/CMakeFiles
/stagedir
**/build/

# ignore emacs temp files
*~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion cookiecutter/{{cookiecutter.project_name}}/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/stagedir",
Copy link
Member

Choose a reason for hiding this comment

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

Now that the tests don't assume an installDir being set by the preset, we should not be mandating the installDir here

"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
}
},
{
Expand Down Expand Up @@ -120,6 +126,9 @@
{
"name": "_root-build",
"hidden": true,
"targets": [
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, mandating targets is no longer required so we shouldn't

"all_verify_interface_header_sets", "all"
],
"jobs": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

The example code should not be used for testing. This code serves no purpose for a user who is copy-pasting the example into their own source directory. It serves only to confuse them.

The test should be a five line project that calls cmake_minimum_required() -> project() -> find_package(REQUIRED) -> if(NOT TARGET). It should not be an example. It should exist solely for the purpose of testing the imports.

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:
Expand All @@ -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})
Expand All @@ -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 $<TARGET_FILE:beman.{{cookiecutter.project_name}}.examples.${example}>
)
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}$<$<CONFIG:Debug>:/debug>
DESTINATION ${CMAKE_INSTALL_LIBDIR}$<$<CONFIG:Debug>:/debug>
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}$<$<CONFIG:Debug>:/debug>
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<CONFIG>
)
add_test(
NAME find-package-test
COMMAND
${CMAKE_CTEST_COMMAND}
# --verbose
--output-on-failure -C $<CONFIG> --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=$<CONFIG>"
"-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/stagedir"
)
endif()
32 changes: 31 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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})
Expand All @@ -24,4 +50,8 @@ foreach(example ${ALL_EXAMPLES})
beman.exemplar.examples.${example}
PRIVATE beman::exemplar
)
add_test(
NAME beman.exemplar.examples.${example}
COMMAND $<TARGET_FILE:beman.exemplar.examples.${example}>
)
endforeach()
12 changes: 6 additions & 6 deletions src/beman/exemplar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}$<$<CONFIG:Debug>:/debug>
DESTINATION ${CMAKE_INSTALL_LIBDIR}$<$<CONFIG:Debug>:/debug>
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}$<$<CONFIG:Debug>:/debug>
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Expand Down
24 changes: 24 additions & 0 deletions tests/beman/exemplar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<CONFIG>
)
add_test(
NAME find-package-test
COMMAND
${CMAKE_CTEST_COMMAND}
# --verbose
--output-on-failure -C $<CONFIG> --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=$<CONFIG>"
"-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/stagedir"
)
endif()