blob: fd016ca7ea0ec21422b56e80480d1aaebcbf34a3 [file] [log] [blame]
Julian Hallb1d5d5f2020-11-23 18:23:48 +01001#-------------------------------------------------------------------------------
Gyorgy Szing82cd4732022-02-08 23:50:26 +01002# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Julian Hallb1d5d5f2020-11-23 18:23:48 +01003#
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 Szingec62ea72022-07-20 12:36:52 +000014option(CFG_FORCE_PREBUILT_LIBTS Off)
15# Try to find a pre-build package.
Gyorgyb27d4162023-09-28 13:58:36 +000016version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt" MAJOR _major MINOR _minor PATCH _patch)
17set(_verstring "${_major}.${_minor}.${_patch}")
18
19find_package(libts "${_verstring}" QUIET PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts)
Gyorgy Szingec62ea72022-07-20 12:36:52 +000020if(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()
28 # If not successful, build libts as a sub-project.
29 execute_process(COMMAND
30 ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
31 ${CMAKE_COMMAND}
32 -S ${TS_ROOT}/deployments/libts/${TS_ENV}
33 -B ${CMAKE_CURRENT_BINARY_DIR}/libts
34 RESULT_VARIABLE
35 _exec_error
36 )
37 if (NOT _exec_error EQUAL 0)
38 message(FATAL_ERROR "Configuring libts failed. ${_exec_error}")
39 endif()
40 execute_process(COMMAND
41 ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
42 ${CMAKE_COMMAND}
43 --build ${CMAKE_CURRENT_BINARY_DIR}/libts
44 --parallel ${PROCESSOR_COUNT}
45 RESULT_VARIABLE
46 _exec_error
47 )
48 if (NOT _exec_error EQUAL 0)
49 message(FATAL_ERROR "Installing libts failed. ${_exec_error}")
50 endif()
51 execute_process(COMMAND
52 ${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
53 ${CMAKE_COMMAND}
54 --install ${CMAKE_CURRENT_BINARY_DIR}/libts
55 --prefix ${CMAKE_CURRENT_BINARY_DIR}/libts_install
56 RESULT_VARIABLE
57 _exec_error
58 )
59 if (NOT _exec_error EQUAL 0)
60 message(FATAL_ERROR "Installing libts failed. ${_exec_error}")
61 endif()
Gyorgy Szing2247d242021-09-03 16:17:25 +020062
Gyorgy Szingec62ea72022-07-20 12:36:52 +000063 install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/libts/cmake_install.cmake)
64
Gyorgyb27d4162023-09-28 13:58:36 +000065 find_package(libts "${_verstring}" QUIET REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/libts_install/${TS_ENV}/lib/cmake/libts)
Gyorgy Szingec62ea72022-07-20 12:36:52 +000066else()
67 message(STATUS "Using prebuilt libts from ${libts_DIR}")
Gyorgy Szing2247d242021-09-03 16:17:25 +020068endif()