From 5b3ca1bb0544048d5c05a9306720887552894f90 Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Fri, 20 Apr 2018 00:20:14 -0600 Subject: [PATCH] CMake: Fix up the "transitive library" metalib logic This fixes some cases where transitive libraries, as nominated by a component library, were not being absorbed into a metalib, due to the library actually not being defined yet. This makes the logic a little more robust, first by explicitly requiring a metalib definition to come after all component library definitions, and second to assume a library "linked" to a component library is a non-component if it isn't defined (yet). --- cmake/macros/BuildMetalib.cmake | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmake/macros/BuildMetalib.cmake b/cmake/macros/BuildMetalib.cmake index c63f6e2e52..3326b50d77 100644 --- a/cmake/macros/BuildMetalib.cmake +++ b/cmake/macros/BuildMetalib.cmake @@ -41,9 +41,14 @@ function(target_link_libraries target) # care of this at configuration time. if(TARGET "${library}") get_target_property(is_component "${library}" IS_COMPONENT) - if(NOT is_component) - set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}") - endif() + else() + # This is a safe assumption, since we define all component libraries + # before the metalib they appear in: + set(is_component OFF) + endif() + + if(NOT is_component) + set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${library}") endif() else() # This is a file path to an out-of-tree library - this needs to be @@ -133,6 +138,11 @@ function(add_metalib target_name) set(includes) set(libs) foreach(component ${components}) + if(NOT TARGET "${component}") + message(FATAL_ERROR + "Missing component library ${component} referenced by metalib ${target_name}! + (Component library targets must be created BEFORE add_metalib.)") + endif() get_target_property(is_component "${component}" IS_COMPONENT) if(NOT is_component) message(FATAL_ERROR