Install.cmake 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. set(LY_INSTALL_ENABLED TRUE CACHE BOOL "Indicates if the install process is enabled")
  9. #! ly_install: wrapper to install that handles common functionality
  10. #
  11. # \notes:
  12. # - this wrapper handles the case where common installs are called multiple times from different
  13. # build folders (when using LY_INSTALL_EXTERNAL_BUILD_DIRS) to generate install layouts that
  14. # have multiple build permutations
  15. #
  16. function(ly_install)
  17. if(NOT LY_INSTALL_ENABLED)
  18. return()
  19. endif()
  20. cmake_parse_arguments(ly_install "" "COMPONENT" "" ${ARGN})
  21. if (NOT ly_install_COMPONENT OR "${ly_install_COMPONENT}" STREQUAL "${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}")
  22. # if it is installing under the default component, we need to de-duplicate since we can have
  23. # cases coming from different build directories (when using LY_INSTALL_EXTERNAL_BUILD_DIRS)
  24. install(CODE "if(NOT LY_CORE_COMPONENT_ALREADY_INCLUDED)" ALL_COMPONENTS)
  25. install(${ARGN})
  26. install(CODE "endif()\n" ALL_COMPONENTS)
  27. else()
  28. install(${ARGN})
  29. endif()
  30. endfunction()
  31. #! ly_install_directory: specifies a directory to be copied to the install layout at install time
  32. #
  33. # \arg:DIRECTORIES directories to install
  34. # \arg:DESTINATION (optional) destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  35. # \arg:EXCLUDE_PATTERNS (optional) patterns to exclude
  36. # \arg:COMPONENT (optional) component to use (defaults to CMAKE_INSTALL_DEFAULT_COMPONENT_NAME)
  37. # \arg:VERBATIM (optional) copies the directories as they are, this excludes the default exclude patterns
  38. #
  39. # \notes:
  40. # - refer to cmake's install(DIRECTORY documentation for more information
  41. # - If the directory contains programs/scripts, exclude them from this call and add a specific ly_install_files with
  42. # PROGRAMS set. This is necessary to set the proper execution permissions.
  43. # - This function will automatically filter out __pycache__, *.egg-info, CMakeLists.txt, *.cmake files. If those files
  44. # need to be installed, use ly_install_files. Use VERBATIM to exclude such filters.
  45. #
  46. function(ly_install_directory)
  47. if(NOT LY_INSTALL_ENABLED)
  48. return()
  49. endif()
  50. set(options VERBATIM)
  51. set(oneValueArgs DESTINATION COMPONENT)
  52. set(multiValueArgs DIRECTORIES EXCLUDE_PATTERNS)
  53. cmake_parse_arguments(ly_install_directory "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  54. if(NOT ly_install_directory_DIRECTORIES)
  55. message(FATAL_ERROR "You must provide at least a directory to install")
  56. endif()
  57. if(NOT ly_install_directory_COMPONENT)
  58. set(ly_install_directory_COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  59. endif()
  60. foreach(directory ${ly_install_directory_DIRECTORIES})
  61. cmake_path(ABSOLUTE_PATH directory)
  62. if(NOT ly_install_directory_DESTINATION)
  63. # maintain the same structure relative to LY_ROOT_FOLDER
  64. set(ly_install_directory_DESTINATION ${directory})
  65. if(${ly_install_directory_DESTINATION} STREQUAL ".")
  66. set(ly_install_directory_DESTINATION ${CMAKE_CURRENT_LIST_DIR})
  67. else()
  68. cmake_path(ABSOLUTE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  69. endif()
  70. # take out the last directory since install asks for the destination of the folder, without including the fodler itself
  71. cmake_path(GET ly_install_directory_DESTINATION PARENT_PATH ly_install_directory_DESTINATION)
  72. cmake_path(RELATIVE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${LY_ROOT_FOLDER})
  73. endif()
  74. unset(exclude_patterns)
  75. if(ly_install_directory_EXCLUDE_PATTERNS)
  76. foreach(exclude_pattern ${ly_install_directory_EXCLUDE_PATTERNS})
  77. list(APPEND exclude_patterns PATTERN ${exclude_pattern} EXCLUDE)
  78. endforeach()
  79. endif()
  80. if(NOT ly_install_directory_VERBATIM)
  81. # Exclude cmake since that has to be generated
  82. list(APPEND exclude_patterns PATTERN CMakeLists.txt EXCLUDE)
  83. list(APPEND exclude_patterns PATTERN *.cmake EXCLUDE)
  84. # Exclude python-related things that dont need to be installed
  85. list(APPEND exclude_patterns PATTERN __pycache__ EXCLUDE)
  86. list(APPEND exclude_patterns PATTERN *.egg-info EXCLUDE)
  87. endif()
  88. ly_install(DIRECTORY ${directory}
  89. DESTINATION ${ly_install_directory_DESTINATION}
  90. COMPONENT ${ly_install_directory_COMPONENT}
  91. ${exclude_patterns}
  92. )
  93. endforeach()
  94. endfunction()
  95. #! ly_install_files: specifies files to be copied to the install layout at install time
  96. #
  97. # \arg:FILES files to install
  98. # \arg:DESTINATION destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  99. # \arg:PROGRAMS (optional) indicates if the files are programs that should be installed with EXECUTE permissions
  100. #
  101. # \notes:
  102. # - refer to cmake's install(FILES/PROGRAMS documentation for more information
  103. #
  104. function(ly_install_files)
  105. if(NOT LY_INSTALL_ENABLED)
  106. return()
  107. endif()
  108. set(options PROGRAMS)
  109. set(oneValueArgs DESTINATION)
  110. set(multiValueArgs FILES)
  111. cmake_parse_arguments(ly_install_files "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  112. if(NOT ly_install_files_FILES)
  113. message(FATAL_ERROR "You must provide a list of files to install")
  114. endif()
  115. if(NOT ly_install_files_DESTINATION)
  116. message(FATAL_ERROR "You must provide a destination to install files to")
  117. endif()
  118. unset(files)
  119. foreach(file ${ly_install_files_FILES})
  120. cmake_path(ABSOLUTE_PATH file)
  121. list(APPEND files ${file})
  122. endforeach()
  123. if(ly_install_files_PROGRAMS)
  124. set(install_type PROGRAMS)
  125. else()
  126. set(install_type FILES)
  127. endif()
  128. ly_install(${install_type} ${files}
  129. DESTINATION ${ly_install_files_DESTINATION}
  130. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  131. )
  132. endfunction()
  133. #! ly_install_run_code: specifies code to be added to the install process (will run at install time)
  134. #
  135. # \notes:
  136. # - refer to cmake's install(CODE documentation for more information
  137. #
  138. function(ly_install_run_code CODE)
  139. if(NOT LY_INSTALL_ENABLED)
  140. return()
  141. endif()
  142. ly_install(CODE ${CODE}
  143. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  144. )
  145. endfunction()
  146. #! ly_install_run_script: specifies path to script to be added to the install process (will run at install time)
  147. #
  148. # \notes:
  149. # - refer to cmake's install(SCRIPT documentation for more information
  150. #
  151. function(ly_install_run_script SCRIPT)
  152. if(NOT LY_INSTALL_ENABLED)
  153. return()
  154. endif()
  155. ly_install(SCRIPT ${SCRIPT}
  156. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the default for the time being
  157. )
  158. endfunction()
  159. if(LY_INSTALL_ENABLED)
  160. o3de_pal_dir(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Platform/${PAL_PLATFORM_NAME} "${O3DE_ENGINE_RESTRICTED_PATH}" "${LY_ROOT_FOLDER}")
  161. include(${pal_dir}/Install_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  162. endif()