Skip to content

Commit 7a1bb49

Browse files
committed
Update Boost example to v1.87.0
1 parent cd28d44 commit 7a1bb49

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

examples/boost/CMakeLists.txt

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,61 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.14...3.31 FATAL_ERROR)
22

3-
project(CPMExampleBoost)
3+
project(CPMExampleBoost LANGUAGES CXX)
44

55
# ---- Create binary ----
66

7-
add_executable(CPMExampleBoost main.cpp)
7+
add_library(CPMExampleBoost main.cpp)
88
target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
99

1010
# ---- Dependencies ----
1111

12+
set(env{CPM_USE_LOCAL_PACKAGES} OFF)
13+
1214
include(../../cmake/CPM.cmake)
1315

16+
set(CMAKE_SKIP_INSTALL_RULES OFF)
17+
set(CMAKE_INSTALL_MESSAGE LAZY)
18+
set(CMAKE_UNITY_BUILD ON)
19+
20+
21+
set(BOOST_VERSION 1.87.0)
22+
list(APPEND BOOST_INCLUDE_LIBRARIES asio container)
23+
24+
set(BUILD_SHARED_LIBS ON)
25+
1426
CPMAddPackage(
1527
NAME Boost
16-
VERSION 1.86.0 # Versions less than 1.85.0 may need patches for installation targets.
17-
URL https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-cmake.tar.xz
18-
URL_HASH SHA256=2c5ec5edcdff47ff55e27ed9560b0a0b94b07bd07ed9928b476150e16b0efc57
19-
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_SKIP_INSTALL_RULES ON" # Set `OFF` for installation
20-
"BUILD_SHARED_LIBS OFF" "BOOST_INCLUDE_LIBRARIES container\\\;asio" # Note the escapes!
28+
VERSION ${BOOST_VERSION}
29+
URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.xz
30+
URL_HASH SHA256=7da75f171837577a52bbf217e17f8ea576c7c246e4594d617bfde7fafd408be5
31+
EXCLUDE_FROM_ALL ON
32+
SYSTEM ON
33+
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_SKIP_INSTALL_RULES ${CMAKE_SKIP_INSTALL_RULES}"
2134
)
2235

2336
# `Boost::headers` is also valid
24-
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio Boost::container)
37+
target_link_libraries(CPMExampleBoost PUBLIC Boost::asio Boost::container)
38+
39+
if(CMAKE_SKIP_INSTALL_RULES)
40+
return()
41+
endif()
42+
43+
# ---- Install rules ----
44+
45+
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.11.0")
46+
47+
packageProject(
48+
NAME CPMExampleBoost
49+
TARGETS CPMExampleBoost
50+
VERSION ${BOOST_VERSION}
51+
NAMESPACE BoostExample
52+
BINARY_DIR ${PROJECT_BINARY_DIR}
53+
ARCH_INDEPENDENT NO
54+
# INCLUDE_DIR ${BOOST_SOURCE}/boost
55+
# INCLUDE_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/boost
56+
# INCLUDE_HEADER_REGEX [=[.*\.(inc|h|hpp|ipp)$]=]
57+
DISABLE_VERSION_SUFFIX YES
58+
COMPATIBILITY SameMajorVersion
59+
DEPENDENCIES "Boost ${BOOST_VERSION}"
60+
CPACK YES
61+
)

examples/boost/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void print(const boost::system::error_code& /*e*/) {
2121
}
2222

2323
int main() {
24-
boost::asio::io_service io;
24+
boost::asio::io_context io;
2525

2626
strings.push_back("Hello, world!\n");
2727

0 commit comments

Comments
 (0)