This project wraps the cppfront repository in a CMake build.
It also acts as a compatibility wrapper for my gcmake-rust tool, so that cppfront can be used out of the box.
As of commit 8dd89ec8c9cfe9633286b2768ad0404455e342c7,
the latest MinGW ld.exe (GNU binutils 2.40) distributed by msys2 fails to link cppfront.exe when
compiling with optimizations off (Debug mode). If you're building in Debug mode with MinGW g++,
you must use the -fuse-ld=lld
flag to use LLVM's lld linker in place of ld (need to install Clang first).
If using GCMake, set the CMake
options -DGCMAKE_ADDITIONAL_COMPILER_FLAGS='fuse-ld=lld'
and
-DGCMAKE_ADDITIONAL_LINK_TIME_FLAGS='-fuse-ld=lld'
. Otherwise, set the CMake option
-DCPPFRONT_ADDITIONAL_COMPILER_FLAGS='-fuse-ld=lld'
.
git clone 'git@github.com:scupit/cppfront-cmake-wrapper.git'
cd cppfront-cmake-wrapper
cmake -B build/ # ... any other CMake options such as -G 'Ninja'
cmake --build build/ --parallel
sudo cmake --install build/ # Or run in an Administrator prompt in Windows
Side note: check out gsudo for a Windows version
of the sudo
command. It allows me to natively use sudo
from PowerShell on Windows, so I don't
have to run a whole separate shell instance as Administrator just to run the CMake install step.
Option | Default Value | Description |
---|---|---|
EMBED_CPPFRONT | ON |
Whether to clone and build cppfront. When set to OFF, CMake will try to find an existing cppfront installation on the system using find_package instead. This option is really only for internal use by gcmake-rust, and should be left ON . |
CPPFRONT_INSTALL | ON when building as the main project, OFF otherwise |
When ON , configures installation information so that cppfront can be installed on the system just by running cmake --install your-build-dir/ . |
CPPFRONT_BUILD_EXAMPLE | ON when building as the main project, OFF otherwise |
When ON , builds the example/ project which only uses .cpp2 files for implementation. |
These targets are always provided when embedding cppfront or by finding it using the provided Find module Findcppfront.cmake
Target | Type | Description |
---|---|---|
cppfront::compiler | Executable | The cppfront compiler executable (cppfront.exe, for example). This can be used as the COMMAND in calls to add_custom_command and add_custom_target. |
cppfront::artifacts | Interface Library | Used to pass along build information needed by files cppfront generates. This includes "include directories" (include/cpp2util.h), flags, c++ standards, etc.. cppfront::artifacts should be PRIVATE linked to any target which is built using cpp files generated by cppfront. target_link_libraries is what you want. |
EmbedCppFront.cmake contains the core script which clones and builds cppfront as part of your project. To use, just copy the file into your project's cmake/ directory and call
include( cmake/EmbedCppFront.cmake )
inside your toplevel CMakeLists.txt. It should work out of the box.
Findcppfront.cmake is a CMake Find Module. When invoked using find_package, CMake will look for an existing cppfront installation on your system and will define the provided cppfront targets if found. To use, copy the file into your project's cmake/ directory. In your toplevel CMakeLists.txt, add the CMake directory to your module search path using
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
Then call find_package:
find_package( cppfront MODULE )
# Use this one if cppfront is required.
# find_package( cppfront MODULE REQUIRED )
This should work out of the box.