CuraPluginInstall.cmake 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # CuraPluginInstall.cmake is released under the terms of the LGPLv3 or higher.
  3. #
  4. # This module detects all plugins that need to be installed and adds them using the CMake install() command.
  5. # It detects all plugin folder in the path "plugins/*" where there's a "plugin.json" in it.
  6. #
  7. # Plugins can be configured to NOT BE INSTALLED via the variable "CURA_NO_INSTALL_PLUGINS" as a list of string in the
  8. # form of "a;b;c" or "a,b,c". By default all plugins will be installed.
  9. #
  10. # FIXME: Remove the code for CMake <3.12 once we have switched over completely.
  11. # FindPython3 is a new module since CMake 3.12. It deprecates FindPythonInterp and FindPythonLibs. The FindPython3
  12. # module is copied from the CMake repository here so in CMake <3.12 we can still use it.
  13. if(${CMAKE_VERSION} VERSION_LESS 3.12)
  14. # Use FindPythonInterp and FindPythonLibs for CMake <3.12
  15. find_package(PythonInterp 3 REQUIRED)
  16. set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
  17. else()
  18. # Use FindPython3 for CMake >=3.12
  19. find_package(Python3 REQUIRED COMPONENTS Interpreter)
  20. endif()
  21. # Options or configuration variables
  22. set(CURA_NO_INSTALL_PLUGINS "" CACHE STRING "A list of plugins that should not be installed, separated with ';' or ','.")
  23. file(GLOB_RECURSE _plugin_json_list ${CMAKE_SOURCE_DIR}/plugins/*/plugin.json)
  24. list(LENGTH _plugin_json_list _plugin_json_list_len)
  25. # Sort the lists alphabetically so we can handle cases like this:
  26. # - plugins/my_plugin/plugin.json
  27. # - plugins/my_plugin/my_module/plugin.json
  28. # In this case, only "plugins/my_plugin" should be added via install().
  29. set(_no_install_plugin_list ${CURA_NO_INSTALL_PLUGINS})
  30. # Sanitize the string so the comparison will be case-insensitive.
  31. string(STRIP "${_no_install_plugin_list}" _no_install_plugin_list)
  32. string(TOLOWER "${_no_install_plugin_list}" _no_install_plugin_list)
  33. # WORKAROUND counterpart of what's in cura-build.
  34. string(REPLACE "," ";" _no_install_plugin_list "${_no_install_plugin_list}")
  35. list(LENGTH _no_install_plugin_list _no_install_plugin_list_len)
  36. if(_no_install_plugin_list_len GREATER 0)
  37. list(SORT _no_install_plugin_list)
  38. endif()
  39. if(_plugin_json_list_len GREATER 0)
  40. list(SORT _plugin_json_list)
  41. endif()
  42. # Check all plugin directories and add them via install() if needed.
  43. set(_install_plugin_list "")
  44. foreach(_plugin_json_path ${_plugin_json_list})
  45. get_filename_component(_plugin_dir ${_plugin_json_path} DIRECTORY)
  46. file(RELATIVE_PATH _rel_plugin_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_plugin_dir})
  47. get_filename_component(_plugin_dir_name ${_plugin_dir} NAME)
  48. # Make plugin name comparison case-insensitive
  49. string(TOLOWER "${_plugin_dir_name}" _plugin_dir_name_lowercase)
  50. # Check if this plugin needs to be skipped for installation
  51. set(_add_plugin ON) # Indicates if this plugin should be added to the build or not.
  52. set(_is_no_install_plugin OFF) # If this plugin will not be added, this indicates if it's because the plugin is
  53. # specified in the NO_INSTALL_PLUGINS list.
  54. if(_no_install_plugin_list)
  55. if("${_plugin_dir_name_lowercase}" IN_LIST _no_install_plugin_list)
  56. set(_add_plugin OFF)
  57. set(_is_no_install_plugin ON)
  58. endif()
  59. endif()
  60. # Make sure this is not a subdirectory in a plugin that's already in the install list
  61. if(_add_plugin)
  62. foreach(_known_install_plugin_dir ${_install_plugin_list})
  63. if(_plugin_dir MATCHES "${_known_install_plugin_dir}.+")
  64. set(_add_plugin OFF)
  65. break()
  66. endif()
  67. endforeach()
  68. endif()
  69. if(_add_plugin)
  70. message(STATUS "[+] PLUGIN TO INSTALL: ${_rel_plugin_dir}")
  71. get_filename_component(_rel_plugin_parent_dir ${_rel_plugin_dir} DIRECTORY)
  72. install(DIRECTORY ${_rel_plugin_dir}
  73. DESTINATION lib${LIB_SUFFIX}/cura/${_rel_plugin_parent_dir}
  74. PATTERN "__pycache__" EXCLUDE
  75. PATTERN "*.qmlc" EXCLUDE
  76. )
  77. list(APPEND _install_plugin_list ${_plugin_dir})
  78. elseif(_is_no_install_plugin)
  79. message(STATUS "[-] PLUGIN TO REMOVE : ${_rel_plugin_dir}")
  80. execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mod_bundled_packages_json.py
  81. -d ${CMAKE_CURRENT_SOURCE_DIR}/resources/bundled_packages
  82. ${_plugin_dir_name}
  83. RESULT_VARIABLE _mod_json_result)
  84. endif()
  85. endforeach()