CuraPluginInstall.cmake 4.6 KB

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