Install.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if(NOT INSTALLED_ENGINE)
  9. ly_get_absolute_pal_filename(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Platform/${PAL_PLATFORM_NAME})
  10. include(${pal_dir}/Install_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  11. endif()
  12. #! ly_install_directory: specifies a directory to be copied to the install layout at install time
  13. #
  14. # \arg:DIRECTORY directory to install
  15. # \arg:DESTINATION (optional) destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  16. # \arg:EXCLUDE_PATTERNS (optional) patterns to exclude
  17. #
  18. # \notes: refer to cmake's install(DIRECTORY documentation for more information
  19. #
  20. function(ly_install_directory)
  21. set(options)
  22. set(oneValueArgs DIRECTORY DESTINATION)
  23. set(multiValueArgs EXCLUDE_PATTERNS)
  24. cmake_parse_arguments(ly_install_directory "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  25. if(NOT ly_install_directory_DIRECTORY)
  26. message(FATAL_ERROR "You must provide a directory to install")
  27. endif()
  28. if(NOT ly_install_directory_DESTINATION)
  29. # maintain the same structure relative to LY_ROOT_FOLDER
  30. set(ly_install_directory_DESTINATION ${ly_install_directory_DIRECTORY})
  31. if(${ly_install_directory_DESTINATION} STREQUAL ".")
  32. set(ly_install_directory_DESTINATION ${CMAKE_CURRENT_LIST_DIR})
  33. else()
  34. cmake_path(ABSOLUTE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  35. endif()
  36. # take out the last directory since install asks for the destination of the folder, without including the fodler itself
  37. cmake_path(GET ly_install_directory_DESTINATION PARENT_PATH ly_install_directory_DESTINATION)
  38. cmake_path(RELATIVE_PATH ly_install_directory_DESTINATION BASE_DIRECTORY ${LY_ROOT_FOLDER})
  39. endif()
  40. unset(exclude_patterns)
  41. if(ly_install_directory_EXCLUDE_PATTERNS)
  42. foreach(exclude_pattern ${ly_install_directory_EXCLUDE_PATTERNS})
  43. list(APPEND exclude_patterns PATTERN ${exclude_pattern} EXCLUDE)
  44. endforeach()
  45. endif()
  46. install(DIRECTORY ${ly_install_directory_DIRECTORY}
  47. DESTINATION ${ly_install_directory_DESTINATION}
  48. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the deafult for the time being
  49. ${exclude_patterns}
  50. )
  51. endfunction()
  52. #! ly_install_files: specifies files to be copied to the install layout at install time
  53. #
  54. # \arg:FILES files to install
  55. # \arg:DESTINATION (optional) destination to install the directory to (relative to CMAKE_PREFIX_PATH)
  56. # \arg:PROGRAMS (optional) indicates if the files are programs that should be installed with EXECUTE permissions
  57. #
  58. # \notes: refer to cmake's install(DIRECTORY documentation for more information
  59. #
  60. function(ly_install_files)
  61. set(options PROGRAMS)
  62. set(oneValueArgs DESTINATION)
  63. set(multiValueArgs FILES)
  64. cmake_parse_arguments(ly_install_files "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  65. if(NOT ly_install_files_FILES)
  66. message(FATAL_ERROR "You must provide a list of files to install")
  67. endif()
  68. if(NOT ly_install_files_DESTINATION)
  69. message(FATAL_ERROR "You must provide a destination to install filest to")
  70. endif()
  71. if(ly_install_files_PROGRAMS)
  72. set(install_type PROGRAMS)
  73. else()
  74. set(install_type FILES)
  75. endif()
  76. install(${install_type} ${ly_install_files_FILES}
  77. DESTINATION ${ly_install_files_DESTINATION}
  78. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME} # use the deafult for the time being
  79. )
  80. endfunction()