Skip to content
Snippets Groups Projects
Unverified Commit 8cbcf5e1 authored by Tim Kaune's avatar Tim Kaune
Browse files

Refactor CMake presets

Update README accordingly
parent 5eb173a0
Branches
Tags
No related merge requests found
...@@ -15,10 +15,10 @@ jobs: ...@@ -15,10 +15,10 @@ jobs:
ninja --version ninja --version
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: configure - name: configure
run: cmake --preset default run: cmake --preset ninja
- name: build - name: build
run: cmake --build ./build --verbose run: cmake --build --preset ninja --verbose
- name: install - name: install
run: cmake --install ./build --prefix ./bin run: cmake --build --preset ninja --verbose --target install
- name: test - name: test
run: cmake --build ./build --target test run: cmake --build --preset ninja --verbose --target test
...@@ -2,3 +2,8 @@ ...@@ -2,3 +2,8 @@
!.gitignore !.gitignore
!.gitattributes !.gitattributes
!.github/ !.github/
CMakeUserPresets.json
build/
install/
...@@ -8,12 +8,42 @@ ...@@ -8,12 +8,42 @@
"configurePresets": [ "configurePresets": [
{ {
"name": "default", "name": "default",
"displayName": "Default Release Build", "hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build", "binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "./install"
},
"warnings": { "warnings": {
"dev": false "dev": false
} }
},
{
"name": "ninja",
"inherits": [
"default"
],
"generator": "Ninja",
"displayName": "Default Build Configuration using Ninja"
},
{
"name": "make",
"inherits": [
"default"
],
"generator": "Unix Makefiles",
"displayName": "Default Build Configuration using Makefiles"
}
],
"buildPresets": [
{
"name": "ninja",
"displayName": "Default Build using Ninja",
"configurePreset": "ninja"
},
{
"name": "make",
"displayName": "Default Build using Make",
"configurePreset": "make"
} }
] ]
} }
...@@ -11,20 +11,58 @@ What you need: ...@@ -11,20 +11,58 @@ What you need:
- [Git](https://git-scm.com/) (optional) for getting the code and contributing - [Git](https://git-scm.com/) (optional) for getting the code and contributing
to the project to the project
- [CMake](https://cmake.org/) for building the project - [CMake](https://cmake.org/) and [Ninja](https://ninja-build.org/) for building
the project
### Linux (Ubuntu) ###
Use your distribution's package manager to install the packages `cmake` and
`ninja-build`.
```shell
$ sudo apt-get install cmake ninja-build
```
### Mac OS X ###
#### Homebrew ####
```shell
$ brew install cmake ninja
```
#### MacPorts ####
```shell
$ sudo port install cmake ninja
```
### Windows ###
Install Cygwin and use the Cygwin package manager to install the packages
`cmake` and `ninja`.
## How to build ## ## How to build ##
1. Clone the git repository or download the source code archive and unpack it to 1. Clone the git repository or download the source code archive and unpack it to
an arbitrary directory (e.g. `load-static-shared-targets`). an arbitrary directory (e.g. `load-static-shared-targets`).
2. For building the module, type `cmake --preset default`. This will populate the 2. Go to this directory and type `cmake --list-presets`. A list of available
`build` directory with a CMake build tree. build configurations will be shown to you.
3. Now, you can build with `cmake --build ./build`. You should see some 3. For configuring the project, type `cmake --preset ninja`. This will populate
the `./build` directory with a CMake configuration tree. By default, the
configured installation directory is `./install`. You can specify a different
install location by setting the `CMAKE_INSTALL_PREFIX` variable:
```shell
$ cmake --preset ninja -D "CMAKE_INSTALL_PREFIX=/path/to/install/prefix"
```
4. Now, you can build with `cmake --build --preset ninja`. You should see some
informative terminal output. informative terminal output.
4. Finally, install the built artifacts to the `bin` folder with `cmake 5. Finally, install the built artifacts to the configured install prefix with
--install ./build --prefix ./bin`. You can also specify a different install `cmake --build --preset ninja --target install`. If the configured install
prefix, e. g. if you want to install system-wide: `cmake --install ./build prefix is a system-wide location (like `/usr/local`), installing might
--prefix /usr/local` (might require `sudo`). require `sudo`.
Now, the `LoadStaticSharedTargets` module is installed and you can use it in Now, the `LoadStaticSharedTargets` module is installed and you can use it in
other projects. The installed `LoadStaticSharedTargets` package is discoverable other projects. The installed `LoadStaticSharedTargets` package is discoverable
...@@ -45,7 +83,17 @@ FetchContent_MakeAvailable(LoadStaticSharedTargets) ...@@ -45,7 +83,17 @@ FetchContent_MakeAvailable(LoadStaticSharedTargets)
``` ```
This discovers an installed version of the LoadStaticSharedTargets module or This discovers an installed version of the LoadStaticSharedTargets module or
adds it to the other project's install targets. adds it to the other project's install targets. To help CMake discover an
installed LoadStaticSharedTargets package, call CMake for the other project like
this:
```shell
$ cmake -B ./build -D "CMAKE_PREFIX_PATH=/path/to/LoadStaticSharedTargets/install/prefix"
```
Replace the path to the LoadStaticSharedTargets install prefix with the actual
path on your system! If LoadStaticSharedTargets is installed in a proper
system-wide location, the `CMAKE_PREFIX_PATH` shouldn't be necessary.
In the other project's package config CMake file, you can now use the module like this: In the other project's package config CMake file, you can now use the module like this:
...@@ -64,17 +112,6 @@ load_static_shared_targets( ...@@ -64,17 +112,6 @@ load_static_shared_targets(
This adds the LoadStaticSharedTargets module to the `CMAKE_MODULE_PATH` variable This adds the LoadStaticSharedTargets module to the `CMAKE_MODULE_PATH` variable
which enables the include by name only. which enables the include by name only.
Then, to help CMake discover the LoadStaticSharedTargets package, call CMake for
the other project like this:
```shell
$ cmake -B ./build -DCMAKE_PREFIX_PATH=/path/to/LoadStaticSharedTargets/install/prefix
```
Replace the path to the LoadStaticSharedTargets install prefix with the actual
path on your system! If LoadStaticSharedTargets is installed in a proper
system-wide location, the `CMAKE_PREFIX_PATH` shouldn't be necessary.
## Further Reading ## ## Further Reading ##
The idea for this code was taken from The idea for this code was taken from
......
*
!.gitignore
*
!.gitignore
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment