1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
# CMake Linux helper functions module
include_guard(GLOBAL)
include(helpers_common)
# set_target_properties_plugin: Set target properties for use in obs-studio
function(set_target_properties_plugin target)
set(options "")
set(oneValueArgs "")
set(multiValueArgs PROPERTIES)
cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}")
message(DEBUG "Setting additional properties for target ${target}...")
while(_STPO_PROPERTIES)
list(POP_FRONT _STPO_PROPERTIES key value)
set_property(TARGET ${target} PROPERTY ${key} "${value}")
endwhile()
set_target_properties(
${target}
PROPERTIES VERSION ${PLUGIN_VERSION} SOVERSION ${PLUGIN_VERSION_MAJOR} PREFIX ""
)
install(
TARGETS ${target}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/obs-plugins
)
if(TARGET plugin-support)
target_link_libraries(${target} PRIVATE plugin-support)
endif()
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:${target}>" "${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>"
COMMENT "Copy ${target} to rundir"
VERBATIM
)
target_install_resources(${target})
get_target_property(target_sources ${target} SOURCES)
set(target_ui_files ${target_sources})
list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "UI Files" FILES ${target_ui_files})
endfunction()
# Helper function to add resources into bundle
function(target_install_resources target)
message(DEBUG "Installing resources for target ${target}...")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data")
file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
foreach(data_file IN LISTS data_files)
cmake_path(
RELATIVE_PATH
data_file
BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
OUTPUT_VARIABLE relative_path
)
cmake_path(GET relative_path PARENT_PATH relative_path)
target_sources(${target} PRIVATE "${data_file}")
source_group("Resources/${relative_path}" FILES "${data_file}")
endforeach()
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-plugins/${target}
USE_SOURCE_PERMISSIONS
)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>/${target}"
COMMAND
"${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data"
"${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>/${target}"
COMMENT "Copy ${target} resources to rundir"
VERBATIM
)
endif()
endfunction()
# Helper function to add a specific resource to a bundle
function(target_add_resource target resource)
message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...")
install(FILES "${resource}" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/obs/obs-plugins/${target})
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>/${target}"
COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${CMAKE_CURRENT_BINARY_DIR}/rundir/$<CONFIG>/${target}"
COMMENT "Copy ${target} resource ${resource} to rundir"
VERBATIM
)
source_group("Resources" FILES "${resource}")
endfunction()
|