diff --git a/modules/find/FindMorseCommon.cmake b/modules/find/FindMorseCommon.cmake index 98c1406d75a9b9a5cc9b4a0344de74a9ad2dc12a..0e31cd84c64befe3cc20ab0884c949f2156c8c10 100644 --- a/modules/find/FindMorseCommon.cmake +++ b/modules/find/FindMorseCommon.cmake @@ -194,18 +194,19 @@ macro(morse_create_imported_target name) endmacro() -# export existing imported target namespace1::namespace2 in cmake file -# ${targetname}Targets.cmake and installed in lib/cmake/cmakesubdir/. To be used +# export existing imported target ${targetname} in cmake file +# ${targetfilename}Targets.cmake and installed in lib/cmake/${cmakesubdir}/. To be used # by "PROJECT"Config.cmake file at installation -macro(morse_export_imported_target namespace1 namespace2 targetname cmakesubdir) - - if (TARGET ${namespace1}::${namespace2}) - get_target_property(_INCLUDES ${namespace1}::${namespace2} INTERFACE_INCLUDE_DIRECTORIES) - get_target_property(_LIBDIRS ${namespace1}::${namespace2} INTERFACE_LINK_DIRECTORIES) - get_target_property(_LIBRARIES ${namespace1}::${namespace2} INTERFACE_LINK_LIBRARIES) - get_target_property(_CFLAGS ${namespace1}::${namespace2} INTERFACE_COMPILE_OPTIONS) - get_target_property(_DEFS ${namespace1}::${namespace2} INTERFACE_COMPILE_DEFINITIONS) - get_target_property(_LDFLAGS ${namespace1}::${namespace2} INTERFACE_LINK_OPTIONS) +macro(morse_export_imported_target targetname targetfilename cmakesubdir) + + if (TARGET ${targetname}) + get_target_property(_INCLUDES ${targetname} INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(_LIBDIRS ${targetname} INTERFACE_LINK_DIRECTORIES) + get_target_property(_LIBRARIES ${targetname} INTERFACE_LINK_LIBRARIES) + get_target_property(_CFLAGS ${targetname} INTERFACE_COMPILE_OPTIONS) + get_target_property(_DEFS ${targetname} INTERFACE_COMPILE_DEFINITIONS) + get_target_property(_LDFLAGS ${targetname} INTERFACE_LINK_OPTIONS) + if (NOT _INCLUDES) set(_INCLUDES "") endif() @@ -225,23 +226,40 @@ macro(morse_export_imported_target namespace1 namespace2 targetname cmakesubdir) set(_LDFLAGS "") endif() - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${targetname}Targets.cmake" -"if (NOT TARGET ${namespace1}::${namespace2}) -add_library(${namespace1}::${namespace2} INTERFACE IMPORTED) -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"${_INCLUDES}\") -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_LINK_DIRECTORIES \"${_LIBDIRS}\") -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_LINK_LIBRARIES \"${_LIBRARIES}\") -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_COMPILE_OPTIONS \"${_CFLAGS}\") -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_COMPILE_DEFINITIONS \"${_DEFS}\") -set_target_properties(${namespace1}::${namespace2} PROPERTIES INTERFACE_LINK_OPTIONS \"${_LDFLAGS}\") + get_target_property(_IMPORTED_CONF ${targetname} IMPORTED_CONFIGURATIONS) + if (NOT _IMPORTED_CONF) + set(_IMPORTED_CONF "NOCONFIG") + endif() + get_target_property(_IMPORTED_DEP ${targetname} IMPORTED_LINK_DEPENDENT_LIBRARIES_${_IMPORTED_CONF}) + get_target_property(_IMPORTED_LOCATION ${targetname} IMPORTED_LOCATION_${_IMPORTED_CONF}) + get_target_property(_IMPORTED_SONAME ${targetname} IMPORTED_SONAME_${_IMPORTED_CONF}) + if (_IMPORTED_DEP) + list(PREPEND _LIBRARIES ${_IMPORTED_DEP}) + endif() + if (_IMPORTED_LOCATION) + list(PREPEND _LIBRARIES ${_IMPORTED_LOCATION}) + endif() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${targetfilename}Targets.cmake" +"if (NOT TARGET ${targetname}) +add_library(${targetname} INTERFACE IMPORTED) +set_target_properties(${targetname} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES \"${_INCLUDES}\") +set_target_properties(${targetname} PROPERTIES INTERFACE_LINK_DIRECTORIES \"${_LIBDIRS}\") +set_target_properties(${targetname} PROPERTIES INTERFACE_LINK_LIBRARIES \"${_LIBRARIES}\") +set_target_properties(${targetname} PROPERTIES INTERFACE_COMPILE_OPTIONS \"${_CFLAGS}\") +set_target_properties(${targetname} PROPERTIES INTERFACE_COMPILE_DEFINITIONS \"${_DEFS}\") +set_target_properties(${targetname} PROPERTIES INTERFACE_LINK_OPTIONS \"${_LDFLAGS}\") endif() ") - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${targetname}Targets.cmake" + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${targetfilename}Targets.cmake" DESTINATION "lib/cmake/${cmakesubdir}") else() - message(WARNING "morse_export_imported_target: try to export target " - "${namespace1}::${namespace2} but it does not exist.") + set(list_var "${ARGV}") + if(NOT "QUIET" IN_LIST list_var) + message(WARNING "morse_export_imported_target_without_namespace: try to export target " + "${targetname} but it does not exist.") + endif() endif() endmacro()