1 #! \ingroup MicroServicesCMake 2 #! \brief Add resources to a library or executable. 4 #! This CMake function uses an external command line program to generate a ZIP archive 5 #! containing data from external resources such as text files or images or other ZIP 6 #! archives. The created archive file can be appended or linked into the target file 7 #! using the usFunctionEmbedResources macro. 9 #! Each module can call this function to add resources and make them available at 10 #! runtime through the Module class. Multiple calls to this function append the 13 #! In the case of linking static modules which contain resources to the target module, 14 #! adding the static module target name to the ZIP_ARCHIVES list will merge its 15 #! resources into the target module. 20 #! usFunctionAddResources(TARGET mylib 21 #! MODULE_NAME org_me_mylib 22 #! FILES config.properties logo.png 26 #! \param TARGET (required) The target to which the resource files are added. 27 #! \param MODULE_NAME (required/optional) The module name of the target, as specified in 28 #! the \c US_MODULE_NAME pre-processor definition of that target. This parameter 29 #! is optional if a target property with the name US_MODULE_NAME exists, containing 30 #! the required module name. 31 #! \param COMPRESSION_LEVEL (optional) The zip compression level (0-9). Defaults to the default zip 32 #! level. Level 0 disables compression. 33 #! \param WORKING_DIRECTORY (optional) The root path for all resource files listed after the 34 #! FILES argument. If no or a relative path is given, it is considered relativ to the 35 #! current CMake source directory. 36 #! \param FILES (optional) A list of resource files (paths to external files in the file system) 37 #! relative to the current working directory. 38 #! \param ZIP_ARCHIVES (optional) A list of zip archives (relative to the current working directory 39 #! or absolute file paths) whose contents is merged into the target module. If a list entry 40 #! is a valid target name and that target is a static library, its absolute file path is 43 #! \sa usFunctionEmbedResources 44 #! \sa \ref MicroServices_Resources 48 cmake_parse_arguments(US_RESOURCE
"" "TARGET;MODULE_NAME;WORKING_DIRECTORY;COMPRESSION_LEVEL" "FILES;ZIP_ARCHIVES" ${ARGN})
50 if(NOT US_RESOURCE_TARGET)
51 message(SEND_ERROR
"TARGET argument not specified.")
54 if(NOT US_RESOURCE_MODULE_NAME)
55 get_target_property(US_RESOURCE_MODULE_NAME ${US_RESOURCE_TARGET} US_MODULE_NAME)
56 if(NOT US_RESOURCE_MODULE_NAME)
57 message(SEND_ERROR
"Either the MODULE_NAME argument or the US_MODULE_NAME target property is required.")
61 if(NOT US_RESOURCE_FILES AND NOT US_RESOURCE_ZIP_ARCHIVES)
62 message(WARNING "No resources specified. Skipping resource processing.")
66 if(NOT US_RESOURCE_WORKING_DIRECTORY)
67 set(US_RESOURCE_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
69 if(NOT IS_ABSOLUTE ${US_RESOURCE_WORKING_DIRECTORY})
70 set(US_RESOURCE_WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/${US_RESOURCE_WORKING_DIRECTORY}")
73 if(US_RESOURCE_COMPRESSION_LEVEL)
74 set(cmd_line_args -${US_RESOURCE_COMPRESSION_LEVEL})
77 set(resource_compiler ${US_RCC_EXECUTABLE})
78 if(
TARGET ${US_RCC_EXECUTABLE_NAME})
79 set(resource_compiler ${US_RCC_EXECUTABLE_NAME})
80 elseif(NOT resource_compiler)
81 message(FATAL_ERROR
"The CppMicroServices resource compiler was not found. Check the US_RCC_EXECUTABLE CMake variable.")
85 foreach(_file ${US_RESOURCE_FILES})
86 if(IS_ABSOLUTE ${_file})
87 list(APPEND _cmd_deps ${_file})
89 list(APPEND _cmd_deps ${US_RESOURCE_WORKING_DIRECTORY}/${_file})
94 if(US_RESOURCE_ZIP_ARCHIVES)
95 foreach(_zip_archive ${US_RESOURCE_ZIP_ARCHIVES})
97 get_target_property(_is_static_lib ${_zip_archive} TYPE)
98 if(_is_static_lib STREQUAL
"STATIC_LIBRARY")
99 list(APPEND _cmd_deps ${_zip_archive})
100 list(APPEND _zip_args $<TARGET_FILE:${_zip_archive}>)
103 if(IS_ABSOLUTE ${_zip_archive})
104 list(APPEND _cmd_deps ${_zip_archive})
106 list(APPEND _cmd_deps ${US_RESOURCE_WORKING_DIRECTORY}/${_zip_archive})
108 list(APPEND _zip_args ${_zip_archive})
113 if(NOT US_RESOURCE_FILES AND NOT _zip_args)
117 if(US_RESOURCE_FILES)
118 set(_file_args -a ${US_RESOURCE_FILES})
121 set(_zip_args -m ${_zip_args})
124 get_target_property(_counter ${US_RESOURCE_TARGET} _us_resource_counter)
125 if((NOT ${_counter} EQUAL 0) AND NOT _counter)
128 math(EXPR _counter
"${_counter} + 1")
131 set(_res_zip "${CMAKE_CURRENT_BINARY_DIR}/us_${US_RESOURCE_TARGET}/res_${_counter}.zip
") 135 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/us_${US_RESOURCE_TARGET}
" 136 COMMAND ${resource_compiler} ${cmd_line_args} ${_res_zip} ${US_RESOURCE_MODULE_NAME} ${_file_args} ${_zip_args} 137 WORKING_DIRECTORY ${US_RESOURCE_WORKING_DIRECTORY} 138 DEPENDS ${_cmd_deps} ${resource_compiler} 139 COMMENT "Checking resource dependencies
for ${US_RESOURCE_TARGET}
" 143 get_target_property(_res_zips ${US_RESOURCE_TARGET} _us_resource_zips) 147 list(APPEND _res_zips ${_res_zip}) 149 set_target_properties(${US_RESOURCE_TARGET} PROPERTIES 150 _us_resource_counter "${_counter}
" 151 _us_resource_zips "${_res_zips}
" usFunctionAddResources()
Add resources to a library or executable.