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

Add test and workflow presets

Cleanup hard-coded test configuration
Bump CMake package version number
parent 8a2f427c
No related branches found
No related tags found
No related merge requests found
...@@ -7,18 +7,12 @@ jobs: ...@@ -7,18 +7,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: prepare - name: prepare
run: sudo apt-get install -y ninja-build run: sudo apt-get install -y git cmake ninja-build
- name: info - name: info
run: | run: |
git version git version
cmake --version cmake --version
ninja --version ninja --version
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: configure - name: build-and-test
run: cmake --preset ninja run: cmake --workflow --preset ci-ninja
- name: build
run: cmake --build --preset ninja --verbose
- name: install
run: cmake --build --preset ninja --verbose --target install
- name: test
run: cmake --build --preset ninja --verbose --target check
...@@ -25,11 +25,11 @@ SOFTWARE. ...@@ -25,11 +25,11 @@ SOFTWARE.
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.29) set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.31)
include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE) include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE)
project(LoadStaticSharedTargets VERSION 1.6.0 LANGUAGES NONE) project(LoadStaticSharedTargets VERSION 1.7.0 LANGUAGES NONE)
include(GNUInstallDirs) include(GNUInstallDirs)
...@@ -37,10 +37,6 @@ string(COMPARE EQUAL "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME}" IS_TOP_LEVEL) ...@@ -37,10 +37,6 @@ string(COMPARE EQUAL "${CMAKE_PROJECT_NAME}" "${PROJECT_NAME}" IS_TOP_LEVEL)
if (IS_TOP_LEVEL) if (IS_TOP_LEVEL)
include(CTest) include(CTest)
if (NOT DEFINED CMAKE_CTEST_ARGUMENTS)
set(CMAKE_CTEST_ARGUMENTS "--verbose")
endif ()
endif () endif ()
option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for LoadStaticSharedTargets" "${IS_TOP_LEVEL}") option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for LoadStaticSharedTargets" "${IS_TOP_LEVEL}")
...@@ -48,8 +44,6 @@ option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for Lo ...@@ -48,8 +44,6 @@ option(LoadStaticSharedTargets_INCLUDE_PACKAGING "Include packaging rules for Lo
add_subdirectory(src) add_subdirectory(src)
if (IS_TOP_LEVEL AND BUILD_TESTING) if (IS_TOP_LEVEL AND BUILD_TESTING)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} -V)
add_subdirectory(tests EXCLUDE_FROM_ALL) add_subdirectory(tests EXCLUDE_FROM_ALL)
endif () endif ()
......
...@@ -35,15 +35,137 @@ ...@@ -35,15 +35,137 @@
} }
], ],
"buildPresets": [ "buildPresets": [
{
"name": "verbose",
"hidden": true,
"verbose": true
},
{ {
"name": "ninja", "name": "ninja",
"inherits": [
"verbose"
],
"displayName": "Default Build using Ninja", "displayName": "Default Build using Ninja",
"configurePreset": "ninja" "configurePreset": "ninja"
}, },
{
"name": "ninja-install",
"inherits": [
"ninja"
],
"displayName": "Default Build and Installation using Ninja",
"targets": [
"install"
]
},
{ {
"name": "make", "name": "make",
"inherits": [
"verbose"
],
"displayName": "Default Build using Make", "displayName": "Default Build using Make",
"configurePreset": "make" "configurePreset": "make"
},
{
"name": "make-install",
"inherits": [
"make"
],
"displayName": "Default Build and Installation using Make",
"targets": [
"install"
]
}
],
"testPresets": [
{
"name": "verbose",
"hidden": true,
"output": {
"verbosity": "verbose"
}
},
{
"name": "ninja",
"inherits": [
"verbose"
],
"displayName": "Default Test using Ninja",
"configurePreset": "ninja"
},
{
"name": "make",
"inherits": [
"verbose"
],
"displayName": "Default Test using Make",
"configurePreset": "make"
}
],
"workflowPresets": [
{
"name": "dev-ninja",
"displayName": "Developer Workflow using Ninja",
"steps": [
{
"type": "configure",
"name": "ninja"
},
{
"type": "build",
"name": "ninja-install"
}
]
},
{
"name": "ci-ninja",
"displayName": "CI Workflow using Ninja",
"steps": [
{
"type": "configure",
"name": "ninja"
},
{
"type": "build",
"name": "ninja"
},
{
"type": "test",
"name": "ninja"
}
]
},
{
"name": "dev-make",
"displayName": "Developer Workflow using Make",
"steps": [
{
"type": "configure",
"name": "make"
},
{
"type": "build",
"name": "make-install"
}
]
},
{
"name": "ci-make",
"displayName": "CI Workflow using Make",
"steps": [
{
"type": "configure",
"name": "make"
},
{
"type": "build",
"name": "make"
},
{
"type": "test",
"name": "make"
}
]
} }
] ]
} }
...@@ -26,9 +26,9 @@ SOFTWARE. ...@@ -26,9 +26,9 @@ SOFTWARE.
# LoadStaticSharedTargets # # LoadStaticSharedTargets #
This CMake module contains a macro for loading static or shared exported library This CMake module contains a macro for loading static or shared exported library
targets in a CMake package config file. Static or shared targets can be targets in a CMake package config file. Static or shared targets can be imported
explicitly (via `COMPONENTS`) or implicitly (via `BUILD_SHARED_LIBS`) imported explicitly (via `COMPONENTS`) or implicitly (via `BUILD_SHARED_LIBS`) with the
with the `find_package()` command. `find_package()` command.
## Prerequisites ## ## Prerequisites ##
...@@ -63,7 +63,7 @@ $ brew install cmake ninja ...@@ -63,7 +63,7 @@ $ brew install cmake ninja
#### MacPorts #### #### MacPorts ####
```shell ```shell
$ sudo port -vb install cmake-devel ninja $ sudo port -v install cmake ninja
``` ```
### Windows ### ### Windows ###
...@@ -87,27 +87,42 @@ process. ...@@ -87,27 +87,42 @@ process.
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. Go to this directory and type `cmake --list-presets`. A list of available 2. Go to this directory and type `cmake --workflow --list-presets`. A list of
build configurations will be shown to you. available build workflows will be shown to you.
3. For configuring the project, type `cmake --preset ninja`. This will populate 3. For configuring, building and installing the project, type `cmake --workflow
the `./build` directory with a CMake configuration tree. By default, the --preset dev-ninja`. This will populate the `./build` directory with a CMake
configured installation directory is `./install`. You can specify a different configuration tree, execute the build and install the project. By default,
install location by setting the `CMAKE_INSTALL_PREFIX` variable: the configured installation directory is `./install`.
4. For running the tests, type `cmake --workflow --preset ci-ninja`.
### How to customize the build from the command line ###
1. You can specify a different install location by using the configure preset
directly while setting the `CMAKE_INSTALL_PREFIX` variable:
```shell ```shell
$ cmake --preset ninja -D "CMAKE_INSTALL_PREFIX=/path/to/install/prefix" $ 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 If the configured install prefix is a system-wide location (like
informative terminal output. `/usr/local`), installing 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 2. Now, you can build manually with `cmake --build --preset ninja-install`. You
prefix is a system-wide location (like `/usr/local`), installing might should see some informative terminal output.
require `sudo`.
### How to customize the build using user presets ###
Create the file `./CMakeUserPresets.json` and build your own configure, build,
test or workflow presets by inheriting from the project's default presets.
Please refer to the [CMake Documentation about presets][1] for details.
[1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
## How to use ##
Now, the `LoadStaticSharedTargets` module is installed and you can use it in With the `LoadStaticSharedTargets` module installed, you can use it in other
other projects. The installed `LoadStaticSharedTargets` package is discoverable projects. The installed `LoadStaticSharedTargets` package is discoverable by
by CMake as __LoadStaticSharedTargets__. In the `CMakeLists.txt` of the other CMake as __LoadStaticSharedTargets__. In the `CMakeLists.txt` of the other
project, do the following: project, do the following:
```cmake ```cmake
...@@ -116,9 +131,9 @@ include(FetchContent) ...@@ -116,9 +131,9 @@ include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
LoadStaticSharedTargets LoadStaticSharedTargets
GIT_REPOSITORY "https://github.com/lepus2589/LoadStaticSharedTargets.git" GIT_REPOSITORY "https://github.com/lepus2589/LoadStaticSharedTargets.git"
GIT_TAG v1.5.2 GIT_TAG v1.7.0
SYSTEM SYSTEM
FIND_PACKAGE_ARGS 1.5.2 CONFIG NAMES LoadStaticSharedTargets FIND_PACKAGE_ARGS 1.7.0 CONFIG NAMES LoadStaticSharedTargets
) )
set(LoadStaticSharedTargets_INCLUDE_PACKAGING TRUE) set(LoadStaticSharedTargets_INCLUDE_PACKAGING TRUE)
FetchContent_MakeAvailable(LoadStaticSharedTargets) FetchContent_MakeAvailable(LoadStaticSharedTargets)
...@@ -151,8 +166,8 @@ load_static_shared_targets( ...@@ -151,8 +166,8 @@ load_static_shared_targets(
) )
``` ```
This adds the LoadStaticSharedTargets module to the `CMAKE_MODULE_PATH` variable The `find_package()` command adds the LoadStaticSharedTargets module to the
which enables the include by name only. `CMAKE_MODULE_PATH` variable which enables the `include()` by name only.
## Further Reading ## ## Further Reading ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment