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. |
| 16 | find_package(libts "1.0.0" QUIET PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts) |
| 17 | if(NOT libts_FOUND) |
| 18 | if (CFG_FORCE_PREBUILT_LIBTS) |
| 19 | string(CONCAT _msg "find_package() failed to find the \"libts\" package. Please pass -Dlibts_ROOT=<path> or" |
| 20 | " -DCMAKE_FIND_ROOT_PATH=<path> cmake variable, where <path> is the INSTALL_PREFIX used" |
| 21 | " when building libts. libts_ROOT can be set in the environment too." |
| 22 | "If you wish to debug the search process pass -DCMAKE_FIND_DEBUG_MODE=ON to cmake.") |
| 23 | message(FATAL_ERROR ${_msg}) |
| 24 | endif() |
| 25 | # If not successful, build libts as a sub-project. |
| 26 | execute_process(COMMAND |
| 27 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 28 | ${CMAKE_COMMAND} |
| 29 | -S ${TS_ROOT}/deployments/libts/${TS_ENV} |
| 30 | -B ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 31 | RESULT_VARIABLE |
| 32 | _exec_error |
| 33 | ) |
| 34 | if (NOT _exec_error EQUAL 0) |
| 35 | message(FATAL_ERROR "Configuring libts failed. ${_exec_error}") |
| 36 | endif() |
| 37 | execute_process(COMMAND |
| 38 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 39 | ${CMAKE_COMMAND} |
| 40 | --build ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 41 | --parallel ${PROCESSOR_COUNT} |
| 42 | RESULT_VARIABLE |
| 43 | _exec_error |
| 44 | ) |
| 45 | if (NOT _exec_error EQUAL 0) |
| 46 | message(FATAL_ERROR "Installing libts failed. ${_exec_error}") |
| 47 | endif() |
| 48 | execute_process(COMMAND |
| 49 | ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}" |
| 50 | ${CMAKE_COMMAND} |
| 51 | --install ${CMAKE_CURRENT_BINARY_DIR}/libts |
| 52 | --prefix ${CMAKE_CURRENT_BINARY_DIR}/libts_install |
| 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() |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 59 | |
Gyorgy Szing | ec62ea7 | 2022-07-20 12:36:52 +0000 | [diff] [blame^] | 60 | install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/libts/cmake_install.cmake) |
| 61 | |
| 62 | find_package(libts "1.0.0" QUIET REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts) |
| 63 | else() |
| 64 | message(STATUS "Using prebuilt libts from ${libts_DIR}") |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 65 | endif() |