Skip to content

Commit

Permalink
feat cmake: don't build everything by default, improve cmake options …
Browse files Browse the repository at this point in the history
…docs

* Add `USERVER_BUILD_TESTS` and `USERVER_BUILD_SAMPLES` options
* Add `USERVER_BUILD_EVERYTHING` option (now `OFF` by default)
* Clean up and document `userver/tools`
* Split cmake options table into multiple tables
commit_hash:01842127a27ffe72d963ecc61c71e95a53648688
  • Loading branch information
Anton3 committed Nov 18, 2024
1 parent c350050 commit 38e9112
Show file tree
Hide file tree
Showing 46 changed files with 348 additions and 246 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ jobs:
-GNinja
-DCMAKE_CXX_COMPILER=clang++-18
-DCMAKE_C_COMPILER=clang-18
-DUSERVER_SANITIZE="ub addr"
-DCMAKE_BUILD_TYPE=Debug
-DUSERVER_NO_WERROR=OFF
-DUSERVER_SANITIZE="ub addr"
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_NAMESPACE=userver_ns
-DUSERVER_NAMESPACE_BEGIN="namespace userver_ns { inline namespace
v1 {"
Expand All @@ -40,9 +43,12 @@ jobs:
-GNinja
-DCMAKE_CXX_COMPILER=clang++-14
-DCMAKE_C_COMPILER=clang-14
-DUSERVER_SANITIZE="ub addr"
-DCMAKE_BUILD_TYPE=Debug
-DUSERVER_NO_WERROR=OFF
-DUSERVER_SANITIZE="ub addr"
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_NAMESPACE=userver_ns
-DUSERVER_NAMESPACE_BEGIN="namespace userver_ns { inline namespace
v1 {"
Expand All @@ -56,12 +62,15 @@ jobs:
- cmake-flags: >-
-GNinja
-DCMAKE_BUILD_TYPE=Release
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_NO_WERROR=1
-DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0
-DUSERVER_FEATURE_REDIS_HI_MALLOC=1
-DUSERVER_NO_WERROR=1
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=0
-DUSERVER_DOWNLOAD_PACKAGE_ABSEIL=0
-DCMAKE_BUILD_TYPE=Release
os: ubuntu-20.04
info: g++-9 + release
tests-flags: '--gtest_filter=-HttpClient.RedirectHeaders:HttpClient.TestUseIPv4v6'
Expand All @@ -72,12 +81,15 @@ jobs:
-GNinja
-DCMAKE_CXX_COMPILER=g++-8
-DCMAKE_C_COMPILER=gcc-8
-DCMAKE_BUILD_TYPE=Debug
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_NO_WERROR=1
-DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0
-DUSERVER_FEATURE_REDIS_HI_MALLOC=1
-DUSERVER_NO_WERROR=1
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=0
-DUSERVER_DOWNLOAD_PACKAGE_ABSEIL=0
-DCMAKE_BUILD_TYPE=Debug
os: ubuntu-20.04
info: g++-8 + debug
tests-flags: '--gtest_filter=-HttpClient.RedirectHeaders:HttpClient.TestUseIPv4v6'
Expand Down
38 changes: 28 additions & 10 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,56 @@ jobs:
matrix:
include:
- cmake-flags: >-
-DUSERVER_BUILD_ALL_LIBRARIES=0
-DCMAKE_CXX_STANDARD=17
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_FEATURE_CORE=1
-DUSERVER_FEATURE_CHAOTIC=0
-DCMAKE_CXX_STANDARD=17
image: ubuntu-22.04-userver-base
info: ubuntu + clang + cxx17 + core
id: ubuntu_clang_cxx17_core
- cmake-flags: >-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16
-DUSERVER_BUILD_ALL_LIBRARIES=1
-DCMAKE_C_COMPILER=clang-16
-DCMAKE_CXX_COMPILER=clang++-16
-DCMAKE_CXX_STANDARD=17
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
image: ubuntu-22.04-userver-base-ci
info: ubuntu + clang + cxx17
id: ubuntu_clang_cxx17
- cmake-flags: >-
-DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11
-DUSERVER_BUILD_ALL_LIBRARIES=1
-DCMAKE_C_COMPILER=gcc-11
-DCMAKE_CXX_COMPILER=g++-11
-DCMAKE_CXX_STANDARD=17
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
image: ubuntu-22.04-userver-base-ci
info: ubuntu + gcc + cxx17
id: ubuntu_gcc_cxx17
- cmake-flags: >-
-DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_C_COMPILER=clang-16
-DUSERVER_BUILD_ALL_LIBRARIES=1
-DCMAKE_C_COMPILER=clang-16
-DCMAKE_CXX_COMPILER=clang++-16
-DCMAKE_CXX_STANDARD=20
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
image: ubuntu-22.04-userver-base-ci
info: ubuntu + clang + cxx20
id: ubuntu_clang_cxx20
- cmake-flags: >-
-DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11
-DUSERVER_BUILD_ALL_LIBRARIES=1
-DCMAKE_C_COMPILER=gcc-11
-DCMAKE_CXX_COMPILER=g++-11
-DCMAKE_CXX_STANDARD=20
-DUSERVER_NO_WERROR=0
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
image: ubuntu-22.04-userver-base-ci
info: ubuntu + gcc + cxx20
id: ubuntu_gcc_cxx20
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:
CMAKE_FLAGS: >-
-GNinja
-DCMAKE_BUILD_TYPE=Debug
-DUSERVER_NO_WERROR=OFF
-DUSERVER_NO_WERROR=1
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_FEATURE_REDIS_HI_MALLOC=1
-DUSERVER_FEATURE_CRYPTOPP_BLAKE2=0
-DUSERVER_BUILD_ALL_LIBRARIES=1
-DUSERVER_FEATURE_POSTGRESQL=0
-DUSERVER_FEATURE_GRPC=0
-DUSERVER_FEATURE_GRPC_REFLECTION=0
Expand Down
24 changes: 13 additions & 11 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -3850,17 +3850,19 @@
"third_party/uboost_coro/src/context/fiber.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/fiber.cpp",
"third_party/uboost_coro/src/context/posix/stack_traits.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/posix/stack_traits.cpp",
"third_party/uboost_coro/src/context/untested.cpp":"taxi/uservices/userver/third_party/uboost_coro/src/context/untested.cpp",
"tools/congestion_control_emulator/CMakeLists.txt":"taxi/uservices/userver/tools/congestion_control_emulator/CMakeLists.txt",
"tools/congestion_control_emulator/congestion_control_emulator.cpp":"taxi/uservices/userver/tools/congestion_control_emulator/congestion_control_emulator.cpp",
"tools/congestion_control_emulator/data/const-overload.txt":"taxi/uservices/userver/tools/congestion_control_emulator/data/const-overload.txt",
"tools/congestion_control_emulator/data/temp-overload.txt":"taxi/uservices/userver/tools/congestion_control_emulator/data/temp-overload.txt",
"tools/congestion_control_emulator/policy/production-2020-10-09.json":"taxi/uservices/userver/tools/congestion_control_emulator/policy/production-2020-10-09.json",
"tools/dns_resolver/CMakeLists.txt":"taxi/uservices/userver/tools/dns_resolver/CMakeLists.txt",
"tools/dns_resolver/resolver.cpp":"taxi/uservices/userver/tools/dns_resolver/resolver.cpp",
"tools/engine/CMakeLists.txt":"taxi/uservices/userver/tools/engine/CMakeLists.txt",
"tools/engine/engine_perf.cpp":"taxi/uservices/userver/tools/engine/engine_perf.cpp",
"tools/httpclient/CMakeLists.txt":"taxi/uservices/userver/tools/httpclient/CMakeLists.txt",
"tools/httpclient/httpclient_perf.cpp":"taxi/uservices/userver/tools/httpclient/httpclient_perf.cpp",
"tools/CMakeLists.txt":"taxi/uservices/userver/tools/CMakeLists.txt",
"tools/Readme.md":"taxi/uservices/userver/tools/Readme.md",
"tools/congestion-control-emulator/CMakeLists.txt":"taxi/uservices/userver/tools/congestion-control-emulator/CMakeLists.txt",
"tools/congestion-control-emulator/congestion_control_emulator.cpp":"taxi/uservices/userver/tools/congestion-control-emulator/congestion_control_emulator.cpp",
"tools/congestion-control-emulator/data/const-overload.txt":"taxi/uservices/userver/tools/congestion-control-emulator/data/const-overload.txt",
"tools/congestion-control-emulator/data/temp-overload.txt":"taxi/uservices/userver/tools/congestion-control-emulator/data/temp-overload.txt",
"tools/congestion-control-emulator/policy/production-2020-10-09.json":"taxi/uservices/userver/tools/congestion-control-emulator/policy/production-2020-10-09.json",
"tools/dns-resolver/CMakeLists.txt":"taxi/uservices/userver/tools/dns-resolver/CMakeLists.txt",
"tools/dns-resolver/resolver.cpp":"taxi/uservices/userver/tools/dns-resolver/resolver.cpp",
"tools/engine-perf/CMakeLists.txt":"taxi/uservices/userver/tools/engine-perf/CMakeLists.txt",
"tools/engine-perf/engine_perf.cpp":"taxi/uservices/userver/tools/engine-perf/engine_perf.cpp",
"tools/http-client-perf/CMakeLists.txt":"taxi/uservices/userver/tools/http-client-perf/CMakeLists.txt",
"tools/http-client-perf/httpclient_perf.cpp":"taxi/uservices/userver/tools/http-client-perf/httpclient_perf.cpp",
"tools/netcat/CMakeLists.txt":"taxi/uservices/userver/tools/netcat/CMakeLists.txt",
"tools/netcat/netcat.cpp":"taxi/uservices/userver/tools/netcat/netcat.cpp",
"universal/CMakeLists.txt":"taxi/uservices/userver/universal/CMakeLists.txt",
Expand Down
56 changes: 26 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ option(
)

set(USERVER_AVAILABLE_COMPONENTS universal)
set(USERVER_NOT_INCLUDED_AS_SUBDIR OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR AND NOT USERVER_INSTALL)
set(USERVER_NOT_INCLUDED_AS_SUBDIR ON)
endif()

option(USERVER_FEATURE_CORE "Provide a core library with coroutines, otherwise build only userver-universal" ON)
option(USERVER_FEATURE_CHAOTIC "Provide chaotic-codegen for jsonschema" ON)
Expand All @@ -45,48 +41,53 @@ if (USERVER_FEATURE_UTEST)
endif()

option(
USERVER_IS_THE_ROOT_PROJECT
"Contributor mode: build userver tests, samples and helper tools"
"${USERVER_NOT_INCLUDED_AS_SUBDIR}"
USERVER_BUILD_TESTS
"Build unit tests, functional tests and benchmarks for userver itself"
OFF
)
if (USERVER_IS_THE_ROOT_PROJECT)
message(STATUS "Building userver as a primary project")
if (NOT USERVER_FEATURE_UTEST)
message(FATAL_ERROR "Cannot build tests without utest")
endif()
else()
message(STATUS "Building userver as a subproject")
option(USERVER_BUILD_SAMPLES "Build userver samples" OFF)

if(USERVER_BUILD_TESTS AND NOT USERVER_FEATURE_UTEST)
message(FATAL_ERROR "Running unit tests for userver requires utest, disabling it is meaningless")
endif()

if(USERVER_INSTALL AND (USERVER_BUILD_TESTS OR USERVER_BUILD_SAMPLES))
message(
FATAL_ERROR
"For USERVER_INSTALL, please turn off USERVER_BUILD_TESTS and USERVER_BUILD_SAMPLES "
"to avoid accidentally installing them"
)
endif()

option(
USERVER_BUILD_ALL_LIBRARIES
USERVER_BUILD_ALL_COMPONENTS
"\
Build all libraries except for those explicitly turned off by 'USERVER_FEATURE_*'\
and except for libraries disabled for the current platform"
"${USERVER_IS_THE_ROOT_PROJECT}"
OFF
)

set(USERVER_LIB_ENABLED_DEFAULT OFF)
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_LIBRARIES)
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_COMPONENTS)
set(USERVER_LIB_ENABLED_DEFAULT ON)
endif()

