12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #
- # Copyright (c) Contributors to the Open 3D Engine Project.
- # For complete copyright and license terms please see the LICENSE at the root of this distribution.
- #
- # SPDX-License-Identifier: Apache-2.0 OR MIT
- #
- #
- cmake_minimum_required(VERSION 3.22)
- cmake_policy(SET CMP0012 NEW) # new policy for the if that evaluates a boolean out of "if(NOT ${same_location})"
- cmake_path(SET target_file_dir "@target_file_dir@")
- set(target_copy_files $<FILTER:$<REMOVE_DUPLICATES:"@target_copy_files@">,EXCLUDE,"^$">)
- set(target_target_files $<FILTER:$<REMOVE_DUPLICATES:"@target_target_files@">,EXCLUDE,"^$">)
- set(target_link_files $<FILTER:$<REMOVE_DUPLICATES:"@target_link_files@">,EXCLUDE,"^$">)
- set(target_imported_files $<FILTER:$<REMOVE_DUPLICATES:"@target_imported_files@">,EXCLUDE,"^$">)
- function(ly_copy source_files relative_target_directory)
- set(options)
- set(oneValueArgs TARGET_FILE_DIR SOURCE_TYPE SOURCE_GEM_MODULE)
- set(multiValueArgs)
- cmake_parse_arguments("${CMAKE_CURRENT_FUNCTION}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
- set(target_file_dir "${${CMAKE_CURRENT_FUNCTION}_TARGET_FILE_DIR}")
- set(source_type "${${CMAKE_CURRENT_FUNCTION}_SOURCE_TYPE}")
- set(source_is_gem "${${CMAKE_CURRENT_FUNCTION}_SOURCE_GEM_MODULE}")
- # Create the full path to the target directory
- cmake_path(APPEND target_directory "${target_file_dir}" "${relative_target_directory}")
- foreach(source_file IN LISTS source_files)
- cmake_path(GET source_file FILENAME target_filename)
- cmake_PATH(GET source_file EXTENSION target_filename_ext)
- cmake_path(APPEND target_file "${target_directory}" "${target_filename}")
- cmake_path(COMPARE "${source_file}" EQUAL "${target_file}" same_location)
- if("${source_file}" MATCHES "@LY_PYTHON_SHARED_LIB@")
- # Special case: Since the shared python library is loaded dynamically, it has the potential of being loaded from multiple
- # sources. To make sure that duplicate loads to the shared python library load to the same handle, create a soft-symlink
- # instead so that the dlopen call can resolve the library properly
- # Use the relative path to the package source for the link
- set(source_python_package_abs @LY_CURRENT_PYTHON_PACKAGE_PATH@/python/lib/@LY_PYTHON_SHARED_LIB@)
- execute_process(COMMAND ln -s -f "${source_python_package_abs}" @LY_PYTHON_SHARED_LIB@
- WORKING_DIRECTORY "${target_directory}")
- elseif(NOT ${same_location})
- file(LOCK "${target_file}.lock" GUARD FUNCTION TIMEOUT 300)
- file(SIZE "${source_file}" source_file_size)
- if(EXISTS "${target_file}")
- file(SIZE "${target_file}" target_file_size)
- else()
- set(target_file_size 0)
- endif()
- if((NOT source_file_size EQUAL target_file_size) OR "${source_file}" IS_NEWER_THAN "${target_file}")
- message(STATUS "Copying \"${source_file}\" to \"${target_directory}\"...")
- file(MAKE_DIRECTORY "${full_target_directory}")
- file(COPY "${source_file}" DESTINATION "${target_directory}" USE_SOURCE_PERMISSIONS FOLLOW_SYMLINK_CHAIN)
- file(TOUCH_NOCREATE "${target_file}")
- # Special case, shared libraries that are copied from qt/plugins have their RPATH set to \$ORIGIN/../../lib
- # which is the correct relative path based on the source location. But when we copy it to their subfolder,
- # the rpath needs to be adjusted to the parent ($ORIGIN/..)
- if("${source_file}" MATCHES "qt/plugins" AND "${target_filename_ext}" STREQUAL ".so")
- file(RPATH_CHANGE FILE "${target_file}" OLD_RPATH "\$ORIGIN/../../lib" NEW_RPATH "\$ORIGIN/..")
- endif()
- endif()
- endif()
- endforeach()
- endfunction()
- @LY_COPY_COMMANDS@
- file(TOUCH "@STAMP_OUTPUT_FILE@")
|