37 lines
1.0 KiB
CMake
37 lines
1.0 KiB
CMake
include_guard(GLOBAL)
|
|
|
|
function(FetchContent_Add NAME)
|
|
set(options "")
|
|
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
|
|
set(multiValueArgs "")
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
find_package(Git)
|
|
if(GIT_FOUND AND ARG_GIT_REMOTE AND ARG_GIT_PATH)
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.${ARG_GIT_REMOTE}.url OUTPUT_VARIABLE REMOTE_URL ERROR_QUIET)
|
|
if(REMOTE_URL)
|
|
string(REGEX REPLACE ":.*" "" SERVER ${REMOTE_URL})
|
|
string(FIND ${SERVER} "http" POS)
|
|
if(NOT POS EQUAL 0)
|
|
if(NOT SERVER STREQUAL REMOTE_URL)
|
|
set(ARG_GIT_REPOSITORY "${SERVER}:${ARG_GIT_PATH}")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
FetchContent_Declare(
|
|
${NAME}
|
|
${ARG_UNPARSED_ARGUMENTS}
|
|
GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
|
|
GIT_SHALLOW 1
|
|
)
|
|
|
|
if(NOT ${NAME}_POPULATED)
|
|
FetchContent_Populate(${NAME})
|
|
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
|
|
endif()
|
|
|
|
endfunction()
|