Created
April 26, 2024 22:42
-
-
Save Caellian/9f92506fa24df111729589d392e84553 to your computer and use it in GitHub Desktop.
A CMake script that automatically fetches git submodules if they're not initalized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_package(Git QUIET) | |
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") | |
option(INIT_SUBMODULES "Check submodules during build" ON) | |
if(INIT_SUBMODULES) | |
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive | |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
RESULT_VARIABLE GIT_SUBMOD_RESULT) | |
if(GIT_SUBMOD_RESULT EQUAL "0") | |
message(STATUS "Submodules initialized") | |
else() | |
message(FATAL_ERROR "Unable to initalize git submodules; error: ${GIT_SUBMOD_RESULT}") | |
endif() | |
endif() | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment