Skip to content

Commit fe2fad0

Browse files
committed
Add experimental install rules
This will also generate a BoostConfig.cmake file ready to be used by "find_package(Boost CONFIG)".
1 parent 7bfe14b commit fe2fad0

File tree

13 files changed

+90
-13
lines changed

13 files changed

+90
-13
lines changed

BoostConfig.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
set(_boost_deps @BOOST_FIND_PACKAGE@)
2+
3+
foreach(dep ${_boost_deps})
4+
find_package(${dep} QUIET)
5+
if(${dep}_FOUND)
6+
list(APPEND _boost_deps_found ${dep})
7+
else()
8+
list(APPEND _boost_deps_missing ${dep})
9+
endif()
10+
endforeach()
11+
12+
message(STATUS "Boost dependencies found: ${_boost_deps_found}")
13+
if(_boost_deps_missing)
14+
message(STATUS "Boost dependencies missing: ${_boost_deps_missing}")
15+
endif()
16+
17+
unset(_boost_deps)
18+
unset(_boost_deps_found)
19+
unset(_boost_deps_missing)
20+
21+
include("${CMAKE_CURRENT_LIST_DIR}/BoostTargets.cmake")

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ endforeach()
6767
# TODO: Move those to option() calls in the right file
6868
if(NOT BOOST_STANDALONE)
6969
# Compilation options required by all platforms
70-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<CONFIG:Release>:BOOST_DISABLE_ASSERT>)
71-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_SYSTEM_NO_DEPRECATED)
72-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_VERSION=4)
73-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_USES_CHRONO)
74-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_PROVIDES_EXECUTORS)
70+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<CONFIG:Release>:BOOST_DISABLE_ASSERT>)
71+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_SYSTEM_NO_DEPRECATED)
72+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_VERSION=4)
73+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_USES_CHRONO)
74+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_PROVIDES_EXECUTORS)
7575
endif()
7676

7777
if(USE_ANDROID)
7878
# Android doesn't support thread local storage through compiler intrinsics
79-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
79+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
8080
endif()
81+
82+
include(ExportLibraries)

cmake/Modules/AddBoostLib.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ function(_add_boost_lib)
99
set_target_properties(Boost_${BOOSTLIB_NAME} PROPERTIES
1010
OUTPUT_NAME "boost_${BOOSTLIB_NAME}"
1111
FOLDER "Boost"
12+
EXPORT_NAME "${BOOSTLIB_NAME}"
1213
)
1314
if(NOT BOOST_STANDALONE)
1415
set_target_properties(Boost_${BOOSTLIB_NAME} PROPERTIES EXCLUDE_FROM_ALL 1)
1516
endif()
1617
target_link_libraries(Boost_${BOOSTLIB_NAME} PUBLIC Boost::boost)
18+
install(TARGETS Boost_${BOOSTLIB_NAME} DESTINATION lib EXPORT boost-libs)
1719
if(MSVC)
1820
target_compile_options(Boost_${BOOSTLIB_NAME} PRIVATE /W0)
1921
else()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include(CMakePackageConfigHelpers)
2+
write_basic_package_Version_file("BoostConfigVersion.cmake"
3+
VERSION ${BOOST_VERSION}
4+
COMPATIBILITY AnyNewerVersion)
5+
6+
get_property(BOOST_FIND_PACKAGE GLOBAL PROPERTY Boost_Find_Package)
7+
if(BOOST_FIND_PACKAGE)
8+
# The list may be empty
9+
list(REMOVE_DUPLICATES BOOST_FIND_PACKAGE)
10+
endif()
11+
configure_file("BoostConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/BoostConfig.cmake" @ONLY)
12+
13+
install(FILES
14+
"${CMAKE_CURRENT_BINARY_DIR}/BoostConfig.cmake"
15+
"${CMAKE_CURRENT_BINARY_DIR}/BoostConfigVersion.cmake"
16+
DESTINATION lib/cmake/Boost
17+
)
18+
install(DIRECTORY ${BOOST_SOURCE}/boost
19+
DESTINATION include
20+
)
21+
install(EXPORT boost-libs
22+
DESTINATION lib/cmake/Boost
23+
NAMESPACE Boost::
24+
FILE BoostTargets.cmake
25+
)

libs/chrono.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ _add_boost_lib(
1111
if(NOT USE_WINDOWS)
1212
find_package(Threads)
1313
target_link_libraries(Boost_chrono PRIVATE Threads::Threads)
14+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package Threads)
1415

1516
find_library(RT_LIBRARY
1617
NAMES rt

libs/header.cmake

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# Define the header-only Boost target
2-
add_library(Boost::boost INTERFACE IMPORTED GLOBAL)
2+
add_library(Boost_boost INTERFACE)
3+
add_library(Boost::boost ALIAS Boost_boost)
4+
set_target_properties(Boost_boost PROPERTIES
5+
EXPORT_NAME "boost"
6+
)
7+
38
if(CMAKE_GENERATOR MATCHES "Xcode")
49
# The CMake Xcode generator doesn't support system headers directly
5-
set_target_properties(Boost::boost PROPERTIES INTERFACE_COMPILE_OPTIONS "-isystem;${BOOST_SOURCE}" )
10+
set_target_properties(Boost_boost PROPERTIES INTERFACE_COMPILE_OPTIONS "-isystem;${BOOST_SOURCE}" )
611
else()
7-
set_target_properties(Boost::boost PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${BOOST_SOURCE} )
8-
set_target_properties(Boost::boost PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${BOOST_SOURCE})
12+
set_target_properties(Boost_boost PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${BOOST_SOURCE} )
13+
set_target_properties(Boost_boost PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${BOOST_SOURCE}>;$<INSTALL_INTERFACE:include>")
914
endif()
15+
install(TARGETS Boost_boost DESTINATION lib EXPORT boost-libs)
1016

1117
# Disable autolink
12-
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ALL_NO_LIB=1)
18+
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ALL_NO_LIB=1)
19+
20+
add_library(Boost::boost_imported INTERFACE IMPORTED)
21+
set_target_properties(Boost::boost_imported PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BOOST_SOURCE}")

libs/iostreams.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if(BOOST_IOSTREAMS_ENABLE_BZIP2)
1919
target_link_libraries(Boost_iostreams PRIVATE
2020
BZip2::BZip2
2121
)
22+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package BZip2)
2223
endif()
2324
endif()
2425

@@ -32,6 +33,7 @@ if(BOOST_IOSTREAMS_ENABLE_ZLIB)
3233
target_link_libraries(Boost_iostreams PRIVATE
3334
ZLIB::ZLIB
3435
)
36+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package ZLIB)
3537
endif()
3638
endif()
3739

libs/locale.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ _add_boost_lib(
5959
# Convenience interface library to link deps to both main library and tests
6060
add_library(Boost_locale_deps INTERFACE)
6161
target_link_libraries(Boost_locale PRIVATE Boost_locale_deps)
62+
install(TARGETS Boost_locale_deps DESTINATION lib EXPORT boost-libs)
6263

6364
if(BOOST_LOCALE_ENABLE_ICU_BACKEND AND ICU_FOUND)
6465
target_sources(Boost_locale PRIVATE
@@ -79,6 +80,7 @@ if(BOOST_LOCALE_ENABLE_ICU_BACKEND AND ICU_FOUND)
7980
ICU::uc
8081
)
8182
target_compile_definitions(Boost_locale_deps INTERFACE BOOST_LOCALE_WITH_ICU=1)
83+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package ICU)
8284
endif()
8385

8486
if(BOOST_LOCALE_ENABLE_STD_BACKEND)
@@ -98,6 +100,7 @@ if(BOOST_LOCALE_ENABLE_ICONV_BACKEND AND ICONV_FOUND)
98100
Iconv::Iconv
99101
)
100102
target_compile_definitions(Boost_locale_deps INTERFACE BOOST_LOCALE_WITH_ICONV=1)
103+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package Iconv)
101104
endif()
102105

103106
if(BOOST_LOCALE_ENABLE_WINAPI_BACKEND)

libs/log.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ endif()
7676
try_compile(HAVE_ATOMIC_INT32
7777
"${CMAKE_CURRENT_BINARY_DIR}"
7878
"${BOOST_SOURCE}/libs/log/config/atomic-int32/atomic_int32.cpp"
79-
LINK_LIBRARIES Boost::boost
79+
LINK_LIBRARIES Boost::boost_imported
8080
)
8181
if(NOT HAVE_ATOMIC_INT32)
8282
target_compile_definitions(Boost_log PRIVATE BOOST_LOG_WITHOUT_IPC)

libs/mpi.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ _add_boost_lib(
3030
)
3131
target_include_directories(Boost_mpi PUBLIC ${MPI_CXX_INCLUDE_PATH})
3232
target_link_libraries(Boost_mpi PUBLIC ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES})
33+
set_property(GLOBAL APPEND PROPERTY Boost_Find_Property MPI)

0 commit comments

Comments
 (0)