Skip to content

Commit

Permalink
Add experimental install rules
Browse files Browse the repository at this point in the history
This will also generate a BoostConfig.cmake file ready to be used
by "find_package(Boost CONFIG)".
  • Loading branch information
Orphis committed Aug 15, 2017
1 parent 7bfe14b commit fe2fad0
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 13 deletions.
21 changes: 21 additions & 0 deletions BoostConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(_boost_deps @BOOST_FIND_PACKAGE@)

foreach(dep ${_boost_deps})
find_package(${dep} QUIET)
if(${dep}_FOUND)
list(APPEND _boost_deps_found ${dep})
else()
list(APPEND _boost_deps_missing ${dep})
endif()
endforeach()

message(STATUS "Boost dependencies found: ${_boost_deps_found}")
if(_boost_deps_missing)
message(STATUS "Boost dependencies missing: ${_boost_deps_missing}")
endif()

unset(_boost_deps)
unset(_boost_deps_found)
unset(_boost_deps_missing)

include("${CMAKE_CURRENT_LIST_DIR}/BoostTargets.cmake")
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ endforeach()
# TODO: Move those to option() calls in the right file
if(NOT BOOST_STANDALONE)
# Compilation options required by all platforms
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<CONFIG:Release>:BOOST_DISABLE_ASSERT>)
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_SYSTEM_NO_DEPRECATED)
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_VERSION=4)
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_USES_CHRONO)
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_PROVIDES_EXECUTORS)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<CONFIG:Release>:BOOST_DISABLE_ASSERT>)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_SYSTEM_NO_DEPRECATED)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_VERSION=4)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_USES_CHRONO)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_THREAD_PROVIDES_EXECUTORS)
endif()

if(USE_ANDROID)
# Android doesn't support thread local storage through compiler intrinsics
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
endif()

include(ExportLibraries)
2 changes: 2 additions & 0 deletions cmake/Modules/AddBoostLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ function(_add_boost_lib)
set_target_properties(Boost_${BOOSTLIB_NAME} PROPERTIES
OUTPUT_NAME "boost_${BOOSTLIB_NAME}"
FOLDER "Boost"
EXPORT_NAME "${BOOSTLIB_NAME}"
)
if(NOT BOOST_STANDALONE)
set_target_properties(Boost_${BOOSTLIB_NAME} PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
target_link_libraries(Boost_${BOOSTLIB_NAME} PUBLIC Boost::boost)
install(TARGETS Boost_${BOOSTLIB_NAME} DESTINATION lib EXPORT boost-libs)
if(MSVC)
target_compile_options(Boost_${BOOSTLIB_NAME} PRIVATE /W0)
else()
Expand Down
25 changes: 25 additions & 0 deletions cmake/Modules/ExportLibraries.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include(CMakePackageConfigHelpers)
write_basic_package_Version_file("BoostConfigVersion.cmake"
VERSION ${BOOST_VERSION}
COMPATIBILITY AnyNewerVersion)

get_property(BOOST_FIND_PACKAGE GLOBAL PROPERTY Boost_Find_Package)
if(BOOST_FIND_PACKAGE)
# The list may be empty
list(REMOVE_DUPLICATES BOOST_FIND_PACKAGE)
endif()
configure_file("BoostConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/BoostConfig.cmake" @ONLY)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BoostConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/BoostConfigVersion.cmake"
DESTINATION lib/cmake/Boost
)
install(DIRECTORY ${BOOST_SOURCE}/boost
DESTINATION include
)
install(EXPORT boost-libs
DESTINATION lib/cmake/Boost
NAMESPACE Boost::
FILE BoostTargets.cmake
)
1 change: 1 addition & 0 deletions libs/chrono.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _add_boost_lib(
if(NOT USE_WINDOWS)
find_package(Threads)
target_link_libraries(Boost_chrono PRIVATE Threads::Threads)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package Threads)

