1
0
Fork 0

Automatically download submodules when necessary

This commit is contained in:
Duncan Ogilvie 2025-04-05 00:13:24 +02:00
parent 2df98d8074
commit a5a25cc4a4
2 changed files with 29 additions and 0 deletions

3
cmake/cmkr.cmake vendored
View File

@ -1,5 +1,8 @@
include_guard()
# Initialize submodule if necessary
include(${CMAKE_CURRENT_LIST_DIR}/init-submodules.cmake)
# Change these defaults to point to your infrastructure if desired
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
set(CMKR_TAG "v0.2.44" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)

View File

@ -0,0 +1,26 @@
function(init_submodule folder)
set(full_path "${CMAKE_CURRENT_SOURCE_DIR}/${folder}")
if(NOT EXISTS ${full_path})
message(FATAL_ERROR "Submodule folder does not exist: ${full_path}")
endif()
file(GLOB files "${full_path}/*")
if(NOT files)
find_package(Git REQUIRED)
message(STATUS "Submodule '${folder}' not initialized, running git...")
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --show-toplevel
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE git_root
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule update --init -- "${full_path}"
WORKING_DIRECTORY "${git_root}"
COMMAND_ERROR_IS_FATAL ANY
)
endif()
endfunction()
init_submodule(src/dbg/btparser)
init_submodule(deps)