CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkFunctionAddPluginRepo.cmake
Go to the documentation of this file.
1 function(ctkFunctionAddPluginRepo)
2 
3  ctkMacroParseArguments("" "NAME;GIT_URL;GIT_TAG;GIT_PROTOCOL" "" ${ARGN})
4 
5  foreach(_required_arg NAME)
6  if(NOT _${_required_arg})
7  message(FATAL_ERROR "${_required_arg} is empty")
8  endif()
9  endforeach()
10 
11  if(NOT _GIT_URL AND NOT ${_NAME}_DIR)
12  message(FATAL_ERROR "Either ${_NAME}_DIR or GIT_URL must be set")
13  endif()
14 
15  if(NOT ${_NAME}_DIR)
16  ctkFunctionCheckoutRepo(
17  NAME ${_NAME}
18  GIT_URL ${_GIT_URL}
19  GIT_TAG ${_GIT_TAG}
20  GIT_PROTOCOL ${_GIT_PROTOCOL}
21  )
22  endif()
23 
24  set(_gitmodules_files ${${_NAME}_DIR}/.gitmodules)
25  if(NOT EXISTS ${_gitmodules_files})
26  message(FATAL_ERROR "The repository at ${${_NAME}_DIR} does not contain a .gitmodules file")
27  endif()
28 
29  # Parse the .gitmodules file and add the submodules as contributed plugins
30  file(STRINGS "${_gitmodules_files}" _plugin_paths REGEX "path =.*")
31  foreach(_plugin_path ${_plugin_paths})
32  string(REPLACE " = " ";" _plugin_path_list ${_plugin_path})
33  list(GET _plugin_path_list 1 _plugin_name)
34  ctk_plugin_option(${_plugin_name} "Build the ${_plugin_name} plugin." OFF)
35 
36  # Push the value which might have been changed in ctk_plugin_option to the parent scope
37  set(CTK_PLUGIN_${_plugin_name} ${CTK_PLUGIN_${_plugin_name}} PARENT_SCOPE)
38 
39  set(${_plugin_name}_SOURCE_DIR ${${_NAME}_DIR}/${_plugin_name})
40  set(${_plugin_name}_SOURCE_DIR ${${_plugin_name}_SOURCE_DIR} PARENT_SCOPE)
41 
42  if(CTK_PLUGIN_${_plugin_name} AND NOT EXISTS ${${_plugin_name}_SOURCE_DIR})
43  execute_process(
44  COMMAND ${GIT_EXECUTABLE} submodule update ${_plugin_name}
45  WORKING_DIRECTORY ${${_NAME}_DIR}
46  RESULT_VARIABLE return_code
47  ERROR_VARIABLE error_msg
48  )
49  if(return_code)
50  message(FATAL_ERROR "Could not invoke git submodule update for ${${_plugin_name}_SOURCE_DIR}")
51  endif()
52  endif()
53  endforeach()
54 
55  set(CTK_PLUGINS ${CTK_PLUGINS} PARENT_SCOPE)
56  set(${_NAME}_DIR ${${_NAME}_DIR} PARENT_SCOPE)
57 
58 endfunction()