Skip to content

Commit

Permalink
cmake: Add hook to checkout submodules
Browse files Browse the repository at this point in the history
Related-to: #126
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Sep 3, 2023
1 parent c213ae4 commit 45c1d60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ indent_style = tab
indent_size = 8

# 4 space indentation
[*.{py.in,py,md}]
[*.{py.in,py,md,cmake}]
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(CONFIG_OSDP_STATIC_PD "Setup PD single statically" OFF)
option(CONFIG_OSDP_LIB_ONLY "Only build the library" OFF)

# Each subdirectory has it's own CMakeLists.txt
include(GitSubmodules)
add_subdirectory(utils)
add_subdirectory(src)
if (NOT CONFIG_OSDP_STATIC_PD AND NOT CONFIG_OSDP_LIB_ONLY)
Expand Down
23 changes: 23 additions & 0 deletions cmake/GitSubmodules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2020-2023 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

find_package(Git QUIET)

if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(STATUS "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 --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/utils/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 45c1d60

Please sign in to comment.