Skip to content

Commit 39d540b

Browse files
committed
Modernize cmake files
Use FILE_SET HEADERS for simplify installation Set VERIFY_INTERFACE_HEADER_SETS property Prevent use of include(CTest) Prepare CPack to easy distribution Add all_verify_interface_header_sets to CI builds Prevent in-source builds Ignore cmake configure trash
1 parent 2b0bb62 commit 39d540b

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ jobs:
104104
- name: Build Release
105105
run: |
106106
cmake --build build --config Release --verbose
107-
# TODO: cmake --build build --config Release --target all_verify_interface_header_sets
107+
cmake --build build --config Release --target all_verify_interface_header_sets
108108
cmake --install build --config Release --prefix /tmp/beman.inplace_vector
109109
find /tmp/beman.inplace_vector -type f
110110
- name: Test Release
111111
run: ctest --test-dir build --build-config Release
112112
- name: Build Debug
113113
run: |
114114
cmake --build build --config Debug --verbose
115-
# TODO: cmake --build build --config Debug --target all_verify_interface_header_sets
115+
cmake --build build --config Debug --target all_verify_interface_header_sets
116116
cmake --install build --config Debug --prefix /tmp/beman.inplace_vector
117117
find /tmp/beman.inplace_vector -type f
118118
- name: Test Debug

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/build
22
/out
33
CMakeUserPresets.json
4+
CMakeCache.txt
5+
CMakeFiles/

CMakeLists.txt

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
# cmake-format: on
55

6-
cmake_minimum_required(VERSION 3.23)
6+
set(CMAKE_SKIP_TEST_ALL_DEPENDENCY FALSE)
7+
8+
cmake_minimum_required(VERSION 3.25...3.31)
79

810
project(
911
beman.inplace_vector
@@ -13,6 +15,10 @@ project(
1315
LANGUAGES CXX
1416
)
1517

18+
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
19+
message(FATAL_ERROR "In-source builds are not allowed!")
20+
endif()
21+
1622
# [CMAKE.SKIP_EXAMPLES]
1723
option(
1824
BEMAN_EXEMPLAR_BUILD_EXAMPLES
@@ -27,38 +33,49 @@ option(
2733
${PROJECT_IS_TOP_LEVEL}
2834
)
2935

36+
set(CPACK_GENERATOR TGZ)
37+
38+
# includes
3039
include(GNUInstallDirs)
40+
include(CPack)
3141

3242
add_library(beman.inplace_vector INTERFACE)
3343
# [CMAKE.LIBRARY_ALIAS]
3444
add_library(beman::inplace_vector ALIAS beman.inplace_vector)
3545

36-
target_include_directories(
46+
target_sources(
47+
beman.inplace_vector
48+
PUBLIC
49+
FILE_SET inplace_vector_public_headers
50+
TYPE HEADERS
51+
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
52+
FILES
53+
"${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp"
54+
)
55+
set_target_properties(
56+
beman.inplace_vector
57+
PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON
58+
)
59+
target_compile_features(
3760
beman.inplace_vector
3861
INTERFACE
39-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
40-
$<INSTALL_INTERFACE:include>
62+
"$<$<COMPILE_FEATURES:cxx_std_23>:cxx_std_23>"
63+
"$<$<NOT:$<COMPILE_FEATURES:cxx_std_23>>:cxx_std_20>"
4164
)
4265

66+
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
67+
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
68+
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
69+
4370
# Install the InplaceVector library to the appropriate destination
4471
install(
4572
TARGETS beman.inplace_vector
4673
EXPORT ${TARGETS_EXPORT_NAME}
47-
DESTINATION
48-
${CMAKE_INSTALL_LIBDIR}
49-
)
50-
51-
# Install the header files to the appropriate destination
52-
install(
53-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
54-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
55-
FILES_MATCHING
56-
PATTERN
57-
"${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp"
74+
FILE_SET inplace_vector_public_headers
5875
)
5976

6077
if(BEMAN_INPLACE_VECTOR_BUILD_TESTS)
61-
include(CTest)
78+
enable_testing()
6279
add_subdirectory(tests/beman/inplace_vector)
6380
endif()
6481

0 commit comments

Comments
 (0)