set(USERVER_MONGODB_DEFAULT OFF)
set(USERVER_CLICKHOUSE_DEFAULT OFF)
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_LIBRARIES AND USERVER_BUILD_PLATFORM_X86)
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_COMPONENTS AND USERVER_BUILD_PLATFORM_X86)
if(NOT CMAKE_SYSTEM_NAME MATCHES "BSD")
set(USERVER_MONGODB_DEFAULT ON)
endif()
set(USERVER_CLICKHOUSE_DEFAULT ON)
endif()

set(USERVER_YDB_DEFAULT OFF)
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_LIBRARIES AND
if(USERVER_FEATURE_CORE AND USERVER_BUILD_ALL_COMPONENTS AND
DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD GREATER_EQUAL 20 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(USERVER_YDB_DEFAULT ON)
endif()

option(USERVER_CONAN "Build with Conan packages" ${CONAN_EXPORTED})
option(USERVER_CONAN "Build with Conan packages" "${CONAN_EXPORTED}")

option(
USERVER_DOWNLOAD_PACKAGES
Expand Down Expand Up @@ -171,7 +172,7 @@ if (USERVER_FEATURE_GRPC)
include(SetupProtobuf)
endif()

if (USERVER_IS_THE_ROOT_PROJECT)
if (USERVER_BUILD_TESTS)
include(testsuite/SetupUserverTestsuiteEnv.cmake)
add_subdirectory(testsuite)
endif()
Expand All @@ -188,14 +189,6 @@ if (USERVER_FEATURE_CHAOTIC)
list(APPEND USERVER_AVAILABLE_COMPONENTS chaotic)
endif()

if (USERVER_IS_THE_ROOT_PROJECT AND USERVER_FEATURE_CORE)
add_subdirectory(tools/engine)
add_subdirectory(tools/httpclient)
add_subdirectory(tools/netcat)
add_subdirectory(tools/dns_resolver)
add_subdirectory(tools/congestion_control_emulator)
endif()

if (USERVER_FEATURE_MONGODB)
_require_userver_core("USERVER_FEATURE_MONGODB")
add_subdirectory(mongo)
Expand Down Expand Up @@ -271,9 +264,12 @@ add_subdirectory(scripts/gdb/tests)
_userver_export_targets()
_userver_make_install_config()

if (USERVER_IS_THE_ROOT_PROJECT AND USERVER_FEATURE_CORE)
if (USERVER_BUILD_SAMPLES AND USERVER_FEATURE_CORE)
add_subdirectory(samples)
endif()
if (USERVER_BUILD_TESTS AND USERVER_FEATURE_CORE)
add_subdirectory(tools)
endif()

if(USERVER_INSTALL)
include(cmake/UserverPack.cmake)
Expand Down
2 changes: 1 addition & 1 deletion chaotic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_include_directories(
)
target_link_libraries(${PROJECT_NAME} PUBLIC userver-universal)

if(USERVER_IS_THE_ROOT_PROJECT)
if(USERVER_BUILD_TESTS)
userver_venv_setup(
NAME userver-chaotic-tests
PYTHON_OUTPUT_VAR USERVER_CHAOTIC_PYTEST_PYTHON_BINARY
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _userver_directory_install(COMPONENT clickhouse FILES
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules
)

if (USERVER_IS_THE_ROOT_PROJECT)
if (USERVER_BUILD_TESTS)
set_tests_properties(${PROJECT_NAME}-dbtest PROPERTIES ENVIRONMENT
"TESTSUITE_CLICKHOUSE_SERVER_START_TIMEOUT=120.0")

Expand Down
6 changes: 3 additions & 3 deletions cmake/UserverModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function(userver_module MODULE)
endif()

## 2. userver-${MODULE}-unittest
if(USERVER_IS_THE_ROOT_PROJECT AND UTEST_SOURCES)
if(USERVER_BUILD_TESTS AND UTEST_SOURCES)
add_executable(userver-${MODULE}-unittest ${UTEST_SOURCES})
target_link_libraries(userver-${MODULE}-unittest PRIVATE
userver-utest
Expand All @@ -121,7 +121,7 @@ function(userver_module MODULE)
endif()

## 3. userver-${MODULE}-dbtest
if(USERVER_IS_THE_ROOT_PROJECT AND DBTEST_SOURCES)
if(USERVER_BUILD_TESTS AND DBTEST_SOURCES)
add_executable(userver-${MODULE}-dbtest ${DBTEST_SOURCES})
target_link_libraries(userver-${MODULE}-dbtest PRIVATE
userver-utest
Expand All @@ -140,7 +140,7 @@ function(userver_module MODULE)
endif()

## 4. userver-${MODULE}-benchmark
if(USERVER_IS_THE_ROOT_PROJECT AND UBENCH_SOURCES)
if(USERVER_BUILD_TESTS AND UBENCH_SOURCES)
add_executable(userver-${MODULE}-benchmark ${UBENCH_SOURCES})
target_link_libraries(userver-${MODULE}-benchmark PRIVATE
userver-ubench
Expand Down
4 changes: 2 additions & 2 deletions cmake/UserverSql.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ function(userver_add_sql_library TARGET)
add_custom_command(
OUTPUT
${ARG_OUTPUT_DIR}/include/${ARG_NAMESPACE}/${FILENAME}.hpp
${ARG_OUTPUT_DIR}/src/${ARG_NAMESPACE}/${FILENAME}.cpp
${ARG_OUTPUT_DIR}/src/${ARG_NAMESPACE}/${FILENAME}.cpp
COMMAND
${USERVER_SQL_PYTHON_BINARY}
${USERVER_SQL_SCRIPTS_PATH}/generator.py
${USERVER_SQL_SCRIPTS_PATH}/generator.py
--namespace ${ARG_NAMESPACE}
--output-dir ${ARG_OUTPUT_DIR}
--query-log-mode ${ARG_QUERY_LOG_MODE}
Expand Down
1 change: 0 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def generate(self):
tool_ch.variables['CMAKE_FIND_DEBUG_MODE'] = False

tool_ch.variables['USERVER_CONAN'] = True
tool_ch.variables['USERVER_IS_THE_ROOT_PROJECT'] = False
tool_ch.variables['USERVER_DOWNLOAD_PACKAGES'] = True
tool_ch.variables['USERVER_FEATURE_DWCAS'] = True
tool_ch.variables['USERVER_NAMESPACE'] = self.options.namespace
Expand Down
Loading

0 comments on commit 38e9112

Please sign in to comment.