Findo3de.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # 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. # This file is temporarly a tweaked version of the o3de's root CMakeLists.txt
  9. # Once we have the install step, this file will be generated and wont require adding subdirectories
  10. include(FindPackageHandleStandardArgs)
  11. # Use CMAKE_CURRENT_FUNCTION_LIST_DIR in case an older projects used add_directory()
  12. function(o3de_current_file_path path)
  13. set(${path} ${CMAKE_CURRENT_FUNCTION_LIST_DIR} PARENT_SCOPE)
  14. endfunction()
  15. o3de_current_file_path(current_path)
  16. # Make sure the cmake configure dependency added here is a normalized path to engine.json,
  17. # because later it's read again using a path like ${LY_ROOT_FOLDER}/engine.json, which
  18. # is also normalized. They should match to avoid errors on some build systems.
  19. cmake_path(SET engine_json_path NORMALIZE ${current_path}/../engine.json)
  20. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${engine_json_path})
  21. if(NOT LY_ENGINE_NAME_TO_USE)
  22. # PACKAGE_VERSION_COMPATIBLE should be set TRUE by o3deConfigVersion.cmake
  23. find_package_handle_standard_args(o3de
  24. "This engine was not found to be compatible with your project, or no compatibility checks were done. For more information, run the command again with '--log-level VERBOSE'."
  25. PACKAGE_VERSION_COMPATIBLE
  26. )
  27. else()
  28. # LY_ENGINE_NAME_TO_USE compatibility check for older projects
  29. set(found_matching_engine FALSE)
  30. file(READ ${engine_json_path} engine_json)
  31. string(JSON this_engine_name ERROR_VARIABLE json_error GET ${engine_json} engine_name)
  32. if(json_error)
  33. message(FATAL_ERROR "Unable to read key 'engine_name' from '${engine_json_path}', error: ${json_error}")
  34. endif()
  35. if(this_engine_name STREQUAL LY_ENGINE_NAME_TO_USE)
  36. set(found_matching_engine TRUE)
  37. else()
  38. message(VERBOSE "Project engine name '${LY_ENGINE_NAME_TO_USE}' does not match this engine name '${this_engine_name}' in '${engine_json_path}'")
  39. endif()
  40. find_package_handle_standard_args(o3de
  41. "The engine name for this engine '${this_engine_name}' does not match the projects engine name '${LY_ENGINE_NAME_TO_USE}'"
  42. found_matching_engine
  43. )
  44. endif()
  45. cmake_path(SET engine_root_folder NORMALIZE ${current_path}/..)
  46. set_property(GLOBAL PROPERTY O3DE_ENGINE_ROOT_FOLDER "${engine_root_folder}")
  47. # Inject the CompilerSettings.cmake to be included before the project command
  48. set(CMAKE_PROJECT_INCLUDE_BEFORE "${engine_root_folder}cmake/CompilerSettings.cmake")
  49. macro(o3de_initialize)
  50. set(INSTALLED_ENGINE FALSE)
  51. set(LY_PROJECTS ${CMAKE_CURRENT_LIST_DIR})
  52. o3de_current_file_path(current_path)
  53. enable_testing()
  54. add_subdirectory(${current_path}/.. o3de)
  55. endmacro()