Skip to content

Commit bfeb908

Browse files
authored
Merge pull request #29 from neatudarius/tweaks-in-cmakelists-for-packaging
Split build production vs testing
2 parents 8f4a5f4 + e167523 commit bfeb908

File tree

12 files changed

+155
-180
lines changed

12 files changed

+155
-180
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
config:
15-
- {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
16-
- {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18-toolchain.cmake", clang_version: 18, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
15+
- {name: "Ubuntu Clang 17", os: ubuntu-24.04, toolchain: "clang-17", clang_version: 17, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
16+
- {name: "Ubuntu Clang 18", os: ubuntu-24.04, toolchain: "clang-18", clang_version: 18, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
1717
# Note: clang-19 + Asan setup causes errors on some platforms. Temporary skip some checks via .asan_options.
18-
- {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19-toolchain.cmake", clang_version: 19, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"}
19-
- {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
20-
- {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14-toolchain.cmake", clang_version: 17, installed_clang_version: 14, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
18+
- {name: "Ubuntu Clang 19", os: ubuntu-24.04, toolchain: "clang-19", clang_version: 19, installed_clang_version: 17, cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" ", asan_options: "new_delete_type_mismatch=0"}
19+
- {name: "Ubuntu GCC 13", os: ubuntu-24.04, toolchain: "gcc-13", cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
20+
- {name: "Ubuntu GCC 14", os: ubuntu-24.04, toolchain: "gcc-14", cmake_args: "-G \"Ninja Multi-Config\" -DCMAKE_CONFIGURATION_TYPES=\"RelWithDebInfo;Asan\" "}
2121
steps:
2222
- uses: actions/checkout@v3
2323
with:
@@ -26,13 +26,14 @@ jobs:
2626
- name: Activate verbose shell
2727
run: set -x
2828
- name: Install LLVM+Clang
29-
if: startsWith(matrix.config.os, 'ubuntu-')
29+
if: startsWith(matrix.config.name, 'Ubuntu Clang')
3030
run: |
3131
set -x
3232
cat /etc/lsb-release
33-
sudo apt-get remove clang-${{matrix.config.installed_clang_version}} \
34-
lldb-${{matrix.config.installed_clang_version}} \
35-
lld-${{matrix.config.installed_clang_version}} \
33+
# Remove existing Clang installations.
34+
sudo apt-get remove \
35+
clang-${{matrix.config.installed_clang_version}} \
36+
clang++-${{matrix.config.installed_clang_version}} \
3637
clangd-${{matrix.config.installed_clang_version}} \
3738
clang-tidy-${{matrix.config.installed_clang_version}} \
3839
clang-format-${{matrix.config.installed_clang_version}} \
@@ -41,39 +42,51 @@ jobs:
4142
lld-${{matrix.config.installed_clang_version}} \
4243
lldb-${{matrix.config.installed_clang_version}} \
4344
llvm-${{matrix.config.installed_clang_version}}-tools \
44-
libomp-${{matrix.config.installed_clang_version}}-dev \
4545
libc++-${{matrix.config.installed_clang_version}}-dev \
4646
libc++abi-${{matrix.config.installed_clang_version}}-dev \
4747
libclang-common-${{matrix.config.installed_clang_version}}-dev \
4848
libclang-${{matrix.config.installed_clang_version}}-dev \
4949
libclang-cpp${{matrix.config.installed_clang_version}}-dev \
50-
libunwind-${{matrix.config.installed_clang_version}}-dev
50+
libomp-${{matrix.config.installed_clang_version}}-dev \
51+
libunwind-${{matrix.config.installed_clang_version}}-dev \
52+
libc++-dev libc++1 libc++abi-dev libc++abi1
53+
# Install LLVM+Clang.
54+
CLANG_VERSION=$(echo ${{matrix.config.toolchain}} | cut -d '-' -f2)
5155
wget https://apt.llvm.org/llvm.sh
5256
chmod +x llvm.sh
53-
sudo ./llvm.sh ${{matrix.config.clang_version}} all
54-
sudo apt-get install libc++-dev libc++1 libc++abi-dev libc++abi1
55-
- name: Install GCC 14
56-
if: matrix.config.name == 'Ubuntu GCC 14'
57+
sudo ./llvm.sh ${CLANG_VERSION} all
58+
# Link Clang libraries (if not done by llvm.sh - some links are already set).
59+
sudo ln -fs /usr/lib/llvm-${CLANG_VERSION}/lib/lib* /usr/lib/x86_64-linux-gnu/ || true
60+
# If Clang 17, install a newer version of libc++ and libc++abi.
61+
[[ ${CLANG_VERSION} = 17 ]] && sudo apt-get install libc++-dev libc++1 libc++abi-dev libc++abi1
62+
find /usr/lib/x86_64-linux-gnu/ -name libc++.so* || true
63+
clang++-${CLANG_VERSION} --version
64+
- name: Install GCC
65+
if: startsWith(matrix.config.name, 'Ubuntu GCC')
5766
run: |
5867
set -x
68+
# Remove existing GCC installations.
69+
sudo apt-get remove gcc-13 g++-13 gcc-14 g++-14 gcc g++
5970
sudo apt update
60-
sudo apt-get install g++-14
61-
- name: Configure
71+
# Install GCC.
72+
GCC_VERSION=$(echo ${{matrix.config.toolchain}} | cut -d '-' -f2)
73+
echo "GCC_VERSION=$GCC_VERSION"
74+
sudo apt-get install g++-${GCC_VERSION} gcc-${GCC_VERSION}
75+
find /usr/lib/x86_64-linux-gnu/ -name libstdc++.so*
76+
g++-${GCC_VERSION} --version
77+
- name: CMake Configure
6278
run: |
6379
set -x
64-
rm -rf .build
65-
mkdir -p .build
66-
cd .build
6780
echo ${{ matrix.config.cmake_args }}
6881
echo ${{ matrix.config.toolchain }}
69-
cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -B . -S ..
70-
- name: Build
82+
rm -rf .build
83+
cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE="etc/${{ matrix.config.toolchain }}-toolchain.cmake" -B .build -S .
84+
- name: CMake Build
7185
run: |
7286
set -x
7387
cmake --build .build --config Asan --target all -- -k 0
74-
- name: Test
88+
- name: CMake Test
7589
run: |
7690
set -x
77-
cd .build
7891
[[ ! -z "${{ matrix.config.asan_options }}" ]] && export ASAN_OPTIONS="${{ matrix.config.asan_options }}"
79-
ctest --build-config Asan --output-on-failure
92+
ctest --build-config Asan --output-on-failure --test-dir .build

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[submodule "papers/wg21"]
22
path = papers/P2988/wg21
33
url = https://github.com/mpark/wg21.git
4-
[submodule "extern/googletest"]
5-
path = extern/googletest
6-
url = https://github.com/google/googletest.git

CMakeLists.txt

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

6-
cmake_minimum_required(VERSION 3.10)
6+
cmake_minimum_required(VERSION 3.27)
77

88
project(
99
beman_optional26
1010
VERSION 0.0.0
1111
LANGUAGES CXX)
1212

13-
enable_testing()
13+
# Includes
14+
include(CTest)
15+
include(FetchContent)
1416

1517
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
1618

17-
add_subdirectory(extern)
18-
add_subdirectory(src)
19+
# Build the tests only if enabled via the CLI flag: BUILD_TESTING.
20+
if(BUILD_TESTING)
21+
# Fetch GoogleTest
22+
FetchContent_Declare(
23+
googletest
24+
GIT_REPOSITORY https://github.com/google/googletest.git
25+
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0
26+
)
27+
FetchContent_MakeAvailable(googletest)
28+
endif()
29+
30+
add_subdirectory(src/Beman/Optional26)
1931
add_subdirectory(examples)
2032

2133
include(GNUInstallDirs)

CMakePresets.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,40 @@
6868
},
6969
{
7070
"name": "system",
71+
"inherits": "common",
7172
"configurePreset": "system"
7273
},
7374
{
7475
"name": "gcc-14",
76+
"inherits": "common",
7577
"configurePreset": "gcc-14"
7678
},
7779
{
7880
"name": "gcc-13",
81+
"inherits": "common",
7982
"configurePreset": "gcc-13"
8083
},
8184
{
8285
"name": "clang-19",
86+
"inherits": "common",
8387
"configurePreset": "clang-19"
8488
},
8589
{
8690
"name": "clang-18",
91+
"inherits": "common",
8792
"configurePreset": "clang-18"
8893
},
8994
{
9095
"name": "clang-17",
96+
"inherits": "common",
9197
"configurePreset": "clang-17"
9298
}
9399
],
94100
"testPresets": [
95101
{
96102
"name": "common",
97103
"hidden": true,
104+
"configuration": "Asan",
98105
"output": {
99106
"outputOnFailure": true
100107
},

Makefile

Lines changed: 0 additions & 97 deletions
This file was deleted.

README.md

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ This repository implements `std::optional` extensions targeting C++26. The `Bema
1313
* [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2)
1414
* [`std::optional<T&>` (P2988R5)](https://wg21.link/P2988R5)
1515

16+
## Table of Contents
17+
18+
* [Beman.Optional26: C++26 Extensions for std::optional](#bemanoptional26-c26-extensions-for-stdoptional)
19+
* [Table of Contents](#table-of-contents)
20+
* [License](#license)
21+
* [Examples](#examples)
22+
* [range\_loop](#range_loop)
23+
* [optional\_ref](#optional_ref)
24+
* [How to Build](#how-to-build)
25+
* [Compiler Support](#compiler-support)
26+
* [Dependencies](#dependencies)
27+
* [Instructions](#instructions)
28+
* [Preset CMake Flows](#preset-cmake-flows)
29+
* [Custom CMake Flows](#custom-cmake-flows)
30+
* [Build and Run Tests](#build-and-run-tests)
31+
* [Build Production, but Skip Tests](#build-production-but-skip-tests)
32+
* [Papers](#papers)
33+
1634
## License
1735

1836
Source is licensed with the Apache 2.0 license with LLVM exceptions
@@ -123,7 +141,7 @@ apt-get install \
123141

124142
Full set of supported toolchains can be found in [.github/workflows/ci.yml](.github/workflows/ci.yml).
125143

126-
#### Basic Build
144+
#### Preset CMake Flows
127145

128146
This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static `beman_optional26` library, ready to package:
129147

@@ -168,15 +186,56 @@ Total Test time (real) = 0.09 sec
168186

169187
This should build and run the tests with GCC 14 with the address and undefined behavior sanitizers enabled.
170188

171-
#### More complex cases
189+
#### Custom CMake Flows
190+
191+
##### Build and Run Tests
172192

173-
The CMake preset system suffers from combinitorial explosion. There is a makefile in the root of the repository to aid in running more configurations.
193+
CI current build and test flows:
174194

175195
```shell
176-
make -k TOOLCHAIN=clang-18 CONFIG=Tsan VERBOSE=1
196+
# Configure build: default build production code + tests (BUILD_TESTING=ON by default).
197+
$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -B .build -S .
198+
-- The CXX compiler identification is Clang 19.0.0
199+
...
200+
-- Build files have been written to: /path/to/Optional26/.build
201+
202+
# Build.
203+
$ cmake --build .build --config Asan --target all -- -k 0
204+
...
205+
[30/30] Linking CXX executable ... # Note: 30 targets here (including tests).
206+
207+
# Run tests.
208+
$ ctest --build-config Asan --output-on-failure --test-dir .build
209+
Internal ctest changing into directory: /path/to/Optional26/.build
210+
Test project /path/to/Optional26/.build
211+
...
212+
100% tests passed, 0 tests failed out of 82
213+
214+
Total Test time (real) = 0.67 sec
177215
```
178216

179-
The makefile will use your system compiler, `c++`, if no toolchain name is provided, otherwise it will use the toolchain in the etc/ directory to perform the build. The Ninja multi config generator is used, with configurations for `RelWithDebugInfo`, `Debug`, `Tsan`, and `Asan` configured by default.
217+
##### Build Production, but Skip Tests
218+
219+
By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and completely disable building tests:
220+
221+
```shell
222+
# Configure build: build production code, skip tests (BUILD_TESTING=OFF).
223+
$ cmake -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake -DBUILD_TESTING=OFF -B .build -S .
224+
-- The CXX compiler identification is Clang 19.0.0
225+
...
226+
-- Build files have been written to: /path/to/Optional26/.build
227+
228+
# Build.
229+
$ cmake --build .build --config Asan --target all -- -k 0
230+
...
231+
[15/15] Linking CXX executable ... # Note: 15 targets here (tests were not built).
232+
233+
# Check that tests are not built/installed.
234+
$ ctest --build-config Asan --output-on-failure --test-dir .build
235+
Internal ctest changing into directory: /path/to/Beman.Optional26/.build
236+
Test project /path/to/Beman.Optional26/.build
237+
No tests were found!!!
238+
```
180239

181240
## Papers
182241

extern/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

extern/googletest

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Beman/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)