Skip to content

Commit 1f03b18

Browse files
authored
Big maintenance update (#143)
* Update cppfront and helpers; require a version of CMake with native support for modules. * Bump version; update README.md * Add LICENSE.txt * Fix CRLF checking in tests * Add macOS job to CI * Add a timeout to CI test script runs.
1 parent a4461f9 commit 1f03b18

File tree

14 files changed

+231
-110
lines changed

14 files changed

+231
-110
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,65 @@
11
name: CI
2+
concurrency:
3+
group: ${{ github.workflow }}-${{ github.ref }}
4+
cancel-in-progress: true
25
on:
36
push:
47
branches: [ main ]
58
pull_request:
69
jobs:
7-
test:
8-
name: test ${{ matrix.os }}
10+
test-linux:
11+
name: Test Linux ${{ matrix.CC }}
12+
runs-on: ubuntu-24.04
913
strategy:
1014
fail-fast: false
1115
matrix:
12-
os: [
13-
windows-latest,
14-
# macos-latest, # cppfront is currently broken on AppleClang
15-
ubuntu-latest,
16-
]
17-
runs-on: ${{ matrix.os }}
16+
include:
17+
# Clang 18 is broken for some reason
18+
# - CC: clang-18
19+
# CXX: clang++-18
20+
# CXXFLAGS: -stdlib=libc++
21+
- CC: gcc-14
22+
CXX: g++-14
1823
steps:
19-
# System set-up
20-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2125
with:
2226
submodules: true
23-
- uses: ilammy/msvc-dev-cmd@v1
24-
- uses: lukka/get-cmake@latest
2527

26-
- name: Install GCC 11
27-
if: startsWith(matrix.os, 'ubuntu')
28-
run: |
29-
sudo apt-get update
30-
sudo apt-get install -y gcc-11 g++-11
31-
echo "CC=gcc-11" >> $GITHUB_ENV
32-
echo "CXX=g++-11" >> $GITHUB_ENV
28+
- name: Install build dependencies
29+
run: sudo apt-get install ninja-build libc++-18-dev libc++abi-18-dev
3330

34-
# Main cppfront library
35-
- name: Configure cppfront
36-
run: cmake -G Ninja -S . -B build/cppfront -DCMAKE_BUILD_TYPE=Release
37-
- name: Build cppfront
38-
run: cmake --build build/cppfront --config Release
39-
- name: Install cppfront locally
40-
run: cmake --install build/cppfront --config Release --prefix _local
31+
- name: Run test script
32+
timeout-minutes: 12
33+
run: ./test-all.sh
34+
env:
35+
CC: ${{ matrix.CC }}
36+
CXX: ${{ matrix.CXX }}
37+
CXXFLAGS: ${{ matrix.CXXFLAGS }}
38+
test-windows:
39+
name: Test Windows
40+
runs-on: windows-2022
41+
steps:
42+
- uses: actions/checkout@v4
43+
with:
44+
submodules: true
45+
46+
- name: Run test script
47+
timeout-minutes: 12
48+
run: ./test-all.ps1
49+
test-macos:
50+
name: Test macOS
51+
runs-on: macos-14
52+
env:
53+
CC: /opt/homebrew/opt/llvm@18/bin/clang
54+
CXX: /opt/homebrew/opt/llvm@18/bin/clang++
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
submodules: true
4159

42-
# Regression tests
43-
- name: Configure regression tests
44-
run: >
45-
cmake -G Ninja -S regression-tests -B build/regression-tests -DCMAKE_BUILD_TYPE=Release
46-
"-DCMAKE_PREFIX_PATH=${{github.workspace}}/_local"
47-
- name: Build regression tests
48-
run: cmake --build build/regression-tests --config Release
49-
- name: Run regression tests
50-
run: ctest --output-on-failure -C Release -j 2
51-
working-directory: build/regression-tests
60+
- name: Install build dependencies
61+
run: brew install ninja llvm@18
5262

53-
# Example
54-
- name: Configure example
55-
run: >
56-
cmake -G Ninja -S example -B build/example -DCMAKE_BUILD_TYPE=Release
57-
"-DCMAKE_PREFIX_PATH=${{github.workspace}}/_local"
58-
- name: Build example
59-
run: cmake --build build/example --config Release
60-
- name: Run example
61-
run: ./build/example/main && cmake -E cat xyzzy
63+
- name: Run test script
64+
timeout-minutes: 12
65+
run: ./test-all.sh

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "cppfront"]
22
path = cppfront
3-
url = git@github.com:hsutter/cppfront.git
3+
url = https://github.com/hsutter/cppfront.git

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
cmake_minimum_required(VERSION 3.23)
1+
cmake_minimum_required(VERSION 3.29)
22
project(
33
cppfront
44
LANGUAGES CXX
5-
VERSION 0.3.0
5+
VERSION 0.4.0
66
)
77

88
##

