36 lines
1012 B
CMake
36 lines
1012 B
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}
|
|
)
|
|
|
|
if(NOT ${NAME}_POPULATED)
|
|
FetchContent_Populate(${NAME})
|
|
add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR})
|
|
endif()
|
|
|
|
endfunction()
|