Skip to content
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

Exporting Boost components #391

Closed
jcarpent opened this issue May 26, 2020 · 10 comments · Fixed by #407
Closed

Exporting Boost components #391

jcarpent opened this issue May 26, 2020 · 10 comments · Fixed by #407
Assignees
Labels

Comments

@jcarpent
Copy link
Contributor

A small remark to mention that at the time being, the Boost components are not exported at all by a project. We need to take on the fact that some of them are only BUILD dependencies, and should not be exported then.

@jcarpent jcarpent added the Bug label May 26, 2020
@gergondet
Copy link
Member

You can/should use add_project_dependency with projects dependencies and find_package with build time dependencies

So for example:

add_project_dependency(Boost REQUIRED COMPONENTS thread)
target_link_libraries(myLib PUBLIC Boost::thread)
# find_package(MyPackage) will also find_package(Boost REQUIRED COMPONENTS thread)

find_package(Boost REQUIRED COMPONENTS test)
target_link_libraries(myTest PUBLIC Boost::test myLib) # still links to Boost::thread

Note: if you only need Boost headers (i.e. the Boost::boost target) you can omit the COMPONENTS if you require cmake > 3.5 (notably, Ubuntu 16.04 has CMake 3.5)

Note 2: I'm not sure how well this works with boost-python as I don't use it

@nim65s
Copy link
Collaborator

nim65s commented May 26, 2020

Do you mean cmake >= 3.5 ?
If so, I think we can require CMake 3.5.

Debian 8 (oldoldstable) has CMake 3.0, so it's broken anyway (ref #338), and Debian 9 (oldstable, 2017) has 3.7. Fedora 27 (2017) has 3.11.

@gergondet
Copy link
Member

Nope, I really mean cmake > 3.5

I'm basing this on a comment I made in a CMakeLists.txt which I'm pretty sure I added after a build failure on Xenial (I was still building on Trusty at the time but with CMake 3.5 too)

Note: this can also be worked-around by using a more recent FindBoost.cmake

@nim65s
Copy link
Collaborator

nim65s commented May 26, 2020

Ok, thanks

@jcarpent
Copy link
Contributor Author

So, currently in the module, we have a specific macro to handle Boost components. It would be nice to add the features of Optional and Required and Build components. In general, Boost.Python is not exported to link the target to an external target.
@nim65s Would have time to handle it? Do you see any good solution?

@nim65s
Copy link
Collaborator

nim65s commented May 26, 2020

I guess this is just a matter of adding parameters to the macro, and using

add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS} REQUIRED)
add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_OPTIONAL_COMPONENTS})
find_package(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_BUILD_COMPONENTS} REQUIRED)
find_package(Boost REQUIRED COMPONENTS ${BOOST_OPTIONAL_BUILD_COMPONENTS})

I can add that, but can you provide a way to test that I'm doing what you need ?

@jcarpent
Copy link
Contributor Author

I think Pinocchio is a good solution, or even hpp-fcl.

@gergondet
Copy link
Member

add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS} REQUIRED)
add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_OPTIONAL_COMPONENTS})
find_package(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_BUILD_COMPONENTS} REQUIRED)
find_package(Boost REQUIRED COMPONENTS ${BOOST_OPTIONAL_BUILD_COMPONENTS})

My two cents here:

  • you don't have to handle the find_package case (anyway this a CMake function)
  • my personnal approach to optional dependency is:
# Check for it
find_package(OptLib QUIET)
if(OptLib_FOUND)
  # Make it required in dependent project
  add_project_dependency(OptLib REQUIRED)
endif()

@nim65s nim65s self-assigned this May 26, 2020
@olivier-stasse
Copy link
Member

My two cents on this: we could just NOT append the package not found when calling find_package in add_project_dependency.
This would avoid cluttering our CMakeLists.txt files.

@jmirabel
Copy link
Collaborator

Shouldn't SEARCH_FOR_BOOST use add_project_dependency instead of find_package ?
This would make the boost components automatically exported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants