Skip to content

Commit 18f3e40

Browse files
authored
Merge pull request #413 from Devsh-Graphics-Programming/git-submodules
New approach of updating submodules in CMake
2 parents 08855e3 + 359a971 commit 18f3e40

File tree

4 files changed

+76
-35
lines changed

4 files changed

+76
-35
lines changed

3rdparty/CMakeLists.txt

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,6 @@
44

55
include(../cmake/common.cmake)
66

7-
# mandatory
8-
option(NBL_UPDATE_GIT_SUBMODULE "" ON)
9-
10-
if(NBL_UPDATE_GIT_SUBMODULE)
11-
update_git_submodule(./volk)
12-
update_git_submodule(./SPIRV-Headers)
13-
update_git_submodule(./SPIRV-Tools)
14-
update_git_submodule(./glslang)
15-
update_git_submodule(./shaderc)
16-
update_git_submodule(./bzip2)
17-
update_git_submodule(./lz4)
18-
update_git_submodule(./nbl_spirv_cross)
19-
update_git_submodule(./zlib)
20-
update_git_submodule(./openexr)
21-
update_git_submodule(./libpng)
22-
update_git_submodule(./openssl)
23-
update_git_submodule(./libjpeg-turbo)
24-
update_git_submodule(./parallel-hashmap)
25-
update_git_submodule(./gli)
26-
# exceptions that get automatically cloned
27-
update_git_submodule(./glm)
28-
update_git_submodule(./freetype2)
29-
update_git_submodule(./portable-file-dialogs)
30-
update_git_submodule(./simdjson)
31-
update_git_submodule(./glTFSampleModels)
32-
update_git_submodule(./pstl/oneTBB)
33-
update_git_submodule(./pstl/oneDPL/oneDPL)
34-
endif()
35-
367
# simdjson
378
set(_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
389
set(_OLD_BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS})

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ option(NBL_BUILD_DOCS "Enable building documentation?" OFF) # No one has doxygen
287287
set(THIRD_PARTY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/3rdparty")
288288
set(THIRD_PARTY_BINARY_DIR "${PROJECT_BINARY_DIR}/3rdparty")
289289

290-
if(NBL_UPDATE_GIT_SUBMODULE)
291-
execute_process(COMMAND git submodule init
292-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
293-
execute_process(COMMAND git submodule sync --recursive
294-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
295-
endif()
290+
option(NBL_UPDATE_GIT_SUBMODULE "Turn this ON to let CMake update all public submodules for you" ON)
291+
option(NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE "Turn this ON to attempt to update private Nabla submodules" OFF)
292+
find_package(Git REQUIRED)
293+
include(common)
294+
295+
NBL_UPDATE_SUBMODULES()
296296
add_subdirectory(${THIRD_PARTY_SOURCE_DIR})
297297

298298
OPTION(NBL_EMBED_BUILTIN_RESOURCES "Embed built-in resources?" ON)

cmake/FindGitBash.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if(NOT DEFINED GIT_EXECUTABLE)
2+
message(FATAL_ERROR "GIT_EXECUTABLE must be defined!")
3+
endif()
4+
5+
cmake_path(GET GIT_EXECUTABLE PARENT_PATH _GIT_CMD_INSTALL_DIR_) # /cmd directory
6+
cmake_path(GET _GIT_CMD_INSTALL_DIR_ PARENT_PATH _GIT_INSTALL_DIR_) # /Git directory
7+
8+
find_program(GIT_BASH_EXECUTABLE NAMES "git-bash.exe" PATHS "${_GIT_INSTALL_DIR_}")
9+
10+
include(FindPackageHandleStandardArgs)
11+
find_package_handle_standard_args(GitBash REQUIRED_VARS GIT_BASH_EXECUTABLE)

cmake/common.cmake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,62 @@ endmacro()
638638
macro(write_source_definitions NBL_FILE NBL_WRAPPER_CODE_TO_WRITE)
639639
file(WRITE "${NBL_FILE}" "${NBL_WRAPPER_CODE_TO_WRITE}")
640640
endmacro()
641+
642+
function(NBL_UPDATE_SUBMODULES)
643+
macro(NBL_WRAPPER_COMMAND GIT_RELATIVE_ENTRY GIT_SUBMODULE_PATH SHOULD_RECURSIVE)
644+
set(SHOULD_RECURSIVE ${SHOULD_RECURSIVE})
645+
646+
if(SHOULD_RECURSIVE)
647+
string(APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "\"${GIT_EXECUTABLE}\" -C \"${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}\" submodule update --init --recursive ${GIT_SUBMODULE_PATH}\n")
648+
else()
649+
string(APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "\"${GIT_EXECUTABLE}\" -C \"${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}\" submodule update --init ${GIT_SUBMODULE_PATH}\n")
650+
endif()
651+
endmacro()
652+
653+
if(NBL_UPDATE_GIT_SUBMODULE)
654+
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "All submodules are about to get updated and initialized in repository because NBL_UPDATE_GIT_SUBMODULE is turned ON!")
655+
set(_NBL_UPDATE_SUBMODULES_CMD_NAME_ "nbl-update-submodules")
656+
set(_NBL_UPDATE_SUBMODULES_CMD_FILE_ "${NBL_ROOT_PATH_BINARY}/${_NBL_UPDATE_SUBMODULES_CMD_NAME_}.cmd")
657+
message(STATUS "test")
658+
if(NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE)
659+
NBL_WRAPPER_COMMAND("" "" TRUE)
660+
else()
661+
NBL_WRAPPER_COMMAND("" ./3rdparty TRUE)
662+
#NBL_WRAPPER_COMMAND("" ./ci TRUE) TODO: enable it once we merge Ditt, etc
663+
NBL_WRAPPER_COMMAND("" ./examples_tests FALSE)
664+
NBL_WRAPPER_COMMAND(examples_tests ./media FALSE)
665+
endif()
666+
667+
file(WRITE "${_NBL_UPDATE_SUBMODULES_CMD_FILE_}" "${_NBL_UPDATE_SUBMODULES_COMMANDS_}")
668+
669+
if(WIN32)
670+
find_package(GitBash REQUIRED)
671+
672+
execute_process(COMMAND "${GIT_BASH_EXECUTABLE}" "-c"
673+
[=[
674+
>&2 echo ""
675+
clear
676+
./nbl-update-submodules.cmd 2>&1 | tee nbl-update-submodules.log
677+
sleep 1
678+
clear
679+
tput setaf 2; echo -e "Submodules have been updated!
680+
Created nbl-update-submodules.log in your build directory.
681+
This window will be closed in 5 seconds..."
682+
sleep 5
683+
]=]
684+
WORKING_DIRECTORY ${NBL_ROOT_PATH_BINARY}
685+
OUTPUT_VARIABLE _NBL_TMP_OUTPUT_
686+
RESULT_VARIABLE _NBL_TMP_RET_CODE_
687+
OUTPUT_STRIP_TRAILING_WHITESPACE
688+
ERROR_STRIP_TRAILING_WHITESPACE
689+
)
690+
691+
unset(_NBL_TMP_OUTPUT_)
692+
unset(_NBL_TMP_RET_CODE_)
693+
else()
694+
execute_process(COMMAND "${_NBL_UPDATE_SUBMODULES_CMD_FILE_}")
695+
endif()
696+
else()
697+
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "NBL_UPDATE_GIT_SUBMODULE is turned OFF therefore submodules won't get updated.")
698+
endif()
699+
endfunction()

0 commit comments

Comments
 (0)