EngineFinder.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # {BEGIN_LICENSE}
  2. #
  3. # All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  4. # its licensors.
  5. #
  6. # For complete copyright and license terms please see the LICENSE at the root of this
  7. # distribution (the "License"). All use of this software is governed by the License,
  8. # or, if provided, by the license below or the license accompanying this file. Do not
  9. # remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. #
  12. # {END_LICENSE}
  13. # This file is copied during engine registration. Edits to this file will be lost next
  14. # time a registration happens.
  15. include_guard()
  16. # Read the engine name from the project_json file
  17. file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json)
  18. string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
  19. if(json_error)
  20. message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}")
  21. endif()
  22. # Read the list of paths from ~.o3de/o3de_manifest.json
  23. file(TO_CMAKE_PATH "$ENV{USERPROFILE}" home_directory) # Windows
  24. if((NOT home_directory) OR (NOT EXISTS ${home_directory}))
  25. file(TO_CMAKE_PATH "$ENV{HOME}" home_directory)# Unix
  26. endif()
  27. if (NOT home_directory)
  28. message(FATAL_ERROR "Cannot find user home directory, the o3de manifest cannot be found")
  29. endif()
  30. # Set manifest path to path in the user home directory
  31. set(manifest_path ${home_directory}/.o3de/o3de_manifest.json)
  32. if(EXISTS ${manifest_path})
  33. file(READ ${manifest_path} manifest_json)
  34. string(JSON engines_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines)
  35. if(json_error)
  36. message(FATAL_ERROR "Unable to read key 'engines' from '${manifest_path}', error: ${json_error}")
  37. endif()
  38. math(EXPR engines_count "${engines_count}-1")
  39. foreach(engine_path_index RANGE ${engines_count})
  40. string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines ${engine_path_index})
  41. if(${json_error})
  42. message(FATAL_ERROR "Unable to read engines[${engine_path_index}] '${manifest_path}', error: ${json_error}")
  43. endif()
  44. list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
  45. endforeach()
  46. endif()