Skip to content

Commit b184041

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 esay distribution Add all_verify_interface_header_sets to CI builds Prevent in-source builds Ignore cmake configure trash
1 parent afd9ff9 commit b184041

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ jobs:
8282
- name: Build Release
8383
run: |
8484
cmake --build build --config Release --verbose
85-
# TODO: cmake --build build --config Release --target all_verify_interface_header_sets
85+
cmake --build build --config Release --target all_verify_interface_header_sets
8686
cmake --install build --config Release --prefix /tmp/beman.inplace_vector
8787
find /tmp/beman.inplace_vector -type f
8888
- name: Test Release
8989
run: ctest --test-dir build --build-config Release
9090
- name: Build Debug
9191
run: |
9292
cmake --build build --config Debug --verbose
93-
# TODO: cmake --build build --config Debug --target all_verify_interface_header_sets
93+
cmake --build build --config Debug --target all_verify_interface_header_sets
9494
cmake --install build --config Debug --prefix /tmp/beman.inplace_vector
9595
find /tmp/beman.inplace_vector -type f
9696
- 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

include/beman/inplace_vector/inplace_vector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct inplace_vector_destruct_base {
7474
inplace_vector_destruct_base(
7575
const inplace_vector_destruct_base
7676
&&other) noexcept(std::is_nothrow_move_constructible_v<T>)
77-
: elems(), size_(other.size()) {}
77+
: elems(), size_(other.size_) {}
7878

7979
inplace_vector_destruct_base &
8080
operator=(const inplace_vector_destruct_base &other) noexcept(

0 commit comments

Comments
 (0)