LICENSE.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright 2024 Alex Reinking
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
[![CI](https://github.com/modern-cmake/cppfront/actions/workflows/ci.yml/badge.svg)](https://github.com/modern-cmake/cppfront/actions/workflows/ci.yml)
44

5-
This is a wrapper around Herb Sutter's [cppfront](https://github.com/hsutter/cppfront)
5+
This is a wrapper around Herb
6+
Sutter's [cppfront](https://github.com/hsutter/cppfront)
67
compiler. Go there to learn more about that project.
78

8-
This repository adds a CMake build with some "magic" helpers to make it easier to use cpp2.
9+
This repository adds a CMake build with some "magic" helpers to make it easier
10+
to use cpp2.
911

10-
Requires CMake 3.23+.
12+
Requires CMake 3.29+. Will soon require 3.30 for better native module support.
1113

12-
**Disclaimer:** As `cppfront` is highly experimental, expect abrupt, backwards-incompatible changes to be made here,
13-
too. This isn't a production-ready ecosystem, and breaking changes will be made if they improve the overall project.
14-
We're on [major-version 0](https://semver.org/#spec-item-4) for the foreseeable future.
14+
**Disclaimer:** As `cppfront` is highly experimental, expect abrupt,
15+
backwards-incompatible changes to be made here, too. This isn't a
16+
production-ready ecosystem, and breaking changes will be made if they improve
17+
the overall project. We're on [major-version 0] for the foreseeable future.
1518

1619
**Note:** This work might one day be merged upstream. The open pull request is
1720
here: https://github.com/hsutter/cppfront/pull/15
1821

22+
PRs are welcome, but please know CMake well.
23+
1924
## Getting started
2025

2126
See the [example](/example) for a full example project.
@@ -35,7 +40,7 @@ $ cmake --build build --target install
3540
Now just write your project like normal:
3641

3742
```cmake
38-
cmake_minimum_required(VERSION 3.23)
43+
cmake_minimum_required(VERSION 3.29)
3944
project(example)
4045
4146
find_package(cppfront REQUIRED)
@@ -44,7 +49,14 @@ add_executable(main main.cpp2)
4449
```
4550

4651
And that's literally it. Any targets with a `.cpp2` source will automatically
47-
get custom commands added to them.
52+
get custom commands added to them. They will also be scanned for modules by
53+
CMake; this requires you to use a compiler that supports this. See
54+
the [cxx-modules] documentation for more detail. As of CMake 3.29, this
55+
includes:
56+
57+
> * MSVC toolset 14.34 and newer (provided with Visual Studio 17.4 and newer)
58+
> * LLVM/Clang 16.0 and newer
59+
> * GCC 14 (for the in-development branch, after 2023-09-20) and newer
4860
4961
### FetchContent
5062

@@ -54,7 +66,7 @@ chance it will be wonky.
5466
Here's the code.
5567

5668
```cmake
57-
cmake_minimum_required(VERSION 3.23)
69+
cmake_minimum_required(VERSION 3.29)
5870
project(example)
5971
6072
include(FetchContent)
@@ -73,45 +85,51 @@ add_executable(main main.cpp2)
7385
The same automatic configuration will happen here, too. Though since
7486
`FetchContent_MakeAvailable` will only run our `CMakeLists.txt` once, the magic
7587
can only happen in the first directory to include it. Thus, you should probably
76-
explicitly run `cppfront_enable(TARGETS main)` and add `set(CPPFRONT_NO_MAGIC 1)`
77-
if you want your project to be consumable via FetchContent. Blech.
88+
explicitly run `cppfront_enable(TARGETS main)` and
89+
add `set(CPPFRONT_NO_MAGIC 1)` if you want your project to be consumable via
90+
FetchContent. Blech.
7891

7992
You can, of course, use this repo as a submodule and call `add_subdirectory`
80-
rather than using `FetchContent`. It's basically the same except FC has some
81-
overriding mechanism now, as of 3.24.
93+
rather than using `FetchContent`. It's basically the same except FetchContent
94+
can be overridden using `FIND_PACKAGE_ARGS`.
8295

83-
I won't personally address issues for FetchContent users. PRs are welcome, but
84-
please know CMake well.
96+
I won't personally address issues for FetchContent users.
8597

8698
## CMake documentation
8799

88-
No matter how you use this CMake build, it exposes the following points of configuration:
100+
No matter how you use this CMake build, it exposes the following points of
101+
configuration:
89102

90103
### Targets
91104

92105
* `cppfront::cppfront` -- this is the executable for the cppfront compiler
93-
* `cppfront::cpp2util` -- this is an `INTERFACE` library providing the path to the `cpp2util.h` runtime header.
106+
* `cppfront::cpp2util` -- this is an `INTERFACE` library providing the path to
107+
the `cpp2util.h` runtime header.
94108

95109
### Options
96110

97111
Universal:
98112

99-
* `CPPFRONT_NO_MAGIC` -- off by default. When enabled, skips the automatic `cpp2`-to-`cpp` translation.
100-
* `CPPFRONT_FLAGS` -- a semicolon-separated list of additional flags to pass to `cppfront`. For now, these are assumed
101-
to be universal to a project, and it is not supported to change them after the package has loaded, whether
113+
* `CPPFRONT_NO_MAGIC` -- off by default. When enabled, skips the automatic
114+
`cpp2`-to-`cpp` translation.
115+
* `CPPFRONT_FLAGS` -- a semicolon-separated list of additional flags to pass
116+
to `cppfront`. For now, these are assumed to be universal to a project, and it
117+
is not supported to change them after the package has loaded, whether
102118
via `find_package`, `add_subdirectory`, FetchContent, or any other mechanism.
103119

104120
FetchContent-only:
105121

106-
* `CPPFRONT_NO_SYSTEM` -- off by default. When enabled, skips marking the `cpp2util.h` header as `SYSTEM`, meaning that
107-
warnings generated by that header will be shown.
108-
* `CPPFRONT_INSTALL_RULES` -- off by default. When enabled, runs the `install()` and packaging rules. Everything is
109-
placed in a component named `cppfront`.
122+
* `CPPFRONT_NO_SYSTEM` -- off by default. When enabled, skips marking
123+
the `cpp2util.h` header as `SYSTEM`, meaning that warnings generated by that
124+
header will be shown.
125+
* `CPPFRONT_INSTALL_RULES` -- off by default. When enabled, runs the `install()`
126+
and packaging rules. Everything is placed in a component named `cppfront`.
110127

111128
### Variables
112129

113-
* `CPPFRONT_EXECUTABLE` -- `find_package`-only. This is the absolute path to the `cppfront` executable file. This is
114-
sometimes useful in limited scenarios where neither the `cppfront::cppfront` target, nor
130+
* `CPPFRONT_EXECUTABLE` -- `find_package`-only. This is the absolute path to
131+
the `cppfront` executable file. This is sometimes useful in limited scenarios
132+
where neither the `cppfront::cppfront` target, nor
115133
the `$<TARGET_FILE:cppfront::cppfront>` generator expression can be used.
116134

117135
### Functions
@@ -120,8 +138,9 @@ FetchContent-only:
120138
cppfront_generate_cpp(<OUTVAR> <cpp2 files>...)
121139
```
122140

123-
Writes to the variable named by `OUTVAR` a list of absolute paths to the generated `.cpp` files associated with
124-
each `.cpp2` file in the arguments list. A hashing scheme prevents `cppfront` from running on the same `.cpp2` file
141+
Writes to the variable named by `OUTVAR` a list of absolute paths to the
142+
generated `.cpp` files associated with each `.cpp2` file in the arguments list.
143+
A hashing scheme prevents `cppfront` from running on the same `.cpp2` file
125144
multiple times.
126145

127146
```cmake
@@ -130,13 +149,20 @@ cppfront_enable(
130149
)
131150
```
132151

133-
Scans the `SOURCES` properties for each target in `<targets>` for entries ending in `.cpp2`. These are passed
134-
to `cppfront_generate_cpp` and the results are added to the target automatically. When `CPPFRONT_NO_MAGIC` is
135-
unset (i.e. by default), this command runs on all targets in the directory that imported this package at the end of
136-
processing the directory.
152+
Scans the `SOURCES` properties for each target in `<targets>` for entries ending
153+
in `.cpp2`. These are passed to `cppfront_generate_cpp` and the results are
154+
added to the target automatically. When `CPPFRONT_NO_MAGIC` is unset (i.e. by
155+
default), this command runs on all targets in the directory that imported this
156+
package at the end of processing the directory.
137157

138158
### Developers
139159

140-
The CMake project `regression-tests/CMakeLists.txt` runs the test suite of cppfront.
141-
See "Regression tests" at [`./.github/workflows/ci.yml`](./.github/workflows/ci.yml) for how to set it up.
142-
To have the test results updated, configure with `-DCPPFRONT_DEVELOPING=TRUE`.
160+
The CMake project `regression-tests/CMakeLists.txt` runs the test suite of
161+
cppfront. Read [`test-all.sh`][test-script] to see how to set it up. To have the
162+
test results updated, configure with `-DCPPFRONT_DEVELOPING=TRUE`.
163+
164+
[cxx-modules]: https://cmake.org/cmake/help/v3.29/manual/cmake-cxxmodules.7.html
165+
166+
[major-version-0]: https://semver.org/#spec-item-4
167+
168+
[test-script]: ./test-all.sh

cmake/CppfrontHelpers.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function(cppfront_enable)
7272
target_link_libraries("${tgt}" PRIVATE cppfront::cpp2util)
7373
cppfront_generate_cpp(cpp1sources ${sources})
7474
target_sources("${tgt}" PRIVATE ${cpp1sources})
75+
set_source_files_properties(${cpp1sources} PROPERTIES CXX_SCAN_FOR_MODULES ON)
7576
endif ()
7677
endforeach ()
7778
endfunction()

cmake/cppfront-config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.23)
1+
cmake_minimum_required(VERSION 3.29)
22
@PACKAGE_INIT@
33

44
include("${CMAKE_CURRENT_LIST_DIR}/cppfront-targets.cmake")

cppfront

Submodule cppfront updated 2946 files

example/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.23)
1+
cmake_minimum_required(VERSION 3.29)
22
project(cpp2-example)
33

44
find_package(cppfront REQUIRED)

0 commit comments

Comments
 (0)