-
Notifications
You must be signed in to change notification settings - Fork 157
Add install rules and BoostConfig script #45
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://cmake.org/cmake/help/v3.6/manual/cmake-packages.7.html#id17 |
||
| 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") | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to get dependency searching working per idiomatic CMake config package methodology, you're going to have to generate an export target per boost component. This means, for example, having:
etc.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't found any documentation for this, not sure if that's the way to go.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you look at this page (a bit towards the bottom of that linked section), you will see an example of how they handle components in config packages: include(CMakeFindDependencyMacro)
find_dependency(Stats 2.6.4)
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStatsMacros.cmake")
set(_supported_components Plot Table)
foreach(_comp ${ClimbingStats_FIND_COMPONENTS})
if (NOT ";${_supported_components};" MATCHES _comp)
set(ClimbingStats_FOUND False)
set(ClimbingStats_NOTFOUND_MESSAGE "Unsupported component: ${_comp}")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/ClimbingStats${_comp}Targets.cmake")
endforeach()This is what I'm basing my suggestion on. Would this make sense for boost?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... That's just extra complexity for the sake of it, I don't really see the point of adding that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're the boss, I'm just sharing my thoughts. Honestly I don't have much experience with configure packages so I'm not sure what is right, wrong, or ideal
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have that much experience either, to be honest!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So let me ask then: If I do this: Will I also have targets like Am I correct on this? I'm having some work machine problems, but once I get past that I'll be able to test that theory for you.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I believe that's relevant for Find*.cmake modules that do a lot of extra work to find various components.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's practical or not, I'm just making a point in terms of design: Having targets defined that you didn't explicitly ask for might go against what the CMake developers originally intended. However, they don't seem to document this. I'll ask on the mailing list, not because I'm particularly concerned about how you've chosen to do this, but more for my own understanding since lately I've been trying to learn more about config packages. I'll let you know what they say, if you're curious. Thanks for discussing!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already got a response: Hi Robert,
In my project I have a bunch of components and do one exported target per component
As far as I know, there are no clear design principles :) (yet, at least nowadays) -- at least doing
I could see the impact on build time only in this case... and for me the most obvious is increasing |
||
| DESTINATION lib/cmake/Boost | ||
| NAMESPACE Boost:: | ||
| FILE BoostTargets.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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To eliminate confusion, I think if you're going to adopt the
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The real targets are already named |
||
| 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}") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per one of my last comments, as I was considering implementing config packages for your projects myself, the way I would have done it is by adding a custom I think this keeps things more modular, and allows you to use the
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my limited testing from weeks ago, the COMPONENTS "worked". But it might just be that everything was just loaded regardless of the value. I'll do more investigation! |
||
|
|
||
| if(BOOST_LOCALE_ENABLE_ICU_BACKEND AND ICU_FOUND) | ||
| target_sources(Boost_locale PRIVATE | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see now. This means you aren't searching for boost components but actual third party dependencies. In that case yes, you should most definitely be using
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the point of it is to make sure that |
||
| endif() | ||
|
|
||
| if(BOOST_LOCALE_ENABLE_WINAPI_BACKEND) | ||
|
|
||
| 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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| int main(int argc, char* argv[]) { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're just trying to find dependencies across boost components right? (For example how
filesystemprobably requiressystem?). In that case, shouldn't you be using thefind_dependency()macro? According to the docs, it's the job of the downstream CMake scripts to find dependencies:https://cmake.org/cmake/help/v3.6/module/CMakeFindDependencyMacro.html#module:CMakeFindDependencyMacro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for third party dependencies as you guessed later. Things like zlib, bzip2 or mpi.