|
Boost : |
Subject: Re: [boost] [cmake] Minimum viable cmakeification for Boost
From: paul (pfultz2_at_[hidden])
Date: 2017-06-21 15:37:42
On Wed, 2017-06-21 at 15:11 +0300, Peter Dimov via Boost wrote:
> Thomas Heller wrote:
> >
> > FWIW, this is totally doable within CMake. Consider this:
> >
> > # I guess this if statement has to persist, if someone knows a way
> > # around it, please fix. Could be placed in another Setup.cmake or so to
> > # seperate the build logic from this logic.
> > if (PUMPKIN_WITH_ZLIB)
> > # This sets ZLIB_FOUND to TRUE if found and exports and gives you the
> > # ZLIB::ZLIB target.
> > Â find_package(ZLIB)
> > else()
> > # Workaround to have the target available even when zlib was not
> > # requested...
> > Â add_library(ZLIB::ZLIB INTERFACE IMPORTED)
> > endif()
> >
> > # Sets up the zlib dependent target...
> > add_library(pumpkin_zlib
> > Â Â Â Â EXCLUDE_FROM_ALL ${PUMPKIN_ZLIB_SOURCES})
> > target_compile_definitions(pumpkin_zlib PUMPKIN_HAVE_ZLIB)
> > target_link_libraries(pumpkin_zlib ZLIB::ZLIB)
> >
> > # setup the main target.
> > add_library(pumpkin ${PUMPKIN_SOURCES})
> > target_link_libraries(pumpkin
> > Â Â Â Â PRIVATE $<$<BOOL:${PUMPKIN_WITH_ZLIB}>:pumpkin_zlib>)
> What I had in mind was more like this:
>
> add_library(pumpkin ${PUMPKIN_SOURCES})
>
> add_library(pumpkin_zlib ${PUMPKIN_ZLIB_SOURCES})
> target_link_libraries(pumpkin_zlib pumpkin)
> target_link_libraries(pumpkin_zlib ZLIB::ZLIB)
>
> with the find_package logic residing in the rootmost CMakeLists, where theÂ
> project links or does not link to pumpkin_zlib, as appropriate.Â
The find_package shouldn't be in the root directory. It should be in the same
project directory as that is what that project needs, and each project should
be standalone.Â
This won't prevent the ability to use `add_subdirectory`, but the root cmake
is aware of what dependencies it is adding as a subdirectory and what
dependencies its relying on being prebuilt, so this is where the adjustments
to `find_package` go.
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boo
> st
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk