PostProcessScriptOnlyMappings.cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # this file is used during generation of the installer layout.
  9. # note that ARGV0 is the cmake command itself, and ARGV1 is the -P command line option, so we skip them
  10. # ARGV2 is the name of this script.
  11. # ARGV3 is the output folder name
  12. # ARGV4 and onwards are the names of input files, generated during the engine configure/generate
  13. # containing information about the 3p libraries available.
  14. #[[ there is 1 input file for each 3p library, and each input file contains a set of "set" commands in this format:
  15. set(target_name ${TARGET_NAME})
  16. set(copy_dependencies_source_file_path ${copy_dependencies_source_file_path})
  17. set(copy_dependencies_target_rel_path ${copy_dependencies_target_rel_path})
  18. The goal of this file is to generate one output_filename/target_name.cmake for each input file such
  19. that it contains the ability to register the given 3p library target
  20. libraries as fake ones (which have the appropriate dependencies so that files get copied).
  21. ]]#
  22. if (${CMAKE_ARGC} LESS 5)
  23. message(FATAL_ERROR "This command was invoked incorrectly.\nUsage:\n"
  24. "cmake -P (SCRIPT_NAME) (OUTPUT_DIR) (INPUT FILE) (INPUT FILE) ...")
  25. return()
  26. endif()
  27. set(output_directory ${CMAKE_ARGV3})
  28. if (NOT output_directory)
  29. message(FATAL_ERROR "Expected the first argument to be an output directory")
  30. endif()
  31. foreach(index RANGE 4 ${CMAKE_ARGC})
  32. if (CMAKE_ARGV${index})
  33. list(APPEND file_list ${CMAKE_ARGV${index}})
  34. endif()
  35. endforeach()
  36. set(copyright_and_preamble [[#
  37. # Copyright (c) Contributors to the Open 3D Engine Project.
  38. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  39. #
  40. # SPDX-License-Identifier: Apache-2.0 OR MIT
  41. #
  42. #
  43. # Generated as part of the install command, this file contains calls to register 3p libraries
  44. # for script-only mode, to ensure that their dependent files are copied to the final location
  45. # during game deploy. It should ONLY be used in script-only mode.
  46. ]])
  47. foreach(data_file IN LISTS file_list)
  48. unset(target_name)
  49. unset(copy_dependencies_source_file_path)
  50. unset(copy_dependencies_target_rel_path)
  51. unset(trimmed_source_paths)
  52. set(final_data ${copyright_and_preamble})
  53. include(${data_file})
  54. if (NOT target_name)
  55. message(FATAL_ERROR "Error parsing data file ${data_file} - consider cleaning it out and rebuilding.")
  56. endif()
  57. foreach(abs_filepath IN LISTS copy_dependencies_source_file_path)
  58. cmake_path(GET abs_filepath FILENAME filename_only)
  59. list(APPEND trimmed_source_paths ${filename_only})
  60. endforeach()
  61. # sanity check
  62. if (trimmed_source_paths OR copy_dependencies_target_rel_path)
  63. list(LENGTH trimmed_source_paths source_list_length)
  64. list(LENGTH copy_dependencies_target_rel_path relpath_list_lenth)
  65. if (NOT source_list_length EQUAL relpath_list_lenth)
  66. message(FATAL_ERROR "Programmer error - for target ${target_name}, lists are supposed to be same length, but\n\
  67. ${source_list_length} source and ${relpath_list_lenth} relpath\n\
  68. source:'${trimmed_source_paths}'\n\
  69. relpath: '${copy_dependencies_target_rel_path}'")
  70. endif()
  71. endif()
  72. string(APPEND final_data "if (NOT TARGET ${target_name})\n")
  73. string(APPEND final_data " add_library(${target_name} INTERFACE IMPORTED GLOBAL)\n")
  74. # binary_folder can be a genex but will always be the Default folder since monolithic
  75. # cannot be combined with script-only
  76. set(installer_binaries [[${LY_ROOT_FOLDER}/bin/${PAL_PLATFORM_NAME}/$<CONFIG>/Default]])
  77. if (trimmed_source_paths)
  78. foreach(file_name relative_path IN ZIP_LISTS trimmed_source_paths copy_dependencies_target_rel_path)
  79. if (relative_path)
  80. set(file_name "${installer_binaries}/${relative_path}/${file_name}")
  81. else()
  82. set(relative_path "")
  83. set(file_name "${installer_binaries}/${file_name}")
  84. endif()
  85. string(APPEND final_data
  86. " ly_add_target_files(TARGETS ${target_name}\n\
  87. FILES\n\
  88. \"${file_name}\"\n\
  89. OUTPUT_SUBDIRECTORY \"${relative_path}\")\n\n")
  90. endforeach()
  91. endif()
  92. string(APPEND final_data "endif() # NOT TARGET ${target_name}\n")
  93. string(REPLACE "::" "__" CLEAN_TARGET_NAME "${target_name}")
  94. file(WRITE "${output_directory}/${CLEAN_TARGET_NAME}.cmake" "${final_data}")
  95. endforeach()