Fixed cmake configuring when using an External Gem (#2020)

The ly_get_absolute_pal_filename method has been refactored to no longer
use regular expressions to determine how to split a PAL directory, but
instead Path operations are used

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
main
lumberyard-employee-dm 4 years ago committed by GitHub
parent 1b530195fc
commit e06ec2caa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,13 +10,7 @@ set(o3de_gem_json ${o3de_gem_path}/gem.json)
o3de_read_json_key(o3de_gem_name ${o3de_gem_json} "gem_name") o3de_read_json_key(o3de_gem_name ${o3de_gem_json} "gem_name")
o3de_restricted_path(${o3de_gem_json} o3de_gem_restricted_path) o3de_restricted_path(${o3de_gem_json} o3de_gem_restricted_path)
# Currently we are in the DefaultProjectSource folder: ${CMAKE_CURRENT_LIST_DIR} ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${o3de_gem_restricted_path}" ${o3de_gem_path} ${o3de_gem_name})
# Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
# Note: ly_get_list_relative_pal_filename will take care of the details for us, as this may be a restricted platform
# in which case it will see if that platform is present here or in the restricted folder.
# i.e. It could here: DefaultProjectSource/Platform/<platorm_name> or
# <restricted_folder>/<platform_name>/DefaultProjectSource
ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} ${o3de_gem_restricted_path} ${o3de_gem_path} ${o3de_gem_name})
# Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the # Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
# project cmake for this platform. # project cmake for this platform.

