Skip to content

Commit f4c21b7

Browse files
segoonAnton3
authored andcommitted
feat cmake: add CPM to Boost
Tests: протестировано CI Pull Request resolved: #1011 commit_hash:4880cdf67f132813d979f0a22fedc9d837ba51cb
1 parent 876d0b7 commit f4c21b7

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@
497497
"cmake/Sanitizers.cmake":"taxi/uservices/userver/cmake/Sanitizers.cmake",
498498
"cmake/SetupAbseil.cmake":"taxi/uservices/userver/cmake/SetupAbseil.cmake",
499499
"cmake/SetupAmqpCPP.cmake":"taxi/uservices/userver/cmake/SetupAmqpCPP.cmake",
500+
"cmake/SetupBoost.cmake":"taxi/uservices/userver/cmake/SetupBoost.cmake",
500501
"cmake/SetupBrotli.cmake":"taxi/uservices/userver/cmake/SetupBrotli.cmake",
501502
"cmake/SetupCAres.cmake":"taxi/uservices/userver/cmake/SetupCAres.cmake",
502503
"cmake/SetupCCTZ.cmake":"taxi/uservices/userver/cmake/SetupCCTZ.cmake",

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ set(USERVER_THIRD_PARTY_DIRS
201201

202202
init_debian_depends()
203203

204+
include(SetupBoost)
204205
include(SetupGTest)
205206

206207
if(USERVER_FEATURE_GRPC)

cmake/SetupBoost.cmake

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
include_guard(GLOBAL)
2+
3+
option(USERVER_DOWNLOAD_PACKAGE_BOOST "Download and setup Boost if no library of matching version was found"
4+
${USERVER_DOWNLOAD_PACKAGES}
5+
)
6+
option(USERVER_FORCE_DOWNLOAD_BOOST "Download Boost even if there is an installed system package"
7+
${USERVER_FORCE_DOWNLOAD_PACKAGES}
8+
)
9+
10+
set(BOOST_VERSION 1.89.0)
11+
set(BOOST_INCLUDE_LIBRARIES_FIND_PACKAGE
12+
atomic
13+
program_options
14+
filesystem
15+
regex
16+
locale
17+
iostreams
18+
context
19+
coroutine
20+
)
21+
set(BOOST_INCLUDE_LIBRARIES
22+
${BOOST_INCLUDE_LIBRARIES_FIND_PACKAGE}
23+
coroutine2
24+
stacktrace
25+
uuid
26+
lockfree
27+
endian
28+
assert
29+
predef
30+
)
31+
string(REGEX REPLACE ";" "\\\\\\\\;" BOOST_INCLUDE_LIBRARIES_LIST "${BOOST_INCLUDE_LIBRARIES}")
32+
33+
if(NOT USERVER_FORCE_DOWNLOAD_BOOST AND NOT BOOST_CPM)
34+
if(USERVER_DOWNLOAD_PACKAGE_BOOST)
35+
set(MAYBE_REQUIRED)
36+
else()
37+
set(MAYBE_REQUIRED REQUIRED)
38+
endif()
39+
find_package(
40+
Boost ${MAYBE_REQUIRED} CONFIG
41+
COMPONENTS ${BOOST_INCLUDE_LIBRARIES_FIND_PACKAGE}
42+
OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_windbg
43+
)
44+
45+
if(Boost_FOUND)
46+
return()
47+
endif()
48+
endif()
49+
50+
include(DownloadUsingCPM)
51+
set(BOOST_CPM TRUE CACHE BOOL "")
52+
53+
cpmaddpackage(
54+
NAME Boost
55+
VERSION ${BOOST_VERSION}
56+
URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.xz
57+
URL_HASH SHA256=67acec02d0d118b5de9eb441f5fb707b3a1cdd884be00ca24b9a73c995511f74
58+
OPTIONS
59+
"BOOST_ENABLE_CMAKE ON"
60+
"BOOST_INCLUDE_LIBRARIES ${BOOST_INCLUDE_LIBRARIES_LIST}"
61+
"BOOST_SKIP_INSTALL_RULES ON"
62+
"BUILD_SHARED_LIBS OFF"
63+
"BOOST_RUNTIME_LINK static"
64+
"BUILD_TESTING OFF"
65+
"BOOST_LOCKFREE_BUILD_TESTS OFF"
66+
EXCLUDE_FROM_ALL
67+
)
68+
69+
# We have fresh version of boost, DWCAS should work
70+
set(USERVER_IMPL_DWCAS_CHECKED TRUE CACHE INTERNAL "TRUE iff checked that DWCAS works")

cmake/UserverRequireDWCAS.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ function(userver_target_require_dwcas target visibility)
9292
try_run(
9393
RUN_RESULT COMPILE_RESULT "${CMAKE_CURRENT_BINARY_DIR}/require_dwcas"
9494
"${USERVER_ROOT_DIR}/cmake/UserverRequireDWCAS.cpp"
95-
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Boost_INCLUDE_DIRS}"
96-
COMPILE_DEFINITIONS ${TEST_DEFINITIONS} LINK_LIBRARIES ${TEST_LIBRARIES}
95+
COMPILE_DEFINITIONS ${TEST_DEFINITIONS}
96+
LINK_LIBRARIES ${TEST_LIBRARIES}
9797
COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
9898
)
9999

