blob: 169ef59fb3d63ef274d01ccaf1a65b8c3ea007e1 [file] [log] [blame]
From 0ff5a6163bd2760bb6a61fd5a185a2b92da5e86b Mon Sep 17 00:00:00 2001
From: Gyorgy Szing <Gyorgy.Szing@arm.com>
Date: Wed, 20 Jul 2022 12:36:52 +0000
Subject: [PATCH] Fix: change libts to export a CMake package
libts install content was not compatible to find_module() which made
using a pre-built libts binary from CMake less than ideal.
This change adds the missing files and updates export and install
commands to make libts generate a proper CMake package.
From now on an external project will be able to use find_module() to
integrate libts into its build.
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Change-Id: I9e86e02030f6fb3c86af45252110f939cb82670c
Upstream-Status: Pending [In review]
Signed-off-by: Anton Antonov <Anton.Antonov@arm.com>
---
diff --git a/components/messaging/ffa/libsp/component.cmake b/components/messaging/ffa/libsp/component.cmake
index a21c630..ec4cf6c 100644
--- a/components/messaging/ffa/libsp/component.cmake
+++ b/components/messaging/ffa/libsp/component.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -21,7 +21,7 @@
"${CMAKE_CURRENT_LIST_DIR}/sp_rxtx.c"
)
-set_property(TARGET ${TGT} PROPERTY PUBLIC_HEADER
+set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER
${CMAKE_CURRENT_LIST_DIR}/include/ffa_api.h
${CMAKE_CURRENT_LIST_DIR}/include/ffa_api_defines.h
${CMAKE_CURRENT_LIST_DIR}/include/ffa_api_types.h
@@ -49,5 +49,5 @@
target_include_directories(${TGT}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
- "$<INSTALL_INTERFACE:include>"
+ "$<INSTALL_INTERFACE:${TS_ENV}/include">
)
diff --git a/components/rpc/common/interface/component.cmake b/components/rpc/common/interface/component.cmake
index d567602..e4b2477 100644
--- a/components/rpc/common/interface/component.cmake
+++ b/components/rpc/common/interface/component.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -8,11 +8,12 @@
message(FATAL_ERROR "mandatory parameter TGT is not defined.")
endif()
-set_property(TARGET ${TGT} PROPERTY RPC_CALLER_PUBLIC_HEADER_FILES
+set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER
"${CMAKE_CURRENT_LIST_DIR}/rpc_caller.h"
"${CMAKE_CURRENT_LIST_DIR}/rpc_status.h"
)
target_include_directories(${TGT} PUBLIC
- "${CMAKE_CURRENT_LIST_DIR}"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
+ "$<INSTALL_INTERFACE:${TS_ENV}/include>"
)
diff --git a/components/service/locator/interface/component.cmake b/components/service/locator/interface/component.cmake
index b5aefa3..84a4d75 100644
--- a/components/service/locator/interface/component.cmake
+++ b/components/service/locator/interface/component.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -8,10 +8,11 @@
message(FATAL_ERROR "mandatory parameter TGT is not defined.")
endif()
-set_property(TARGET ${TGT} PROPERTY SERVICE_LOCATOR_PUBLIC_HEADER_FILES
+set_property(TARGET ${TGT} APPEND PROPERTY PUBLIC_HEADER
"${CMAKE_CURRENT_LIST_DIR}/service_locator.h"
)
target_include_directories(${TGT} PUBLIC
- "${CMAKE_CURRENT_LIST_DIR}"
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
+ "$<INSTALL_INTERFACE:${TS_ENV}/include>"
)
diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake
index dcabc45..fcfc2ac 100644
--- a/deployments/libts/libts-import.cmake
+++ b/deployments/libts/libts-import.cmake
@@ -11,48 +11,18 @@
# CMake build file allows libts to be built and installed into the binary
# directory of the dependent.
#-------------------------------------------------------------------------------
-
-# Determine the number of processes to run while running parallel builds.
-# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
-if(NOT DEFINED PROCESSOR_COUNT)
- include(ProcessorCount)
- ProcessorCount(PROCESSOR_COUNT)
- set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.")
+option(CFG_FORCE_PREBUILT_LIBTS Off)
+# Try to find a pre-build package.
+find_package(libts "1.0.0" QUIET)
+if(NOT libts_FOUND)
+ if (CFG_FORCE_PREBUILT_LIBTS)
+ string(CONCAT _msg "find_package() failed to find the \"libts\" package. Please set libts_DIR or"
+ " CMAKE_FIND_ROOT_PATH properly.\n"
+ "If you wish to debug the search process pass -DCMAKE_FIND_DEBUG_MODE=ON to cmake.")
+ message(FATAL_ERROR ${_msg})
+ endif()
+ # If not successful, build libts as a sub-project.
+ add_subdirectory(${TS_ROOT}/deployments/libts/${TS_ENV} ${CMAKE_BINARY_DIR}/libts)
+else()
+ message(STATUS "Using prebuilt libts from ${libts_DIR}")
endif()
-
-set(LIBTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/libts_install" CACHE PATH "libts installation directory")
-set(LIBTS_PACKAGE_PATH "${LIBTS_INSTALL_PATH}/lib/cmake" CACHE PATH "libts CMake package directory")
-set(LIBTS_SOURCE_DIR "${TS_ROOT}/deployments/libts/${TS_ENV}" CACHE PATH "libts source directory")
-set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH "libts binary directory")
-
-file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR})
-
-#Configure the library
-execute_process(COMMAND
- ${CMAKE_COMMAND}
- -DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH}
- -GUnix\ Makefiles
- -S ${LIBTS_SOURCE_DIR}
- -B ${LIBTS_BINARY_DIR}
- RESULT_VARIABLE _exec_error
-)
-
-if (_exec_error)
- message(FATAL_ERROR "Configuration step of libts failed with ${_exec_error}.")
-endif()
-
-#Build the library
-execute_process(COMMAND
- ${CMAKE_COMMAND} --build ${LIBTS_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install
- RESULT_VARIABLE _exec_error
-)
-
-if (_exec_error)
- message(FATAL_ERROR "Build step of libts failed with ${_exec_error}.")
-endif()
-
-# Import the built library
-include(${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/cmake/libts_targets.cmake)
-add_library(libts SHARED IMPORTED)
-set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/${TS_ENV}/include")
-set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}")
diff --git a/deployments/libts/libts.cmake b/deployments/libts/libts.cmake
index 6463ca1..7f278fd 100644
--- a/deployments/libts/libts.cmake
+++ b/deployments/libts/libts.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -18,12 +18,11 @@
MAJOR _major MINOR _minor PATCH _patch)
set_target_properties(ts PROPERTIES VERSION "${_major}.${_minor}.${_patch}")
set_target_properties(ts PROPERTIES SOVERSION "${_major}")
-unset(_major)
-unset(_minor)
-unset(_patch)
+
+add_library(libts::ts ALIAS ts)
#-------------------------------------------------------------------------------
-# Components that are common accross all deployments
+# Components that are common across all deployments
#
#-------------------------------------------------------------------------------
add_components(
@@ -53,19 +52,13 @@
#-------------------------------------------------------------------------------
include(${TS_ROOT}/tools/cmake/common/ExportLibrary.cmake REQUIRED)
-# Select public header files to export
-get_property(_rpc_caller_public_header_files TARGET ts
- PROPERTY RPC_CALLER_PUBLIC_HEADER_FILES
-)
-
-get_property(_service_locator_public_header_files TARGET ts
- PROPERTY SERVICE_LOCATOR_PUBLIC_HEADER_FILES
-)
+get_property(_tmp TARGET ts PROPERTY PUBLIC_HEADER)
# Exports library information in preparation for install
export_library(
TARGET "ts"
LIB_NAME "libts"
+ PKG_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/libtsConfig.cmake.in"
INTERFACE_FILES
${_rpc_caller_public_header_files}
${_service_locator_public_header_files}
diff --git a/deployments/libts/libtsConfig.cmake.in b/deployments/libts/libtsConfig.cmake.in
new file mode 100644
index 0000000..4860135
--- /dev/null
+++ b/deployments/libts/libtsConfig.cmake.in
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/libtsTargets.cmake")
+
diff --git a/tools/cmake/common/ExportLibrary.cmake b/tools/cmake/common/ExportLibrary.cmake
index fed4e75..4fcf481 100644
--- a/tools/cmake/common/ExportLibrary.cmake
+++ b/tools/cmake/common/ExportLibrary.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -26,17 +26,29 @@
#]===]
function(export_library)
set(options )
- set(oneValueArgs TARGET LIB_NAME)
+ set(oneValueArgs TARGET LIB_NAME PKG_CONFIG_FILE)
set(multiValueArgs INTERFACE_FILES)
cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
- if(NOT DEFINED MY_PARAMS_TARGET)
- message(FATAL_ERROR "export_library: mandatory parameter TARGET not defined!")
+ foreach(_param IN ITEMS MY_PARAMS_TARGET MY_PARAMS_LIB_NAME MY_PARAMS_PKG_CONFIG_FILE)
+ if(NOT DEFINED ${_param})
+ list(APPEND _miss_params "${_param}" )
+ endif()
+ endforeach()
+
+ if (_miss_params)
+ string(REPLACE ";" ", " _miss_params "${_miss_params}")
+ message(FATAL_ERROR "export_library: mandatory parameter(s) ${_miss_params} not defined!")
endif()
- if(NOT DEFINED MY_PARAMS_LIB_NAME)
- message(FATAL_ERROR "export_library: mandatory parameter LIB_NAME not defined!")
- endif()
+
+
+ string(TOUPPER "${MY_PARAMS_LIB_NAME}" UC_LIB_NAME)
+ string(TOLOWER "${MY_PARAMS_LIB_NAME}" LC_LIB_NAME)
+ string(SUBSTRING "${UC_LIB_NAME}" 0 1 CAP_LIB_NAME)
+ string(SUBSTRING "${LC_LIB_NAME}" 1 -1 _tmp)
+ string(APPEND CAP_LIB_NAME "${_tmp}")
+
# Set default install location if none specified
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
@@ -55,6 +67,42 @@
DESTINATION ${TS_ENV}/include
)
+ # Create a config file package.
+ include(CMakePackageConfigHelpers)
+ get_target_property(_ver ${MY_PARAMS_TARGET} VERSION)
+ write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/${LC_LIB_NAME}ConfigVersion.cmake"
+ VERSION "${_ver}"
+ COMPATIBILITY SameMajorVersion
+ )
+
+ # Create targets file.
+ export(
+ EXPORT
+ ${MY_PARAMS_LIB_NAME}_targets
+ FILE
+ "${CMAKE_CURRENT_BINARY_DIR}/${MY_PARAMS_LIB_NAME}Targets.cmake"
+ NAMESPACE
+ ${MY_PARAMS_LIB_NAME}::
+ )
+
+ # Finalize config file.
+ # Config package location relative to install root.
+ set(ConfigPackageLocation ${TS_ENV}/lib/cmake)
+ # Config package location ??
+ get_filename_component(ConfigPackageLocationRel ${ConfigPackageLocation} PATH)
+
+ get_filename_component(_configured_pkgcfg_name "${MY_PARAMS_PKG_CONFIG_FILE}" NAME_WLE)
+ set(_configured_pkgcfg_name "${CMAKE_CURRENT_BINARY_DIR}/${_configured_pkgcfg_name}")
+ configure_package_config_file(
+ "${MY_PARAMS_PKG_CONFIG_FILE}"
+ "${_configured_pkgcfg_name}"
+ PATH_VARS
+
+ INSTALL_DESTINATION
+ ${ConfigPackageLocationRel}
+ )
+
# Install library header files files
install(
FILES ${MY_PARAMS_INTERFACE_FILES}
@@ -64,9 +112,21 @@
# Install the export details
install(
EXPORT ${MY_PARAMS_LIB_NAME}_targets
- FILE ${MY_PARAMS_LIB_NAME}_targets.cmake
+ FILE ${MY_PARAMS_LIB_NAME}Targets.cmake
NAMESPACE ${MY_PARAMS_LIB_NAME}::
- DESTINATION ${TS_ENV}/lib/cmake
+ DESTINATION ${ConfigPackageLocation}
COMPONENT ${MY_PARAMS_LIB_NAME}
)
+
+
+ # install config and version files
+ install(
+ FILES
+ "${_configured_pkgcfg_name}"
+ "${CMAKE_CURRENT_BINARY_DIR}/${LC_LIB_NAME}ConfigVersion.cmake"
+ DESTINATION
+ ${ConfigPackageLocation}
+ COMPONENT
+ ${MY_PARAMS_LIB_NAME}
+ )
endfunction()