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