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.

60 lines
2.5 KiB

3 months ago
  1. #### From carl.
  2. function(_export_target_add_lib output TARGET TYPE)
  3. set(${output} "${${output}}
  4. add_library(${TARGET} ${TYPE} IMPORTED)" PARENT_SCOPE)
  5. endfunction(_export_target_add_lib)
  6. function(_export_target_start output TARGET)
  7. set(${output} "${${output}}
  8. if(NOT TARGET ${TARGET})" PARENT_SCOPE)
  9. endfunction(_export_target_start)
  10. function(_export_target_end output)
  11. set(${output} "${${output}}
  12. endif()" PARENT_SCOPE)
  13. endfunction(_export_target_end)
  14. macro(_export_target_set_prop output TARGET REQUIRED PROPERTY)
  15. get_target_property(VALUE ${TARGET} ${PROPERTY})
  16. set(extra_args ${ARGN})
  17. list(GET extra_args 0 NEWPROPERTY)
  18. if(NOT NEWPROPERTY)
  19. set(NEWPROPERTY ${PROPERTY})
  20. endif()
  21. if(VALUE)
  22. set(${output} "${${output}}
  23. set_target_properties(${TARGET} PROPERTIES ${NEWPROPERTY} \"${VALUE}\")")
  24. elseif(${REQUIRED})
  25. message(STATUS "Did not find ${PROPERTY} of ${TARGET} for export.")
  26. endif()
  27. endmacro(_export_target_set_prop)
  28. macro(export_target output TARGET)
  29. get_target_property(TYPE ${TARGET} TYPE)
  30. _export_target_start(${output} ${TARGET})
  31. if(TYPE STREQUAL "SHARED_LIBRARY")
  32. _export_target_add_lib(${output} ${TARGET} SHARED)
  33. _export_target_set_prop(${output} ${TARGET} TRUE IMPORTED_LOCATION)
  34. _export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_INCLUDE_DIRECTORIES)
  35. _export_target_set_prop(${output} ${TARGET} FALSE LINK_INTERFACE_LIBRARIES)
  36. elseif(TYPE STREQUAL "STATIC_LIBRARY")
  37. _export_target_add_lib(${output} ${TARGET} STATIC)
  38. _export_target_set_prop(${output} ${TARGET} TRUE IMPORTED_LOCATION)
  39. _export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_INCLUDE_DIRECTORIES)
  40. _export_target_set_prop(${output} ${TARGET} FALSE LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES)
  41. elseif(TYPE STREQUAL "INTERFACE_LIBRARY")
  42. _export_target_add_lib(${output} ${TARGET} INTERFACE)
  43. _export_target_set_prop(${output} ${TARGET} TRUE INTERFACE_INCLUDE_DIRECTORIES)
  44. _export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_LINK_LIBRARIES)
  45. else()
  46. message(STATUS "Unknown type ${TYPE}")
  47. endif()
  48. if(NOT "${ARGN}" STREQUAL "")
  49. set(deps ${ARGN})
  50. foreach(d ${deps})
  51. set(${output} "${${output}}
  52. set_target_properties(${TARGET} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES \"${d}\")")
  53. endforeach()
  54. endif()
  55. _export_target_end(${output})
  56. endmacro(export_target)