CuraPluginInstall.cmake 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Copyright (c) 2022 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. # Options or configuration variables
  12. set(CURA_NO_INSTALL_PLUGINS "" CACHE STRING "A list of plugins that should not be installed, separated with ';' or ','.")
  13. file(GLOB_RECURSE _plugin_json_list ${CMAKE_SOURCE_DIR}/plugins/*/plugin.json)
  14. list(LENGTH _plugin_json_list _plugin_json_list_len)
  15. # Sort the lists alphabetically so we can handle cases like this:
  16. # - plugins/my_plugin/plugin.json
  17. # - plugins/my_plugin/my_module/plugin.json
  18. # In this case, only "plugins/my_plugin" should be added via install().
  19. set(_no_install_plugin_list ${CURA_NO_INSTALL_PLUGINS})
  20. # Sanitize the string so the comparison will be case-insensitive.
  21. string(STRIP "${_no_install_plugin_list}" _no_install_plugin_list)
  22. string(TOLOWER "${_no_install_plugin_list}" _no_install_plugin_list)
  23. # WORKAROUND counterpart of what's in cura-build.
  24. string(REPLACE "," ";" _no_install_plugin_list "${_no_install_plugin_list}")
  25. list(LENGTH _no_install_plugin_list _no_install_plugin_list_len)
  26. if(_no_install_plugin_list_len GREATER 0)
  27. list(SORT _no_install_plugin_list)
  28. endif()
  29. if(_plugin_json_list_len GREATER 0)
  30. list(SORT _plugin_json_list)
  31. endif()
  32. # Check all plugin directories and add them via install() if needed.
  33. set(_install_plugin_list "")
  34. foreach(_plugin_json_path ${_plugin_json_list})
  35. get_filename_component(_plugin_dir ${_plugin_json_path} DIRECTORY)
  36. file(RELATIVE_PATH _rel_plugin_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_plugin_dir})
  37. get_filename_component(_plugin_dir_name ${_plugin_dir} NAME)
  38. # Make plugin name comparison case-insensitive
  39. string(TOLOWER "${_plugin_dir_name}" _plugin_dir_name_lowercase)
  40. # Check if this plugin needs to be skipped for installation
  41. set(_add_plugin ON) # Indicates if this plugin should be added to the build or not.
  42. set(_is_no_install_plugin OFF) # If this plugin will not be added, this indicates if it's because the plugin is
  43. # specified in the NO_INSTALL_PLUGINS list.
  44. if(_no_install_plugin_list)
  45. if("${_plugin_dir_name_lowercase}" IN_LIST _no_install_plugin_list)
  46. set(_add_plugin OFF)
  47. set(_is_no_install_plugin ON)
  48. endif()
  49. endif()
  50. # Make sure this is not a subdirectory in a plugin that's already in the install list
  51. if(_add_plugin)
  52. foreach(_known_install_plugin_dir ${_install_plugin_list})
  53. if(_plugin_dir MATCHES "${_known_install_plugin_dir}.+")
  54. set(_add_plugin OFF)
  55. break()
  56. endif()
  57. endforeach()
  58. endif()
  59. if(_add_plugin)
  60. if(${PRINT_PLUGIN_LIST})
  61. message(STATUS "[+] PLUGIN TO INSTALL: ${_rel_plugin_dir}")
  62. endif()
  63. get_filename_component(_rel_plugin_parent_dir ${_rel_plugin_dir} DIRECTORY)
  64. install(DIRECTORY ${_rel_plugin_dir}
  65. DESTINATION lib${LIB_SUFFIX}/cura/${_rel_plugin_parent_dir}
  66. PATTERN "__pycache__" EXCLUDE
  67. PATTERN "*.qmlc" EXCLUDE
  68. )
  69. list(APPEND _install_plugin_list ${_plugin_dir})
  70. elseif(_is_no_install_plugin)
  71. if(${PRINT_PLUGIN_LIST})
  72. message(STATUS "[-] PLUGIN TO REMOVE : ${_rel_plugin_dir}")
  73. endif()
  74. execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mod_bundled_packages_json.py
  75. -d ${CMAKE_CURRENT_SOURCE_DIR}/resources/bundled_packages
  76. ${_plugin_dir_name}
  77. RESULT_VARIABLE _mod_json_result)
  78. endif()
  79. endforeach()