Install.cmake 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. ly_set(LY_INSTALL_ENABLED TRUE)
  9. if(INSTALLED_ENGINE)
  10. ly_set(LY_INSTALL_ENABLED FALSE)
  11. endif()
  12. if(LY_INSTALL_ENABLED)
  13. ly_get_absolute_pal_filename(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Platform/${PAL_PLATFORM_NAME})
  14. include(${pal_dir}/Install_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  15. endif()
  16. #! ly_install_directory: specifies a directory to be copied to the install layout at install time
  17. #
  18. # \arg:DIRECTORIES directories to install
  19. # \arg:DESTINATION (optional) destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  20. # \arg:EXCLUDE_PATTERNS (optional) patterns to exclude
  21. # \arg:VERBATIM (optional) copies the directories as they are, this excludes the default exclude patterns
  22. #
  23. # \notes:
  24. # - refer to cmake's install(DIRECTORY documentation for more information
  25. # - If the directory contains programs/scripts, exclude them from this call and add a specific ly_install_files with
  26. # PROGRAMS set. This is necessary to set the proper execution permissions.
  27. # - This function will automatically filter out __pycache__, *.egg-info, CMakeLists.txt, *.cmake files. If those files
  28. # need to be installed, use ly_install_files. Use VERBATIM to exclude such filters.
  29. #
  30. function(ly_install_directory)
  31. if(NOT LY_INSTALL_ENABLED)
  32. return()
  33. endif()
  34. set(options VERBATIM)
  35. set(oneValueArgs DESTINATION)
  36. set(multiValueArgs DIRECTORIES EXCLUDE_PATTERNS)
  37. cmake_parse_arguments(ly_install_directory "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  38. if(NOT ly_install_directory_DIRECTORIES)
  39. message(FATAL_ERROR "You must provide at least a directory to install")
  40. endif()
  41. foreach(directory ${ly_install_directory_DIRECTORIES})
  42. cmake_path(ABSOLUTE_PATH directory)
  43. if(NOT ly_install_directory_DESTINATION)
  44. # maintain the same structure relative to LY_ROOT_FOLDER
  45. set(ly_install_directory_DESTINATION ${directory})
  46. if(${ly_install_directory_DESTINATION} STREQUAL ".")
  47. set(ly_install_directory_DESTINATION ${CMAKE_CURRENT_LIST_DIR})
  48. else()
  49. cmake_path(ABSOLUTE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  50. endif()
  51. # take out the last directory since install asks for the destination of the folder, without including the fodler itself
  52. cmake_path(GET ly_install_directory_DESTINATION PARENT_PATH ly_install_directory_DESTINATION)
  53. cmake_path(RELATIVE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${LY_ROOT_FOLDER})
  54. endif()
  55. unset(exclude_patterns)
  56. if(ly_install_directory_EXCLUDE_PATTERNS)
  57. foreach(exclude_pattern ${ly_install_directory_EXCLUDE_PATTERNS})
  58. list(APPEND exclude_patterns PATTERN ${exclude_pattern} EXCLUDE)
  59. endforeach()
  60. endif()
  61. if(NOT ly_install_directory_VERBATIM)
  62. # Exclude cmake since that has to be generated
  63. list(APPEND exclude_patterns PATTERN CMakeLists.txt EXCLUDE)
  64. list(APPEND exclude_patterns PATTERN *.cmake EXCLUDE)
  65. # Exclude python-related things that dont need to be installed
  66. list(APPEND exclude_patterns PATTERN __pycache__ EXCLUDE)
  67. list(APPEND exclude_patterns PATTERN *.egg-info EXCLUDE)
  68. endif()
  69. install(DIRECTORY ${directory}
  70. DESTINATION ${ly_install_directory_DESTINATION}
  71. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the deafult for the time being
  72. ${exclude_patterns}
  73. )
  74. endforeach()
  75. endfunction()
  76. #! ly_install_files: specifies files to be copied to the install layout at install time
  77. #
  78. # \arg:FILES files to install
  79. # \arg:DESTINATION destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  80. # \arg:PROGRAMS (optional) indicates if the files are programs that should be installed with EXECUTE permissions
  81. #
  82. # \notes:
  83. # - refer to cmake's install(FILES/PROGRAMS documentation for more information
  84. #
  85. function(ly_install_files)
  86. if(NOT LY_INSTALL_ENABLED)
  87. return()
  88. endif()
  89. set(options PROGRAMS)
  90. set(oneValueArgs DESTINATION)
  91. set(multiValueArgs FILES)
  92. cmake_parse_arguments(ly_install_files "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  93. if(NOT ly_install_files_FILES)
  94. message(FATAL_ERROR "You must provide a list of files to install")
  95. endif()
  96. if(NOT ly_install_files_DESTINATION)
  97. message(FATAL_ERROR "You must provide a destination to install files to")
  98. endif()
  99. unset(files)
  100. foreach(file ${ly_install_files_FILES})
  101. cmake_path(ABSOLUTE_PATH file)
  102. list(APPEND files ${file})
  103. endforeach()
  104. if(ly_install_files_PROGRAMS)
  105. set(install_type PROGRAMS)
  106. else()
  107. set(install_type FILES)
  108. endif()
  109. install(${install_type} ${files}
  110. DESTINATION ${ly_install_files_DESTINATION}
  111. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  112. )
  113. endfunction()
  114. #! ly_install_run_code: specifies code to be added to the install process (will run at install time)
  115. #
  116. # \notes:
  117. # - refer to cmake's install(CODE documentation for more information
  118. #
  119. function(ly_install_run_code CODE)
  120. if(NOT LY_INSTALL_ENABLED)
  121. return()
  122. endif()
  123. install(CODE ${CODE}
  124. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  125. )
  126. endfunction()
  127. #! ly_install_run_script: specifies path to script to be added to the install process (will run at install time)
  128. #
  129. # \notes:
  130. # - refer to cmake's install(SCRIPT documentation for more information
  131. #
  132. function(ly_install_run_script SCRIPT)
  133. if(NOT LY_INSTALL_ENABLED)
  134. return()
  135. endif()
  136. install(SCRIPT ${SCRIPT}
  137. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  138. )
  139. endfunction()