core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ file(GLOB_RECURSE INTERNAL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/internal/*.cpp
3737

3838
list(REMOVE_ITEM SOURCES ${INTERNAL_SOURCES})
3939

40-
find_package(Boost REQUIRED CONFIG COMPONENTS program_options filesystem locale regex iostreams)
4140
find_package_required(ZLIB "zlib1g-dev")
4241

4342
find_package(Iconv REQUIRED)
@@ -139,7 +138,6 @@ if(USERVER_FEATURE_UBOOST_CORO)
139138
target_link_libraries(${PROJECT_NAME} PRIVATE userver-uboost-coro)
140139
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/uboost_coro/include)
141140
else()
142-
find_package(Boost REQUIRED CONFIG COMPONENTS context coroutine)
143141
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::context)
144142
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/sys_coro/include)
145143
endif()

third_party/uboost_coro/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ if(UBOOST_CORO_USE_UCONTEXT)
9393
endif()
9494
endif()
9595

96-
find_package(Boost REQUIRED CONFIG)
97-
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost userver-internal-compile-options)
96+
97+
target_link_libraries(${PROJECT_NAME} PUBLIC userver-internal-compile-options)
9898
_userver_install_targets(COMPONENT core TARGETS ${PROJECT_NAME})

universal/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ list(REMOVE_ITEM SOURCES ${UNIT_TEST_SOURCES} ${BENCH_SOURCES} ${INTERNAL_SOURCE
2525
set(CMAKE_THREAD_PREFER_PTHREAD ON)
2626
set(THREADS_PREFER_PTHREAD_FLAG ON)
2727
find_package(Threads REQUIRED)
28-
find_package(
29-
Boost REQUIRED CONFIG
30-
COMPONENTS program_options filesystem regex stacktrace_basic
31-
OPTIONAL_COMPONENTS stacktrace_backtrace stacktrace_windbg
32-
)
3328
include(UserverRequireDWCAS) # Should be called after `find_package(Boost)`
3429

3530
message(STATUS "boost: ${Boost_VERSION_STRING}")
@@ -242,6 +237,12 @@ target_link_libraries(
242237
PUBLIC Threads::Threads userver-internal-sanitize-options userver-internal-compile-options
243238
PRIVATE Boost::filesystem Boost::program_options OpenSSL::Crypto OpenSSL::SSL
244239
)
240+
if(TARGET Boost::algorithm)
241+
target_link_libraries(
242+
${PROJECT_NAME}
243+
PUBLIC Boost::algorithm Boost::uuid Boost::random Boost::container
244+
)
245+
endif()
245246

246247
if(USERVER_CONAN)
247248
target_link_libraries(

0 commit comments

Comments
 (0)