Skip to content

Commit

Permalink
Update cmake submodule handling
Browse files Browse the repository at this point in the history
- Guard against duplicating btwxt builds
  • Loading branch information
pmskintner committed Mar 23, 2022
1 parent 58fc6e7 commit dd8e413
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
27 changes: 27 additions & 0 deletions cmake/initialize-submodules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
macro(initialize_submodules)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
set(git_modules_file "${PROJECT_SOURCE_DIR}/.gitmodules")
if (EXISTS ${git_modules_file})
file(STRINGS ${git_modules_file} file_lines)
foreach(line ${file_lines})
if (${line} MATCHES "url =")
string(REGEX REPLACE "\\s*url = .*/(.*).git" "\\1" submodule "${line}")
string(STRIP "${submodule}" submodule)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${submodule}")
message(FATAL_ERROR "Submodule directory \"${CMAKE_CURRENT_SOURCE_DIR}/${submodule}\" does not exist")
endif()
# Initialize submodule if it hasn't already been cloned
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${submodule}/.git")
message(STATUS "Initialize ${submodule} submodule")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive "${CMAKE_CURRENT_SOURCE_DIR}/${submodule}"
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 ${CMAKE_CURRENT_SOURCE_DIR}/${submodule} failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
endforeach()
endif()
endif()
endmacro()
19 changes: 5 additions & 14 deletions vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@

if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
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()
endif()

include(initialize-submodules)
initialize_submodules()

add_subdirectory(btwxt)
if (NOT TARGET btwxt)
add_subdirectory(btwxt)
endif ()

0 comments on commit dd8e413

Please sign in to comment.