Skip to content

Commit

Permalink
cmake: update git submodules when cmake is run
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dcpleung authored and lgirdwood committed May 13, 2020
1 parent c00d39c commit d53778f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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"
)
Expand Down
23 changes: 23 additions & 0 deletions scripts/cmake/git-submodules.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d53778f

Please sign in to comment.