Balint Dobszay | 82753b7 | 2022-03-03 11:30:31 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Imre Kis | 1a0997c | 2024-05-29 14:41:38 +0200 | [diff] [blame] | 2 | # Copyright (c) 2022-2024, Arm Limited and Contributors. All rights reserved. |
Balint Dobszay | 82753b7 | 2022-03-03 11:30:31 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | # Use libfdt path from the environment if defined |
| 9 | if (DEFINED ENV{TS_LIBFDT_PATH}) |
| 10 | set(LIBFDT_PATH $ENV{TS_LIBFDT_PATH} CACHE PATH "Location of libfdt" FORCE) |
| 11 | endif() |
| 12 | |
| 13 | # Otherwise clone the dtc repo (which contains libfdt) |
| 14 | set(DTC_URL "https://github.com/dgibson/dtc" CACHE STRING "dtc repository URL") |
| 15 | set(DTC_REFSPEC "v1.6.1" CACHE STRING "dtc git refspec") |
| 16 | set(DTC_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/dtc-src" CACHE PATH "Location of dtc source") |
| 17 | |
| 18 | set(GIT_OPTIONS |
| 19 | GIT_REPOSITORY ${DTC_URL} |
| 20 | GIT_TAG ${DTC_REFSPEC} |
Balint Dobszay | 82753b7 | 2022-03-03 11:30:31 +0100 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED) |
| 24 | LazyFetch_MakeAvailable( |
| 25 | DEP_NAME dtc |
| 26 | FETCH_OPTIONS "${GIT_OPTIONS}" |
| 27 | SOURCE_DIR ${DTC_SOURCE_DIR} |
| 28 | ) |
| 29 | |
| 30 | find_path(LIBFDT_PATH |
| 31 | NAMES fdt.c |
| 32 | PATHS ${DTC_SOURCE_DIR}/libfdt |
| 33 | NO_DEFAULT_PATH |
| 34 | REQUIRED |
| 35 | DOC "Location of libfdt" |
| 36 | ) |
| 37 | |
| 38 | # Add libfdt source files to the target |
| 39 | if (NOT DEFINED TGT) |
| 40 | message(FATAL_ERROR "mandatory parameter TGT is not defined.") |
| 41 | endif() |
| 42 | |
| 43 | target_sources(${TGT} PRIVATE |
| 44 | "${LIBFDT_PATH}/fdt.c" |
| 45 | "${LIBFDT_PATH}/fdt_ro.c" |
| 46 | "${LIBFDT_PATH}/fdt_wip.c" |
| 47 | "${LIBFDT_PATH}/fdt_sw.c" |
| 48 | "${LIBFDT_PATH}/fdt_rw.c" |
| 49 | "${LIBFDT_PATH}/fdt_strerror.c" |
| 50 | "${LIBFDT_PATH}/fdt_empty_tree.c" |
| 51 | "${LIBFDT_PATH}/fdt_addresses.c" |
| 52 | "${LIBFDT_PATH}/fdt_overlay.c" |
| 53 | "${LIBFDT_PATH}/fdt_check.c" |
| 54 | ) |
| 55 | |
| 56 | target_include_directories(${TGT} PRIVATE ${LIBFDT_PATH}) |