ObsHelpers_Linux.cmake 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Helper function to set up runtime or library targets
  2. function(setup_binary_target target)
  3. set_target_properties(
  4. ${target}
  5. PROPERTIES
  6. BUILD_RPATH
  7. "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}$<$<BOOL:LINUX_PORTABLE>:/${_ARCH_SUFFIX}bit>"
  8. )
  9. _setup_binary_target(${target})
  10. endfunction()
  11. # Helper function to export target to build and install tree Allows usage of
  12. # `find_package(libobs)` by other build trees
  13. function(export_target target)
  14. _export_target(${ARGV})
  15. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig")
  16. export_target_pkgconf(${target})
  17. endif()
  18. endfunction()
  19. # Helper function to build pkgconfig file for target
  20. function(export_target_pkgconf target)
  21. get_target_property(_TARGET_DEPENDENCIES ${target} INTERFACE_LINK_LIBRARIES)
  22. get_target_property(_TARGET_DEFINITIONS ${target}
  23. INTERFACE_COMPILE_DEFINITIONS)
  24. get_target_property(_TARGET_OPTIONS ${target} INTERFACE_LINK_OPTIONS)
  25. foreach(_LIBRARY IN LISTS _TARGET_DEPENDENCIES)
  26. get_target_property(_LINK_LIBRARY ${_LIBRARY} INTERFACE_LINK_LIBRARIES)
  27. get_target_property(_LINK_DEFINITIONS ${_LIBRARY}
  28. INTERFACE_COMPILE_DEFINITIONS)
  29. list(APPEND _LINKED_LIBRARIES "${_LINK_LIBRARY}")
  30. if(NOT "${_LINK_DEFINITIONS}" STREQUAL "_LINK_DEFINITIONS-NOTFOUND")
  31. list(APPEND _LINKED_DEFINITIONS "${_LINK_DEFINITIONS}")
  32. endif()
  33. endforeach()
  34. string(REPLACE ";" " " _LINKED_LIBRARIES "${_LINKED_LIBRARIES}")
  35. string(REPLACE ";" " " _LINKED_DEFINITIONS "${_LINKED_DEFINITIONS}")
  36. if(NOT "${_TARGET_DEFINITIONS}" STREQUAL "_TARGET_DEFINITIONS-NOTFOUND")
  37. list(JOIN _TARGET_DEFINITIONS "-D" _TARGET_DEFINITIONS)
  38. set(_TARGET_DEFINITIONS "-D${_TARGET_DEFINITIONS}")
  39. else()
  40. set(_TARGET_DEFINITIONS "")
  41. endif()
  42. if(NOT "${_TARGET_OPTIONS}" STREQUAL "_TARGET_OPTIONS-NOTFOUND")
  43. list(JOIN _TARGET_OPTIONS "-" _TARGET_OPTIONS)
  44. set(_TARGET_OPTIONS "-${_TARGET_OPTIONS}")
  45. else()
  46. set(_TARGET_OPTIONS "")
  47. endif()
  48. configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/${target}.pc.in"
  49. "${target}.pc" @ONLY)
  50. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}.pc"
  51. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  52. endfunction()