Skip to content

Commit

Permalink
feat cmake: unify target names, prefer config mode for conan
Browse files Browse the repository at this point in the history
Tests: протестировано CI
Pull Request resolved: #829

Co-authored-by: Fedor Osetrov <[email protected]>
commit_hash:b291d72a6564d544aaacb1d26e9ecc2abe8f6040
  • Loading branch information
fdr400 committed Jan 28, 2025
1 parent 48f7ee4 commit 429a6c8
Show file tree
Hide file tree
Showing 58 changed files with 258 additions and 242 deletions.
45 changes: 26 additions & 19 deletions .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ jobs:
name: ubuntu-24.04 (build-only)
runs-on: ubuntu-24.04

env:
CMAKE_PROGRAM_PATH: /usr/lib/llvm17/bin
CMAKE_FLAGS: >-
-DCMAKE_BUILD_TYPE=Debug
-DUSERVER_USE_LD=lld
-DUSERVER_NO_WERROR=OFF
-DUSERVER_BUILD_ALL_COMPONENTS=1
-DUSERVER_BUILD_SAMPLES=1
-DUSERVER_BUILD_TESTS=1
-DUSERVER_FEATURE_JEMALLOC=OFF
-DUSERVER_FEATURE_KAFKA=OFF
-DUSERVER_FEATURE_CLICKHOUSE=OFF
-DUSERVER_FEATURE_STACKTRACE=OFF
-DUSERVER_FEATURE_PATCH_LIBPQ=OFF
-DUSERVER_DISABLE_RSEQ_ACCELERATION=YES
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=1
-DUSERVER_FORCE_DOWNLOAD_PROTOBUF=1
-DUSERVER_FORCE_DOWNLOAD_GRPC=1
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -88,25 +107,13 @@ jobs:
shell: alpine.sh --root {0}
run: |
pwd
CMAKE_PROGRAM_PATH=/usr/lib/llvm17/bin/ \
cmake -S . -B build_debug \
-DCMAKE_BUILD_TYPE=Debug \
-DUSERVER_USE_LD=lld \
-DUSERVER_NO_WERROR=OFF \
-DUSERVER_BUILD_ALL_COMPONENTS=1 \
-DUSERVER_BUILD_SAMPLES=1 \
-DUSERVER_BUILD_TESTS=1 \
-DUSERVER_FEATURE_JEMALLOC=OFF \
-DUSERVER_FEATURE_KAFKA=OFF \
-DUSERVER_FEATURE_CLICKHOUSE=OFF \
-DUSERVER_FEATURE_STACKTRACE=OFF \
-DUSERVER_FEATURE_PATCH_LIBPQ=OFF \
-DUSERVER_DOWNLOAD_PACKAGE_PROTOBUF=ON \
-DUSERVER_DISABLE_RSEQ_ACCELERATION=YES \
-DUSERVER_FORCE_DOWNLOAD_RE2=1 \
-DUSERVER_FORCE_DOWNLOAD_ABSEIL=1 \
-DUSERVER_FORCE_DOWNLOAD_PROTOBUF=1 \
-DUSERVER_FORCE_DOWNLOAD_GRPC=1 \
cmake -S . -B build_debug $CMAKE_FLAGS
- name: Reconfigure cmake
shell: alpine.sh --root {0}
run: |
pwd
cmake -S . -B build_debug $CMAKE_FLAGS
- name: Compile
shell: alpine.sh --root {0}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ jobs:
run: |
cmake -S . -B build_debug ${{matrix.cmake-flags}}
- name: Reconfigure cmake
run: |
cmake -S . -B build_debug ${{matrix.cmake-flags}}
- name: Run clang-tidy
if: matrix.info == 'clang-14 + debug + sanitize addr+ub'
run: |
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,21 @@ jobs:
run: docker-compose -f .github/docker-compose.yml run --rm ${{ matrix.image
}} bash -c 'ccache -M 2.0GB && ccache -s -v'

