From 4e699138b8033b63843d6814d819786c2fd05e86 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:46:02 -0700 Subject: [PATCH] better handling of CMAKE_MODULE_PATH when passed to another project Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../DefaultProject/Template/EngineFinder.cmake | 15 +++++++++++++++ .../MinimalProject/Template/EngineFinder.cmake | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Templates/DefaultProject/Template/EngineFinder.cmake b/Templates/DefaultProject/Template/EngineFinder.cmake index ccbfcbecfd..1bb4950e7d 100644 --- a/Templates/DefaultProject/Template/EngineFinder.cmake +++ b/Templates/DefaultProject/Template/EngineFinder.cmake @@ -21,6 +21,21 @@ if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") endif() +if(CMAKE_MODULE_PATH) + foreach(module_path ${CMAKE_MODULE_PATH}) + if(EXISTS ${module_path}/Findo3de.cmake) + file(READ ${module_path}/../engine.json engine_json) + string(JSON engine_name ERROR_VARIABLE json_error GET ${engine_json} engine_name) + if(json_error) + message(FATAL_ERROR "Unable to read key 'engine_name' from 'engine.json', error: ${json_error}") + endif() + if(LY_ENGINE_NAME_TO_USE STREQUAL engine_name) + return() # Engine being forced through CMAKE_MODULE_PATH + endif() + endif() + endforeach() +endif() + if(DEFINED ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE}) set(manifest_path $ENV{USERPROFILE}/.o3de/o3de_manifest.json) # Windows else() diff --git a/Templates/MinimalProject/Template/EngineFinder.cmake b/Templates/MinimalProject/Template/EngineFinder.cmake index ccbfcbecfd..1bb4950e7d 100644 --- a/Templates/MinimalProject/Template/EngineFinder.cmake +++ b/Templates/MinimalProject/Template/EngineFinder.cmake @@ -21,6 +21,21 @@ if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") endif() +if(CMAKE_MODULE_PATH) + foreach(module_path ${CMAKE_MODULE_PATH}) + if(EXISTS ${module_path}/Findo3de.cmake) + file(READ ${module_path}/../engine.json engine_json) + string(JSON engine_name ERROR_VARIABLE json_error GET ${engine_json} engine_name) + if(json_error) + message(FATAL_ERROR "Unable to read key 'engine_name' from 'engine.json', error: ${json_error}") + endif() + if(LY_ENGINE_NAME_TO_USE STREQUAL engine_name) + return() # Engine being forced through CMAKE_MODULE_PATH + endif() + endif() + endforeach() +endif() + if(DEFINED ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE}) set(manifest_path $ENV{USERPROFILE}/.o3de/o3de_manifest.json) # Windows else()