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 | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 14 | |
| 15 | # Determine the number of processes to run while running parallel builds. |
| 16 | # Pass -DPROCESSOR_COUNT=<n> to cmake to override. |
| 17 | if(NOT DEFINED PROCESSOR_COUNT) |
| 18 | include(ProcessorCount) |
| 19 | ProcessorCount(PROCESSOR_COUNT) |
| 20 | set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.") |
| 21 | endif() |
| 22 | |
Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 23 | set(LIBTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/libts_install" CACHE PATH "libts installation directory") |
| 24 | set(LIBTS_PACKAGE_PATH "${LIBTS_INSTALL_PATH}/lib/cmake" CACHE PATH "libts CMake package directory") |
| 25 | set(LIBTS_SOURCE_DIR "${TS_ROOT}/deployments/libts/${TS_ENV}" CACHE PATH "libts source directory") |
| 26 | set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH "libts binary directory") |
| 27 | |
| 28 | file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR}) |
| 29 | |
| 30 | #Configure the library |
| 31 | execute_process(COMMAND |
| 32 | ${CMAKE_COMMAND} |
| 33 | -DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH} |
| 34 | -GUnix\ Makefiles |
Gyorgy Szing | 82cd473 | 2022-02-08 23:50:26 +0100 | [diff] [blame] | 35 | -S ${LIBTS_SOURCE_DIR} |
| 36 | -B ${LIBTS_BINARY_DIR} |
| 37 | RESULT_VARIABLE _exec_error |
Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | if (_exec_error) |
| 41 | message(FATAL_ERROR "Configuration step of libts failed with ${_exec_error}.") |
| 42 | endif() |
| 43 | |
| 44 | #Build the library |
| 45 | execute_process(COMMAND |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 46 | ${CMAKE_COMMAND} --build ${LIBTS_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install |
Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 47 | RESULT_VARIABLE _exec_error |
| 48 | ) |
| 49 | |
| 50 | if (_exec_error) |
| 51 | message(FATAL_ERROR "Build step of libts failed with ${_exec_error}.") |
| 52 | endif() |
| 53 | |
| 54 | # Import the built library |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 55 | include(${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/cmake/libts_targets.cmake) |
Julian Hall | b1d5d5f | 2020-11-23 18:23:48 +0100 | [diff] [blame] | 56 | add_library(libts SHARED IMPORTED) |
Gyorgy Szing | c31afbf | 2021-02-12 01:51:55 +0100 | [diff] [blame] | 57 | set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/${TS_ENV}/include") |
| 58 | set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}") |