Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sofa/framework/Config/cmake/SofaMacrosConfigure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ macro(sofa_fetch_dependency name)
file(MAKE_DIRECTORY "${fetched_dir}-temp/")
endif()

set(GIT_SHALLOW_VALUE TRUE)
# GIT_SHALLOW does work if GIT_TAG is a commit SHA hash
__is_git_tag_commit_hash(${upper_name}_GIT_TAG IS_GIT_TAG_COMMIT_HASH)
if(IS_GIT_TAG_COMMIT_HASH)
set(GIT_SHALLOW_VALUE FALSE)
endif()

file(WRITE ${fetched_dir}-temp/CMakeLists.txt "
cmake_minimum_required(VERSION 3.22)
Expand All @@ -219,6 +225,7 @@ macro(sofa_fetch_dependency name)
INSTALL_COMMAND \"\"
TEST_COMMAND \"\"
GIT_CONFIG \"remote.origin.fetch=+refs/pull/*:refs/remotes/origin/pr/*\"
GIT_SHALLOW ${GIT_SHALLOW_VALUE}
)"
)

Expand Down
15 changes: 15 additions & 0 deletions Sofa/framework/Config/cmake/SofaMacrosUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ function(sofa_get_all_targets var)
set(${var} ${targets} PARENT_SCOPE)
endfunction()

# guess if the git tag is a commit hash or an actual tag or a branch nane.
# heavily inspired by https://github.com/cpm-cmake/CPM.cmake/pull/130/changes#diff-6fcfee7f313f15253f88285a499e62cb58746d47ff2cfec173f1f4cd29feb44d
function(__is_git_tag_commit_hash GIT_TAG RESULT)
string(LENGTH ${GIT_TAG} length)
# full hash has 40 characters, and short hash has at least 7 characters.
if (length LESS 7 OR length GREATER 40)
SET(${RESULT} 0 PARENT_SCOPE)
else()
if (${GIT_TAG} MATCHES "^[a-fA-F0-9]+$")
SET(${RESULT} 1 PARENT_SCOPE)
else()
SET(${RESULT} 0 PARENT_SCOPE)
endif()
endif()
endfunction()