ctkFunctionAddPluginRepo.cmake 1.8 KB

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