diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f7e6040147a696c5c42ae9b553236715ef797400..af14d6cb44f15422a53dd633e9d810417c092279 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,10 +15,10 @@ jobs: ninja --version - uses: actions/checkout@v4 - name: configure - run: cmake --preset default + run: cmake --preset ninja - name: build - run: cmake --build ./build --verbose + run: cmake --build --preset ninja --verbose - name: install - run: cmake --install ./build --prefix ./bin + run: cmake --build --preset ninja --verbose --target install - name: test - run: cmake --build ./build --target test + run: cmake --build --preset ninja --verbose --target test diff --git a/.gitignore b/.gitignore index ced691f7a6d193f42d88eb7d349d6763b7224070..e4ed20bd8a73ade4a2f29d45484e1c9088c3f2c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,8 @@ !.gitignore !.gitattributes !.github/ + +CMakeUserPresets.json + +build/ +install/ diff --git a/CMakePresets.json b/CMakePresets.json index 417faafa4f09d4091d98c4a26804caebf77a5766..a8ba655cd80503310048f3d4c97d1e9853885bbf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -8,12 +8,42 @@ "configurePresets": [ { "name": "default", - "displayName": "Default Release Build", - "generator": "Ninja", + "hidden": true, "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_INSTALL_PREFIX": "./install" + }, "warnings": { "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" } ] } diff --git a/README.md b/README.md index 9f14a20e71ecf3844d83af6c685da82c228e91a6..deb036f6c367707242af685804bb07f2da43ec73 100644 --- a/README.md +++ b/README.md @@ -11,20 +11,58 @@ What you need: - [Git](https://git-scm.com/) (optional) for getting the code and contributing 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 ## 1. Clone the git repository or download the source code archive and unpack it to an arbitrary directory (e.g. `load-static-shared-targets`). -2. For building the module, type `cmake --preset default`. This will populate the - `build` directory with a CMake build tree. -3. Now, you can build with `cmake --build ./build`. You should see some +2. Go to this directory and type `cmake --list-presets`. A list of available + build configurations will be shown to you. +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. -4. Finally, install the built artifacts to the `bin` folder with `cmake - --install ./build --prefix ./bin`. You can also specify a different install - prefix, e. g. if you want to install system-wide: `cmake --install ./build - --prefix /usr/local` (might require `sudo`). +5. Finally, install the built artifacts to the configured install prefix with + `cmake --build --preset ninja --target install`. If the configured install + prefix is a system-wide location (like `/usr/local`), installing might + require `sudo`. Now, the `LoadStaticSharedTargets` module is installed and you can use it in other projects. The installed `LoadStaticSharedTargets` package is discoverable @@ -45,7 +83,17 @@ FetchContent_MakeAvailable(LoadStaticSharedTargets) ``` 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: @@ -64,17 +112,6 @@ load_static_shared_targets( This adds the LoadStaticSharedTargets module to the `CMAKE_MODULE_PATH` variable 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 ## The idea for this code was taken from diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index d6b7ef32c8478a48c3994dcadc86837f4371184d..0000000000000000000000000000000000000000 --- a/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index d6b7ef32c8478a48c3994dcadc86837f4371184d..0000000000000000000000000000000000000000 --- a/build/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore