Skip to content

Commit e9b94ce

Browse files
committed
Export cmake config package
Fix windows build Add CI for macos and windows
1 parent 8f6435b commit e9b94ce

File tree

14 files changed

+468
-29
lines changed

14 files changed

+468
-29
lines changed

.cmake-format

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
format:
2+
line_width: 119
3+
tab_size: 4
4+
max_subgroups_hwrap: 4
5+
max_rows_cmdline: 8
6+
separate_ctrl_name_with_space: false
7+
separate_fn_name_with_space: false
8+
dangle_parens: true
9+
dangle_align: prefix
10+
line_ending: unix
11+
keyword_case: upper
12+
always_wrap:
13+
- file
14+
- install
15+
- project
16+
- write_basic_package_version_file
17+
18+
markup:
19+
enable_markup: false

.github/workflows/macos.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# .github/workflows/macos.yml
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
name: Macos Build
5+
6+
on:
7+
push:
8+
branches: ["main", "develop"]
9+
pull_request:
10+
branches: ["main", "develop"]
11+
12+
jobs:
13+
build:
14+
runs-on: macos-15
15+
strategy:
16+
fail-fast: false
17+
18+
matrix:
19+
preset: [debug, release]
20+
# TODO: compiler: [g++, clang++-19]
21+
compiler: [g++, clang++-18]
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Setup Cpp
27+
# if: startsWith(matrix.compiler, 'clang')
28+
uses: aminya/setup-cpp@v1
29+
with:
30+
# TODO: compiler: llvm-19
31+
# clangtidy: true
32+
# cmake: true
33+
ninja: true
34+
35+
- name: Install llvm-19
36+
if: startsWith(matrix.compiler, 'clang')
37+
run: |
38+
brew install llvm@19 || echo ignored
39+
40+
- name: macos clang++-18 ${{ matrix.preset }}
41+
if: startsWith(matrix.compiler, 'clang')
42+
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
43+
44+
- name: macos g++ ${{ matrix.preset }}
45+
if: startsWith(matrix.compiler, 'g++')
46+
run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}

.github/workflows/windows.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# .github/workflows/windows.yml
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
name: Windows Build
5+
6+
on:
7+
push:
8+
branches: ["main", "develop"]
9+
pull_request:
10+
branches: ["main", "develop"]
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
strategy:
16+
fail-fast: false
17+
18+
matrix:
19+
preset: [debug, release]
20+
# TODO: compiler: [cl, clang-cl]
21+
compiler: [cl]
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
# see https://github.com/marketplace/actions/enable-developer-command-prompt
27+
- uses: ilammy/msvc-dev-cmd@v1
28+
with:
29+
vsversion: 2022
30+
31+
# - name: build environment
32+
# run: pip install -r requirements.txt
33+
34+
- name: cmake workflow ${{ matrix.preset }}
35+
shell: bash
36+
run: |
37+
cmake --version
38+
ninja --version
39+
CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}
40+
41+
# - name: configure
42+
# run: CXX=${{ matrix.compiler }} cmake --preset ${{ matrix.preset }}
43+
44+
# - name: build
45+
# run: cmake --build --preset ${{ matrix.preset }}
46+
47+
# - name: ctest
48+
# run: ctest --preset ${{ matrix.preset }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/stagedir
12
/build
23
/out
34
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
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(
9-
beman.inplace_vector
11+
beman_inplace_vector
1012
VERSION 1.0.0
1113
DESCRIPTION
1214
"A dynamically-resizable vector with fixed capacity and embedded storage"
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
@@ -28,37 +34,87 @@ option(
2834
)
2935

3036
include(GNUInstallDirs)
37+
include(CMakePackageConfigHelpers)
3138

32-
add_library(beman.inplace_vector INTERFACE)
39+
add_library(beman_inplace_vector INTERFACE)
3340
# [CMAKE.LIBRARY_ALIAS]
34-
add_library(beman::inplace_vector ALIAS beman.inplace_vector)
41+
add_library(beman::inplace_vector ALIAS beman_inplace_vector)
42+
43+
#XXX target_include_directories(beman.inplace_vector ... ?
3544

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

43-
# Install the InplaceVector library to the appropriate destination
44-
install(
45-
TARGETS beman.inplace_vector
46-
EXPORT ${TARGETS_EXPORT_NAME}
47-
DESTINATION
48-
${CMAKE_INSTALL_LIBDIR}
49-
)
65+
block()
66+
# copied from execution26:
67+
set(TARGET_NAME beman_inplace_vector)
68+
set(TARGET_NAMESPACE beman)
69+
# set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # FIXME: not used yet? CK
70+
# set(TARGET_LIBRARY ${PROJECT_NAME})
71+
# set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY})
72+
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
73+
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
74+
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
5075

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"
58-
)
76+
# Install the InplaceVector library to the appropriate destination
77+
install(
78+
TARGETS beman_inplace_vector
79+
EXPORT ${TARGETS_EXPORT_NAME}
80+
FILE_SET inplace_vector_public_headers
81+
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
82+
)
83+
84+
if(EXISTS cmake/Config.cmake.in)
85+
write_basic_package_version_file(
86+
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
87+
VERSION ${PROJECT_VERSION}
88+
COMPATIBILITY AnyNewerVersion
89+
)
90+
91+
configure_package_config_file(
92+
cmake/Config.cmake.in
93+
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake
94+
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
95+
)
96+
97+
install(
98+
FILES
99+
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake
100+
${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake
101+
DESTINATION ${INSTALL_CONFIGDIR}
102+
)
103+
104+
install(
105+
EXPORT ${TARGETS_EXPORT_NAME}
106+
FILE ${TARGETS_EXPORT_NAME}.cmake
107+
DESTINATION "${INSTALL_CONFIGDIR}"
108+
NAMESPACE beman::
109+
)
110+
111+
set(CPACK_GENERATOR TGZ)
112+
include(CPack)
113+
endif()
114+
endblock()
59115

60116
if(BEMAN_INPLACE_VECTOR_BUILD_TESTS)
61-
include(CTest)
117+
enable_testing()
62118
add_subdirectory(tests/beman/inplace_vector)
63119
endif()
64120

CMakePresets.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"version": 9,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 30,
6+
"patch": 0
7+
},
8+
"include": [
9+
"cmake/CMake${hostSystemName}Presets.json"
10+
],
11+
"buildPresets": [
12+
{
13+
"name": "debug",
14+
"configurePreset": "debug",
15+
"configuration": "Debug",
16+
"targets": [
17+
"install"
18+
]
19+
},
20+
{
21+
"name": "release",
22+
"configurePreset": "release",
23+
"configuration": "Release",
24+
"targets": [
25+
"all_verify_interface_header_sets",
26+
"install"
27+
]
28+
}
29+
],
30+
"testPresets": [
31+
{
32+
"name": "test_base",
33+
"hidden": true,
34+
"output": {
35+
"outputOnFailure": true
36+
},
37+
"execution": {
38+
"noTestsAction": "error",
39+
"stopOnFailure": false
40+
}
41+
},
42+
{
43+
"name": "debug",
44+
"inherits": "test_base",
45+
"configuration": "Debug",
46+
"configurePreset": "debug"
47+
},
48+
{
49+
"name": "release",
50+
"inherits": "test_base",
51+
"configuration": "Release",
52+
"configurePreset": "release"
53+
}
54+
],
55+
"packagePresets": [
56+
{
57+
"name": "release",
58+
"configurePreset": "release",
59+
"configurations": [
60+
"Release"
61+
],
62+
"generators": [
63+
"TGZ"
64+
]
65+
}
66+
],
67+
"workflowPresets": [
68+
{
69+
"name": "debug",
70+
"steps": [
71+
{
72+
"type": "configure",
73+
"name": "debug"
74+
},
75+
{
76+
"type": "build",
77+
"name": "debug"
78+
},
79+
{
80+
"type": "test",
81+
"name": "debug"
82+
}
83+
]
84+
},
85+
{
86+
"name": "release",
87+
"steps": [
88+
{
89+
"type": "configure",
90+
"name": "release"
91+
},
92+
{
93+
"type": "build",
94+
"name": "release"
95+
},
96+
{
97+
"type": "test",
98+
"name": "release"
99+
},
100+
{
101+
"type": "package",
102+
"name": "release"
103+
}
104+
]
105+
}
106+
]
107+
}

0 commit comments

Comments
 (0)