Modify external dependencies to use LazyFetch
Refactor external dependencies use the new module. This gives more
control over how external components is made available and allows
the environment to use pre-build binaries or pre-fetched content.
Moreover, passing parameters to external CMake build systems is made
more robust by using initial cache files.
Signed-off-by: Benedek Tomasik <benedek.tomasik@arm.com>
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Change-Id: I85d1990fc7697847307b0ca3a91052b35423d823
diff --git a/external/qcbor/qcbor.cmake b/external/qcbor/qcbor.cmake
index 96e5dcb..f563fe2 100644
--- a/external/qcbor/qcbor.cmake
+++ b/external/qcbor/qcbor.cmake
@@ -1,36 +1,17 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# QCBOR is a library for encoding and decoding CBOR objects, as per RFC8949
#-------------------------------------------------------------------------------
-# Determine the number of processes to run while running parallel builds.
-# Pass -DPROCESSOR_COUNT=<n> to cmake to override.
-if(NOT DEFINED PROCESSOR_COUNT)
- include(ProcessorCount)
- ProcessorCount(PROCESSOR_COUNT)
- set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.")
-endif()
-
-# External component details
set(QCBOR_URL "https://github.com/laurencelundblade/QCBOR.git" CACHE STRING "qcbor repository URL")
set(QCBOR_REFSPEC "master" CACHE STRING "qcbor git refspec")
-set(QCBOR_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory")
-set(QCBOR_PACKAGE_PATH "${QCBOR_INSTALL_PATH}/libqcbor/cmake" CACHE PATH "qcbor CMake package directory")
+set(QCBOR_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/qcbor-src" CACHE PATH "qcbor installation directory")
+set(QCBOR_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory")
-include(FetchContent)
-
-# Checking git
-find_program(GIT_COMMAND "git")
-if (NOT GIT_COMMAND)
- message(FATAL_ERROR "Please install git")
-endif()
-
-# Fetching qcbor
-FetchContent_Declare(
- qcbor
+set(GIT_OPTIONS
GIT_REPOSITORY ${QCBOR_URL}
GIT_TAG ${QCBOR_REFSPEC}
GIT_SHALLOW TRUE
@@ -41,50 +22,18 @@
COMMAND git reset bf-patch
)
-# FetchContent_GetProperties exports qcbor_SOURCE_DIR and qcbor_BINARY_DIR variables
-FetchContent_GetProperties(qcbor)
-if(NOT qcbor_POPULATED)
- message(STATUS "Fetching qcbor")
- FetchContent_Populate(qcbor)
-endif()
-# Determine floating point configuration
-if (TS_NO_FLOAT_HW)
- set(_thirdparty_def -DQCBOR_DISABLE_FLOAT_HW_USE)
-endif()
-
-# Configure the qcbor library
-if (NOT "${QCBOR_EXTERNAL_INCLUDE_PATHS}" STREQUAL "")
- string(REPLACE ";" "\\;" QCBOR_EXTERNAL_INCLUDE_PATHS "${QCBOR_EXTERNAL_INCLUDE_PATHS}")
- set(QCBOR_EXTRA_OPTION -Dthirdparty_inc=${QCBOR_EXTERNAL_INCLUDE_PATHS})
- unset(QCBOR_EXTERNAL_INCLUDE_PATHS)
-else()
- set(QCBOR_EXTRA_OPTION "")
-endif()
-
-execute_process(COMMAND
- ${CMAKE_COMMAND}
- -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
- -GUnix\ Makefiles
- -Dthirdparty_def=${_thirdparty_def}
- -DCMAKE_INSTALL_PREFIX=${QCBOR_INSTALL_PATH}
- ${QCBOR_EXTRA_OPTION}
- ${qcbor_SOURCE_DIR}
- WORKING_DIRECTORY
- ${qcbor_BINARY_DIR}
-)
-unset(QCBOR_EXTRA_OPTION)
-
-# Build the library
-execute_process(COMMAND
- ${CMAKE_COMMAND} --build ${qcbor_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install
- RESULT_VARIABLE _exec_error
+include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED)
+LazyFetch_MakeAvailable(DEP_NAME qcbor
+ FETCH_OPTIONS "${GIT_OPTIONS}"
+ INSTALL_DIR "${QCBOR_INSTALL_DIR}"
+ CACHE_FILE "${CMAKE_CURRENT_LIST_DIR}/qcbor-init-cache.cmake.in"
+ SOURCE_DIR "${QCBOR_SOURCE_DIR}"
)
-if (_exec_error)
- message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.")
-endif()
# Create an imported target to have clean abstraction in the build-system.
add_library(qcbor STATIC IMPORTED)
-set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
-set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_PATH}/include")
+set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
+set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_DIR}/include")
+
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${QCBOR_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")