- name: CMake
- name: Run cmake
run: >-
docker-compose -f .github/docker-compose.yml
run --rm ${{ matrix.image }} bash -c
'cd /userver && cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos
${{ matrix.cmake-flags }} -B./build -S./'
- name: Build
- name: Reconfigure cmake
run: >-
docker-compose -f .github/docker-compose.yml
run --rm ${{ matrix.image }} bash -c
'cd /userver && cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos
${{ matrix.cmake-flags }} -B./build -S./'
- name: Compile
run: >-
docker-compose -f .github/docker-compose.yml
run --rm ${{ matrix.image }} bash -c
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
run: |
cmake -S./ -B./build_debug -DUSERVER_PYTHON_PATH=$(brew --prefix)/bin/python3.11 $CMAKE_FLAGS
- name: Reconfigure cmake
run: |
cmake -S./ -B./build_debug -DUSERVER_PYTHON_PATH=$(brew --prefix)/bin/python3.11 $CMAKE_FLAGS
- name: Compile
run: |
cmake --build build_debug -j$(nproc) -- -k 1
Expand Down
18 changes: 9 additions & 9 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,34 +452,34 @@
"cmake/install/userver-universal-config.cmake":"taxi/uservices/userver/cmake/install/userver-universal-config.cmake",
"cmake/install/userver-ydb-config.cmake":"taxi/uservices/userver/cmake/install/userver-ydb-config.cmake",
"cmake/modules/FindBrotli.cmake":"taxi/uservices/userver/cmake/modules/FindBrotli.cmake",
"cmake/modules/FindCryptoPP.cmake":"taxi/uservices/userver/cmake/modules/FindCryptoPP.cmake",
"cmake/modules/FindGrpcChannelz.cmake":"taxi/uservices/userver/cmake/modules/FindGrpcChannelz.cmake",
"cmake/modules/FindGssApi.cmake":"taxi/uservices/userver/cmake/modules/FindGssApi.cmake",
"cmake/modules/FindHiredis.cmake":"taxi/uservices/userver/cmake/modules/FindHiredis.cmake",
"cmake/modules/FindJemalloc.cmake":"taxi/uservices/userver/cmake/modules/FindJemalloc.cmake",
"cmake/modules/FindLibEv.cmake":"taxi/uservices/userver/cmake/modules/FindLibEv.cmake",
"cmake/modules/FindNghttp2.cmake":"taxi/uservices/userver/cmake/modules/FindNghttp2.cmake",
"cmake/modules/FindPostgreSQLInternal.cmake":"taxi/uservices/userver/cmake/modules/FindPostgreSQLInternal.cmake",
"cmake/modules/FindPugixml.cmake":"taxi/uservices/userver/cmake/modules/FindPugixml.cmake",
"cmake/modules/FindPythonDev.cmake":"taxi/uservices/userver/cmake/modules/FindPythonDev.cmake",
"cmake/modules/FindRdKafka.cmake":"taxi/uservices/userver/cmake/modules/FindRdKafka.cmake",
"cmake/modules/FindRocksDB.cmake":"taxi/uservices/userver/cmake/modules/FindRocksDB.cmake",
"cmake/modules/FindSASL2.cmake":"taxi/uservices/userver/cmake/modules/FindSASL2.cmake",
"cmake/modules/FindUserverGBench.cmake":"taxi/uservices/userver/cmake/modules/FindUserverGBench.cmake",
"cmake/modules/FindUserverGrpc.cmake":"taxi/uservices/userver/cmake/modules/FindUserverGrpc.cmake",
"cmake/modules/Findamqpcpp.cmake":"taxi/uservices/userver/cmake/modules/Findamqpcpp.cmake",
"cmake/modules/Findbson.cmake":"taxi/uservices/userver/cmake/modules/Findbson.cmake",
"cmake/modules/Findc-ares.cmake":"taxi/uservices/userver/cmake/modules/Findc-ares.cmake",
"cmake/modules/Findcctz.cmake":"taxi/uservices/userver/cmake/modules/Findcctz.cmake",
"cmake/modules/Findclickhouse-cpp.cmake":"taxi/uservices/userver/cmake/modules/Findclickhouse-cpp.cmake",
"cmake/modules/Findcryptopp.cmake":"taxi/uservices/userver/cmake/modules/Findcryptopp.cmake",
"cmake/modules/Findfmt.cmake":"taxi/uservices/userver/cmake/modules/Findfmt.cmake",
"cmake/modules/Findhiredis.cmake":"taxi/uservices/userver/cmake/modules/Findhiredis.cmake",
"cmake/modules/Findjemalloc.cmake":"taxi/uservices/userver/cmake/modules/Findjemalloc.cmake",
"cmake/modules/Findlibev.cmake":"taxi/uservices/userver/cmake/modules/Findlibev.cmake",
"cmake/modules/Findlibgflags.cmake":"taxi/uservices/userver/cmake/modules/Findlibgflags.cmake",
"cmake/modules/Findlibmariadb.cmake":"taxi/uservices/userver/cmake/modules/Findlibmariadb.cmake",
"cmake/modules/Findlibnghttp2.cmake":"taxi/uservices/userver/cmake/modules/Findlibnghttp2.cmake",
"cmake/modules/Findlibsnappy.cmake":"taxi/uservices/userver/cmake/modules/Findlibsnappy.cmake",
"cmake/modules/Findlibyamlcpp.cmake":"taxi/uservices/userver/cmake/modules/Findlibyamlcpp.cmake",
"cmake/modules/Findlibzstd.cmake":"taxi/uservices/userver/cmake/modules/Findlibzstd.cmake",
"cmake/modules/Findlz4.cmake":"taxi/uservices/userver/cmake/modules/Findlz4.cmake",
"cmake/modules/Findmongoc.cmake":"taxi/uservices/userver/cmake/modules/Findmongoc.cmake",
"cmake/modules/Findpugixml.cmake":"taxi/uservices/userver/cmake/modules/Findpugixml.cmake",
"cmake/modules/Findre2.cmake":"taxi/uservices/userver/cmake/modules/Findre2.cmake",
"cmake/modules/Findyaml-cpp.cmake":"taxi/uservices/userver/cmake/modules/Findyaml-cpp.cmake",
"cmake/modules/Findzstd.cmake":"taxi/uservices/userver/cmake/modules/Findzstd.cmake",
"cmake/sanitize-macos.blacklist.txt":"taxi/uservices/userver/cmake/sanitize-macos.blacklist.txt",
"cmake/sanitize.blacklist.txt":"taxi/uservices/userver/cmake/sanitize.blacklist.txt",
"conanfile.py":"taxi/uservices/userver/conanfile.py",
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ option(USERVER_FEATURE_OTLP "Provide asynchronous OTLP exporters" "${USERVER_LIB
set(CMAKE_DEBUG_POSTFIX d)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(USERVER_CONAN AND NOT DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
endif()

set(USERVER_USE_STATIC_LIBS_DEFAULT OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0)
Expand Down
6 changes: 2 additions & 4 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
project(userver-clickhouse CXX)

if (USERVER_CONAN)
find_package(clickhouse-cpp REQUIRED CONFIG)
set(CLICKHOUSE_CPP_TARGET clickhouse-cpp-lib::clickhouse-cpp-lib)
find_package(clickhouse-cpp REQUIRED)
else()
include(SetupClickhouseCPP)
set(CLICKHOUSE_CPP_TARGET clickhouse-cpp)
endif()

userver_module(clickhouse
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
LINK_LIBRARIES_PRIVATE "${CLICKHOUSE_CPP_TARGET}"
LINK_LIBRARIES_PRIVATE clickhouse-cpp-lib::clickhouse-cpp-lib

UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
DBTEST_SOURCES
Expand Down
4 changes: 2 additions & 2 deletions cmake/ModuleHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ macro(_userver_module_end)
add_library("${name}" INTERFACE IMPORTED GLOBAL)

if(NOT "${${includes_variable}}" STREQUAL "")
target_include_directories("${name}" INTERFACE ${${includes_variable}})
set_target_properties("${name}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${${includes_variable}}")
message(STATUS "${name} include directories: ${${includes_variable}}")
endif()

if(NOT "${${libraries_variable}}" STREQUAL "")
target_link_libraries("${name}" INTERFACE ${${libraries_variable}})
set_target_properties("${name}" PROPERTIES INTERFACE_LINK_LIBRARIES "${${libraries_variable}}")
message(STATUS "${name} libraries: ${${libraries_variable}}")
endif()
endif()
Expand Down
6 changes: 0 additions & 6 deletions cmake/SetupBrotli.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ if (NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
endif()

if (Brotli_FOUND)
if(NOT TARGET Brotli::dec)
add_library(Brotli::dec ALIAS brotlidec)
endif()
if(NOT TARGET Brotli::enc)
add_library(Brotli::enc ALIAS brotlienc)
endif()
return()
endif()
endif()
Expand Down
3 changes: 0 additions & 3 deletions cmake/SetupCAres.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ if (NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
endif()

if (c-ares_FOUND)
if(NOT TARGET c-ares::cares)
add_library(c-ares::cares ALIAS c-ares)
endif()
return()
endif()
endif()
Expand Down
4 changes: 3 additions & 1 deletion cmake/SetupClickhouseCPP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ CPMAddPackage(
"DEBUG_DEPENDENCIES OFF"
)

add_library(clickhouse-cpp ALIAS clickhouse-cpp-lib)
if(NOT TARGET clickhouse-cpp-lib::clickhouse-cpp-lib)
add_library(clickhouse-cpp-lib::clickhouse-cpp-lib ALIAS clickhouse-cpp-lib)
endif()
6 changes: 3 additions & 3 deletions cmake/SetupCryptoPP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ option(

if (NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
if (USERVER_DOWNLOAD_PACKAGE_CRYPTOPP)
find_package(CryptoPP QUIET)
find_package(cryptopp QUIET)
else()
find_package(CryptoPP REQUIRED)
find_package(cryptopp REQUIRED)
endif()

if (CryptoPP_FOUND)
if (cryptopp_FOUND)
return()
endif()
endif()
Expand Down
3 changes: 0 additions & 3 deletions cmake/SetupFmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ if (NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
endif()

if (fmt_FOUND)
if(NOT TARGET fmt)
add_library(fmt ALIAS fmt::fmt)
endif()
return()
endif()
endif()
Expand Down
3 changes: 0 additions & 3 deletions cmake/SetupGBench.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ if (NOT USERVER_FORCE_DOWNLOAD_PACKAGES)
endif()

if (UserverGBench_FOUND)
if (NOT TARGET benchmark::benchmark)
add_library(benchmark::benchmark ALIAS UserverGBench) # Unify link names
endif()
return()
endif()
endif()
Expand Down
2 changes: 0 additions & 2 deletions cmake/SetupMongoDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ if (USERVER_MONGODB_USE_CMAKE_CONFIG)
find_package(mongoc-1.0 QUIET CONFIG)
if(mongoc-1.0_FOUND)
message(STATUS "Mongoc: using config version: (bson: ${bson-1.0_VERSION}, mongoc: ${mongoc-1.0_VERSION})")
add_library(bson ALIAS mongo::bson_static)
add_library(mongoc ALIAS mongo::mongoc_static)
return()
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function(_userver_set_protobuf_version_category)
endfunction()

if(USERVER_CONAN)
find_package(Protobuf REQUIRED CONFIG)
find_package(Protobuf REQUIRED)
_userver_set_protobuf_version_category()
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
return()
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupRdKafka.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/SetupCURL.cmake")

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(libzstd REQUIRED)
find_package(zstd REQUIRED)
find_package(lz4 REQUIRED)
find_package(SASL2 REQUIRED)

Expand Down
8 changes: 5 additions & 3 deletions cmake/SetupRocksDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ find_package(libgflags REQUIRED)
find_package(libsnappy REQUIRED)
find_package(ZLIB REQUIRED)
find_package(BZip2 REQUIRED)
find_package(libzstd REQUIRED)
find_package(zstd REQUIRED)

include(DownloadUsingCPM)

CPMAddPackage(
NAME rocksdb
NAME RocksDB
GITHUB_REPOSITORY facebook/rocksdb
GIT_TAG v9.7.4
OPTIONS
Expand All @@ -41,4 +41,6 @@ CPMAddPackage(
)

mark_targets_as_system("${rocksdb_SOURCE_DIR}")
add_library(RocksDB::rocksdb ALIAS rocksdb)
if(NOT TARGET RocksDB::rocksdb)
add_library(RocksDB::rocksdb ALIAS rocksdb)
endif()
1 change: 1 addition & 0 deletions cmake/SetupYdbCppSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CPMAddPackage(
"Brotli_VERSION ${Brotli_VERSION}"
"RAPIDJSON_INCLUDE_DIRS ${RAPIDJSON_INCLUDE_DIRS}"
"YDB_SDK_GOOGLE_COMMON_PROTOS_TARGET ${YDB_SDK_GOOGLE_COMMON_PROTOS_TARGET}"
"YDB_SDK_EXAMPLES OFF"
)

list(APPEND ydb-cpp-sdk_INCLUDE_DIRS
Expand Down
12 changes: 11 additions & 1 deletion cmake/install/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ set(USERVER_IMPL_ORIGINAL_CXX_STANDARD @CMAKE_CXX_STANDARD@)
set(USERVER_IMPL_FEATURE_JEMALLOC @USERVER_FEATURE_JEMALLOC@)
set(USERVER_USE_STATIC_LIBS @USERVER_USE_STATIC_LIBS@)

if(USERVER_CONAN AND NOT DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
endif()

set_property(GLOBAL PROPERTY userver_cmake_dir "${USERVER_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${USERVER_CMAKE_DIR}/modules")
if(NOT USERVER_CONAN)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
list(PREPEND CMAKE_MODULE_PATH "${USERVER_CMAKE_DIR}/modules")
else()
list(APPEND CMAKE_MODULE_PATH "${USERVER_CMAKE_DIR}/modules")
endif()
endif()

include("${USERVER_CMAKE_DIR}/UserverPreferStaticLibs.cmake")

Expand Down
6 changes: 1 addition & 5 deletions cmake/install/userver-clickhouse-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ find_package(userver REQUIRED COMPONENTS
core
)

if (USERVER_CONAN)
find_package(clickhouse-cpp REQUIRED CONFIG)
else()
include("${USERVER_CMAKE_DIR}/modules/Findclickhouse-cpp.cmake")
endif()
find_package(clickhouse-cpp REQUIRED)

set(userver_clickhouse_FOUND TRUE)
18 changes: 6 additions & 12 deletions cmake/install/userver-core-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@ find_package(Boost REQUIRED CONFIG COMPONENTS
)

find_package(ZLIB REQUIRED)

include("${USERVER_CMAKE_DIR}/UserverTestsuite.cmake")
find_package(c-ares REQUIRED)
find_package(libnghttp2 REQUIRED)
find_package(libev REQUIRED)

if (USERVER_CONAN)
find_package(c-ares REQUIRED CONFIG)
find_package(libnghttp2 REQUIRED CONFIG)
find_package(libev REQUIRED CONFIG)
find_package(concurrentqueue REQUIRED CONFIG)
find_package(concurrentqueue REQUIRED)
find_package(CURL "7.68" REQUIRED)
else()
find_package(Nghttp2 REQUIRED)
find_package(LibEv REQUIRED)
find_package(c-ares REQUIRED)
if (c-ares_FOUND AND NOT TARGET c-ares::cares)
add_library(c-ares::cares ALIAS c-ares)
endif()
include("${USERVER_CMAKE_DIR}/SetupCURL.cmake")
endif()

include("${USERVER_CMAKE_DIR}/UserverTestsuite.cmake")

set(userver_core_FOUND TRUE)
2 changes: 1 addition & 1 deletion cmake/install/userver-kafka-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ find_package(userver REQUIRED COMPONENTS
)

if(USERVER_CONAN)
find_package(RdKafka REQUIRED CONFIG)
find_package(RdKafka REQUIRED)
else()
include("${USERVER_CMAKE_DIR}/SetupRdKafka.cmake")
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/install/userver-mongo-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ find_package(userver REQUIRED COMPONENTS
)

if (USERVER_CONAN)
find_package(mongoc-1.0 REQUIRED CONFIG)
find_package(mongoc-1.0 REQUIRED)
else()
include("${USERVER_CMAKE_DIR}/SetupMongoDeps.cmake")
endif()
Expand Down
Loading

0 comments on commit 429a6c8

Please sign in to comment.