find_library(RT_LIBRARY
NAMES rt
Expand Down
19 changes: 14 additions & 5 deletions libs/header.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Define the header-only Boost target
add_library(Boost::boost INTERFACE IMPORTED GLOBAL)
add_library(Boost_boost INTERFACE)
add_library(Boost::boost ALIAS Boost_boost)
set_target_properties(Boost_boost PROPERTIES
EXPORT_NAME "boost"
)

if(CMAKE_GENERATOR MATCHES "Xcode")
# The CMake Xcode generator doesn't support system headers directly
set_target_properties(Boost::boost PROPERTIES INTERFACE_COMPILE_OPTIONS "-isystem;${BOOST_SOURCE}" )
set_target_properties(Boost_boost PROPERTIES INTERFACE_COMPILE_OPTIONS "-isystem;${BOOST_SOURCE}" )
else()
set_target_properties(Boost::boost PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${BOOST_SOURCE} )
set_target_properties(Boost::boost PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${BOOST_SOURCE})
set_target_properties(Boost_boost PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${BOOST_SOURCE} )
set_target_properties(Boost_boost PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${BOOST_SOURCE}>;$<INSTALL_INTERFACE:include>")
endif()
install(TARGETS Boost_boost DESTINATION lib EXPORT boost-libs)

# Disable autolink
set_property(TARGET Boost::boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ALL_NO_LIB=1)
set_property(TARGET Boost_boost APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS BOOST_ALL_NO_LIB=1)

add_library(Boost::boost_imported INTERFACE IMPORTED)
set_target_properties(Boost::boost_imported PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BOOST_SOURCE}")
2 changes: 2 additions & 0 deletions libs/iostreams.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if(BOOST_IOSTREAMS_ENABLE_BZIP2)
target_link_libraries(Boost_iostreams PRIVATE
BZip2::BZip2
)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package BZip2)
endif()
endif()

Expand All @@ -32,6 +33,7 @@ if(BOOST_IOSTREAMS_ENABLE_ZLIB)
target_link_libraries(Boost_iostreams PRIVATE
ZLIB::ZLIB
)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package ZLIB)
endif()
endif()

Expand Down
3 changes: 3 additions & 0 deletions libs/locale.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ _add_boost_lib(
# Convenience interface library to link deps to both main library and tests
add_library(Boost_locale_deps INTERFACE)
target_link_libraries(Boost_locale PRIVATE Boost_locale_deps)
install(TARGETS Boost_locale_deps DESTINATION lib EXPORT boost-libs)

if(BOOST_LOCALE_ENABLE_ICU_BACKEND AND ICU_FOUND)
target_sources(Boost_locale PRIVATE
Expand All @@ -79,6 +80,7 @@ if(BOOST_LOCALE_ENABLE_ICU_BACKEND AND ICU_FOUND)
ICU::uc
)
target_compile_definitions(Boost_locale_deps INTERFACE BOOST_LOCALE_WITH_ICU=1)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package ICU)
endif()

if(BOOST_LOCALE_ENABLE_STD_BACKEND)
Expand All @@ -98,6 +100,7 @@ if(BOOST_LOCALE_ENABLE_ICONV_BACKEND AND ICONV_FOUND)
Iconv::Iconv
)
target_compile_definitions(Boost_locale_deps INTERFACE BOOST_LOCALE_WITH_ICONV=1)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package Iconv)
endif()

if(BOOST_LOCALE_ENABLE_WINAPI_BACKEND)
Expand Down
2 changes: 1 addition & 1 deletion libs/log.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ endif()
try_compile(HAVE_ATOMIC_INT32
"${CMAKE_CURRENT_BINARY_DIR}"
"${BOOST_SOURCE}/libs/log/config/atomic-int32/atomic_int32.cpp"
LINK_LIBRARIES Boost::boost
LINK_LIBRARIES Boost::boost_imported
)
if(NOT HAVE_ATOMIC_INT32)
target_compile_definitions(Boost_log PRIVATE BOOST_LOG_WITHOUT_IPC)
Expand Down
1 change: 1 addition & 0 deletions libs/mpi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ _add_boost_lib(
)
target_include_directories(Boost_mpi PUBLIC ${MPI_CXX_INCLUDE_PATH})
target_link_libraries(Boost_mpi PUBLIC ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES})
set_property(GLOBAL APPEND PROPERTY Boost_Find_Property MPI)
3 changes: 2 additions & 1 deletion libs/thread.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ _add_boost_lib(
Boost::system
)
if(NOT USE_WINDOWS)
find_package(Threads REQUIRED)
find_package(Threads)

target_link_libraries(Boost_thread PUBLIC Threads::Threads)
target_compile_definitions(Boost_thread PRIVATE
BOOST_THREAD_POSIX
)
set_property(GLOBAL APPEND PROPERTY Boost_Find_Package "Threads")
endif()
7 changes: 7 additions & 0 deletions test/import-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.8.0)
project(import_test)

find_package(Boost CONFIG COMPONENTS unit_test_framework)

add_executable(import_test main.cpp)
target_link_libraries(import_test PRIVATE Boost::unit_test_framework Boost::iostreams)
3 changes: 3 additions & 0 deletions test/import-test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(int argc, char* argv[]) {
return 0;
}

0 comments on commit fe2fad0

Please sign in to comment.