Skip to content

Commit

Permalink
Upgrade all use package versions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Jul 31, 2023
1 parent fcbedfe commit b66dba3
Show file tree
Hide file tree
Showing 22 changed files with 543 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ parse:
SVN_REPOSITORY: 1
SVN_REVISION: 1
SOURCE_DIR: 1
SYSTEM: 1
DOWNLOAD_COMMAND: 1
EXCLUDE_FROM_ALL: 1
FIND_PACKAGE_ARGUMENTS: 1
NO_CACHE: 1
GIT_SHALLOW: 1
Expand Down
14 changes: 14 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Define environment in this dir only with direnv.
# On first usage enter: direnv allow
# man direnv for more infos
#
# see too https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html
export CMAKE_PREFIX_PATH=${PWD}/stagedir
export CMAKE_EXPORT_COMPILE_COMMANDS=YES
export CTEST_OUTPUT_ON_FAILURE=YES

export CPM_USE_LOCAL_PACKAGES=YES
export CPM_SOURCE_CACHE=${PWD}/.cache/CPM

export LD_LIBRARY_PATH=${CMAKE_PREFIX_PATH}/lib
export BUILD_DIR=${PWD}/build
7 changes: 4 additions & 3 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Install

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand All @@ -33,7 +34,7 @@ jobs:
rm -rf build
- name: configure
run: cmake -Stest -Bbuild -DTEST_INSTALLED_VERSION=1
run: cmake -S test -B build -D TEST_INSTALLED_VERSION=1

- name: build
run: cmake --build build --config Debug -j4
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: MacOS

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand All @@ -27,7 +28,7 @@ jobs:
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure
run: cmake -Stest -Bbuild -DCMAKE_BUILD_TYPE=Debug
run: cmake -S test -B build -D CMAKE_BUILD_TYPE=Debug

- name: build
run: cmake --build build -j4
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Standalone

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules
Expand All @@ -26,10 +27,12 @@ jobs:
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure
run: cmake -Sstandalone -Bbuild -DCMAKE_BUILD_TYPE=Debug
run: cmake -S standalone -B build -D CMAKE_BUILD_TYPE=Debug

- name: build
run: cmake --build build -j4

- name: run
run: ./build/Greeter
- name: test
run: |
cd build
ctest --build-config Debug
7 changes: 4 additions & 3 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Style

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules
Expand All @@ -29,7 +30,7 @@ jobs:
run: pip3 install clang-format==14.0.6 cmake_format==0.6.11 pyyaml

- name: configure
run: cmake -Stest -Bbuild
run: cmake -S test -B build

- name: check style
run: cmake --build build --target check-format
7 changes: 4 additions & 3 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Ubuntu

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand All @@ -28,7 +29,7 @@ jobs:
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure
run: cmake -Stest -Bbuild -DENABLE_TEST_COVERAGE=1 -DCMAKE_BUILD_TYPE=Debug
run: cmake -S test -B build -D ENABLE_TEST_COVERAGE=1 -D CMAKE_BUILD_TYPE=Debug

- name: build
run: cmake --build build -j4
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: Windows

on:
push:
branches:
- master
- main
- develop
pull_request:
branches:
- master
- main
- develop

env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand All @@ -27,7 +28,7 @@ jobs:
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure
run: cmake -Stest -Bbuild
run: cmake -S test -B build # -G "Visual Studio 17 2022" -D BUILD_SHARED_LIBS=NO

- name: build
run: cmake --build build --config Debug -j4
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
*~
*.swp
/build*
/stagedir
/.vscode
/cpm_modules
.DS_Store
.DS_Store
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.27)
cmake_minimum_required(VERSION 3.21...3.27)

# ---- Project ----

Expand All @@ -18,18 +18,25 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
)
endif()

if(NOT PROJECT_IS_TOP_LEVEL)
option(CMAKE_SKIP_INSTALL_RULES "Whether to disable generation of installation rules" YES)
endif()

option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON)

# ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info

include(cmake/CPM.cmake)

# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0")
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.10.0")

CPMAddPackage(
NAME fmt
GIT_TAG 9.1.0
GITHUB_REPOSITORY fmtlib/fmt
SYSTEM ON # used in case of cmake v3.25
OPTIONS "FMT_INSTALL YES" # create an installable target
)

Expand All @@ -46,12 +53,15 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/
# target: add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME} ${headers} ${sources})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${OPTION_ENABLE_UNITY})

# enable compiler warnings
include(cmake/WarningsAsErrors.cmake)
if(PROJECT_IS_TOP_LEVEL)
# enable compiler warnings
include(cmake/WarningsAsErrors.cmake)

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
endif()

# Link dependencies
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
Expand Down Expand Up @@ -79,3 +89,5 @@ packageProject(
COMPATIBILITY SameMajorVersion
DEPENDENCIES "fmt 9.1.0"
)

include(CPack)
97 changes: 97 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default user Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"installDir": "${sourceDir}/stagedir",
"cacheVariables": {
"CMAKE_PREFIX_PATH": {
"type": "path",
"value": "${sourceDir}/stagedir"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_DEBUG_POSTFIX": "D",
"BUILD_SHARED_LIBS": "YES"
},
"environment": {
"CPM_USE_LOCAL_PACKAGES": "NO",
"PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}"
},
"warnings": {
"deprecated": true,
"uninitialized": true
}
},
{
"name": "ninja-multi",
"inherits": "default",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
},
{
"name": "windows-only",
"inherits": "default",
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
},
{
"name": "install",
"configurePreset": "default",
"targets": ["install"]
}
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "build",
"name": "install"
},
{
"type": "package",
"name": "default"
}
]
}
]
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This template is the result of learnings from many previous projects and should
- Installable target with automatic versioning information and header generation via [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake)
- Automatic [documentation](https://thelartians.github.io/ModernCppStarter) and deployment with [Doxygen](https://www.doxygen.nl) and [GitHub Pages](https://pages.github.com)
- Support for [sanitizer tools, and more](#additional-tools)
- Supports [CMake Workflow Presets](https://cmake.org/cmake/help/v3.25/manual/cmake-presets.7.html#id10)

## Usage

Expand All @@ -52,6 +53,8 @@ During development it is usually convenient to [build all subprojects at once](#
Use the following command to build and run the executable target.

```bash
cd standalone && cmake --workflow --preset=default
# or
cmake -S standalone -B build/standalone
cmake --build build/standalone
./build/standalone/Greeter --help
Expand All @@ -62,6 +65,8 @@ cmake --build build/standalone
Use the following commands from the project's root directory to run the test suite.

```bash
cd test && cmake --workflow --preset=default
# or
cmake -S test -B build/test
cmake --build build/test
CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test
Expand Down Expand Up @@ -114,6 +119,8 @@ The project also includes an `all` directory that allows building all targets at
This is useful during development, as it exposes all subprojects to your IDE and avoids redundant builds of the library.

```bash
cd all && cmake --workflow --preset=default
# or
cmake -S all -B build
cmake --build build

Expand Down
Loading

0 comments on commit b66dba3

Please sign in to comment.