mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
82 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f4b376e42 | |||
| fcbf937c49 | |||
| e609c8a48f | |||
| 735898dbac | |||
| f7126b0158 | |||
| b6702714eb | |||
| efa4f716c2 | |||
| 76b7b8e778 | |||
| 501b26ced5 | |||
| 5bc36275ad | |||
| 35c837a181 | |||
| 710dfa4963 | |||
| c49ee6bafe | |||
| 368273bab2 | |||
| b1249af365 | |||
| ea2ff31b5a | |||
| a32eb66df4 | |||
| 9b85833240 | |||
| ccb3d0b9ef | |||
| 49cdab39bd | |||
| e318139314 | |||
| 0f2a9a55fb | |||
| 38cec2d5d1 | |||
| 3caf593438 | |||
| c94dbd6416 | |||
| a1eaf601c6 | |||
| 10320c8e55 | |||
| 45e12c8d98 | |||
| e12ebc060d | |||
| c6e3fc159f | |||
| dc6f306d9c | |||
| e08bd5a311 | |||
| 068977e2f5 | |||
| 73147747a4 | |||
| a64fa9cc34 | |||
| eb6ccb39ee | |||
| 91dd8ce51f | |||
| efbfca27bd | |||
| 78bcf2acf7 | |||
| 83559cc5d4 | |||
| 5d85cc83e3 | |||
| dea41d80b5 | |||
| b52cf5b241 | |||
| e9480a625f | |||
| 13a7a8788a | |||
| 45ca74099c | |||
| ae3d73896e | |||
| 57042565d1 | |||
| d02ee3ed24 | |||
| 4a15d2ba55 | |||
| 87c0295f93 | |||
| a608e6b778 | |||
| 523f5f4a8a | |||
| 510cf71af5 | |||
| 87d90138b4 | |||
| 50615e0c27 | |||
| 42ed3048b3 | |||
| b0a1d79a42 | |||
| 5882bc082d | |||
| a90b3c6095 | |||
| 0a887c08f8 | |||
| 9f2cfe4083 | |||
| 15ad1dc6a7 | |||
| dabffeaed9 | |||
| 59fe5c38b8 | |||
| dcdc7ac410 | |||
| 88377a8bfb | |||
| 3a9685be82 | |||
| 5576789c18 | |||
| a362978f99 | |||
| a2f33297e4 | |||
| 674c976647 | |||
| 714a666e88 | |||
| d613e433d5 | |||
| 7c828d8740 | |||
| 559f750c89 | |||
| 4b6b72874e | |||
| 6bffa7cc71 | |||
| f415b432ed | |||
| 6c46664336 | |||
| f32aac63aa | |||
| 33d4cc4156 |
@@ -13,6 +13,7 @@ AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: None
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
|
||||
@@ -10,19 +10,16 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-2022, macos-latest, ubuntu-20.04]
|
||||
os: [windows-2022, macos-latest, ubuntu-22.04]
|
||||
env:
|
||||
BUILD_TYPE: 'Release'
|
||||
CMAKE_GENERATOR: 'Ninja'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Ninja
|
||||
uses: seanmiddleditch/gha-setup-ninja@6263846cf3c17009dfc81604efabae16044fc074 # master
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Visual Studio Development Environment
|
||||
uses: ilammy/msvc-dev-cmd@cec98b9d092141f74527d0afa6feb2af698cfe89 # v1.12.1
|
||||
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.1
|
||||
|
||||
- name: Tag cmkr.cmake
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
@@ -45,27 +42,27 @@ jobs:
|
||||
ctest -C ${{ env.BUILD_TYPE }} --verbose
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-${{ matrix.os }}
|
||||
path: install/bin/*
|
||||
|
||||
- name: Get lowercase OS name
|
||||
id: osname
|
||||
uses: ASzc/change-string-case-action@07c1e24a97f0951e13f88870b99c058fcf0b14cf # v5
|
||||
uses: ASzc/change-string-case-action@ccb130a4e483d3e86287289183704dc9bf53e77e # master 2024-04-05
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
string: ${{ runner.os }}
|
||||
|
||||
- name: Compress artifacts
|
||||
uses: vimtor/action-zip@26a249fb00d43ca98dad77a4b3838025fc226aa1 # v1.1
|
||||
uses: vimtor/action-zip@1379ea20d4c5705669ba81fd626dd01b1c738f26 # v1.2
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
files: install/bin/
|
||||
dest: ${{ github.event.repository.name }}-${{ steps.osname.outputs.lowercase }}.zip
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
|
||||
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2.2.2
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') || contains(github.ref, '-pre') }}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
name: lint
|
||||
|
||||
on: [push]
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
# Skip building pull requests from the same repository
|
||||
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: clang-format
|
||||
id: clang-format
|
||||
uses: DoozyX/clang-format-lint-action@c3b2c943e924028b93a707a5b1b017976ab8d50c # v0.15
|
||||
uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 # v0.18.2
|
||||
with:
|
||||
exclude: './third_party'
|
||||
extensions: 'c,h,cpp,hpp'
|
||||
@@ -27,11 +29,13 @@ jobs:
|
||||
exit 1
|
||||
|
||||
editorconfig:
|
||||
# Skip building pull requests from the same repository
|
||||
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run editorconfig-checker
|
||||
uses: editorconfig-checker/action-editorconfig-checker@d4fca16fc71adef10fbe101903b654449fa9570c # master 2022-03-15
|
||||
uses: editorconfig-checker/action-editorconfig-checker@27dd658c2b1282c7f1f4dc242cdf0f6d8af728ab # master 2025-05-30
|
||||
|
||||
Generated
+12
-13
@@ -1,7 +1,7 @@
|
||||
# This file is automatically generated from cmake.toml - DO NOT EDIT
|
||||
# See https://github.com/build-cpp/cmkr for more information
|
||||
|
||||
cmake_minimum_required(VERSION 2.8...3.8)
|
||||
cmake_minimum_required(VERSION 2.8...3.31)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build")
|
||||
@@ -22,7 +22,7 @@ project(cmkr
|
||||
LANGUAGES
|
||||
CXX
|
||||
VERSION
|
||||
0.2.29
|
||||
0.2.45
|
||||
DESCRIPTION
|
||||
"CMakeLists generator from TOML"
|
||||
)
|
||||
@@ -58,12 +58,9 @@ generate_documentation()
|
||||
|
||||
# Target: cmkr
|
||||
set(cmkr_SOURCES
|
||||
"src/arguments.cpp"
|
||||
"src/build.cpp"
|
||||
"src/cmake_generator.cpp"
|
||||
"src/help.cpp"
|
||||
"src/main.cpp"
|
||||
"src/project_parser.cpp"
|
||||
cmake.toml
|
||||
"cmake/cmkr.cmake"
|
||||
"cmake/version.hpp.in"
|
||||
"include/arguments.hpp"
|
||||
"include/build.hpp"
|
||||
"include/cmake_generator.hpp"
|
||||
@@ -71,9 +68,12 @@ set(cmkr_SOURCES
|
||||
"include/help.hpp"
|
||||
"include/literals.hpp"
|
||||
"include/project_parser.hpp"
|
||||
"cmake/cmkr.cmake"
|
||||
"cmake/version.hpp.in"
|
||||
cmake.toml
|
||||
"src/arguments.cpp"
|
||||
"src/build.cpp"
|
||||
"src/cmake_generator.cpp"
|
||||
"src/help.cpp"
|
||||
"src/main.cpp"
|
||||
"src/project_parser.cpp"
|
||||
)
|
||||
|
||||
add_executable(cmkr)
|
||||
@@ -94,7 +94,6 @@ target_link_libraries(cmkr PRIVATE
|
||||
ghc_filesystem
|
||||
mpark_variant
|
||||
ordered_map
|
||||
nlohmann_json
|
||||
)
|
||||
|
||||
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
|
||||
@@ -103,7 +102,7 @@ if(NOT CMKR_VS_STARTUP_PROJECT)
|
||||
endif()
|
||||
|
||||
set(CMKR_TARGET cmkr)
|
||||
generate_resources(${CMKR_TARGET})
|
||||
include("cmake/custom_targets.cmake")
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# cmkr
|
||||
|
||||
[](https://deepwiki.com/build-cpp/cmkr)
|
||||
|
||||
`cmkr`, pronounced "cmaker", is a modern build system based on [CMake](https://cmake.org/) and [TOML](https://toml.io).
|
||||
|
||||
`cmkr` parses `cmake.toml` files and generates a modern, idiomatic `CMakeLists.txt` for you. A minimal example:
|
||||
|
||||
+3
-6
@@ -1,10 +1,10 @@
|
||||
[cmake]
|
||||
version = "2.8...3.8"
|
||||
version = "2.8...3.31"
|
||||
cmkr-include = false
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.2.29"
|
||||
version = "0.2.45"
|
||||
description = "CMakeLists generator from TOML"
|
||||
languages = ["CXX"]
|
||||
include-after = [
|
||||
@@ -36,11 +36,8 @@ link-libraries = [
|
||||
"ghc_filesystem",
|
||||
"mpark_variant",
|
||||
"ordered_map",
|
||||
"nlohmann_json",
|
||||
]
|
||||
cmake-after = """
|
||||
generate_resources(${CMKR_TARGET})
|
||||
"""
|
||||
include-after = ["cmake/custom_targets.cmake"]
|
||||
|
||||
[[install]]
|
||||
targets = ["cmkr"]
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ include_guard()
|
||||
|
||||
# Change these defaults to point to your infrastructure if desired
|
||||
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
|
||||
set(CMKR_TAG "v0.2.29" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
set(CMKR_TAG "v0.2.45" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
set(CMKR_COMMIT_HASH "" CACHE STRING "cmkr git commit hash (optional)" FORCE)
|
||||
|
||||
# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
generate_resources(cmkr)
|
||||
|
||||
add_custom_target(regenerate-cmake
|
||||
COMMAND "$<TARGET_FILE:cmkr>" gen
|
||||
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
add_custom_target(run-tests
|
||||
COMMAND "${CMAKE_CTEST_COMMAND}" -C $<CONFIG>
|
||||
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/tests"
|
||||
)
|
||||
else()
|
||||
add_custom_target(run-tests
|
||||
COMMAND "${CMAKE_CTEST_COMMAND}"
|
||||
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/tests"
|
||||
)
|
||||
endif()
|
||||
+80
-13
@@ -6,7 +6,7 @@ nav_order: 1
|
||||
|
||||
# Basics
|
||||
|
||||
To effectively use cmkr it helps to understand the basic concepts of CMake.
|
||||
To effectively use cmkr it helps to understand the basic concepts of CMake. This page serves as an introduction to CMake for beginners. Links to the CMake documentation are included for reference.
|
||||
|
||||
## Projects
|
||||
|
||||
@@ -16,25 +16,41 @@ A CMake **project** is a collection of targets. In the context of libraries the
|
||||
|
||||
## Targets
|
||||
|
||||
The basic unit of CMake is called a **target**. A target (also referred to as [binary target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#binary-targets) in the CMake documentation) corresponds to an executable or library you can build. There are also [pseudo targets](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#pseudo-targets), but we ignore them for now.
|
||||
The basic unit of CMake is called a **target**. A target (also referred to as [binary target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#binary-targets) in the CMake documentation) corresponds to an executable or static/dynamic library you can build.
|
||||
|
||||
<sub>Visual Studio: a **target** corresponds to a _project_.</sub>
|
||||
|
||||
Most important target types:
|
||||
|
||||
|Type|Purpose|
|
||||
|-|-|
|
||||
|Executable|Program you run on your computer (`.exe`)|
|
||||
|Static library|Library code _compiled into_ the final executable (`.lib`, `.a`)|
|
||||
|Dynamic library|Library code loaded at runtime (`.dll`, `.so`, `.dylib`)|
|
||||
|Interface|Used for organizational purposes (common flags/includes/libraries)|
|
||||
|
||||
There are also other [pseudo targets](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#pseudo-targets), but they are not important for now.
|
||||
|
||||
## Target Properties
|
||||
|
||||
Targets have a collection of **properties** that describe how to build them.
|
||||
Targets have a collection of **properties** that describe how the compiler builds them.
|
||||
|
||||
Examples of properties:
|
||||
The most commonly-used properties:
|
||||
|
||||
- _Sources_: the `*.cpp` files used to build the target.
|
||||
- _Compile options_: Command line flags for the compiler.
|
||||
- _Link libraries_: The **dependencies** required to build this target.
|
||||
- [_Sources_](https://cmake.org/cmake/help/latest/command/target_sources.html): the `*.cpp` files used to build the target.
|
||||
- [_Include directories_](https://cmake.org/cmake/help/latest/command/target_include_directories.html): Paths to directories the compiler will search when doing `#include`.
|
||||
- [_Compile definitions_](https://cmake.org/cmake/help/latest/command/target_compile_definitions.html): Preprocessor macro definitions used for compilation (`-DMYOPTION`).
|
||||
- [_Compile options_](https://cmake.org/cmake/help/latest/command/target_compile_options.html): Command line flags for the compiler (platform/compiler specific).
|
||||
- [_Compile features_](https://cmake.org/cmake/help/latest/command/target_compile_features.html): C/C++ standard version to build with.
|
||||
- [_Link libraries_](https://cmake.org/cmake/help/latest/command/target_link_libraries.html): The **dependencies** required to build this target.
|
||||
- [_Link options_](https://cmake.org/cmake/help/latest/command/target_link_options.html): Command line flags for the linker (platform/linker specific).
|
||||
|
||||
<sub>See the [CMake documentation](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets) for an exhaustive list of target properties.</sub>
|
||||
|
||||
**Important**: The term **link** has a slightly different meaning in CMake than you might expect. In addition to adding a library to the command line of the linker, CMake also propagates properties of the target you link to.
|
||||
**Important**: The term **link** has a slightly different meaning in CMake than you might expect. In addition to adding a library to the command line, CMake also (transitively) propagates properties of the target you link to based on their _visibility_.
|
||||
|
||||
<sub>You can think of **linking** as _depending on_.</sub>
|
||||
You should think of **linking** in CMake as _depending on_.
|
||||
{:.info}
|
||||
|
||||
The propagation of properties depends on their **visibility**:
|
||||
|
||||
@@ -44,7 +60,7 @@ The propagation of properties depends on their **visibility**:
|
||||
|
||||
In practice you default to **private**, unless consumers of your library _require_ the property to build their target. In that case you use **public**.
|
||||
|
||||
### Example
|
||||
## Example
|
||||
|
||||
The most intuitive example is with _include directories_. Imagine there are two targets:
|
||||
|
||||
@@ -67,10 +83,61 @@ name = "DataProcessor"
|
||||
type = "static"
|
||||
sources = ["StringUtils/src/stringutils.cpp"]
|
||||
headers = ["StringUtils/include/stringutils.hpp"]
|
||||
include-directories = ["StringUtils/include"]
|
||||
include-directories = ["StringUtils/include"] # public (default for libraries)
|
||||
|
||||
[target.DataProcessor]
|
||||
type = "executable"
|
||||
sources = ["DataProcessor/src/main.cpp"]
|
||||
link-libraries = ["StringUtils"]
|
||||
```
|
||||
link-libraries = ["StringUtils"] # private (default for executables)
|
||||
```
|
||||
|
||||
The generated `CMakeLists.txt` (simplified) looks like this:
|
||||
|
||||
```cmake
|
||||
project(DataProcessor)
|
||||
|
||||
# Target: StringUtils
|
||||
add_library(StringUtils STATIC
|
||||
"StringUtils/include/stringutils.hpp"
|
||||
"StringUtils/src/stringutils.cpp"
|
||||
)
|
||||
target_include_directories(StringUtils PUBLIC
|
||||
"StringUtils/include"
|
||||
)
|
||||
|
||||
# Target: DataProcessor
|
||||
add_executable(DataProcessor
|
||||
"DataProcessor/src/main.cpp"
|
||||
)
|
||||
target_link_libraries(DataProcessor PRIVATE
|
||||
StringUtils
|
||||
)
|
||||
```
|
||||
|
||||
## CMake Phases
|
||||
|
||||
CMake works in three phases:
|
||||
1. **Configure**: Execute `CMakeLists.txt` (find dependencies, create targets, OS/compiler-specific conditions, etc).
|
||||
2. **Generate**: Generate build files (propagates target properties and handles [_generator expressions_](https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html)).
|
||||
3. **Build**: Execute the compiler to produce executables/libraries.
|
||||
|
||||
CMake keeps generated files separate from your source in a **build directory**. You specify a [**generator**](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html) (Visual Studio/Ninja) and [**build type**](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-configurations) (Debug/Release) during configuration.
|
||||
|
||||
```bash
|
||||
# Configure project and generate build files in build directory
|
||||
cmake -B build -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
# Build the project
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
We specify both `CMAKE_BUILD_TYPE` and `--config` to be compatible with generators that support multiple configurations at once ((like Visual Studio/Xcode/Ninja Multi-Config).
|
||||
{:.info}
|
||||
|
||||
**Build Types**:
|
||||
- `Debug`: No optimization, debug symbols
|
||||
- `Release`: Full optimization, no debug symbols
|
||||
- `RelWithDebInfo`: Medium optimizations, debug symbols
|
||||
- `MinSizeRel`: Optimize for size, no debug symbols
|
||||
|
||||
**Generators**: CMake auto-detects (Makefiles on Linux/macOS, Visual Studio on Windows), but you can specify explicitly with `-G` during the _configure_ step.
|
||||
|
||||
+69
-23
@@ -109,6 +109,13 @@ clang-any = "CMAKE_CXX_COMPILER_ID MATCHES \"Clang\" OR CMAKE_C_COMPILER_ID MATC
|
||||
root = "CMKR_ROOT_PROJECT"
|
||||
x64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
|
||||
x32 = "CMAKE_SIZEOF_VOID_P EQUAL 4"
|
||||
android = "ANDROID"
|
||||
apple = "APPLE"
|
||||
bsd = "BSD"
|
||||
cygwin = "CYGWIN"
|
||||
ios = "IOS"
|
||||
xcode = "XCODE"
|
||||
wince = "WINCE"
|
||||
```
|
||||
|
||||
## Subdirectories
|
||||
@@ -153,14 +160,20 @@ Variables emit a [`set`](https://cmake.org/cmake/help/latest/command/set.html) a
|
||||
|
||||
```toml
|
||||
[vcpkg]
|
||||
version = "2024.03.25"
|
||||
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.03.25.tar.gz"
|
||||
version = "2024.11.16"
|
||||
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.11.16.tar.gz"
|
||||
packages = ["fmt", "zlib"]
|
||||
overlay-ports = ["my-ports"]
|
||||
overlay-triplets = ["my-triplets"]
|
||||
```
|
||||
|
||||
The vcpkg `version` will automatically generate the `url` from the [official repository](https://github.com/microsoft/vcpkg/releases). For a custom registry you can specify your own `url` (and omit the `version`). You can browse available packages on [vcpkg.io](https://vcpkg.io/en/packages.html).
|
||||
The vcpkg `version` will automatically generate the `url` from the [official repository](https://github.com/microsoft/vcpkg/releases). For a custom registry you can specify your own `url` (and omit the `version`). You can browse available packages on [vcpkg.io](https://vcpkg.io/en/packages.html) or [vcpkg.link](https://vcpkg.link).
|
||||
|
||||
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
|
||||
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. To disable the [default features](https://learn.microsoft.com/en-us/vcpkg/concepts/default-features) you can do: `cpp-httplib[core,openssl]`
|
||||
|
||||
The `overlay-ports` feature allows you to embed vcpkg ports inside your project, without having to fork the main vcpkg registry or creating a custom registry. You can find more information in the relevant [documentation](https://learn.microsoft.com/en-us/vcpkg/concepts/overlay-ports). The `overlay-triplets` feature allows you to customize triplets and change the default behavior (for example always preferring static libraries on Windows). To specify both in one go you can do `[vcpkg].overlay = "vcpkg-overlay"`.
|
||||
|
||||
For a concrete example of all the features, take a look at the [vcpkg_template](https://github.com/build-cpp/vcpkg_template) repository.
|
||||
|
||||
## Packages
|
||||
|
||||
@@ -178,26 +191,28 @@ components = ["mycomponent"]
|
||||
**Note**: The `[fetch-content]` feature is unpolished and will likely change in a future release.
|
||||
|
||||
```toml
|
||||
# Include CMake project from git
|
||||
[fetch-content.gitcontent]
|
||||
condition = "mycondition"
|
||||
git = "https://github.com/myuser/gitcontent"
|
||||
tag = "v0.1"
|
||||
shallow = false
|
||||
shallow = false # shallow clone (--depth 1)
|
||||
system = false
|
||||
subdir = ""
|
||||
subdir = "" # folder containing CMakeLists.txt
|
||||
|
||||
# Include a CMake project from a URL
|
||||
[fetch-content.urlcontent]
|
||||
condition = "mycondition"
|
||||
url = "https://content-host.com/urlcontent.zip"
|
||||
# Other supported algorithms:
|
||||
# md5, sha1, sha224, sha256, sha384, sha512, sha3_224, sha3_256, sha3_384, sha3_512
|
||||
hash = "SHA1 502a4e25b8b209889c99c7fa0732102682c2e4ff"
|
||||
sha1 = "502a4e25b8b209889c99c7fa0732102682c2e4ff"
|
||||
|
||||
[fetch-content.svncontent]
|
||||
condition = "mycondition"
|
||||
svn = "https://svn-host.com/url"
|
||||
rev = "svn_rev"
|
||||
|
||||
[fetch-content.urlcontent]
|
||||
condition = "mycondition"
|
||||
url = "https://content-host.com/urlcontent.zip"
|
||||
# These are equivalent, supported algorithms:
|
||||
# md5, sha1, sha224, sha256, sha384, sha512, sha3_224, sha3_256, sha3_384, sha3_512
|
||||
hash = "SHA1 502a4e25b8b209889c99c7fa0732102682c2e4ff"
|
||||
sha1 = "502a4e25b8b209889c99c7fa0732102682c2e4ff"
|
||||
```
|
||||
|
||||
Table keys that match CMake variable names (`[A-Z_]+`) will be passed to the [`FetchContent_Declare`](https://cmake.org/cmake/help/latest/module/FetchContent.html#command:fetchcontent_declare) command.
|
||||
@@ -208,28 +223,28 @@ Table keys that match CMake variable names (`[A-Z_]+`) will be passed to the [`F
|
||||
[target.mytarget]
|
||||
condition = "mycondition"
|
||||
alias = "mytarget::mytarget"
|
||||
type = "static" # executable, shared (DLL), static, interface, object, library, custom
|
||||
type = "static" # executable, library, shared (DLL), static, interface, object, custom
|
||||
headers = ["src/mytarget.h"]
|
||||
sources = ["src/mytarget.cpp"]
|
||||
msvc-runtime = "" # dynamic (implicit default), static
|
||||
|
||||
# The keys below match the target_xxx CMake commands
|
||||
# Keys prefixed with private- will get PRIVATE visibility
|
||||
compile-definitions = [""]
|
||||
compile-definitions = [""] # preprocessor define (-DFOO)
|
||||
private-compile-definitions = [""]
|
||||
compile-features = [""]
|
||||
compile-features = [""] # C++ standard version (cxx_std_20)
|
||||
private-compile-features = [""]
|
||||
compile-options = [""]
|
||||
compile-options = [""] # compiler flags
|
||||
private-compile-options = [""]
|
||||
include-directories = [""]
|
||||
include-directories = [""] # include paths/directories
|
||||
private-include-directories = [""]
|
||||
link-directories = [""]
|
||||
link-directories = [""] # library directories
|
||||
private-link-directories = [""]
|
||||
link-libraries = [""]
|
||||
link-libraries = [""] # dependencies
|
||||
private-link-libraries = [""]
|
||||
link-options = [""]
|
||||
link-options = [""] # linker flags
|
||||
private-link-options = [""]
|
||||
precompile-headers = [""]
|
||||
precompile-headers = [""] # precompiled headers
|
||||
private-precompile-headers = [""]
|
||||
|
||||
cmake-before = """
|
||||
@@ -248,6 +263,35 @@ CXX_STANDARD_REQUIRED = true
|
||||
FOLDER = "MyFolder"
|
||||
```
|
||||
|
||||
A table mapping the cmkr features to the relevant CMake construct and the relevant documentation pages:
|
||||
|
||||
| cmkr | CMake construct | Description |
|
||||
| ---- | ----- | ----------- |
|
||||
| `alias` | [Alias Libraries](https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries) | Create an [alias target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#alias-targets), used for namespacing or clarity. |
|
||||
| `sources` | [`target_sources`](https://cmake.org/cmake/help/latest/command/target_sources.html) | Source files (`PRIVATE` except `interface` targets). |
|
||||
| `headers` | [`target_sources`](https://cmake.org/cmake/help/latest/command/target_sources.html) | For readability (and future packaging). |
|
||||
| `msvc-runtime` | [`MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html) | The [CMP0091](https://cmake.org/cmake/help/latest/policy/CMP0091.html) policy is set automatically. |
|
||||
| `compile-definitions` | [`target_compile_definitions`](https://cmake.org/cmake/help/latest/command/target_compile_definitions.html) | Adds a macro definition (define, `-DMYMACRO=XXX`). |
|
||||
| `compile-features` | [`target_compile_features`](https://cmake.org/cmake/help/latest/command/target_compile_features.html) | Specifies the C++ standard version (`cxx_std_20`). |
|
||||
| `compile-options` | [`target_compile_options`](https://cmake.org/cmake/help/latest/command/target_compile_options.html) | Adds compiler flags. |
|
||||
| `include-directories` | [`target_include_directories`](https://cmake.org/cmake/help/latest/command/target_include_directories.html) | Adds include directories. |
|
||||
| `link-directories` | [`target_link_directories`](https://cmake.org/cmake/help/latest/command/target_link_directories.html) | Adds library directories. |
|
||||
| `link-libraries` | [`target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) | Adds library dependencies. Use `::mylib` to make sure a target exists. |
|
||||
| `link-options` | [`target_link_options`](https://cmake.org/cmake/help/latest/command/target_link_options.html) | Adds linker flags. |
|
||||
| `precompile-headers` | [`target_precompile_headers`](https://cmake.org/cmake/help/latest/command/target_precompile_headers.html) | Specifies precompiled headers. |
|
||||
| `properties` | [`set_target_properties`](https://cmake.org/cmake/help/latest/command/set_target_properties.html) | See [properties on targets](https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets) for more information. |
|
||||
|
||||
The default [visibility](/basics) is as follows:
|
||||
|
||||
| Type | Visibility |
|
||||
| ------------ | ----------- |
|
||||
| `executable` | `PRIVATE` |
|
||||
| `library` | `PUBLIC` |
|
||||
| `shared` | `PUBLIC` |
|
||||
| `static` | `PUBLIC` |
|
||||
| `object` | `PUBLIC` |
|
||||
| `interface` | `INTERFACE` |
|
||||
|
||||
## Templates
|
||||
|
||||
To avoid repeating yourself you can create your own target type and use it in your targets:
|
||||
@@ -258,6 +302,7 @@ condition = "MYPROJECT_BUILD_EXAMPLES"
|
||||
type = "executable"
|
||||
link-libraries = ["myproject::mylib"]
|
||||
add-function = ""
|
||||
add-arguments = ["myoption"]
|
||||
pass-sources = false
|
||||
|
||||
# Properties from the template are merged with the ones here
|
||||
@@ -269,6 +314,7 @@ sources = ["src/myexample.cpp"]
|
||||
The properties declared on a `template` are the same as the ones you use for targets. The only exceptions are:
|
||||
|
||||
- `add-function`: Specifies a custom add function. Projects like [pybind11](https://pybind11.readthedocs.io/en/stable/cmake/index.html#new-findpython-mode) have their own `add_xxx` function, which you can specify here.
|
||||
- `add-arguments`: Arguments to pass to the `add-function` before the list of sources. See [cmake_parse_arguments](https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html) for more details.
|
||||
- `pass-sources`: Pass sources directly to the add function instead of using `target_sources`.
|
||||
|
||||
## Tests and installation (unfinished)
|
||||
|
||||
@@ -9,7 +9,7 @@ nav_order: 9
|
||||
|
||||
# Compiler flags
|
||||
|
||||
Example project that sets compiler/linker flags for various platforms.
|
||||
Example project that sets compiler flags and preprocessor defines for various platforms.
|
||||
|
||||
```toml
|
||||
[project]
|
||||
@@ -20,11 +20,14 @@ description = "Compiler flags"
|
||||
type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
msvc.compile-options = ["/W2"]
|
||||
msvc.compile-definitions = ["PLATFORM=\"msvc\""]
|
||||
gcc.compile-options = ["-Wall"]
|
||||
gcc.compile-definitions = ["PLATFORM=\"gcc\""]
|
||||
clang.compile-options = ["-Wall"]
|
||||
clang.compile-definitions = ["PLATFORM=\"clang\""]
|
||||
```
|
||||
|
||||
The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
|
||||
The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags and definitions depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
|
||||
|
||||
_Note_: In general you only want to specify flags _required_ to compile your code without errors.
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) from [GitHub](https://github.com)
|
||||
name = "fetch-content"
|
||||
description = "Fetching from git"
|
||||
|
||||
[fetch-content]
|
||||
fmt = { git = "https://github.com/fmtlib/fmt", tag = "7.1.3" }
|
||||
[fetch-content.fmt]
|
||||
git = "https://github.com/fmtlib/fmt"
|
||||
tag = "7.1.3"
|
||||
|
||||
[target.example]
|
||||
type = "executable"
|
||||
|
||||
@@ -9,7 +9,7 @@ nav_order: 4
|
||||
|
||||
# Dependencies from vcpkg
|
||||
|
||||
Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://vcpkg.io/) and links an `example` target to it:
|
||||
Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://github.com/microsoft/vcpkg) and links an `example` target to it:
|
||||
|
||||
```toml
|
||||
[project]
|
||||
@@ -17,13 +17,12 @@ name = "vcpkg"
|
||||
description = "Dependencies from vcpkg"
|
||||
|
||||
# See https://github.com/microsoft/vcpkg/releases for vcpkg versions
|
||||
# See https://vcpkg.io/en/packages.html for available packages
|
||||
# See https://vcpkg.io/en/packages or https://vcpkg.link for available packages
|
||||
[vcpkg]
|
||||
version = "2024.03.25"
|
||||
version = "2024.11.16"
|
||||
packages = ["fmt"]
|
||||
|
||||
[find-package]
|
||||
fmt = {}
|
||||
[find-package.fmt]
|
||||
|
||||
[target.example]
|
||||
type = "executable"
|
||||
|
||||
@@ -45,10 +45,15 @@ struct Vcpkg {
|
||||
struct Package {
|
||||
std::string name;
|
||||
std::vector<std::string> features;
|
||||
bool default_features = true;
|
||||
};
|
||||
|
||||
std::vector<Package> packages;
|
||||
|
||||
// https://github.com/Microsoft/vcpkg-docs/blob/main/vcpkg/users/buildsystems/cmake-integration.md
|
||||
std::vector<std::string> overlay_ports;
|
||||
std::vector<std::string> overlay_triplets;
|
||||
|
||||
bool enabled() const {
|
||||
return !packages.empty();
|
||||
}
|
||||
@@ -113,6 +118,7 @@ struct Target {
|
||||
struct Template {
|
||||
Target outline;
|
||||
std::string add_function;
|
||||
std::vector<std::string> add_arguments;
|
||||
bool pass_sources_to_add_function = false;
|
||||
};
|
||||
|
||||
@@ -155,7 +161,7 @@ struct Content {
|
||||
Condition<std::string> cmake_after;
|
||||
ConditionVector include_before;
|
||||
ConditionVector include_after;
|
||||
bool system;
|
||||
bool system = false;
|
||||
std::string subdir;
|
||||
};
|
||||
|
||||
|
||||
+192
-84
@@ -54,57 +54,85 @@ static std::string format(const char *format, const tsl::ordered_map<std::string
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::vector<std::string> expand_cmake_path(const fs::path &name, const fs::path &toml_dir, bool is_root_project) {
|
||||
std::vector<std::string> temp;
|
||||
|
||||
auto extract_suffix = [](const fs::path &base, const fs::path &full) {
|
||||
auto fullpath = full.string();
|
||||
auto base_len = base.string().length();
|
||||
auto delet = fullpath.substr(base_len + 1, fullpath.length() - base_len);
|
||||
return delet;
|
||||
static std::vector<fs::path> expand_cmake_path(const fs::path &source_path, const fs::path &toml_dir, bool is_root_project) {
|
||||
auto is_subdir = [](fs::path p, const fs::path &root) {
|
||||
while (true) {
|
||||
if (p == root) {
|
||||
return true;
|
||||
}
|
||||
auto parent = p.parent_path();
|
||||
if (parent == p) {
|
||||
break;
|
||||
}
|
||||
p = parent;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
auto stem = name.filename().stem().string();
|
||||
auto ext = name.extension();
|
||||
|
||||
if (is_root_project && stem == "**" && name == name.filename()) {
|
||||
throw std::runtime_error("Recursive globbing not allowed in project root: " + name.string());
|
||||
if (!is_subdir(fs::absolute(toml_dir / source_path), toml_dir)) {
|
||||
throw std::runtime_error("Path traversal is not allowed: " + source_path.string());
|
||||
}
|
||||
|
||||
// Split the path at the first period (since fs::path::stem() and fs::path::extension() split at the last period)
|
||||
std::string stem, extension;
|
||||
auto filename = source_path.filename().string();
|
||||
auto dot_position = filename.find('.');
|
||||
if (dot_position != std::string::npos) {
|
||||
stem = filename.substr(0, dot_position);
|
||||
extension = filename.substr(dot_position);
|
||||
} else {
|
||||
stem = filename;
|
||||
}
|
||||
|
||||
if (is_root_project && stem == "**" && !source_path.has_parent_path()) {
|
||||
throw std::runtime_error("Recursive globbing not allowed in project root: " + source_path.string());
|
||||
}
|
||||
|
||||
auto has_extension = [](const fs::path &file_path, const std::string &extension) {
|
||||
auto path = file_path.string();
|
||||
return path.rfind(extension) == path.length() - extension.length();
|
||||
};
|
||||
|
||||
std::vector<fs::path> paths;
|
||||
if (stem == "*") {
|
||||
for (const auto &f : fs::directory_iterator(toml_dir / name.parent_path(), fs::directory_options::follow_directory_symlink)) {
|
||||
if (!f.is_directory() && f.path().extension() == ext) {
|
||||
temp.push_back(extract_suffix(toml_dir, f));
|
||||
for (const auto &f : fs::directory_iterator(toml_dir / source_path.parent_path(), fs::directory_options::follow_directory_symlink)) {
|
||||
if (!f.is_directory() && has_extension(f.path(), extension)) {
|
||||
paths.push_back(fs::relative(f, toml_dir));
|
||||
}
|
||||
}
|
||||
} else if (stem == "**") {
|
||||
for (const auto &f : fs::recursive_directory_iterator(toml_dir / name.parent_path(), fs::directory_options::follow_directory_symlink)) {
|
||||
if (!f.is_directory() && f.path().extension() == ext) {
|
||||
temp.push_back(extract_suffix(toml_dir, f.path()));
|
||||
for (const auto &f :
|
||||
fs::recursive_directory_iterator(toml_dir / source_path.parent_path(), fs::directory_options::follow_directory_symlink)) {
|
||||
if (!f.is_directory() && has_extension(f.path(), extension)) {
|
||||
paths.push_back(fs::relative(f, toml_dir));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
temp.push_back(name.string());
|
||||
paths.push_back(source_path);
|
||||
}
|
||||
// Normalize all paths to work with CMake (it needs a / on Windows as well)
|
||||
for (auto &path : temp) {
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
}
|
||||
// Sort paths alphabetically for consistent cross-OS generation
|
||||
std::sort(temp.begin(), temp.end());
|
||||
return temp;
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
static std::vector<std::string> expand_cmake_paths(const std::vector<std::string> &sources, const fs::path &toml_dir, bool is_root_project) {
|
||||
// TODO: add duplicate checking
|
||||
std::vector<std::string> result;
|
||||
std::vector<std::string> paths;
|
||||
for (const auto &src : sources) {
|
||||
auto expanded = expand_cmake_path(src, toml_dir, is_root_project);
|
||||
for (const auto &f : expanded) {
|
||||
result.push_back(f);
|
||||
paths.push_back(f.string());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
// Normalize all paths to work with CMake (it needs a / on Windows as well)
|
||||
for (auto &path : paths) {
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
}
|
||||
|
||||
// Sort paths alphabetically for consistent cross-OS generation
|
||||
std::sort(paths.begin(), paths.end());
|
||||
|
||||
// TODO: remove duplicates
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
static void create_file(const fs::path &path, const std::string &contents) {
|
||||
@@ -261,6 +289,10 @@ struct RawArg {
|
||||
}
|
||||
|
||||
std::string arg;
|
||||
|
||||
bool empty() const {
|
||||
return arg.empty();
|
||||
}
|
||||
};
|
||||
|
||||
// Credit: JustMagic
|
||||
@@ -378,7 +410,7 @@ struct Command {
|
||||
}
|
||||
|
||||
bool print_arg(const RawArg &arg) {
|
||||
if (arg.arg.empty()) {
|
||||
if (arg.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -530,11 +562,15 @@ struct Generator {
|
||||
}
|
||||
|
||||
void conditional_includes(const parser::ConditionVector &include) {
|
||||
handle_condition(include, [this](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
handle_condition(include, [this](const std::string &, const std::vector<std::string> &includes) {
|
||||
inject_includes(includes);
|
||||
});
|
||||
}
|
||||
|
||||
void conditional_cmake(const parser::Condition<std::string> &cmake) {
|
||||
handle_condition(cmake, [this](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
handle_condition(cmake, [this](const std::string &, const std::string &cmake) {
|
||||
inject_cmake(cmake);
|
||||
});
|
||||
}
|
||||
|
||||
bool if_condition(const std::string &condition) {
|
||||
@@ -549,7 +585,7 @@ struct Generator {
|
||||
}
|
||||
cmd("if", "NOTE: unnamed condition")(RawArg(cmake_condition(condition)));
|
||||
} else {
|
||||
cmd("if", condition)(RawArg(found->second));
|
||||
cmd("if", condition)(RawArg(cmake_condition(found->second)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -653,7 +689,10 @@ static std::string vcpkg_escape_identifier(const std::string &name) {
|
||||
ch = '-';
|
||||
}
|
||||
|
||||
escaped += std::tolower(ch);
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
ch += ('a' - 'A');
|
||||
}
|
||||
escaped += ch;
|
||||
}
|
||||
if (!vcpkg_valid_identifier(escaped)) {
|
||||
throw std::runtime_error("The escaped project name '" + escaped + "' is not usable with [vcpkg]");
|
||||
@@ -674,7 +713,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
|
||||
parser::Project project(parent_project, path, false);
|
||||
|
||||
for (auto const &lang : project.project_languages) {
|
||||
for (const auto &lang : project.project_languages) {
|
||||
if (known_languages.find(lang) == known_languages.end()) {
|
||||
if (project.project_allow_unknown_languages) {
|
||||
printf("[warning] Unknown language '%s' specified\n", lang.c_str());
|
||||
@@ -688,9 +727,15 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
|
||||
// Helper lambdas for more convenient CMake generation
|
||||
auto &ss = gen.ss;
|
||||
auto cmd = [&gen](const std::string &command) { return gen.cmd(command); };
|
||||
auto comment = [&gen](const std::string &comment) { return gen.comment(comment); };
|
||||
auto endl = [&gen]() { gen.endl(); };
|
||||
auto cmd = [&gen](const std::string &command) {
|
||||
return gen.cmd(command);
|
||||
};
|
||||
auto comment = [&gen](const std::string &comment) {
|
||||
return gen.comment(comment);
|
||||
};
|
||||
auto endl = [&gen]() {
|
||||
gen.endl();
|
||||
};
|
||||
|
||||
std::string cmkr_url = "https://github.com/build-cpp/cmkr";
|
||||
comment("This file is automatically generated from cmake.toml - DO NOT EDIT");
|
||||
@@ -700,24 +745,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
if (is_root_project) {
|
||||
cmd("cmake_minimum_required")("VERSION", project.cmake_version).endl();
|
||||
|
||||
if (project.project_msvc_runtime != parser::msvc_last) {
|
||||
comment("Enable support for MSVC_RUNTIME_LIBRARY");
|
||||
cmd("cmake_policy")("SET", "CMP0091", "NEW");
|
||||
|
||||
switch (project.project_msvc_runtime) {
|
||||
case parser::msvc_dynamic:
|
||||
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
|
||||
break;
|
||||
case parser::msvc_static:
|
||||
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
endl();
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
if (!project.allow_in_tree) {
|
||||
// clang-format off
|
||||
cmd("if")("CMAKE_SOURCE_DIR", "STREQUAL", "CMAKE_BINARY_DIR");
|
||||
@@ -726,6 +753,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
if (project.project_msvc_runtime != parser::msvc_last) {
|
||||
comment("Enable support for MSVC_RUNTIME_LIBRARY");
|
||||
cmd("cmake_policy")("SET", "CMP0091", "NEW").endl();
|
||||
}
|
||||
|
||||
cmd("set")("CMKR_ROOT_PROJECT", "OFF");
|
||||
// clang-format off
|
||||
cmd("if")("CMAKE_CURRENT_SOURCE_DIR", "STREQUAL", "CMAKE_SOURCE_DIR");
|
||||
@@ -743,7 +775,26 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
cmd("set_property")("GLOBAL", "PROPERTY", "USE_FOLDERS", "ON").endl();
|
||||
|
||||
comment("Create a configure-time dependency on cmake.toml to improve IDE support");
|
||||
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
|
||||
if (project.cmake_minimum_version(3, 0)) {
|
||||
cmd("set_property")("DIRECTORY", "APPEND", "PROPERTY", "CMAKE_CONFIGURE_DEPENDS", "cmake.toml");
|
||||
} else {
|
||||
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
|
||||
}
|
||||
|
||||
if (project.project_msvc_runtime != parser::msvc_last) {
|
||||
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
|
||||
switch (project.project_msvc_runtime) {
|
||||
case parser::msvc_dynamic:
|
||||
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
|
||||
break;
|
||||
case parser::msvc_static:
|
||||
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cmd("endif")().endl();
|
||||
}
|
||||
cmd("endif")().endl();
|
||||
// clang-format on
|
||||
|
||||
@@ -752,12 +803,14 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
create_file(cmkr_include, resources::cmkr);
|
||||
}
|
||||
} else {
|
||||
// clang-format off
|
||||
comment("Create a configure-time dependency on cmake.toml to improve IDE support");
|
||||
cmd("if")("CMKR_ROOT_PROJECT");
|
||||
if (project.cmake_minimum_version(3, 0)) {
|
||||
cmd("set_property")("DIRECTORY", "APPEND", "PROPERTY", "CMAKE_CONFIGURE_DEPENDS", "cmake.toml");
|
||||
} else {
|
||||
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
|
||||
}
|
||||
cmd("endif")().endl();
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
// TODO: remove support and replace with global compile-features
|
||||
@@ -822,6 +875,27 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
endl();
|
||||
}
|
||||
|
||||
if (project.vcpkg.enabled()) {
|
||||
comment("vcpkg settings");
|
||||
auto emit_overlay = [&cmd](const std::string &name, const std::vector<std::string> &overlay) {
|
||||
if (!overlay.empty()) {
|
||||
std::vector<std::string> set_args;
|
||||
for (const auto &directory : overlay) {
|
||||
if (!fs::path(directory).is_relative()) {
|
||||
throw std::runtime_error("[vcpkg] overlay is not a relative path: " + directory);
|
||||
}
|
||||
if (!fs::is_directory(directory)) {
|
||||
throw std::runtime_error("[vcpkg] overlay is not a directory: " + directory);
|
||||
}
|
||||
set_args.emplace_back("${CMAKE_CURRENT_SOURCE_DIR}/" + directory);
|
||||
}
|
||||
cmd("set")(name, set_args);
|
||||
}
|
||||
};
|
||||
emit_overlay("VCPKG_OVERLAY_PORTS", project.vcpkg.overlay_ports);
|
||||
emit_overlay("VCPKG_OVERLAY_TRIPLETS", project.vcpkg.overlay_triplets);
|
||||
}
|
||||
|
||||
gen.conditional_includes(project.include_before);
|
||||
gen.conditional_cmake(project.cmake_before);
|
||||
|
||||
@@ -866,6 +940,13 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
}
|
||||
}
|
||||
|
||||
tsl::ordered_map<std::string, std::string> vcpkg_args = {
|
||||
{"URL", url},
|
||||
{"SUBBUILD_DIR", "CMakeFiles/vcpkg-subbuild"},
|
||||
{"SOURCE_DIR", "vcpkg"},
|
||||
{"BINARY_DIR", "CMakeFiles/vcpkg-build"},
|
||||
};
|
||||
|
||||
// CMake to bootstrap vcpkg and download the packages
|
||||
// clang-format off
|
||||
cmd("if")("CMKR_ROOT_PROJECT", "AND", "NOT", "CMKR_DISABLE_VCPKG");
|
||||
@@ -875,16 +956,12 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
cmd("cmake_policy")("SET", "CMP0135", "NEW");
|
||||
cmd("endif")();
|
||||
cmd("message")("STATUS", "Fetching vcpkg (" + version_name + ")...");
|
||||
cmd("FetchContent_Declare")("vcpkg", "URL", url);
|
||||
// Not using FetchContent_MakeAvailable here in case vcpkg adds CMakeLists.txt
|
||||
cmd("FetchContent_GetProperties")("vcpkg");
|
||||
cmd("if")("NOT", "vcpkg_POPULATED");
|
||||
cmd("FetchContent_Populate")("vcpkg");
|
||||
cmd("if")("CMAKE_HOST_SYSTEM_NAME", "STREQUAL", "Darwin", "AND", "CMAKE_OSX_ARCHITECTURES", "STREQUAL", RawArg("\"\""));
|
||||
cmd("set")("CMAKE_OSX_ARCHITECTURES", "${CMAKE_HOST_SYSTEM_PROCESSOR}", "CACHE", "STRING", RawArg("\"\""), "FORCE");
|
||||
cmd("endif")();
|
||||
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
|
||||
cmd("FetchContent_Declare")("vcpkg", vcpkg_args);
|
||||
cmd("FetchContent_MakeAvailable")("vcpkg").endl();
|
||||
cmd("if")("CMAKE_HOST_SYSTEM_NAME", "STREQUAL", "Darwin", "AND", "CMAKE_OSX_ARCHITECTURES", "STREQUAL", RawArg("\"\""));
|
||||
cmd("set")("CMAKE_OSX_ARCHITECTURES", "${CMAKE_HOST_SYSTEM_PROCESSOR}", "CACHE", "STRING", RawArg("\"\""), "FORCE");
|
||||
cmd("endif")();
|
||||
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
|
||||
cmd("endif")();
|
||||
endl();
|
||||
// clang-format on
|
||||
@@ -897,7 +974,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
ofs << R"({
|
||||
"$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT",
|
||||
"$cmkr-url": "https://github.com/build-cpp/cmkr",
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
|
||||
"dependencies": [
|
||||
)";
|
||||
|
||||
@@ -918,17 +995,20 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "', name is reserved");
|
||||
}
|
||||
}
|
||||
if (features.empty()) {
|
||||
if (features.empty() && package.default_features) {
|
||||
ofs << " \"" << package.name << '\"';
|
||||
} else {
|
||||
ofs << " {\n";
|
||||
ofs << " \"name\": \"" << package.name << "\",\n";
|
||||
if (!package.default_features) {
|
||||
ofs << " \"default-features\": false,\n";
|
||||
}
|
||||
ofs << " \"features\": [";
|
||||
for (size_t j = 0; j < features.size(); j++) {
|
||||
const auto &feature = features[j];
|
||||
ofs << '\"' << feature << '\"';
|
||||
if (j + 1 < features.size()) {
|
||||
ofs << ',';
|
||||
ofs << ", ";
|
||||
}
|
||||
}
|
||||
ofs << "]\n";
|
||||
@@ -954,7 +1034,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
ofs << " ],\n";
|
||||
ofs << " \"description\": \"" << escape(project.project_description) << "\",\n";
|
||||
ofs << " \"name\": \"" << escape(vcpkg_escape_identifier(project.project_name)) << "\",\n";
|
||||
ofs << R"( "version-string": "")" << '\n';
|
||||
ofs << " \"version-string\": \"none\"\n";
|
||||
ofs << "}\n";
|
||||
}
|
||||
|
||||
@@ -1052,6 +1132,9 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
if (project_languages.empty())
|
||||
project_languages = {"C", "CXX"};
|
||||
|
||||
// Reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24340#note_1304703
|
||||
project_languages.push_back("RC");
|
||||
|
||||
// All acceptable extensions based off our given languages.
|
||||
tsl::ordered_set<std::string> project_extensions;
|
||||
for (const auto &language : project_languages) {
|
||||
@@ -1076,7 +1159,9 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
for (size_t i = 0; i < project.targets.size(); i++) {
|
||||
const auto &target = project.targets[i];
|
||||
|
||||
auto throw_target_error = [&target](const std::string &message) { throw std::runtime_error("[target." + target.name + "] " + message); };
|
||||
auto throw_target_error = [&target](const std::string &message) {
|
||||
throw std::runtime_error("[target." + target.name + "] " + message);
|
||||
};
|
||||
|
||||
const parser::Template *tmplate = nullptr;
|
||||
std::unique_ptr<ConditionScope> tmplate_cs{};
|
||||
@@ -1287,12 +1372,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
// Handle custom add commands from templates.
|
||||
if (tmplate != nullptr && !tmplate->add_function.empty()) {
|
||||
add_command = tmplate->add_function;
|
||||
target_type_string = ""; // TODO: let templates supply options to the add_command here?
|
||||
|
||||
if (tmplate->pass_sources_to_add_function) {
|
||||
cmd(add_command)(target.name, target_type_string, "${" + sources_var + "}");
|
||||
cmd(add_command)(target.name, tmplate->add_arguments, "${" + sources_var + "}");
|
||||
} else {
|
||||
cmd(add_command)(target.name, target_type_string).endl();
|
||||
cmd(add_command)(target.name, tmplate->add_arguments).endl();
|
||||
if (has_sources) {
|
||||
cmd("target_sources")(target.name, target_type == parser::target_interface ? "INTERFACE" : "PRIVATE",
|
||||
"${" + sources_var + "}");
|
||||
@@ -1315,8 +1399,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
}
|
||||
|
||||
auto target_cmd = [&](const char *command, const parser::ConditionVector &cargs, const std::string &scope) {
|
||||
gen.handle_condition(cargs,
|
||||
[&](const std::string &, const std::vector<std::string> &args) { cmd(command)(target.name, scope, args); });
|
||||
gen.handle_condition(cargs, [&](const std::string &, const std::vector<std::string> &args) {
|
||||
cmd(command)(target.name, scope, args);
|
||||
});
|
||||
};
|
||||
|
||||
auto link_libraries = [&](const parser::ConditionVector &cargs, const std::string &scope) {
|
||||
gen.handle_condition(cargs, [&](const std::string &, const std::vector<std::string> &args) {
|
||||
std::vector<std::string> targs;
|
||||
for (const std::string &arg : args) {
|
||||
if (arg.find("::") == 0) {
|
||||
auto library = arg.substr(2);
|
||||
// clang-format off
|
||||
cmd("if")("NOT", "TARGET", library);
|
||||
cmd("message")("FATAL_ERROR", "Target \"" + library + "\" referenced by \"" + target.name + "\" does not exist!");
|
||||
cmd("endif")().endl();
|
||||
// clang-format on
|
||||
targs.push_back(std::move(library));
|
||||
} else {
|
||||
targs.push_back(arg);
|
||||
}
|
||||
}
|
||||
cmd("target_link_libraries")(target.name, scope, targs);
|
||||
});
|
||||
};
|
||||
|
||||
auto gen_target_cmds = [&](const parser::Target &t) {
|
||||
@@ -1335,8 +1440,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
target_cmd("target_link_directories", t.link_directories, target_scope);
|
||||
target_cmd("target_link_directories", t.private_link_directories, "PRIVATE");
|
||||
|
||||
target_cmd("target_link_libraries", t.link_libraries, target_scope);
|
||||
target_cmd("target_link_libraries", t.private_link_libraries, "PRIVATE");
|
||||
link_libraries(t.link_libraries, target_scope);
|
||||
link_libraries(t.private_link_libraries, "PRIVATE");
|
||||
|
||||
target_cmd("target_link_options", t.link_options, target_scope);
|
||||
target_cmd("target_link_options", t.private_link_options, "PRIVATE");
|
||||
@@ -1359,14 +1464,17 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
}
|
||||
|
||||
gen.handle_condition(props, [&](const std::string &, const tsl::ordered_map<std::string, std::string> &properties) {
|
||||
tsl::ordered_map<std::string, RawArg> raw_properties;
|
||||
for (const auto &propItr : properties) {
|
||||
if (propItr.first == "MSVC_RUNTIME_LIBRARY") {
|
||||
if (project_root->project_msvc_runtime == parser::msvc_last) {
|
||||
throw_target_error("You cannot set msvc-runtime without setting the root [project].msvc-runtime");
|
||||
}
|
||||
}
|
||||
// NOTE: We need to make sure that empty strings do not get omitted
|
||||
raw_properties.emplace(propItr.first, Command::quote(propItr.second));
|
||||
}
|
||||
cmd("set_target_properties")(target.name, "PROPERTIES", properties);
|
||||
cmd("set_target_properties")(target.name, "PROPERTIES", raw_properties);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+65
-22
@@ -274,6 +274,13 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
conditions["root"] = R"cmake(CMKR_ROOT_PROJECT)cmake";
|
||||
conditions["x64"] = R"cmake(CMAKE_SIZEOF_VOID_P EQUAL 8)cmake";
|
||||
conditions["x32"] = R"cmake(CMAKE_SIZEOF_VOID_P EQUAL 4)cmake";
|
||||
conditions["android"] = R"cmake(ANDROID)cmake";
|
||||
conditions["apple"] = R"cmake(APPLE)cmake";
|
||||
conditions["bsd"] = R"cmake(BSD)cmake";
|
||||
conditions["cygwin"] = R"cmake(CYGWIN)cmake";
|
||||
conditions["ios"] = R"cmake(IOS)cmake";
|
||||
conditions["xcode"] = R"cmake(XCODE)cmake";
|
||||
conditions["wince"] = R"cmake(WINCE)cmake";
|
||||
} else {
|
||||
conditions = parent->conditions;
|
||||
templates = parent->templates;
|
||||
@@ -381,7 +388,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
if (ch == '_') {
|
||||
normalized += '-';
|
||||
} else if (ch >= 'A' && ch <= 'Z') {
|
||||
normalized += std::tolower(ch);
|
||||
ch += ('a' - 'A');
|
||||
normalized += ch;
|
||||
} else if (ch == '-' || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z')) {
|
||||
normalized += ch;
|
||||
} else {
|
||||
@@ -431,6 +439,9 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
}
|
||||
options.push_back(o);
|
||||
|
||||
// Add a condition matching the option name
|
||||
conditions.emplace(o.name, o.name);
|
||||
|
||||
// Add an implicit condition for the option
|
||||
auto ncondition = normalize(o.name);
|
||||
if (ncondition.find(nproject_prefix) == 0) {
|
||||
@@ -532,10 +543,21 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
key = "URL";
|
||||
} else if (hash_algorithms.contains(key)) {
|
||||
std::string algo;
|
||||
for (auto c : key) {
|
||||
algo.push_back(std::toupper(c));
|
||||
for (auto ch : key) {
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
ch -= ('a' - 'A');
|
||||
}
|
||||
algo.push_back(ch);
|
||||
}
|
||||
key = "URL_HASH";
|
||||
if (value.empty()) {
|
||||
throw_key_error("Empty hash value", argItr.first, argItr.second);
|
||||
}
|
||||
for (char c : value) {
|
||||
if (!std::isxdigit(c)) {
|
||||
throw_key_error("Hash value must be a hex string", argItr.first, argItr.second);
|
||||
}
|
||||
}
|
||||
value = algo + "=" + value;
|
||||
} else if (key == "hash") {
|
||||
key = "URL_HASH";
|
||||
@@ -634,29 +656,28 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
// Add support for relative paths for (private-)link-libraries
|
||||
const auto fix_relative_paths = [&name, &path](ConditionVector &libraries, const char *key) {
|
||||
for (const auto &library_entries : libraries) {
|
||||
for (auto &library_path : libraries[library_entries.first]) {
|
||||
for (auto &library : libraries[library_entries.first]) {
|
||||
// Skip processing paths with potential CMake macros in them (this check isn't perfect)
|
||||
// https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#variable-references
|
||||
if ((library_path.find("${") != std::string::npos || library_path.find("$ENV{") != std::string::npos ||
|
||||
library_path.find("$CACHE{") != std::string::npos) &&
|
||||
library_path.find('}') != std::string::npos) {
|
||||
if ((library.find("${") != std::string::npos || library.find("$ENV{") != std::string::npos ||
|
||||
library.find("$CACHE{") != std::string::npos) &&
|
||||
library.find('}') != std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip paths that don't contain backwards or forwards slashes
|
||||
if (library_path.find_first_of(R"(\/)") == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the new file path exists, otherwise emit an error
|
||||
const auto expected_library_file_path = fs::path{path} / library_path;
|
||||
if (!fs::exists(expected_library_file_path)) {
|
||||
auto library_path = fs::path(path) / library;
|
||||
if (fs::exists(library_path)) {
|
||||
if (!fs::is_directory(library_path)) {
|
||||
// If the file path is relative (and not a directory), prepend ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
library.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
|
||||
}
|
||||
} else if (library.find_first_of(R"(\/)") != std::string::npos) {
|
||||
// Error if the path contains a directory separator and the file doesn't exist
|
||||
throw std::runtime_error("Attempted to link against a library file that doesn't exist for target \"" + name + "\" in \"" +
|
||||
key + "\": " + library_path);
|
||||
key + "\": " + library);
|
||||
} else {
|
||||
// NOTE: We cannot check if system libraries exist, so we leave them as-is
|
||||
}
|
||||
|
||||
// Prepend ${CMAKE_CURRENT_SOURCE_DIR} to the path
|
||||
library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -711,6 +732,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
property_list += list_val.as_string();
|
||||
}
|
||||
target.properties[condition][k] = property_list;
|
||||
} else if (v.is_integer()) {
|
||||
target.properties[condition][k] = std::to_string(v.as_integer());
|
||||
} else if (v.is_boolean()) {
|
||||
target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
|
||||
} else {
|
||||
@@ -762,6 +785,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
tmplate.outline = parse_target(name, t, true);
|
||||
|
||||
t.optional("add-function", tmplate.add_function);
|
||||
t.optional("add-arguments", tmplate.add_arguments);
|
||||
t.optional("pass-sources-to-add-function", tmplate.pass_sources_to_add_function);
|
||||
t.optional("pass-sources", tmplate.pass_sources_to_add_function);
|
||||
|
||||
@@ -827,13 +851,33 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
|
||||
std::istringstream feature_stream{features};
|
||||
std::string feature;
|
||||
while (std::getline(feature_stream, feature, ',')) {
|
||||
package.features.emplace_back(feature);
|
||||
// Disable default features with package-name[core,feature1]
|
||||
if (feature == "core") {
|
||||
package.default_features = false;
|
||||
} else {
|
||||
package.features.emplace_back(feature);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw_key_error("Invalid package name '" + package_str + "'", "packages", p);
|
||||
}
|
||||
vcpkg.packages.emplace_back(std::move(package));
|
||||
}
|
||||
|
||||
if (v.contains("overlay")) {
|
||||
std::string overlay;
|
||||
v.optional("overlay", overlay);
|
||||
vcpkg.overlay_triplets = vcpkg.overlay_ports = {overlay};
|
||||
if (v.contains("overlay-ports")) {
|
||||
throw_key_error("[vcpkg].overlay was already specified", "overlay-ports", v.find("overlay-ports"));
|
||||
}
|
||||
if (v.contains("overlay-triplets")) {
|
||||
throw_key_error("[vcpkg].overlay was already specified", "overlay-triplets", v.find("overlay-triplets"));
|
||||
}
|
||||
} else {
|
||||
v.optional("overlay-ports", vcpkg.overlay_ports);
|
||||
v.optional("overlay-triplets", vcpkg.overlay_triplets);
|
||||
}
|
||||
}
|
||||
|
||||
checker.check(conditions, true);
|
||||
@@ -866,9 +910,8 @@ bool Project::cmake_minimum_version(int major, int minor) const {
|
||||
}
|
||||
|
||||
bool Project::is_condition_name(const std::string &name) {
|
||||
auto is_named_condition = true;
|
||||
for (auto ch : name) {
|
||||
if (!(ch == '-' || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z'))) {
|
||||
if (!std::isalnum(ch) && ch != '-' && ch != '_') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
# These will be generated by cmkr, so no point in tracking them
|
||||
**/CMakeLists.txt
|
||||
**/cmkr.cmake
|
||||
**/cmkr.cmake
|
||||
**/vcpkg.json
|
||||
@@ -1,4 +1,4 @@
|
||||
# Example project that sets compiler/linker flags for various platforms.
|
||||
# Example project that sets compiler flags and preprocessor defines for various platforms.
|
||||
|
||||
[project]
|
||||
name = "compile-options"
|
||||
@@ -8,8 +8,11 @@ description = "Compiler flags"
|
||||
type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
msvc.compile-options = ["/W2"]
|
||||
msvc.compile-definitions = ["PLATFORM=\"msvc\""]
|
||||
gcc.compile-options = ["-Wall"]
|
||||
gcc.compile-definitions = ["PLATFORM=\"gcc\""]
|
||||
clang.compile-options = ["-Wall"]
|
||||
clang.compile-definitions = ["PLATFORM=\"clang\""]
|
||||
|
||||
# The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
|
||||
# The `hello` target uses [conditions](/cmake-toml#conditions) to set different compiler flags and definitions depending on the platform. See the [targets](/cmake-toml/#targets) documentation for other things you can set.
|
||||
# _Note_: In general you only want to specify flags _required_ to compile your code without errors.
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
name = "fetch-content"
|
||||
description = "Fetching from git"
|
||||
|
||||
[fetch-content]
|
||||
fmt = { git = "https://github.com/fmtlib/fmt", tag = "7.1.3" }
|
||||
[fetch-content.fmt]
|
||||
git = "https://github.com/fmtlib/fmt"
|
||||
tag = "7.1.3"
|
||||
|
||||
[target.example]
|
||||
type = "executable"
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
namespace mylib {
|
||||
std::string message();
|
||||
}
|
||||
} // namespace mylib
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
# Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://vcpkg.io/) and links an `example` target to it:
|
||||
# Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://github.com/microsoft/vcpkg) and links an `example` target to it:
|
||||
|
||||
[project]
|
||||
name = "vcpkg"
|
||||
description = "Dependencies from vcpkg"
|
||||
|
||||
# See https://github.com/microsoft/vcpkg/releases for vcpkg versions
|
||||
# See https://vcpkg.io/en/packages.html for available packages
|
||||
# See https://vcpkg.io/en/packages or https://vcpkg.link for available packages
|
||||
[vcpkg]
|
||||
version = "2024.03.25"
|
||||
version = "2024.11.16"
|
||||
packages = ["fmt"]
|
||||
|
||||
[find-package]
|
||||
fmt = {}
|
||||
[find-package.fmt]
|
||||
|
||||
[target.example]
|
||||
type = "executable"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT",
|
||||
"$cmkr-url": "https://github.com/build-cpp/cmkr",
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
||||
"dependencies": [
|
||||
"fmt"
|
||||
],
|
||||
"description": "Dependencies from vcpkg",
|
||||
"name": "vcpkg",
|
||||
"version-string": ""
|
||||
}
|
||||
-4
@@ -16,7 +16,3 @@ target_include_directories(toml11 INTERFACE toml11-3.6.0)
|
||||
# https://github.com/mpark/variant (BSL-1.0)
|
||||
add_library(mpark_variant INTERFACE)
|
||||
target_include_directories(mpark_variant INTERFACE variant-1.4.0/include)
|
||||
|
||||
# https://github.com/nlohmann/json (MIT)
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE nlohmann-3.9.1/include)
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2021 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-25447
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user