Allow providing a shared lib as dependency for a static lib

Previously the case when the dependency of a static library
was provided by a dynamic library has not been handled
correctly leading to linker errors when building the final
application.
experiment/srcref_basic_cfg
Martchus 6 years ago
parent 86e12a1164
commit b45fe7eaeb

@ -43,6 +43,7 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
endif()
# add library to list of libraries to link against when building dynamic libraries or applications
# - prefer dynamic lib if linkage not explicitely specified
if(${NAME}_STATIC_LIB AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE" AND ((NOT (${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)) OR (STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${LINKAGE}" STREQUAL "STATIC")))
set(USE_${NAME} ON)
set(USE_STATIC_${NAME} ON)
@ -53,15 +54,15 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
message(STATUS "Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}")
endif()
if(${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
if(${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if(${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif()
else()
list(APPEND ${PRIVATE_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if(${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
list(APPEND PRIVATE_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif()
endif()
@ -78,7 +79,7 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
message(STATUS "Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}")
endif()
if(${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
if(${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if(${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
@ -98,16 +99,19 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
endif()
# add library to list of libraries to be provided as transitive dependencies when building static libraries
if(${NAME}_STATIC_LIB)
# - prefer static lib if linkage not explicitely specified
if(${NAME}_STATIC_LIB AND ("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "STATIC"))
set(USE_${NAME} ON)
set(USE_STATIC_${NAME} ON)
list(APPEND STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
message(STATUS "Adding ${${NAME}_STATIC_LIB} to static library dependencies of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.")
message(STATUS "Adding static external library ${NAME} (${${NAME}_STATIC_LIB}) to dependencies of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.")
if(${NAME}_STATIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
message(STATUS "Adding include path for ${NAME} to static include directories of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}")
message(STATUS "Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}")
endif()
if(${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND ${PUBLIC_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if(${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if(${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif()
@ -118,6 +122,36 @@ if(NOT DEFINED THIRD_PARTY_MODULE_LOADED)
endif()
endif()
elseif((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB) AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE" AND (NOT ${NAME}_STATIC_LIB OR (NOT STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (NOT STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${LINKAGE}" STREQUAL "SHARED")))
set(USE_${NAME} ON)
set(USE_SHARED_${NAME} ON)
if(NOT ${NAME}_DYNAMIC_LIB)
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
endif()
list(APPEND STATIC_LIBRARIES ${${NAME}_DYNAMIC_LIB})
message(STATUS "Adding dynamic external library ${NAME} (${${NAME}_DYNAMIC_LIB}) to dependencies of static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.")
if(${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
message(STATUS "Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}")
endif()
if(${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if(${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif()
else()
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if(${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif()
endif()
else()
if(${NAME}_REQUIRED)
message(FATAL_ERROR "External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}.")
else()
message(WARNING "External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}.")
endif()
endif()
endmacro()

@ -197,8 +197,7 @@ if(BUILD_STATIC_LIBS)
else()
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static STATIC ${ALL_FILES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC "${PUBLIC_STATIC_LIBRARIES}"
PRIVATE "${PRIVATE_STATIC_LIBRARIES}"
PUBLIC "${PUBLIC_STATIC_LIBRARIES}" "${PRIVATE_STATIC_LIBRARIES}"
)
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC

@ -73,8 +73,14 @@ macro(use_@META_PROJECT_VARNAME@)
endif()
link_against_library(@META_PROJECT_VARNAME_UPPER@ "${@META_PROJECT_VARNAME_UPPER@_LINKAGE}" REQUIRED)
# add required Qt and KF modules
list(APPEND IMPORTED_QT_MODULES ${@META_PROJECT_VARNAME_UPPER@_PUBLIC_QT_MODULES})
list(APPEND IMPORTED_KF_MODULES ${@META_PROJECT_VARNAME_UPPER@_PUBLIC_KF_MODULES})
list(APPEND IMPORTED_QT_MODULES
${@META_PROJECT_VARNAME_UPPER@_PUBLIC_QT_MODULES}
${@META_PROJECT_VARNAME_UPPER@_PRIVATE_QT_MODULES}
)
list(APPEND IMPORTED_KF_MODULES
${@META_PROJECT_VARNAME_UPPER@_PUBLIC_KF_MODULES}
${@META_PROJECT_VARNAME_UPPER@_PRIVATE_KF_MODULES}
)
# add required translations to APP_SPECIFIC_QT_TRANSLATION_FILES_ARRAY
if(@META_PROJECT_VARNAME_UPPER@_HAS_QT_TRANSLATION_FILES)
list(APPEND APP_SPECIFIC_QT_TRANSLATION_FILES @META_PROJECT_NAME@)

Loading…
Cancel
Save