Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | From 0ff5a6163bd2760bb6a61fd5a185a2b92da5e86b Mon Sep 17 00:00:00 2001 |
| 2 | From: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| 3 | Date: Wed, 20 Jul 2022 12:36:52 +0000 |
| 4 | Subject: [PATCH] Fix: change libts to export a CMake package |
| 5 | |
| 6 | libts install content was not compatible to find_module() which made |
| 7 | using a pre-built libts binary from CMake less than ideal. |
| 8 | |
| 9 | This change adds the missing files and updates export and install |
| 10 | commands to make libts generate a proper CMake package. |
| 11 | |
| 12 | From now on an external project will be able to use find_module() to |
| 13 | integrate libts into its build. |
| 14 | |
| 15 | Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com> |
| 16 | Change-Id: I9e86e02030f6fb3c86af45252110f939cb82670c |
| 17 | |
| 18 | Upstream-Status: Pending [In review] |
| 19 | Signed-off-by: Anton Antonov <Anton.Antonov@arm.com> |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | diff --git a/components/messaging/ffa/libsp/component.cmake b/components/messaging/ffa/libsp/component.cmake |
| 24 | index a21c630..ec4cf6c 100644 |
| 25 | --- a/components/messaging/ffa/libsp/component.cmake |
| 26 | +++ b/components/messaging/ffa/libsp/component.cmake |
| 27 | @@ -1,5 +1,5 @@ |
| 28 | #------------------------------------------------------------------------------- |
| 29 | -# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
| 30 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 31 | # |
| 32 | # SPDX-License-Identifier: BSD-3-Clause |
| 33 | # |
| 34 | @@ -21,7 +21,7 @@ |
| 35 | "${CMAKE_CURRENT_LIST_DIR}/sp_rxtx.c" |
| 36 | ) |
| 37 | |
| 38 | -set_property(TARGET ${TGT} PROPERTY PUBLIC_HEADER |
| 39 | +set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER |
| 40 | ${CMAKE_CURRENT_LIST_DIR}/include/ffa_api.h |
| 41 | ${CMAKE_CURRENT_LIST_DIR}/include/ffa_api_defines.h |
| 42 | ${CMAKE_CURRENT_LIST_DIR}/include/ffa_api_types.h |
| 43 | @@ -49,5 +49,5 @@ |
| 44 | target_include_directories(${TGT} |
| 45 | PUBLIC |
| 46 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" |
| 47 | - "$<INSTALL_INTERFACE:include>" |
| 48 | + "$<INSTALL_INTERFACE:${TS_ENV}/include"> |
| 49 | ) |
| 50 | diff --git a/components/rpc/common/interface/component.cmake b/components/rpc/common/interface/component.cmake |
| 51 | index d567602..e4b2477 100644 |
| 52 | --- a/components/rpc/common/interface/component.cmake |
| 53 | +++ b/components/rpc/common/interface/component.cmake |
| 54 | @@ -1,5 +1,5 @@ |
| 55 | #------------------------------------------------------------------------------- |
| 56 | -# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved. |
| 57 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 58 | # |
| 59 | # SPDX-License-Identifier: BSD-3-Clause |
| 60 | # |
| 61 | @@ -8,11 +8,12 @@ |
| 62 | message(FATAL_ERROR "mandatory parameter TGT is not defined.") |
| 63 | endif() |
| 64 | |
| 65 | -set_property(TARGET ${TGT} PROPERTY RPC_CALLER_PUBLIC_HEADER_FILES |
| 66 | +set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER |
| 67 | "${CMAKE_CURRENT_LIST_DIR}/rpc_caller.h" |
| 68 | "${CMAKE_CURRENT_LIST_DIR}/rpc_status.h" |
| 69 | ) |
| 70 | |
| 71 | target_include_directories(${TGT} PUBLIC |
| 72 | - "${CMAKE_CURRENT_LIST_DIR}" |
| 73 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>" |
| 74 | + "$<INSTALL_INTERFACE:${TS_ENV}/include>" |
| 75 | ) |
| 76 | diff --git a/components/service/locator/interface/component.cmake b/components/service/locator/interface/component.cmake |
| 77 | index b5aefa3..84a4d75 100644 |
| 78 | --- a/components/service/locator/interface/component.cmake |
| 79 | +++ b/components/service/locator/interface/component.cmake |
| 80 | @@ -1,5 +1,5 @@ |
| 81 | #------------------------------------------------------------------------------- |
| 82 | -# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved. |
| 83 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 84 | # |
| 85 | # SPDX-License-Identifier: BSD-3-Clause |
| 86 | # |
| 87 | @@ -8,10 +8,11 @@ |
| 88 | message(FATAL_ERROR "mandatory parameter TGT is not defined.") |
| 89 | endif() |
| 90 | |
| 91 | -set_property(TARGET ${TGT} PROPERTY SERVICE_LOCATOR_PUBLIC_HEADER_FILES |
| 92 | +set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER |
| 93 | "${CMAKE_CURRENT_LIST_DIR}/service_locator.h" |
| 94 | ) |
| 95 | |
| 96 | target_include_directories(${TGT} PUBLIC |
| 97 | - "${CMAKE_CURRENT_LIST_DIR}" |
| 98 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>" |
| 99 | + "$<INSTALL_INTERFACE:${TS_ENV}/include>" |
| 100 | ) |
| 101 | diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake |
| 102 | index dcabc45..fcfc2ac 100644 |
| 103 | --- a/deployments/libts/libts-import.cmake |
| 104 | +++ b/deployments/libts/libts-import.cmake |
| 105 | @@ -11,48 +11,18 @@ |
| 106 | # CMake build file allows libts to be built and installed into the binary |
| 107 | # directory of the dependent. |
| 108 | #------------------------------------------------------------------------------- |
| 109 | - |
| 110 | -# Determine the number of processes to run while running parallel builds. |
| 111 | -# Pass -DPROCESSOR_COUNT=<n> to cmake to override. |
| 112 | -if(NOT DEFINED PROCESSOR_COUNT) |
| 113 | - include(ProcessorCount) |
| 114 | - ProcessorCount(PROCESSOR_COUNT) |
| 115 | - set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.") |
| 116 | +option(CFG_FORCE_PREBUILT_LIBTS Off) |
| 117 | +# Try to find a pre-build package. |
| 118 | +find_package(libts "1.0.0" QUIET) |
| 119 | +if(NOT libts_FOUND) |
| 120 | + if (CFG_FORCE_PREBUILT_LIBTS) |
| 121 | + string(CONCAT _msg "find_package() failed to find the \"libts\" package. Please set libts_DIR or" |
| 122 | + " CMAKE_FIND_ROOT_PATH properly.\n" |
| 123 | + "If you wish to debug the search process pass -DCMAKE_FIND_DEBUG_MODE=ON to cmake.") |
| 124 | + message(FATAL_ERROR ${_msg}) |
| 125 | + endif() |
| 126 | + # If not successful, build libts as a sub-project. |
| 127 | + add_subdirectory(${TS_ROOT}/deployments/libts/${TS_ENV} ${CMAKE_BINARY_DIR}/libts) |
| 128 | +else() |
| 129 | + message(STATUS "Using prebuilt libts from ${libts_DIR}") |
| 130 | endif() |
| 131 | - |
| 132 | -set(LIBTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/libts_install" CACHE PATH "libts installation directory") |
| 133 | -set(LIBTS_PACKAGE_PATH "${LIBTS_INSTALL_PATH}/lib/cmake" CACHE PATH "libts CMake package directory") |
| 134 | -set(LIBTS_SOURCE_DIR "${TS_ROOT}/deployments/libts/${TS_ENV}" CACHE PATH "libts source directory") |
| 135 | -set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH "libts binary directory") |
| 136 | - |
| 137 | -file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR}) |
| 138 | - |
| 139 | -#Configure the library |
| 140 | -execute_process(COMMAND |
| 141 | - ${CMAKE_COMMAND} |
| 142 | - -DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH} |
| 143 | - -GUnix\ Makefiles |
| 144 | - -S ${LIBTS_SOURCE_DIR} |
| 145 | - -B ${LIBTS_BINARY_DIR} |
| 146 | - RESULT_VARIABLE _exec_error |
| 147 | -) |
| 148 | - |
| 149 | -if (_exec_error) |
| 150 | - message(FATAL_ERROR "Configuration step of libts failed with ${_exec_error}.") |
| 151 | -endif() |
| 152 | - |
| 153 | -#Build the library |
| 154 | -execute_process(COMMAND |
| 155 | - ${CMAKE_COMMAND} --build ${LIBTS_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install |
| 156 | - RESULT_VARIABLE _exec_error |
| 157 | -) |
| 158 | - |
| 159 | -if (_exec_error) |
| 160 | - message(FATAL_ERROR "Build step of libts failed with ${_exec_error}.") |
| 161 | -endif() |
| 162 | - |
| 163 | -# Import the built library |
| 164 | -include(${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/cmake/libts_targets.cmake) |
| 165 | -add_library(libts SHARED IMPORTED) |
| 166 | -set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/${TS_ENV}/include") |
| 167 | -set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}") |
| 168 | diff --git a/deployments/libts/libts.cmake b/deployments/libts/libts.cmake |
| 169 | index 6463ca1..7f278fd 100644 |
| 170 | --- a/deployments/libts/libts.cmake |
| 171 | +++ b/deployments/libts/libts.cmake |
| 172 | @@ -1,5 +1,5 @@ |
| 173 | #------------------------------------------------------------------------------- |
| 174 | -# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
| 175 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 176 | # |
| 177 | # SPDX-License-Identifier: BSD-3-Clause |
| 178 | # |
| 179 | @@ -18,12 +18,11 @@ |
| 180 | MAJOR _major MINOR _minor PATCH _patch) |
| 181 | set_target_properties(ts PROPERTIES VERSION "${_major}.${_minor}.${_patch}") |
| 182 | set_target_properties(ts PROPERTIES SOVERSION "${_major}") |
| 183 | -unset(_major) |
| 184 | -unset(_minor) |
| 185 | -unset(_patch) |
| 186 | + |
| 187 | +add_library(libts::ts ALIAS ts) |
| 188 | |
| 189 | #------------------------------------------------------------------------------- |
| 190 | -# Components that are common accross all deployments |
| 191 | +# Components that are common across all deployments |
| 192 | # |
| 193 | #------------------------------------------------------------------------------- |
| 194 | add_components( |
| 195 | @@ -53,19 +52,13 @@ |
| 196 | #------------------------------------------------------------------------------- |
| 197 | include(${TS_ROOT}/tools/cmake/common/ExportLibrary.cmake REQUIRED) |
| 198 | |
| 199 | -# Select public header files to export |
| 200 | -get_property(_rpc_caller_public_header_files TARGET ts |
| 201 | - PROPERTY RPC_CALLER_PUBLIC_HEADER_FILES |
| 202 | -) |
| 203 | - |
| 204 | -get_property(_service_locator_public_header_files TARGET ts |
| 205 | - PROPERTY SERVICE_LOCATOR_PUBLIC_HEADER_FILES |
| 206 | -) |
| 207 | +get_property(_tmp TARGET ts PROPERTY PUBLIC_HEADER) |
| 208 | |
| 209 | # Exports library information in preparation for install |
| 210 | export_library( |
| 211 | TARGET "ts" |
| 212 | LIB_NAME "libts" |
| 213 | + PKG_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/libtsConfig.cmake.in" |
| 214 | INTERFACE_FILES |
| 215 | ${_rpc_caller_public_header_files} |
| 216 | ${_service_locator_public_header_files} |
| 217 | diff --git a/deployments/libts/libtsConfig.cmake.in b/deployments/libts/libtsConfig.cmake.in |
| 218 | new file mode 100644 |
| 219 | index 0000000..4860135 |
| 220 | --- /dev/null |
| 221 | +++ b/deployments/libts/libtsConfig.cmake.in |
| 222 | @@ -0,0 +1,10 @@ |
| 223 | +# |
| 224 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 225 | +# |
| 226 | +# SPDX-License-Identifier: BSD-3-Clause |
| 227 | +# |
| 228 | + |
| 229 | +@PACKAGE_INIT@ |
| 230 | + |
| 231 | +include("${CMAKE_CURRENT_LIST_DIR}/libtsTargets.cmake") |
| 232 | + |
| 233 | diff --git a/tools/cmake/common/ExportLibrary.cmake b/tools/cmake/common/ExportLibrary.cmake |
| 234 | index fed4e75..4fcf481 100644 |
| 235 | --- a/tools/cmake/common/ExportLibrary.cmake |
| 236 | +++ b/tools/cmake/common/ExportLibrary.cmake |
| 237 | @@ -1,5 +1,5 @@ |
| 238 | #------------------------------------------------------------------------------- |
| 239 | -# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
| 240 | +# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
| 241 | # |
| 242 | # SPDX-License-Identifier: BSD-3-Clause |
| 243 | # |
| 244 | @@ -26,17 +26,29 @@ |
| 245 | #]===] |
| 246 | function(export_library) |
| 247 | set(options ) |
| 248 | - set(oneValueArgs TARGET LIB_NAME) |
| 249 | + set(oneValueArgs TARGET LIB_NAME PKG_CONFIG_FILE) |
| 250 | set(multiValueArgs INTERFACE_FILES) |
| 251 | cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}" |
| 252 | "${multiValueArgs}" ${ARGN} ) |
| 253 | |
| 254 | - if(NOT DEFINED MY_PARAMS_TARGET) |
| 255 | - message(FATAL_ERROR "export_library: mandatory parameter TARGET not defined!") |
| 256 | + foreach(_param IN ITEMS MY_PARAMS_TARGET MY_PARAMS_LIB_NAME MY_PARAMS_PKG_CONFIG_FILE) |
| 257 | + if(NOT DEFINED ${_param}) |
| 258 | + list(APPEND _miss_params "${_param}" ) |
| 259 | + endif() |
| 260 | + endforeach() |
| 261 | + |
| 262 | + if (_miss_params) |
| 263 | + string(REPLACE ";" ", " _miss_params "${_miss_params}") |
| 264 | + message(FATAL_ERROR "export_library: mandatory parameter(s) ${_miss_params} not defined!") |
| 265 | endif() |
| 266 | - if(NOT DEFINED MY_PARAMS_LIB_NAME) |
| 267 | - message(FATAL_ERROR "export_library: mandatory parameter LIB_NAME not defined!") |
| 268 | - endif() |
| 269 | + |
| 270 | + |
| 271 | + string(TOUPPER "${MY_PARAMS_LIB_NAME}" UC_LIB_NAME) |
| 272 | + string(TOLOWER "${MY_PARAMS_LIB_NAME}" LC_LIB_NAME) |
| 273 | + string(SUBSTRING "${UC_LIB_NAME}" 0 1 CAP_LIB_NAME) |
| 274 | + string(SUBSTRING "${LC_LIB_NAME}" 1 -1 _tmp) |
| 275 | + string(APPEND CAP_LIB_NAME "${_tmp}") |
| 276 | + |
| 277 | |
| 278 | # Set default install location if none specified |
| 279 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 280 | @@ -55,6 +67,42 @@ |
| 281 | DESTINATION ${TS_ENV}/include |
| 282 | ) |
| 283 | |
| 284 | + # Create a config file package. |
| 285 | + include(CMakePackageConfigHelpers) |
| 286 | + get_target_property(_ver ${MY_PARAMS_TARGET} VERSION) |
| 287 | + write_basic_package_version_file( |
| 288 | + "${CMAKE_CURRENT_BINARY_DIR}/${LC_LIB_NAME}ConfigVersion.cmake" |
| 289 | + VERSION "${_ver}" |
| 290 | + COMPATIBILITY SameMajorVersion |
| 291 | + ) |
| 292 | + |
| 293 | + # Create targets file. |
| 294 | + export( |
| 295 | + EXPORT |
| 296 | + ${MY_PARAMS_LIB_NAME}_targets |
| 297 | + FILE |
| 298 | + "${CMAKE_CURRENT_BINARY_DIR}/${MY_PARAMS_LIB_NAME}Targets.cmake" |
| 299 | + NAMESPACE |
| 300 | + ${MY_PARAMS_LIB_NAME}:: |
| 301 | + ) |
| 302 | + |
| 303 | + # Finalize config file. |
| 304 | + # Config package location relative to install root. |
| 305 | + set(ConfigPackageLocation ${TS_ENV}/lib/cmake) |
| 306 | + # Config package location ?? |
| 307 | + get_filename_component(ConfigPackageLocationRel ${ConfigPackageLocation} PATH) |
| 308 | + |
| 309 | + get_filename_component(_configured_pkgcfg_name "${MY_PARAMS_PKG_CONFIG_FILE}" NAME_WLE) |
| 310 | + set(_configured_pkgcfg_name "${CMAKE_CURRENT_BINARY_DIR}/${_configured_pkgcfg_name}") |
| 311 | + configure_package_config_file( |
| 312 | + "${MY_PARAMS_PKG_CONFIG_FILE}" |
| 313 | + "${_configured_pkgcfg_name}" |
| 314 | + PATH_VARS |
| 315 | + |
| 316 | + INSTALL_DESTINATION |
| 317 | + ${ConfigPackageLocationRel} |
| 318 | + ) |
| 319 | + |
| 320 | # Install library header files files |
| 321 | install( |
| 322 | FILES ${MY_PARAMS_INTERFACE_FILES} |
| 323 | @@ -64,9 +112,21 @@ |
| 324 | # Install the export details |
| 325 | install( |
| 326 | EXPORT ${MY_PARAMS_LIB_NAME}_targets |
| 327 | - FILE ${MY_PARAMS_LIB_NAME}_targets.cmake |
| 328 | + FILE ${MY_PARAMS_LIB_NAME}Targets.cmake |
| 329 | NAMESPACE ${MY_PARAMS_LIB_NAME}:: |
| 330 | - DESTINATION ${TS_ENV}/lib/cmake |
| 331 | + DESTINATION ${ConfigPackageLocation} |
| 332 | COMPONENT ${MY_PARAMS_LIB_NAME} |
| 333 | ) |
| 334 | + |
| 335 | + |
| 336 | + # install config and version files |
| 337 | + install( |
| 338 | + FILES |
| 339 | + "${_configured_pkgcfg_name}" |
| 340 | + "${CMAKE_CURRENT_BINARY_DIR}/${LC_LIB_NAME}ConfigVersion.cmake" |
| 341 | + DESTINATION |
| 342 | + ${ConfigPackageLocation} |
| 343 | + COMPONENT |
| 344 | + ${MY_PARAMS_LIB_NAME} |
| 345 | + ) |
| 346 | endfunction() |