Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Gyorgy Szing | 82cd473 | 2022-02-08 23:50:26 +0100 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | #------------------------------------------------------------------------------- |
| 9 | # Import libts into a dependent in-tree deployment build. Where another |
| 10 | # deployment uses libts, including this file in the dependent deployment |
| 11 | # CMake build file allows libts to be built and installed into the binary |
| 12 | # directory of the dependent. |
| 13 | #------------------------------------------------------------------------------- |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 14 | option(CFG_FORCE_PREBUILT_LIBTS Off) |
| 15 | # Try to find a pre-build package. |
Gyorgy | b27d416 | 2023-09-28 13:58:36 +0000 | [diff] [blame] | 16 | version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt" MAJOR _major MINOR _minor PATCH _patch) |
| 17 | set(_verstring "${_major}.${_minor}.${_patch}") |
| 18 | |
| 19 | find_package(libts "${_verstring}" QUIET PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts) |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 20 | if(NOT libts_FOUND) |
| 21 | if (CFG_FORCE_PREBUILT_LIBTS) |
| 22 | string(CONCAT _msg "find_package() failed to find the \"libts\" package. Please pass -Dlibts_ROOT=<path> or" |
| 23 | " -DCMAKE_FIND_ROOT_PATH=<path> cmake variable, where <path> is the INSTALL_PREFIX used" |
| 24 | " when building libts. libts_ROOT can be set in the environment too." |
| 25 | "If you wish to debug the search process pass -DCMAKE_FIND_DEBUG_MODE=ON to cmake.") |
| 26 | message(FATAL_ERROR ${_msg}) |
| 27 | endif() |
Gyorgy Szing | 09daade | 2024-09-18 13:45:26 +0200 | [diff] [blame^] | 28 | # Set build type, if a specific value is required. This leaves the default value in the hands of the |
| 29 | # libts deployment being built. |
| 30 | if (DEFINED LIBTS_BUILD_TYPE) |
| 31 | set(_libts_build_type_arg "-DCMAKE_BUILD_TYPE=${LIBTS_BUILD_TYPE}") |
| 32 | endif() |
| 33 | |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 34 | # If not successful, build libts as a sub-project. |
| 35 | execute_process(COMMAND |
| 36 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 37 | ${CMAKE_COMMAND} |
Gyorgy Szing | 09daade | 2024-09-18 13:45:26 +0200 | [diff] [blame^] | 38 | ${_libts_build_type_arg} |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 39 | -S ${TS_ROOT}/deployments/libts/${TS_ENV} |
| 40 | -B ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 41 | RESULT_VARIABLE |
| 42 | _exec_error |
| 43 | ) |
Gyorgy Szing | 09daade | 2024-09-18 13:45:26 +0200 | [diff] [blame^] | 44 | unset(_libts_build_type_arg) |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 45 | if (NOT _exec_error EQUAL 0) |
| 46 | message(FATAL_ERROR "Configuring libts failed. ${_exec_error}") |
| 47 | endif() |
| 48 | execute_process(COMMAND |
| 49 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 50 | ${CMAKE_COMMAND} |
| 51 | --build ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 52 | --parallel ${PROCESSOR_COUNT} |
| 53 | RESULT_VARIABLE |
| 54 | _exec_error |
| 55 | ) |
| 56 | if (NOT _exec_error EQUAL 0) |
| 57 | message(FATAL_ERROR "Installing libts failed. ${_exec_error}") |
| 58 | endif() |
| 59 | execute_process(COMMAND |
| 60 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 61 | ${CMAKE_COMMAND} |
| 62 | --install ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 63 | --prefix ${CMAKE_CURRENT_BINARY_DIR}/libts_install |
| 64 | RESULT_VARIABLE |
| 65 | _exec_error |
| 66 | ) |
| 67 | if (NOT _exec_error EQUAL 0) |
| 68 | message(FATAL_ERROR "Installing libts failed. ${_exec_error}") |
| 69 | endif() |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 70 | |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 71 | install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/libts/cmake_install.cmake) |
| 72 | |
Gyorgy | b27d416 | 2023-09-28 13:58:36 +0000 | [diff] [blame] | 73 | find_package(libts "${_verstring}" QUIET REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts) |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame] | 74 | else() |
| 75 | message(STATUS "Using prebuilt libts from ${libts_DIR}") |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 76 | endif() |
Gyorgy Szing | 09daade | 2024-09-18 13:45:26 +0200 | [diff] [blame^] | 77 | |
| 78 | # Cmake will use the same build type of the imported target as used by the main project. If no mapping is configured and |
| 79 | # the matching build type is not found, cmake will fall back to any build type. Details of the fall back mechanism are not |
| 80 | # documented. |
| 81 | # If a mapping is defined, and the imported target does not define the mapped build type, cmake will treat the library |
| 82 | # as not found. |
| 83 | # |
| 84 | # If LIBTS_BUILD_TYPE is set and the main project wants to use a specific build type, configure build type mapping to |
| 85 | # only allow using the requested build type. |
| 86 | if (DEFINED LIBTS_BUILD_TYPE) |
| 87 | set_target_properties(libts::ts PROPERTIES |
| 88 | MAP_IMPORTED_CONFIG_DEBUG ${LIBTS_BUILD_TYPE} |
| 89 | MAP_IMPORTED_CONFIG_MINSIZEREL ${LIBTS_BUILD_TYPE} |
| 90 | MAP_IMPORTED_CONFIG_MINSIZWITHDEBINFO ${LIBTS_BUILD_TYPE} |
| 91 | MAP_IMPORTED_CONFIG_RELEASE ${LIBTS_BUILD_TYPE} |
| 92 | MAP_IMPORTED_CONFIG_RELWITHDEBINFO ${LIBTS_BUILD_TYPE} |
| 93 | MAP_IMPORTED_CONFIG_DEBUGCOVERAGE ${LIBTS_BUILD_TYPE} |
| 94 | ) |
| 95 | |
| 96 | # Do a manual check and issue a better message than the default one. |
| 97 | get_property(_libts_build_type TARGET libts::ts PROPERTY IMPORTED_CONFIGURATIONS) |
| 98 | string(TOUPPER ${LIBTS_BUILD_TYPE} _uc_libts_build_type) |
| 99 | if(${_uc_libts_build_type} IN_LIST _libts_build_type) |
| 100 | else() |
| 101 | message(FATAL_ERROR "Installed libts package does not supports required build type ${LIBTS_BUILD_TYPE}.") |
| 102 | endif() |
| 103 | unset(_libts_build_type) |
| 104 | unset(_uc_libts_build_type) |
| 105 | endif() |