2
2
3
3
[ ![ CI] ( https://github.com/modern-cmake/cppfront/actions/workflows/ci.yml/badge.svg )] ( https://github.com/modern-cmake/cppfront/actions/workflows/ci.yml )
4
4
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 )
6
7
compiler. Go there to learn more about that project.
7
8
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.
9
11
10
- Requires CMake 3.23+ .
12
+ Requires CMake 3.29+. Will soon require 3.30 for better native module support .
11
13
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.
15
18
16
19
** Note:** This work might one day be merged upstream. The open pull request is
17
20
here: https://github.com/hsutter/cppfront/pull/15
18
21
22
+ PRs are welcome, but please know CMake well.
23
+
19
24
## Getting started
20
25
21
26
See the [ example] ( /example ) for a full example project.
@@ -35,7 +40,7 @@ $ cmake --build build --target install
35
40
Now just write your project like normal:
36
41
37
42
``` cmake
38
- cmake_minimum_required(VERSION 3.23 )
43
+ cmake_minimum_required(VERSION 3.29 )
39
44
project(example)
40
45
41
46
find_package(cppfront REQUIRED)
@@ -44,7 +49,14 @@ add_executable(main main.cpp2)
44
49
```
45
50
46
51
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
48
60
49
61
### FetchContent
50
62
@@ -54,7 +66,7 @@ chance it will be wonky.
54
66
Here's the code.
55
67
56
68
``` cmake
57
- cmake_minimum_required(VERSION 3.23 )
69
+ cmake_minimum_required(VERSION 3.29 )
58
70
project(example)
59
71
60
72
include(FetchContent)
@@ -73,45 +85,51 @@ add_executable(main main.cpp2)
73
85
The same automatic configuration will happen here, too. Though since
74
86
` FetchContent_MakeAvailable ` will only run our ` CMakeLists.txt ` once, the magic
75
87
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.
78
91
79
92
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 ` .
82
95
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.
85
97
86
98
## CMake documentation
87
99
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:
89
102
90
103
### Targets
91
104
92
105
* ` 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.
94
108
95
109
### Options
96
110
97
111
Universal:
98
112
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
102
118
via ` find_package ` , ` add_subdirectory ` , FetchContent, or any other mechanism.
103
119
104
120
FetchContent-only:
105
121
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 ` .
110
127
111
128
### Variables
112
129
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
115
133
the ` $<TARGET_FILE:cppfront::cppfront> ` generator expression can be used.
116
134
117
135
### Functions
@@ -120,8 +138,9 @@ FetchContent-only:
120
138
cppfront_generate_cpp(<OUTVAR> <cpp2 files>...)
121
139
```
122
140
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
125
144
multiple times.
126
145
127
146
``` cmake
@@ -130,13 +149,20 @@ cppfront_enable(
130
149
)
131
150
```
132
151
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.
137
157
138
158
### Developers
139
159
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
0 commit comments