Balint Dobszay | 82753b7 | 2022-03-03 11:30:31 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| 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} |
| 21 | PATCH_COMMAND git stash COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/fix-strnlen.patch |
| 22 | ) |
| 23 | |
| 24 | include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED) |
| 25 | LazyFetch_MakeAvailable( |
| 26 | DEP_NAME dtc |
| 27 | FETCH_OPTIONS "${GIT_OPTIONS}" |
| 28 | SOURCE_DIR ${DTC_SOURCE_DIR} |
| 29 | ) |
| 30 | |
| 31 | find_path(LIBFDT_PATH |
| 32 | NAMES fdt.c |
| 33 | PATHS ${DTC_SOURCE_DIR}/libfdt |
| 34 | NO_DEFAULT_PATH |
| 35 | REQUIRED |
| 36 | DOC "Location of libfdt" |
| 37 | ) |
| 38 | |
| 39 | # Add libfdt source files to the target |
| 40 | if (NOT DEFINED TGT) |
| 41 | message(FATAL_ERROR "mandatory parameter TGT is not defined.") |
| 42 | endif() |
| 43 | |
| 44 | target_sources(${TGT} PRIVATE |
| 45 | "${LIBFDT_PATH}/fdt.c" |
| 46 | "${LIBFDT_PATH}/fdt_ro.c" |
| 47 | "${LIBFDT_PATH}/fdt_wip.c" |
| 48 | "${LIBFDT_PATH}/fdt_sw.c" |
| 49 | "${LIBFDT_PATH}/fdt_rw.c" |
| 50 | "${LIBFDT_PATH}/fdt_strerror.c" |
| 51 | "${LIBFDT_PATH}/fdt_empty_tree.c" |
| 52 | "${LIBFDT_PATH}/fdt_addresses.c" |
| 53 | "${LIBFDT_PATH}/fdt_overlay.c" |
| 54 | "${LIBFDT_PATH}/fdt_check.c" |
| 55 | ) |
| 56 | |
| 57 | target_include_directories(${TGT} PRIVATE ${LIBFDT_PATH}) |