1
0
Fork 0
mirror of https://github.com/TheLartians/ModernCppStarter.git synced 2025-09-04 16:10:53 +02:00

- Add CMake Workflow Presets

- Upgrade to gitup workflow action v3
- Prepare use of git-flow
- Use CMake v3.21 variable PROJECT_IS_TOP_LEVEL
- Use CMAKE_DEBUG_POSTFIX to prevent name clashes
- Add more config files
This commit is contained in:
Claus Klein 2023-07-31 07:13:34 +02:00
parent fcbedfe9d8
commit d81a42450c
22 changed files with 540 additions and 31 deletions

View file

@ -1,7 +1,16 @@
cmake_minimum_required(VERSION 3.14...3.27)
cmake_minimum_required(VERSION 3.21...3.27)
project(GreeterStandalone LANGUAGES CXX)
if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_SKIP_INSTALL_RULES
NO
CACHE BOOL "Forced generation of installation rules" FORCE
)
endif()
option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON)
# --- Import tools ----
include(../cmake/tools.cmake)
@ -13,6 +22,7 @@ include(../cmake/CPM.cmake)
CPMAddPackage(
GITHUB_REPOSITORY jarro2783/cxxopts
VERSION 3.1.1
SYSTEM ON # used in case of cmake v3.25
OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" "CXXOPTS_ENABLE_INSTALL YES"
)
@ -27,8 +37,22 @@ CPMAddPackage(
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
add_executable(${PROJECT_NAME} ${sources})
if(CMAKE_DEBUG_POSTFIX)
set_property(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
endif()
target_link_libraries(${PROJECT_NAME} Greeter::Greeter cxxopts::cxxopts)
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${OPTION_ENABLE_UNITY})
# TODO(CK): why is this needed?
# TODO(CK): why is this used? This overrides the CMAKE_DEBUG_POSTFIX!
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME Greeter)
target_link_libraries(${PROJECT_NAME} Greeter::Greeter cxxopts::cxxopts)
# --- Test it ---
enable_testing()
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} --help)
# --- Install it ---
install(TARGETS ${PROJECT_NAME} RUNTIME)
include(CPack)

View file

@ -0,0 +1,106 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default standalone Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceParentDir}/build/standalone",
"installDir": "${sourceParentDir}/stagedir",
"cacheVariables": {
"CMAKE_PREFIX_PATH": {
"type": "path",
"value": "${sourceParentDir}/stagedir"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_DEBUG_POSTFIX": "D",
"CPM_USE_LOCAL_PACKAGES": "YES",
"BUILD_SHARED_LIBS": "YES"
},
"environment": {
"CPM_USE_LOCAL_PACKAGES": "YES",
"PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}"
}
},
{
"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"]
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
},
{
"type": "build",
"name": "install"
},
{
"type": "package",
"name": "default"
}
]
}
]
}