blob: 9da9bba95ef91a467a6b9400eb32cb8f7bc3effa [file] [log] [blame]
Balint Dobszay82753b72022-03-03 11:30:31 +01001#-------------------------------------------------------------------------------
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
9if (DEFINED ENV{TS_LIBFDT_PATH})
10 set(LIBFDT_PATH $ENV{TS_LIBFDT_PATH} CACHE PATH "Location of libfdt" FORCE)
11endif()
12
13# Otherwise clone the dtc repo (which contains libfdt)
14set(DTC_URL "https://github.com/dgibson/dtc" CACHE STRING "dtc repository URL")
15set(DTC_REFSPEC "v1.6.1" CACHE STRING "dtc git refspec")
16set(DTC_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/dtc-src" CACHE PATH "Location of dtc source")
17
18set(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
24include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED)
25LazyFetch_MakeAvailable(
26 DEP_NAME dtc
27 FETCH_OPTIONS "${GIT_OPTIONS}"
28 SOURCE_DIR ${DTC_SOURCE_DIR}
29)
30
31find_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
40if (NOT DEFINED TGT)
41 message(FATAL_ERROR "mandatory parameter TGT is not defined.")
42endif()
43
44target_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
57target_include_directories(${TGT} PRIVATE ${LIBFDT_PATH})