|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: cmake.toml |
| 4 | +permalink: /cmake-toml/ |
| 5 | +nav_order: 3 |
| 6 | +--- |
| 7 | + |
| 8 | +# cmake.toml |
| 9 | + |
| 10 | +This page is supposed to be a reference for the options in the `cmake.toml` file. If you think anything is missing or unclear, please [edit this page](https://github.com/build-cpp/cmkr/edit/main/docs/cmake-toml.md) or open an [issue](https://github.com/build-cpp/cmkr/issues). |
| 11 | + |
| 12 | +See the [examples](/examples) section for more real-world examples. |
| 13 | + |
| 14 | +## CMake configuration |
| 15 | + |
| 16 | +```toml |
| 17 | +[cmake] |
| 18 | +version = "3.15" |
| 19 | +cmkr-include = "cmkr.cmake" |
| 20 | +``` |
| 21 | + |
| 22 | +## Project configuration |
| 23 | + |
| 24 | +```toml |
| 25 | +[project] |
| 26 | +name = "myproject" |
| 27 | +version = "1.0.0" |
| 28 | +description = "Description of the project" |
| 29 | +languages = ["C", "CXX"] |
| 30 | +cmake-before = """ |
| 31 | +message(STATUS "CMake injected before the project() call") |
| 32 | +""" |
| 33 | +cmake-after = """ |
| 34 | +message(STATUS "CMake injected after the project() call") |
| 35 | +""" |
| 36 | +include-before = ["cmake/before-project.cmake"] |
| 37 | +include-after = ["cmake/after-project.cmake"] |
| 38 | +``` |
| 39 | + |
| 40 | +## Conditions |
| 41 | + |
| 42 | +```toml |
| 43 | +[conditions] |
| 44 | +arch64 = "CMAKE_SIZEOF_VOID_P EQUALS 8" |
| 45 | +arch32 = "CMAKE_SIZEOF_VOID_P EQUALS 4" |
| 46 | +``` |
| 47 | + |
| 48 | +## Subdirectories |
| 49 | + |
| 50 | +```toml |
| 51 | +[subdir.mysubdir] |
| 52 | +condition = "linux" |
| 53 | +cmake-before = """ |
| 54 | +message(STATUS "CMake injected before the add_subdirectory() call" |
| 55 | +""" |
| 56 | +cmake-after = """ |
| 57 | +message(STATUS "CMake injected after the add_subdirectory() call") |
| 58 | +""" |
| 59 | +include-before = ["cmake/before-subdir.cmake"] |
| 60 | +include-after = ["cmake/after-subdir.cmake"] |
| 61 | +``` |
| 62 | + |
| 63 | +## Vcpkg |
| 64 | + |
| 65 | +```toml |
| 66 | +[vcpkg] |
| 67 | +version = "2021.05.12" |
| 68 | +url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2021.05.12.tar.gz" |
| 69 | +packages = ["fmt", "zlib"] |
| 70 | +``` |
| 71 | + |
| 72 | +The vcpkg `version` will automatically generate the `url` from the official repository. For a custom registry you can specify your own `url` (and omit the `version`). |
| 73 | + |
| 74 | +## Packages |
| 75 | + |
| 76 | +```toml |
| 77 | +[find-package] |
| 78 | +mypackage = { version = "1.0", required = true, config = true, components = ["mycomponent"] } |
| 79 | + |
| 80 | +# Alternative syntax |
| 81 | +[find-package.mypackage] |
| 82 | +version = "1.0" |
| 83 | +required = true |
| 84 | +config = true |
| 85 | +components = ["mycomponent"] |
| 86 | +``` |
| 87 | + |
| 88 | +## FetchContent |
| 89 | + |
| 90 | +**Note**: The `[fetch-content]` feature is unpolished and will likely change in a future release. |
| 91 | + |
| 92 | +```toml |
| 93 | +[fetch-content] |
| 94 | +gitcontent = { git = "https://github.com/myuser/gitcontent", tag = "v0.1" } |
| 95 | +svncontent = { svn = "https://svn-host.com/url", rev = "svn_rev" } |
| 96 | +urlcontent = { url = "https://content-host.com/urlcontent.zip", hash = "123123123123" } |
| 97 | + |
| 98 | +# Alternative syntax |
| 99 | +[fetch-content.gitcontent] |
| 100 | +git = "https://github.com/myuser/gitcontent" |
| 101 | +tag = "v0.1" |
| 102 | +``` |
| 103 | + |
| 104 | +## Targets |
| 105 | + |
| 106 | +```toml |
| 107 | +[target.mytarget] |
| 108 | +condition = "linux" |
| 109 | +alias = "mytarget::mytarget" |
| 110 | +type = "static" # executable, library, shared, static, interface, custom |
| 111 | +headers = ["src/mytarget.h"] |
| 112 | +sources = ["src/mytarget.cpp"] |
| 113 | + |
| 114 | +# The keys below match the target_xxx CMake commands |
| 115 | +# Keys prefixed with private- will get PRIVATE visibility |
| 116 | +compile-definitions = [""] |
| 117 | +private-compile-definitions = [""] |
| 118 | +compile-features = [""] |
| 119 | +private-compile-features = [""] |
| 120 | +compile-options = [""] |
| 121 | +private-compile-options = [""] |
| 122 | +include-directories = [""] |
| 123 | +private-include-directories = [""] |
| 124 | +link-directories = [""] |
| 125 | +private-link-directories = [""] |
| 126 | +link-libraries = [""] |
| 127 | +private-link-libraries = [""] |
| 128 | +link-options = [""] |
| 129 | +private-link-options = [""] |
| 130 | +precompile-headers = [""] |
| 131 | +private-precompile-headers = [""] |
| 132 | + |
| 133 | +cmake-before = """ |
| 134 | +message(STATUS "CMake injected before the target") |
| 135 | +""" |
| 136 | +cmake-after = """ |
| 137 | +message(STATUS "CMake injected after the target") |
| 138 | +""" |
| 139 | +include-before = "cmake/target-before.cmake" |
| 140 | +include-after = "cmake/target-after.cmake" |
| 141 | + |
| 142 | +# See https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html#properties-on-targets for a list of target properties |
| 143 | +[target.mytarget.properties] |
| 144 | +CXX_STANDARD = 17 |
| 145 | +CXX_STANDARD_REQUIRED = true |
| 146 | +FOLDER = "MyFolder" |
| 147 | +``` |
| 148 | + |
| 149 | +## Tests and installation (unfinished) |
| 150 | + |
| 151 | +**Note**: The `[[test]]` and `[[install]]` are unfinished features and will likely change in a future release. |
| 152 | + |
| 153 | +```toml |
| 154 | +# You can declare as many as you want like this, but the name has to be unique |
| 155 | +[[test]] |
| 156 | +name = "mytest" |
| 157 | +command = "$<TARGET_FILE:mytest>" |
| 158 | +arguments = ["arg1", "arg2"] |
| 159 | +configurations = ["Debug", "Release", "RelWithDebInfo", "MinSizeRelease"] |
| 160 | +working-directory = "mytest-dir" |
| 161 | +``` |
| 162 | + |
| 163 | +```toml |
| 164 | +[[install]] |
| 165 | +targets = ["mytarget", "mytest"] |
| 166 | +destination = ["bin"] |
| 167 | +files = ["content/my.png"] |
| 168 | +dirs = [""] |
| 169 | +configs = [""] |
| 170 | +``` |
0 commit comments