You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1KB

  1. #.rst:
  2. # CopyImportedTargetProperties
  3. # --------------------------
  4. #
  5. # Copies the `INTERFACE*` and `IMPORTED*` properties from a target
  6. # to another one.
  7. # This function can be used to duplicate an `IMPORTED` or an `ALIAS` library
  8. # with a different name since ``add_library(... ALIAS ...)`` does not work
  9. # for those targets.
  10. #
  11. # ::
  12. #
  13. # copy_imported_target_properties(<source-target> <destination-target>)
  14. #
  15. # The function copies all the `INTERFACE*` and `IMPORTED*` target
  16. # properties from `<source-target>` to `<destination-target>`.
  17. #
  18. # The function uses the `IMPORTED_CONFIGURATIONS` property to determine
  19. # which configuration-dependent properties should be copied
  20. # (`IMPORTED_LOCATION_<CONFIG>`, etc...)
  21. #
  22. # Example:
  23. #
  24. # Internally the CMake project of ZLIB builds the ``zlib`` and
  25. # ``zlibstatic`` targets which can be exported in the ``ZLIB::`` namespace
  26. # with the ``install(EXPORT ...)`` command.
  27. #
  28. # The config-module will then create the import libraries ``ZLIB::zlib`` and
  29. # ``ZLIB::zlibstatic``. To use ``ZLIB::zlibstatic`` under the standard
  30. # ``ZLIB::ZLIB`` name we need to create the ``ZLIB::ZLIB`` imported library
  31. # and copy the appropriate properties:
  32. #
  33. # add_library(ZLIB::ZLIB STATIC IMPORTED)
  34. # copy_imported_target_properties(ZLIB::zlibstatic ZLIB::ZLIB)
  35. #
  36. function(copy_imported_target_properties src_target dest_target)
  37. set(config_dependent_props
  38. IMPORTED_IMPLIB
  39. IMPORTED_LINK_DEPENDENT_LIBRARIES
  40. IMPORTED_LINK_INTERFACE_LANGUAGES
  41. IMPORTED_LINK_INTERFACE_LIBRARIES
  42. IMPORTED_LINK_INTERFACE_MULTIPLICITY
  43. IMPORTED_LOCATION
  44. IMPORTED_NO_SONAME
  45. IMPORTED_SONAME
  46. )
  47. # copy configuration-independent properties
  48. foreach(prop
  49. ${config_dependent_props}
  50. IMPORTED_CONFIGURATIONS
  51. INTERFACE_AUTOUIC_OPTIONS
  52. INTERFACE_COMPILE_DEFINITIONS
  53. INTERFACE_COMPILE_FEATURES
  54. INTERFACE_COMPILE_OPTIONS
  55. INTERFACE_INCLUDE_DIRECTORIES
  56. INTERFACE_LINK_LIBRARIES
  57. INTERFACE_POSITION_INDEPENDENT_CODE
  58. INTERFACE_SOURCES
  59. INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
  60. )
  61. get_property(is_set TARGET ${src_target} PROPERTY ${prop} SET)
  62. if(is_set)
  63. get_target_property(v ${src_target} ${prop})
  64. set_target_properties(${dest_target} PROPERTIES ${prop} "${v}")
  65. # message(STATUS "set_target_properties(${dest_target} PROPERTIES ${prop} ${v})")
  66. endif()
  67. endforeach()
  68. # copy configuration-dependent properties
  69. get_target_property(imported_configs ${src_target}
  70. IMPORTED_CONFIGURATIONS)
  71. foreach(config ${imported_configs})
  72. foreach(prop_prefix ${config_dependent_props})
  73. set(prop ${prop_prefix}_${config})
  74. get_property(is_set TARGET ${src_target} PROPERTY ${prop} SET)
  75. if(is_set)
  76. get_target_property(v ${src_target} ${prop})
  77. set_target_properties(${dest_target}
  78. PROPERTIES ${prop} "${v}")
  79. # message(STATUS "set_target_properties(${dest_target} PROPERTIES ${prop} ${v})")
  80. endif()
  81. endforeach()
  82. endforeach()
  83. endfunction()