Skip to content

Big maintenance update #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 49 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
name: CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches: [ main ]
pull_request:
jobs:
test:
name: test ${{ matrix.os }}
test-linux:
name: Test Linux ${{ matrix.CC }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
os: [
windows-latest,
# macos-latest, # cppfront is currently broken on AppleClang
ubuntu-latest,
]
runs-on: ${{ matrix.os }}
include:
# Clang 18 is broken for some reason
# - CC: clang-18
# CXX: clang++-18
# CXXFLAGS: -stdlib=libc++
- CC: gcc-14
CXX: g++-14
steps:
# System set-up
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ilammy/msvc-dev-cmd@v1
- uses: lukka/get-cmake@latest

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

# Main cppfront library
- name: Configure cppfront
run: cmake -G Ninja -S . -B build/cppfront -DCMAKE_BUILD_TYPE=Release
- name: Build cppfront
run: cmake --build build/cppfront --config Release
- name: Install cppfront locally
run: cmake --install build/cppfront --config Release --prefix _local
- name: Run test script
timeout-minutes: 12
run: ./test-all.sh
env:
CC: ${{ matrix.CC }}
CXX: ${{ matrix.CXX }}
CXXFLAGS: ${{ matrix.CXXFLAGS }}
test-windows:
name: Test Windows
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Run test script
timeout-minutes: 12
run: ./test-all.ps1
test-macos:
name: Test macOS
runs-on: macos-14
env:
CC: /opt/homebrew/opt/llvm@18/bin/clang
CXX: /opt/homebrew/opt/llvm@18/bin/clang++
steps:
- uses: actions/checkout@v4
with:
submodules: true

# Regression tests
- name: Configure regression tests
run: >
cmake -G Ninja -S regression-tests -B build/regression-tests -DCMAKE_BUILD_TYPE=Release
"-DCMAKE_PREFIX_PATH=${{github.workspace}}/_local"
- name: Build regression tests
run: cmake --build build/regression-tests --config Release
- name: Run regression tests
run: ctest --output-on-failure -C Release -j 2
working-directory: build/regression-tests
- name: Install build dependencies
run: brew install ninja llvm@18

# Example
- name: Configure example
run: >
cmake -G Ninja -S example -B build/example -DCMAKE_BUILD_TYPE=Release
"-DCMAKE_PREFIX_PATH=${{github.workspace}}/_local"
- name: Build example
run: cmake --build build/example --config Release
- name: Run example
run: ./build/example/main && cmake -E cat xyzzy
- name: Run test script
timeout-minutes: 12
run: ./test-all.sh
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cppfront"]
path = cppfront
url = git@github.com:hsutter/cppfront.git
url = https://github.com/hsutter/cppfront.git
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.29)
project(
cppfront
LANGUAGES CXX
VERSION 0.3.0
VERSION 0.4.0
)

##
Expand Down
11 changes: 11 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright 2024 Alex Reinking

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

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.

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.

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.
96 changes: 61 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

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

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

This repository adds a CMake build with some "magic" helpers to make it easier to use cpp2.
This repository adds a CMake build with some "magic" helpers to make it easier
to use cpp2.

Requires CMake 3.23+.
Requires CMake 3.29+. Will soon require 3.30 for better native module support.

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

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

PRs are welcome, but please know CMake well.

## Getting started

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

```cmake
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.29)
project(example)

find_package(cppfront REQUIRED)
Expand All @@ -44,7 +49,14 @@ add_executable(main main.cpp2)
```

And that's literally it. Any targets with a `.cpp2` source will automatically
get custom commands added to them.
get custom commands added to them. They will also be scanned for modules by
CMake; this requires you to use a compiler that supports this. See
the [cxx-modules] documentation for more detail. As of CMake 3.29, this
includes:

> * MSVC toolset 14.34 and newer (provided with Visual Studio 17.4 and newer)
> * LLVM/Clang 16.0 and newer
> * GCC 14 (for the in-development branch, after 2023-09-20) and newer

### FetchContent

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

