CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  9. set(GOOGLETEST_GIT_REPOSITORY "https://github.com/google/googletest.git")
  10. set(GOOGLETEST_GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59) # tag name is v1.15.2
  11. set(GOOGLETEST_VERSION_STRING "v1.15.2")
  12. # there are optional flags you can pass FetchContent that make the project cleaner but require newer versions of cmake
  13. set(ADDITIONAL_FETCHCONTENT_FLAGS "")
  14. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25")
  15. list(APPEND ADDITIONAL_FETCHCONTENT_FLAGS "SYSTEM") # treat it as a 3p library, that is, do not issue warnings using the same warning level
  16. endif()
  17. o3de_pal_dir(pal_aztest_dir ${CMAKE_CURRENT_LIST_DIR}/AzTest/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
  18. set(CMAKE_POLICY_DEFAULT_CMP0148 OLD)
  19. set(OLD_CMAKE_WARN_DEPRECATED ${CMAKE_WARN_DEPRECATED})
  20. set(CMAKE_WARN_DEPRECATED FALSE CACHE BOOL "" FORCE)
  21. include(FetchContent)
  22. message(STATUS "Using googletest from ${GOOGLETEST_GIT_REPOSITORY} ${GOOGLETEST_VERSION_STRING}")
  23. FetchContent_Declare(
  24. googletest
  25. GIT_REPOSITORY ${GOOGLETEST_GIT_REPOSITORY}
  26. GIT_TAG ${GOOGLETEST_GIT_TAG}
  27. ${ADDITIONAL_FETCHCONTENT_FLAGS}
  28. CMAKE_ARGS "-DCMAKE_WARN_DEPRECATED=FALSE;-Dgtest_force_shared_crt=ON;-DBUILD_GMOCK=ON;-DBUILD_GTEST=ON;-DINSTALL_GTEST=OFF;-Dgmock_build_tests=OFF;-Dgtest_build_tests=OFF;-Dgtest_build_samples=OFF;-Dgtest_hide_internal_symbols=ON"
  29. )
  30. set(PYTHONINTERP_FOUND ON)
  31. set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
  32. set(PYTHON_VERSION_STRING ${Python_VERSION})
  33. FetchContent_MakeAvailable(googletest)
  34. # Let's not clutter the root of any IDE folder structure with 3rd party dependencies
  35. # Setting the FOLDER makes it show up there in the solution build in VS and similarly
  36. # any other IDEs that organize in folders.
  37. # Setting EXCLUDE_FROM_ALL Makes it not appear in the first place.
  38. set_target_properties(
  39. gtest
  40. gmock
  41. gtest_main
  42. gmock_main
  43. PROPERTIES
  44. FOLDER "3rdParty Dependencies"
  45. EXCLUDE_FROM_ALL TRUE)
  46. unset(CMAKE_POLICY_DEFAULT_CMP0148)
  47. set(CMAKE_WARN_DEPRECATED ${OLD_CMAKE_WARN_DEPRECATED} CACHE BOOL "" FORCE)
  48. ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
  49. ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
  50. ly_add_target(
  51. NAME AzTest STATIC
  52. NAMESPACE AZ
  53. FILES_CMAKE
  54. AzTest/aztest_files.cmake
  55. ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  56. INCLUDE_DIRECTORIES
  57. PUBLIC
  58. .
  59. ${pal_aztest_dir}
  60. BUILD_DEPENDENCIES
  61. PUBLIC
  62. 3rdParty::googletest::GMock
  63. 3rdParty::googletest::GTest
  64. 3rdParty::GoogleBenchmark
  65. AZ::AzCore
  66. PLATFORM_INCLUDE_FILES
  67. ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  68. )
  69. # Maintainers, please note that when building O3DE from source, this entire script file you are looking at right now
  70. # will execute during configure. However, only the below literal block between the [[ and ]] below will
  71. # be included in the built installer, the rest of this file will not be, the above targets will be synthesized
  72. # as if they were prebuilt libraries (For example, the AzTest library declared above will instead be autogenerated in its
  73. # own file as if it were a STATIC IMPORTED GLOBAL target instead of a built-from-source-code target).
  74. # This means that the below block must declare all necessary 3rd Party libraries fetched and built by fetchcontent,
  75. # and cannot refer to variables from the rest of this script file - only the snippet below will exist, and must be self-contained.
  76. # Export external googletest targets for installers.
  77. set_property(DIRECTORY APPEND PROPERTY O3DE_SUBDIRECTORY_INSTALL_CODE [[
  78. add_library(gtest STATIC IMPORTED GLOBAL)
  79. set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
  80. ly_target_include_system_directories(TARGET gtest INTERFACE "${LY_ROOT_FOLDER}/include/gtest")
  81. add_library(gmock STATIC IMPORTED GLOBAL)
  82. set_target_properties(gmock PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}")
  83. ly_target_include_system_directories(TARGET gmock INTERFACE "${LY_ROOT_FOLDER}/include/gmock")
  84. ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
  85. ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
  86. ]]
  87. )
  88. endif()