mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-14 10:09:41 +00:00
Enable GMock and improve gtest configuration (#2976)
Our current cmake/gtest.cmake file does not enable gmock. Gmock is needed for matchers that are needed for more readable unit tests. This PR enables gmock and does a little cleanup in gtest.cmake:
* Enable BUILD_GMOCK by default (was previously disabled)
* Patch gtest-src/googlemock/CMakeLists.txt for broken include path.
* Add configuration to gmock if the target is used.
No other changes in this PR, but I've verified I can use gmock matchers correctly once I include these changes in other code.
[ROCm/composable_kernel commit: fc2a121c44]
This commit is contained in:
@@ -12,6 +12,17 @@ FetchContent_Declare(
|
||||
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571
|
||||
)
|
||||
|
||||
FetchContent_Populate(GTest)
|
||||
|
||||
# Patch googlemock/CMakeLists.txt to fix invalid include path
|
||||
set(GMOCK_CMAKE "${gtest_SOURCE_DIR}/googlemock/CMakeLists.txt")
|
||||
file(READ "${GMOCK_CMAKE}" GMOCK_CMAKE_CONTENT)
|
||||
string(REPLACE [[gtest_SOURCE_DIR}/include]]
|
||||
[[gtest_SOURCE_DIR}/googletest/include]]
|
||||
GMOCK_CMAKE_CONTENT
|
||||
"${GMOCK_CMAKE_CONTENT}")
|
||||
file(WRITE "${GMOCK_CMAKE}" "${GMOCK_CMAKE_CONTENT}")
|
||||
|
||||
# Suppress ROCMChecks WARNING on GoogleTests
|
||||
set(ROCM_DISABLE_CHECKS FALSE)
|
||||
macro(rocm_check_toolchain_var var access value list_file)
|
||||
@@ -24,7 +35,7 @@ if(WIN32)
|
||||
set(gtest_force_shared_crt ON CACHE_INTERNAL "")
|
||||
endif()
|
||||
|
||||
set(BUILD_GMOCK OFF CACHE INTERNAL "")
|
||||
set(BUILD_GMOCK ON CACHE INTERNAL "")
|
||||
set(INSTALL_GTEST OFF CACHE INTERNAL "")
|
||||
|
||||
# Store the current value of BUILD_SHARED_LIBS
|
||||
@@ -32,15 +43,12 @@ set(__build_shared_libs ${BUILD_SHARED_LIBS})
|
||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
|
||||
|
||||
set(ROCM_DISABLE_CHECKS TRUE)
|
||||
FetchContent_MakeAvailable(GTest)
|
||||
add_subdirectory(${gtest_SOURCE_DIR} ${gtest_BINARY_DIR})
|
||||
set(ROCM_DISABLE_CHECKS FALSE)
|
||||
|
||||
# Restore the old value of BUILD_SHARED_LIBS
|
||||
set(BUILD_SHARED_LIBS ${__build_shared_libs} CACHE BOOL "Type of libraries to build" FORCE)
|
||||
|
||||
set(BUILD_GMOCK OFF CACHE INTERNAL "")
|
||||
set(INSTALL_GTEST OFF CACHE INTERNAL "")
|
||||
|
||||
set(GTEST_CXX_FLAGS
|
||||
-Wno-undef
|
||||
-Wno-reserved-identifier
|
||||
@@ -71,3 +79,12 @@ target_compile_options(gtest_main PRIVATE ${GTEST_CXX_FLAGS})
|
||||
target_compile_definitions(gtest PRIVATE GTEST_HAS_SEH=0)
|
||||
target_compile_definitions(gtest_main PRIVATE GTEST_HAS_SEH=0)
|
||||
|
||||
if(TARGET gmock)
|
||||
target_compile_options(gmock PRIVATE ${GTEST_CXX_FLAGS})
|
||||
target_compile_definitions(gmock PRIVATE GTEST_HAS_SEH=0)
|
||||
endif()
|
||||
|
||||
if(TARGET gmock_main)
|
||||
target_compile_options(gmock_main PRIVATE ${GTEST_CXX_FLAGS})
|
||||
target_compile_definitions(gmock_main PRIVATE GTEST_HAS_SEH=0)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user