diff --git a/CMakeLists.txt b/CMakeLists.txt index eec2b25..75dbd27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,30 @@ cmake_minimum_required(VERSION 3.12) project(service_template CXX) + +# 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 include(third_party/userver/cmake/SetupEnvironment.cmake) include(GNUInstallDirs) add_subdirectory(third_party/userver) diff --git a/CMakePresets.json b/CMakePresets.json index 2ca9fc0..c64160d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -62,6 +62,7 @@ "hidden": true, "generator": "Ninja", "cacheVariables": { + "SERVICE_TEMPLATE_OVERRIDES": "OFF", "USERVER_FEATURE_MONGODB": "OFF", "USERVER_FEATURE_POSTGRESQL": "OFF", "USERVER_FEATURE_REDIS": "OFF", diff --git a/Makefile b/Makefile index 62bf0d5..1c4902d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ -DEBUG_PRESET ?= debug -RELEASE_PRESET ?= release +CMAKE_COMMON_FLAGS ?= -DCMAKE_EXPORT_COMPILE_COMMANDS=ON +CMAKE_DEBUG_FLAGS ?= -DUSERVER_SANITIZE='addr ub' +CMAKE_RELEASE_FLAGS ?= NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format DOCKER_COMPOSE ?= docker-compose @@ -7,6 +8,9 @@ DOCKER_COMPOSE ?= docker-compose # NOTE: use Makefile.local to override the options defined above. -include Makefile.local +CMAKE_DEBUG_FLAGS += -DCMAKE_BUILD_TYPE=Debug $(CMAKE_COMMON_FLAGS) +CMAKE_RELEASE_FLAGS += -DCMAKE_BUILD_TYPE=Release $(CMAKE_COMMON_FLAGS) + .PHONY: all all: test-debug test-release @@ -14,12 +18,12 @@ all: test-debug test-release .PHONY: cmake-debug cmake-debug: git submodule update --init - cmake --preset $(DEBUG_PRESET) + cmake -B build_debug $(CMAKE_DEBUG_FLAGS) .PHONY: cmake-release cmake-release: git submodule update --init - cmake --preset $(RELEASE_PRESET) + cmake -B build_release $(CMAKE_RELEASE_FLAGS) build_debug/CMakeCache.txt: cmake-debug build_release/CMakeCache.txt: cmake-release