@ -29,7 +29,8 @@ function(o3de_restricted_id o3de_json_file restricted)
ly_file_read(${o3de_json_file} json_data) ly_file_read(${o3de_json_file} json_data)
string(JSON restricted_entry ERROR_VARIABLE json_error GET ${json_data} "restricted_name") string(JSON restricted_entry ERROR_VARIABLE json_error GET ${json_data} "restricted_name")
if(json_error) if(json_error)
message(WARNING "Unable to read restricted from '${o3de_json_file}', error: ${json_error}") # Restricted fields can never be a requirement so no warning is issued
return()
endif() endif()
if(restricted_entry) if(restricted_entry)
set(${restricted} ${restricted_entry} PARENT_SCOPE) set(${restricted} ${restricted_entry} PARENT_SCOPE)
@ -148,86 +149,89 @@ function(ly_get_absolute_pal_filename out_name in_name)
set(full_name ${in_name}) set(full_name ${in_name})
if(${ARGC} GREATER 4) if(${ARGC} GREATER 4)
# The user has supplied an object restricted path, the object path and the object name for consideration # The object name is used to resolve ambiguities when a PAL directory is requested from
set(object_restricted_path ${ARGV2}) # two different external subdirectory root paths
set(object_path ${ARGV3}) # Such as if a PAL directory for two root object paths with same relative structure was requested to be Palified
# i.e <gem-root1>/Platform/<platform-name>/IO and <gem-root2>/Platform/<platform-name>/IO
# Normally the restricted PAL path for both gems would be "<restricted-root-path>/<platform-name>/IO".
# The object name can be used to make this path unique
# "<restricted-root-path>/<platform-name>/<custom-name1>/IO" for gem 1 and
# "<restricted-root-path>/<platform-name>/<custom-name2>/IO" for gem 2
set(object_name ${ARGV4}) set(object_name ${ARGV4})
endif()
# if the file is not in the object path then we cannot determine a PAL file for it # The Default object path for path is the LY_ROOT_FOLDER
file(RELATIVE_PATH relative_path ${object_path} ${full_name}) cmake_path(SET object_path NORMALIZE "${LY_ROOT_FOLDER}")
if (NOT (IS_ABSOLUTE relative_path OR relative_path MATCHES [[^(\.\./)+(.*)]])) if(${ARGC} GREATER 3)
if (NOT EXISTS ${full_name})
string(REGEX MATCH "${object_path}/(.*)/Platform/([^/]*)/?(.*)$" match ${full_name})
if(NOT CMAKE_MATCH_1)
string(REGEX MATCH "${object_path}/Platform/([^/]*)/?(.*)$" match ${full_name})
set(full_name ${object_restricted_path}/${CMAKE_MATCH_1}/${object_name})
if(CMAKE_MATCH_2)
string(APPEND full_name "/" ${CMAKE_MATCH_2})
endif()
elseif("${CMAKE_MATCH_2}" IN_LIST PAL_RESTRICTED_PLATFORMS)
set(full_name ${object_restricted_path}/${CMAKE_MATCH_2}/${object_name}/${CMAKE_MATCH_1})
if(CMAKE_MATCH_3)
string(APPEND full_name "/" ${CMAKE_MATCH_3})
endif()
endif()
endif()
endif()
set(${out_name} ${full_name} PARENT_SCOPE)
elseif(${ARGC} GREATER 3)
# The user has supplied an object restricted path, the object path for consideration # The user has supplied an object restricted path, the object path for consideration
set(object_restricted_path ${ARGV2}) cmake_path(SET object_path NORMALIZE ${ARGV3})
set(object_path ${ARGV3}) endif()
# The Default restricted object path is the result of the read_engine_restricted_path function
cmake_path(SET object_restricted_path NORMALIZE "${O3DE_ENGINE_RESTRICTED_PATH}")
if(${ARGC} GREATER 2)
# The user has supplied an object restricted path
cmake_path(SET object_restricted_path NORMALIZE ${ARGV2})
endif()
# The input path must exist in order to form a PAL path
if (NOT EXISTS ${full_name})
# if the file is not in the object path then we cannot determine a PAL file for it # if the file is not in the object path then we cannot determine a PAL file for it
file(RELATIVE_PATH relative_path ${object_path} ${full_name}) cmake_path(IS_PREFIX object_path ${full_name} is_input_path_in_root)
if (NOT (IS_ABSOLUTE relative_path OR relative_path MATCHES [[^(\.\./)+(.*)]])) if(is_input_path_in_root)
if (NOT EXISTS ${full_name}) cmake_path(RELATIVE_PATH full_name BASE_DIRECTORY ${object_path} OUTPUT_VARIABLE relative_object_path)
string(REGEX MATCH "${object_path}/(.*)/Platform/([^/]*)/?(.*)$" match ${full_name}) cmake_path(SET current_object_path ${relative_object_path})
if(NOT CMAKE_MATCH_1)
string(REGEX MATCH "${object_path}/Platform/([^/]*)/?(.*)$" match ${full_name}) # Remove one path segment from the end of the current_object_path and prepend it to the list path_segments
set(full_name ${object_restricted_path}/${CMAKE_MATCH_1}) cmake_path(GET current_object_path PARENT_PATH parent_path)
if(CMAKE_MATCH_2) cmake_path(GET current_object_path FILENAME path_segment)
string(APPEND full_name "/" ${CMAKE_MATCH_2}) list(PREPEND path_segments_visited path_segment)
endif() cmake_path(COMPARE current_object_path NOT_EQUAL parent_path is_prev_path_segment)
elseif("${CMAKE_MATCH_2}" IN_LIST PAL_RESTRICTED_PLATFORMS) cmake_path(SET current_object_path "${parent_path}")
set(full_name ${object_restricted_path}/${CMAKE_MATCH_2}/${CMAKE_MATCH_1})
if(CMAKE_MATCH_3) while(is_prev_path_segment)
string(APPEND full_name "/" ${CMAKE_MATCH_3}) # The Path is in a PAL structure
endif() # Decompose the path into sections before "Platform" and after "Platform"
if(path_segment STREQUAL "Platform")
# The first path segment after the "<pre-platform-paths>/Platform/<post-platform-paths>"
# is a potential platform name. Store it off for later checks
list(GET path_segments_visited 0 candidate_platform_name)
# Store off all the path segments iterated from the end in the post-"Platform" path
cmake_path(APPEND post_platform_paths ${path_segments_visited})
# The parent path is just the pre-"Platform" section of the path
cmake_path(SET pre_platform_paths "${parent_path}")
break()
endif() endif()
endif()
endif() # Remove one path segment from the end of the current_object_path and prepend it to the list path_segments
set(${out_name} ${full_name} PARENT_SCOPE) cmake_path(GET current_object_path PARENT_PATH parent_path)
cmake_path(GET current_object_path FILENAME path_segment)
else() list(PREPEND path_segments_visited path_segment)
# The user has not supplied any path so we must assume it is the o3de engine restricted and o3de engine path cmake_path(COMPARE current_object_path NOT_EQUAL parent_path is_prev_path_segment)
# if the file is not in the o3de engine path then we cannot determine a PAL file for it cmake_path(SET current_object_path "${parent_path}")
file(RELATIVE_PATH relative_path ${LY_ROOT_FOLDER} ${full_name}) endwhile()
if (NOT (IS_ABSOLUTE relative_path OR relative_path MATCHES [[^(\.\./)+(.*)]]))
if (NOT EXISTS ${full_name}) # Compose a candidate restricted path and examine if it exists
string(REGEX MATCH "${LY_ROOT_FOLDER}/(.*)/Platform/([^/]*)/?(.*)$" match ${full_name}) cmake_path(APPEND object_restricted_path ${pre_platform_paths} "Platform" ${post_platform_paths}
if(NOT CMAKE_MATCH_1) OUTPUT_VARIABLE candidate_PAL_path)
string(REGEX MATCH "${LY_ROOT_FOLDER}/Platform/([^/]*)/?(.*)$" match ${full_name}) if(NOT EXISTS ${candidate_PAL_path})
set(full_name ${O3DE_ENGINE_RESTRICTED_PATH}/${CMAKE_MATCH_1}) if("${candidate_platform_name}" IN_LIST PAL_RESTRICTED_PLATFORMS)
if(CMAKE_MATCH_2) cmake_path(APPEND object_restricted_path ${candidate_platform_name} ${object_name}
string(APPEND full_name "/" ${CMAKE_MATCH_2}) ${pre_platform_paths} ${post_platform_paths} OUTPUT_VARIABLE candidate_PAL_path)
endif()
elseif("${CMAKE_MATCH_2}" IN_LIST PAL_RESTRICTED_PLATFORMS)
set(full_name ${O3DE_ENGINE_RESTRICTED_PATH}/${CMAKE_MATCH_2}/${CMAKE_MATCH_1})
if(CMAKE_MATCH_3)
string(APPEND full_name "/" ${CMAKE_MATCH_3})
endif()
endif() endif()
endif() endif()
if(EXISTS ${candidate_PAL_path})
cmake_path(SET full_name ${candidate_PAL_path})
endif()
endif() endif()
set(${out_name} ${full_name} PARENT_SCOPE)
endif() endif()
set(${out_name} ${full_name} PARENT_SCOPE)
endfunction() endfunction()
function(ly_get_list_relative_pal_filename out_name in_name) function(ly_get_list_relative_pal_filename out_name in_name)
ly_get_absolute_pal_filename(abs_name ${in_name} ${ARGN}) ly_get_absolute_pal_filename(abs_name ${in_name} ${ARGN})
file(RELATIVE_PATH relative_name ${CMAKE_CURRENT_LIST_DIR} ${abs_name}) cmake_path(RELATIVE_PATH abs_name BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE relative_name)
set(${out_name} ${relative_name} PARENT_SCOPE) set(${out_name} ${relative_name} PARENT_SCOPE)
endfunction() endfunction()

Loading…
Cancel
Save