CMakeLists.txt 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 2fe3bd994b3189899d93f1d5a881e725e046fdc2) # release-1.8.1
  11. set(GOOGLETEST_VERSION_STRING "release-1.8.1")
  12. o3de_pal_dir(pal_aztest_dir ${CMAKE_CURRENT_LIST_DIR}/AzTest/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
  13. set(CMAKE_POLICY_DEFAULT_CMP0148 OLD)
  14. set(OLD_CMAKE_WARN_DEPRECATED ${CMAKE_WARN_DEPRECATED})
  15. set(CMAKE_WARN_DEPRECATED FALSE CACHE BOOL "" FORCE)
  16. include(FetchContent)
  17. message(STATUS "Using googletest from ${GOOGLETEST_GIT_REPOSITORY} ${GOOGLETEST_VERSION_STRING}")
  18. FetchContent_Declare(
  19. googletest
  20. GIT_REPOSITORY ${GOOGLETEST_GIT_REPOSITORY}
  21. GIT_TAG ${GOOGLETEST_GIT_TAG}
  22. 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"
  23. )
  24. set(PYTHONINTERP_FOUND ON)
  25. set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
  26. set(PYTHON_VERSION_STRING ${Python_VERSION})
  27. FetchContent_MakeAvailable(googletest)
  28. unset(CMAKE_POLICY_DEFAULT_CMP0148)
  29. set(CMAKE_WARN_DEPRECATED ${OLD_CMAKE_WARN_DEPRECATED} CACHE BOOL "" FORCE)
  30. ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
  31. ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
  32. ly_add_target(
  33. NAME AzTest STATIC
  34. NAMESPACE AZ
  35. FILES_CMAKE
  36. AzTest/aztest_files.cmake
  37. ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  38. INCLUDE_DIRECTORIES
  39. PUBLIC
  40. .
  41. ${pal_aztest_dir}
  42. BUILD_DEPENDENCIES
  43. PUBLIC
  44. 3rdParty::googletest::GMock
  45. 3rdParty::googletest::GTest
  46. 3rdParty::GoogleBenchmark
  47. AZ::AzCore
  48. PLATFORM_INCLUDE_FILES
  49. ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  50. )
  51. # Maintainers, please note that when building O3DE from source, this entire script file you are looking at right now
  52. # will execute during configure. However, only the below literal block between the [[ and ]] below will
  53. # be included in the built installer, the rest of this file will not be, the above targets will be synthesized
  54. # as if they were prebuilt libraries (For example, the AzTest library declared above will instead be autogenerated in its
  55. # own file as if it were a STATIC IMPORTED GLOBAL target instead of a built-from-source-code target).
  56. # This means that the below block must declare all necessary 3rd Party libraries fetched and built by fetchcontent,
  57. # and cannot refer to variables from the rest of this script file - only the snippet below will exist, and must be self-contained.
  58. # Export external googletest targets for installers.
  59. set_property(DIRECTORY APPEND PROPERTY O3DE_SUBDIRECTORY_INSTALL_CODE [[
  60. add_library(gtest STATIC IMPORTED GLOBAL)
  61. set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
  62. ly_target_include_system_directories(TARGET gtest INTERFACE "${LY_ROOT_FOLDER}/include/gtest")
  63. add_library(gmock STATIC IMPORTED GLOBAL)
  64. set_target_properties(gmock PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}")
  65. ly_target_include_system_directories(TARGET gmock INTERFACE "${LY_ROOT_FOLDER}/include/gmock")
  66. ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
  67. ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
  68. ]]
  69. )
  70. endif()