EngineFinder.cmake 2.2 KB

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