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 cmake: use direct includes for find packages in install, test reconfigure #829

Closed
wants to merge 9 commits into from
Closed
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
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
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
6 changes: 1 addition & 5 deletions cmake/install/userver-mysql-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(libmariadb REQUIRED CONFIG)
else()
include("${USERVER_CMAKE_DIR}/modules/Findlibmariadb.cmake")
endif()
find_package(libmariadb REQUIRED)

set(userver_mysql_FOUND TRUE)
2 changes: 1 addition & 1 deletion cmake/install/userver-rabbitmq-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ find_package(userver REQUIRED COMPONENTS
core
)

include("${USERVER_CMAKE_DIR}/SetupAmqpCPP.cmake")
find_package(amqpcpp REQUIRED)

set(userver_rabbitmq_FOUND TRUE)
6 changes: 1 addition & 5 deletions cmake/install/userver-redis-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(hiredis REQUIRED CONFIG)
else()
include("${USERVER_CMAKE_DIR}/modules/FindHiredis.cmake")
endif()
find_package(hiredis REQUIRED)

set(userver_redis_FOUND TRUE)
2 changes: 1 addition & 1 deletion cmake/install/userver-rocks-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ find_package(userver REQUIRED COMPONENTS
core
)

include("${USERVER_CMAKE_DIR}/modules/FindRocksDB.cmake")
find_package(RocksDB REQUIRED)

set(userver_rocks_FOUND TRUE)
Loading
Loading