EngineFinder.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # {BEGIN_LICENSE}
  2. #
  3. # 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.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # {END_LICENSE}
  9. # This file is copied during engine registration. Edits to this file will be lost next
  10. # time a registration happens.
  11. include_guard()
  12. # Read the engine name from the project_json file
  13. file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json)
  14. string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
  15. if(json_error)
  16. message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}")
  17. endif()
  18. # Read the list of paths from ~.o3de/o3de_manifest.json
  19. file(TO_CMAKE_PATH "$ENV{USERPROFILE}" home_directory) # Windows
  20. if((NOT home_directory) OR (NOT EXISTS ${home_directory}))
  21. file(TO_CMAKE_PATH "$ENV{HOME}" home_directory)# Unix
  22. endif()
  23. if (NOT home_directory)
  24. message(FATAL_ERROR "Cannot find user home directory, the o3de manifest cannot be found")
  25. endif()
  26. # Set manifest path to path in the user home directory
  27. set(manifest_path ${home_directory}/.o3de/o3de_manifest.json)
  28. if(EXISTS ${manifest_path})
  29. file(READ ${manifest_path} manifest_json)
  30. string(JSON engines_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines)
  31. if(json_error)
  32. message(FATAL_ERROR "Unable to read key 'engines' from '${manifest_path}', error: ${json_error}")
  33. endif()
  34. math(EXPR engines_count "${engines_count}-1")
  35. foreach(engine_path_index RANGE ${engines_count})
  36. string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines ${engine_path_index})
  37. if(${json_error})
  38. message(FATAL_ERROR "Unable to read engines[${engine_path_index}] '${manifest_path}', error: ${json_error}")
  39. endif()
  40. list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
  41. endforeach()
  42. endif()