Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat build: allow using CMake presets #60

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ cmake-build-*
Testing/
.DS_Store
Makefile.local
CmakeUserPresets.json
33 changes: 21 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
cmake_minimum_required(VERSION 3.12)
project(service_template CXX)

# Disable userver libraries that are not needed in this project
set(USERVER_FEATURE_MONGODB OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_POSTGRESQL OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_REDIS OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_CLICKHOUSE OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_GRPC OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_RABBITMQ OFF CACHE BOOL "" FORCE)

# Compatibility mode: some systems don't support these features
set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE)

# This option is disabled when using CMake presets
option(
SERVICE_TEMPLATE_OVERRIDES
"Use hardcoded overrides for userver options from the service template"
ON
)
if(SERVICE_TEMPLATE_OVERRIDES)
# Disable userver libraries that are not needed in this project
set(USERVER_FEATURE_MONGODB OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_POSTGRESQL OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_REDIS OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_CLICKHOUSE OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_GRPC OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_RABBITMQ OFF CACHE BOOL "" FORCE)

# Compatibility mode: some systems don't support these features
set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE)
set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE)
endif()


# Adding userver dependency
Expand Down
86 changes: 86 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "debug",
"displayName": "Default Debug",
"description": "Fully featured Debug build, some platforms miss the required dependencies",
"inherits": [
"common-flags"
],
"binaryDir": "${sourceDir}/build_debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"USERVER_SANITIZE": "addr;ub"
}
},
{
"name": "compat-debug",
"displayName": "Compatibility-mode Debug",
"description": "Debug build with some features (e.g. sanitizers) disabled for compatibility",
"inherits": [
"compat-flags",
"common-flags"
],
"binaryDir": "${sourceDir}/build_debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"displayName": "Default Release",
"description": "Fully featured Release build, some platforms miss the required dependencies",
"inherits": [
"common-flags"
],
"binaryDir": "${sourceDir}/build_release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "compat-release",
"displayName": "Compatibility-mode Release",
"description": "Release build with some features disabled for compatibility",
"inherits": [
"common-flags",
"compat-flags"
],
"binaryDir": "${sourceDir}/build_release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "common-flags",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"SERVICE_TEMPLATE_OVERRIDES": "OFF",
"USERVER_FEATURE_MONGODB": "OFF",
"USERVER_FEATURE_POSTGRESQL": "OFF",
"USERVER_FEATURE_REDIS": "OFF",
"USERVER_FEATURE_CLICKHOUSE": "OFF",
"USERVER_FEATURE_GRPC": "OFF",
"USERVER_FEATURE_RABBITMQ": "OFF",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "compat-flags",
"hidden": true,
"generator": "Unix Makefiles",
"cacheVariables": {
"USERVER_FEATURE_CRYPTOPP_BLAKE2": "OFF",
"USERVER_FEATURE_GRPC_CHANNELZ": "OFF",
"USERVER_FEATURE_REDIS_HI_MALLOC": "ON"
}
}
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test-debug test-release: test-%: build-%
# Start the service (via testsuite service runner)
.PHONY: service-start-debug service-start-release
service-start-debug service-start-release: service-start-%:
cmake --build build_$* -v --target=start-service_template
cmake --build build_$* -v --target start-service_template

# Cleanup data
.PHONY: clean-debug clean-release
Expand Down
Loading