123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #
- # Copyright (c) Contributors to the Open 3D Engine Project.
- # For complete copyright and license terms please see the LICENSE at the root of this distribution.
- #
- # SPDX-License-Identifier: Apache-2.0 OR MIT
- #
- #
- if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
- set(GOOGLETEST_GIT_REPOSITORY "https://github.com/google/googletest.git")
- set(GOOGLETEST_GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59) # tag name is v1.15.2
- set(GOOGLETEST_VERSION_STRING "v1.15.2")
- # there are optional flags you can pass FetchContent that make the project cleaner but require newer versions of cmake
-
- set(ADDITIONAL_FETCHCONTENT_FLAGS "")
- if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25")
- list(APPEND ADDITIONAL_FETCHCONTENT_FLAGS "SYSTEM") # treat it as a 3p library, that is, do not issue warnings using the same warning level
- endif()
- o3de_pal_dir(pal_aztest_dir ${CMAKE_CURRENT_LIST_DIR}/AzTest/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
- set(CMAKE_POLICY_DEFAULT_CMP0148 OLD)
- set(OLD_CMAKE_WARN_DEPRECATED ${CMAKE_WARN_DEPRECATED})
- set(CMAKE_WARN_DEPRECATED FALSE CACHE BOOL "" FORCE)
- include(FetchContent)
- message(STATUS "Using googletest from ${GOOGLETEST_GIT_REPOSITORY} ${GOOGLETEST_VERSION_STRING}")
- FetchContent_Declare(
- googletest
- GIT_REPOSITORY ${GOOGLETEST_GIT_REPOSITORY}
- GIT_TAG ${GOOGLETEST_GIT_TAG}
- ${ADDITIONAL_FETCHCONTENT_FLAGS}
- 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"
- )
-
- set(PYTHONINTERP_FOUND ON)
- set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
- set(PYTHON_VERSION_STRING ${Python_VERSION})
- FetchContent_MakeAvailable(googletest)
- # Let's not clutter the root of any IDE folder structure with 3rd party dependencies
- # Setting the FOLDER makes it show up there in the solution build in VS and similarly
- # any other IDEs that organize in folders.
- # Setting EXCLUDE_FROM_ALL Makes it not appear in the first place.
- set_target_properties(
- gtest
- gmock
- gtest_main
- gmock_main
- PROPERTIES
- FOLDER "3rdParty Dependencies"
- EXCLUDE_FROM_ALL TRUE)
- unset(CMAKE_POLICY_DEFAULT_CMP0148)
- set(CMAKE_WARN_DEPRECATED ${OLD_CMAKE_WARN_DEPRECATED} CACHE BOOL "" FORCE)
- ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
- ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
- ly_add_target(
- NAME AzTest STATIC
- NAMESPACE AZ
- FILES_CMAKE
- AzTest/aztest_files.cmake
- ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
- INCLUDE_DIRECTORIES
- PUBLIC
- .
- ${pal_aztest_dir}
- BUILD_DEPENDENCIES
- PUBLIC
- 3rdParty::googletest::GMock
- 3rdParty::googletest::GTest
- 3rdParty::GoogleBenchmark
- AZ::AzCore
- PLATFORM_INCLUDE_FILES
- ${pal_aztest_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
- )
- # Maintainers, please note that when building O3DE from source, this entire script file you are looking at right now
- # will execute during configure. However, only the below literal block between the [[ and ]] below will
- # be included in the built installer, the rest of this file will not be, the above targets will be synthesized
- # as if they were prebuilt libraries (For example, the AzTest library declared above will instead be autogenerated in its
- # own file as if it were a STATIC IMPORTED GLOBAL target instead of a built-from-source-code target).
- # This means that the below block must declare all necessary 3rd Party libraries fetched and built by fetchcontent,
- # and cannot refer to variables from the rest of this script file - only the snippet below will exist, and must be self-contained.
- # Export external googletest targets for installers.
- set_property(DIRECTORY APPEND PROPERTY O3DE_SUBDIRECTORY_INSTALL_CODE [[
- add_library(gtest STATIC IMPORTED GLOBAL)
- set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
- ly_target_include_system_directories(TARGET gtest INTERFACE "${LY_ROOT_FOLDER}/include/gtest")
-
- add_library(gmock STATIC IMPORTED GLOBAL)
- set_target_properties(gmock PROPERTIES IMPORTED_LOCATION "${LY_ROOT_FOLDER}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}")
- ly_target_include_system_directories(TARGET gmock INTERFACE "${LY_ROOT_FOLDER}/include/gmock")
-
- ly_create_alias(NAME googletest::GTest NAMESPACE 3rdParty TARGETS gtest)
- ly_create_alias(NAME googletest::GMock NAMESPACE 3rdParty TARGETS gmock)
- ]]
- )
- endif()
|