CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # {BEGIN_LICENSE}
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. #
  9. # {END_LICENSE}
  10. if(NOT PROJECT_NAME)
  11. cmake_minimum_required(VERSION 3.22)
  12. # Utility function to look for an optional 'engine_finder_cmake_path'setting
  13. function(get_engine_finder_cmake_path project_json_file_path path_value)
  14. if(NOT ${path_value} AND EXISTS "${project_json_file_path}")
  15. file(READ "${project_json_file_path}" project_json_data)
  16. string(JSON engine_finder_cmake_value ERROR_VARIABLE json_error GET ${project_json_data} "engine_finder_cmake_path")
  17. cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "${engine_finder_cmake_value}" engine_finder_cmake_value)
  18. if(NOT json_error AND EXISTS "${engine_finder_cmake_value}")
  19. set(${path_value} "${engine_finder_cmake_value}" PARENT_SCOPE)
  20. elseif(json_error AND ${engine_finder_cmake_value} STREQUAL "NOTFOUND")
  21. # When the error value is just NOTFOUND that means there is a JSON
  22. # parsing error, and not simply a missing key
  23. message(WARNING "Unable to read 'engine_finder_cmake_path'.\nError: ${json_error} ${engine_finder_cmake_value}")
  24. endif()
  25. endif()
  26. endfunction()
  27. # Check for optional 'engine_finder_cmake_path' in order of preference
  28. # We support per-project customization to make it easier to upgrade
  29. # or revert to a custom EngineFinder.cmake
  30. get_engine_finder_cmake_path("${CMAKE_CURRENT_SOURCE_DIR}/user/project.json" engine_finder_cmake_path)
  31. get_engine_finder_cmake_path("${CMAKE_CURRENT_SOURCE_DIR}/project.json" engine_finder_cmake_path)
  32. if(NOT engine_finder_cmake_path)
  33. set(engine_finder_cmake_path cmake/EngineFinder.cmake)
  34. endif()
  35. include(${engine_finder_cmake_path} OPTIONAL)
  36. find_package(o3de REQUIRED)
  37. project(${Name}
  38. LANGUAGES C CXX
  39. VERSION 1.0.0.0
  40. )
  41. o3de_initialize()
  42. endif()