ctkFunctionAddPluginRepo.cmake 2.0 KB

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