Boost logo

Boost :

Subject: Re: [boost] [cmake] Minimum viable cmakeification for Boost
From: Peter Dimov (lists_at_[hidden])
Date: 2017-06-21 12:11:07

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.
> # 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...
> endif()
> # Sets up the zlib dependent target...
> add_library(pumpkin_zlib
> 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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at