From d53778f3729799cd2f18dcd52d5e0bd52b55ef9c Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Sun, 5 Apr 2020 02:19:44 -0700 Subject: [PATCH] cmake: update git submodules when cmake is run This adds the necessary bits to update git submodules when cmake is run, with the option to turn this behavior off if needed. This is in preparation to use fw.h and manifest.h from the rimage repo to prevent having two copies of each file in two different repos. Obviously, the files in the submodules must exist before building the firmware, so run git submodule update to checkout the files. Signed-off-by: Daniel Leung --- CMakeLists.txt | 6 ++++++ scripts/cmake/git-submodules.cmake | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 scripts/cmake/git-submodules.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dda22470e38..96746a4d7c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,9 @@ set(SOF_ROOT_BINARY_DIRECTORY "${PROJECT_BINARY_DIR}") # check git hooks include(scripts/cmake/git-hooks.cmake) +# checkout submodules +include(scripts/cmake/git-submodules.cmake) + # most of other options are set on per-arch and per-target basis set(CMAKE_ASM_FLAGS -DASSEMBLY) @@ -55,6 +58,7 @@ set(CMAKE_ASM_FLAGS -DASSEMBLY) add_library(sof_public_headers INTERFACE) target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/src/include) +target_include_directories(sof_public_headers INTERFACE ${PROJECT_SOURCE_DIR}/rimage/src/include/sof) # interface library that is used only as container for sof binary options # other targets can use it to build with the same options @@ -162,6 +166,8 @@ install( ${PROJECT_SOURCE_DIR}/src/include/ipc ${PROJECT_SOURCE_DIR}/src/include/kernel ${PROJECT_SOURCE_DIR}/src/include/user + ${PROJECT_SOURCE_DIR}/rimage/src/include/sof/kernel + ${PROJECT_SOURCE_DIR}/rimage/src/include/sof/user DESTINATION include/sof PATTERN "*.h" ) diff --git a/scripts/cmake/git-submodules.cmake b/scripts/cmake/git-submodules.cmake new file mode 100644 index 000000000000..dc27797637e5 --- /dev/null +++ b/scripts/cmake/git-submodules.cmake @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: BSD-3-Clause + +find_package(Git) +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + # Update submodules by default + option(GIT_SUBMODULE "Check submodules during build" ON) + + if(GIT_SUBMODULE) + message(STATUS "Git submodule update") + + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE GIT_SUBMOD_RESULT) + + if(NOT GIT_SUBMOD_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") + endif() + endif() +endif() + +if(NOT EXISTS "${PROJECT_SOURCE_DIR}/rimage/CMakeLists.txt") + message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") +endif()