```cmake
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.29)
project(example)

include(FetchContent)
Expand All @@ -73,45 +85,51 @@ add_executable(main main.cpp2)
The same automatic configuration will happen here, too. Though since
`FetchContent_MakeAvailable` will only run our `CMakeLists.txt` once, the magic
can only happen in the first directory to include it. Thus, you should probably
explicitly run `cppfront_enable(TARGETS main)` and add `set(CPPFRONT_NO_MAGIC 1)`
if you want your project to be consumable via FetchContent. Blech.
explicitly run `cppfront_enable(TARGETS main)` and
add `set(CPPFRONT_NO_MAGIC 1)` if you want your project to be consumable via
FetchContent. Blech.

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

I won't personally address issues for FetchContent users. PRs are welcome, but
please know CMake well.
I won't personally address issues for FetchContent users.

## CMake documentation

No matter how you use this CMake build, it exposes the following points of configuration:
No matter how you use this CMake build, it exposes the following points of
configuration:

### Targets

* `cppfront::cppfront` -- this is the executable for the cppfront compiler
* `cppfront::cpp2util` -- this is an `INTERFACE` library providing the path to the `cpp2util.h` runtime header.
* `cppfront::cpp2util` -- this is an `INTERFACE` library providing the path to
the `cpp2util.h` runtime header.

### Options

Universal:

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

FetchContent-only:

* `CPPFRONT_NO_SYSTEM` -- off by default. When enabled, skips marking the `cpp2util.h` header as `SYSTEM`, meaning that
warnings generated by that header will be shown.
* `CPPFRONT_INSTALL_RULES` -- off by default. When enabled, runs the `install()` and packaging rules. Everything is
placed in a component named `cppfront`.
* `CPPFRONT_NO_SYSTEM` -- off by default. When enabled, skips marking
the `cpp2util.h` header as `SYSTEM`, meaning that warnings generated by that
header will be shown.
* `CPPFRONT_INSTALL_RULES` -- off by default. When enabled, runs the `install()`
and packaging rules. Everything is placed in a component named `cppfront`.

### Variables

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

### Functions
Expand All @@ -120,8 +138,9 @@ FetchContent-only:
cppfront_generate_cpp(<OUTVAR> <cpp2 files>...)
```

Writes to the variable named by `OUTVAR` a list of absolute paths to the generated `.cpp` files associated with
each `.cpp2` file in the arguments list. A hashing scheme prevents `cppfront` from running on the same `.cpp2` file
Writes to the variable named by `OUTVAR` a list of absolute paths to the
generated `.cpp` files associated with each `.cpp2` file in the arguments list.
A hashing scheme prevents `cppfront` from running on the same `.cpp2` file
multiple times.

```cmake
Expand All @@ -130,13 +149,20 @@ cppfront_enable(
)
```

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

### Developers

The CMake project `regression-tests/CMakeLists.txt` runs the test suite of cppfront.
See "Regression tests" at [`./.github/workflows/ci.yml`](./.github/workflows/ci.yml) for how to set it up.
To have the test results updated, configure with `-DCPPFRONT_DEVELOPING=TRUE`.
The CMake project `regression-tests/CMakeLists.txt` runs the test suite of
cppfront. Read [`test-all.sh`][test-script] to see how to set it up. To have the
test results updated, configure with `-DCPPFRONT_DEVELOPING=TRUE`.

[cxx-modules]: https://cmake.org/cmake/help/v3.29/manual/cmake-cxxmodules.7.html

[major-version-0]: https://semver.org/#spec-item-4

[test-script]: ./test-all.sh
1 change: 1 addition & 0 deletions cmake/CppfrontHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function(cppfront_enable)
target_link_libraries("${tgt}" PRIVATE cppfront::cpp2util)
cppfront_generate_cpp(cpp1sources ${sources})
target_sources("${tgt}" PRIVATE ${cpp1sources})
set_source_files_properties(${cpp1sources} PROPERTIES CXX_SCAN_FOR_MODULES ON)
endif ()
endforeach ()
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion cmake/cppfront-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.29)
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/cppfront-targets.cmake")
Expand Down
2 changes: 1 addition & 1 deletion cppfront
Submodule cppfront updated 2946 files
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.29)
project(cpp2-example)

find_package(cppfront REQUIRED)
Expand Down
Loading
Loading