|
Boost : |
Subject: Re: [boost] [cmake] Pull request announcement
From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2018-09-20 08:42:59
> Easiest thing to do here is in each project's CMakeLists.txt file, use a
> standard naming
> convention to hoist the public include directory up to the superproject. I
> would macro-ize
> the dependency definition and building of the dependency header list, like:
>
> in libs/uuid/CMakeLists.txt:
>
> boost_depends_on ( serialization throw_exception )
>
> Which would in turn set:
>
> set ( BOOST_UUID_DEPINCS ${BOOST_SERIALIZATION_HEADERS}
> ${BOOST_THROW_EXCEPTION_HEADERS} )
> (and if those had link libraries, which would be identified by another
> variable of some sort, it would add to the link library list needed)
>
> The project itself would set the variable BOOST_UUID_HEADERS as:
>
> set ( BOOST_UUID_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include
> ${BOOST_UUID_DEPINCS} PARENT_SCOPE )
>
> This defines BOOST_UUID_HEADERS one level up - in the "libs" project. This
> variable now contains all of the include
> paths needed build anything that depends on uuid.
>
> In each dependent project, adding the following allows for access to the
> headers:
>
> boost_depends_on ( uuid )
>
> which as part of the macro would run:
>
> include_directories ( ${BOOST_UUID_HEADERS} )
Definitely NOT. What you describe here is already part of modern CMake:
You use targets:
add_library(boost_serialization INTERFACE)
target_include_directories(boost_serialization INTERFACE include) #
CMAKE_CURRENT_SOURCE_DIR is implicit
and in uuid:
add_library(boost_uuid src/mysrc.cpp)
target_include_directories(boost_uuid PUBLIC include)
target_link_libraries(boost_uuid PUBLIC boost_serialization)
This basically does the same as your macros and stuff but in the modern
CMake way where CMake resolves all dependencies. For cases where you may
not have e.g. the boost_serialization target yet one may assume to be
run as part of the super-boost project and do this instead:
add_library(boost_uuid src/mysrc.cpp)
target_include_directories(boost_uuid PUBLIC include
${CMAKE_SOURCE_DIR}/libs/boost_serialization/include)
Or better: Define the target yourself: if(NOT TARGET
boost_serialization) add_library(boost_serialization IMPORTED) ...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk