CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Loading...
Searching...
No Matches
ctkFunctionCheckoutRepo.cmake
Go to the documentation of this file.
1function(ctkFunctionCheckoutRepo)
2
3 ctkMacroParseArguments("" "NAME;GIT_URL;GIT_TAG;GIT_PROTOCOL;CHECKOUT_DIR" "" ${ARGN})
4
5 if(${_NAME}_DIR)
6 # if a *_DIR variable is supplied, the repository is not cloned.
7 return()
8 endif()
9
10 foreach(_required_arg NAME GIT_URL)
11 if(NOT _${_required_arg})
12 message(FATAL_ERROR "${_required_arg} is empty")
13 endif()
14 endforeach()
15
16 if(NOT _GIT_PROTOCOL)
17 set(_GIT_PROTOCOL ${EP_GIT_PROTOCOL})
18 endif()
19 if(NOT _CHECKOUT_DIR)
20 set(_CHECKOUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
21 endif()
22 if(NOT IS_ABSOLUTE "${_CHECKOUT_DIR}")
23 message(FATAL_ERROR "The value of the CHECKOUT_DIR argument must be an absolute path.")
24 endif()
25
26 if(NOT _GIT_TAG)
27 set(_GIT_TAG origin/master)
28 endif()
29
30 set(_repo_build_dir ${CMAKE_CURRENT_BINARY_DIR}/${_NAME}-proj)
31 configure_file(${CTK_CMAKE_DIR}/ctkCheckoutRepo.cmake.in
32 ${_repo_build_dir}/CMakeLists.txt)
33
34 execute_process(
35 COMMAND ${CMAKE_COMMAND} .
36 WORKING_DIRECTORY ${_repo_build_dir}
37 RESULT_VARIABLE _result_code
38 ERROR_VARIABLE _err_msg
39 )
40 if(_result_code)
41 message(FATAL_ERROR "Configuring directory ${_repo_build_dir} failed: ${_err_msg}")
42 endif()
43
44 execute_process(
45 COMMAND ${CMAKE_COMMAND} --build ${_repo_build_dir}
46 RESULT_VARIABLE _result_code
47 ERROR_VARIABLE _err_msg
48 )
49 if(_result_code)
50 message(FATAL_ERROR "Building directory ${_repo_build_dir} failed: ${_err_msg}")
51 endif()
52
53 set(${_NAME}_DIR ${_CHECKOUT_DIR}/${_NAME} PARENT_SCOPE)
54
55endfunction()