blob: 792ba86c7b2e2bee70d0fafed0f2923d292ce7e4 [file] [log] [blame]
Julian Hallb1d5d5f2020-11-23 18:23:48 +01001#-------------------------------------------------------------------------------
Gyorgy Szingc31afbf2021-02-12 01:51:55 +01002# Copyright (c) 2020-2021, 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 Szing2247d242021-09-03 16:17:25 +020014
15# Determine the number of processes to run while running parallel builds.
16# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
17if(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.")
21endif()
22
Julian Hallb1d5d5f2020-11-23 18:23:48 +010023set(LIBTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/libts_install" CACHE PATH "libts installation directory")
24set(LIBTS_PACKAGE_PATH "${LIBTS_INSTALL_PATH}/lib/cmake" CACHE PATH "libts CMake package directory")
25set(LIBTS_SOURCE_DIR "${TS_ROOT}/deployments/libts/${TS_ENV}" CACHE PATH "libts source directory")
26set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH "libts binary directory")
27
28file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR})
29
30#Configure the library
31execute_process(COMMAND
32 ${CMAKE_COMMAND}
33 -DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH}
34 -GUnix\ Makefiles
35 ${LIBTS_SOURCE_DIR}
36 WORKING_DIRECTORY
37 ${LIBTS_BINARY_DIR}
38)
39
40if (_exec_error)
41 message(FATAL_ERROR "Configuration step of libts failed with ${_exec_error}.")
42endif()
43
44#Build the library
45execute_process(COMMAND
Gyorgy Szing2247d242021-09-03 16:17:25 +020046 ${CMAKE_COMMAND} --build ${LIBTS_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install
Julian Hallb1d5d5f2020-11-23 18:23:48 +010047 RESULT_VARIABLE _exec_error
48)
49
50if (_exec_error)
51 message(FATAL_ERROR "Build step of libts failed with ${_exec_error}.")
52endif()
53
54# Import the built library
Gyorgy Szingc31afbf2021-02-12 01:51:55 +010055include(${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/cmake/libts_targets.cmake)
Julian Hallb1d5d5f2020-11-23 18:23:48 +010056add_library(libts SHARED IMPORTED)
Gyorgy Szingc31afbf2021-02-12 01:51:55 +010057set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/${TS_ENV}/include")
58set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}")