From 5607691251ea4d00c7572f7f690e78d258a8f305 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 15 Jun 2019 15:30:56 +0200 Subject: [PATCH] Deal with "bundled" dependencies * Allow exporting targets from 3rd party projects which are built within my own projects. This is required if the build scripts of these 3rd party projects don't have an export on their own but are used in the public interface or as a dependency of a static library. * Add those libraries to the pkg-config file as well. --- cmake/modules/LibraryTarget.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/modules/LibraryTarget.cmake b/cmake/modules/LibraryTarget.cmake index 03262f4..fff14eb 100644 --- a/cmake/modules/LibraryTarget.cmake +++ b/cmake/modules/LibraryTarget.cmake @@ -299,6 +299,10 @@ macro (compute_dependencies_for_package_config set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION}") continue() endif () + # assume the target is a 3rd party library built within the current project as a bundled dependency + # -> the target is supposed to be installed in either a standard search directory or the same directory as this library + # so a simple -l flag should be sufficient + set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} -l${DEPENDENCY}") else () # add raw dependency set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${DEPENDENCY}") @@ -389,7 +393,13 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS) endif () # add install targets and export targets - install(TARGETS "${META_TARGET_NAME}" + set(TARGETS_TO_EXPORT "${META_TARGET_NAME}") + foreach (BUNDLED_TARGET ${BUNDLED_TARGETS}) + if (NOT ${BUNDLED_TARGET} IN_LIST LIBRARIES OR (NOT BUILD_SHARED_LIBS AND ${BUNDLED_TARGET} IN_LIST PRIVATE_LIBRARIES)) + list(APPEND TARGETS_TO_EXPORT ${BUNDLED_TARGET}) + endif () + endforeach () + install(TARGETS ${TARGETS_TO_EXPORT} EXPORT "${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Targets" RUNTIME DESTINATION bin COMPONENT binary LIBRARY DESTINATION ${LIBRARY_DESTINATION} COMPONENT binary