Skip to content

Commit

Permalink
[Windows] cmake: fix cmake/googletest.cmake on Windows (#2350)
Browse files Browse the repository at this point in the history
* cmake: fix cmake/googletest.cmake on Windows

* incorporate review feedback

---------

Co-authored-by: Artur Wojcik <artur.wojcik@amd.com>
  • Loading branch information
apwojcik and apwojcik authored Oct 31, 2023
1 parent 799ef00 commit 50cf4b1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 51 deletions.
44 changes: 0 additions & 44 deletions cmake/googletest.cmake

This file was deleted.

82 changes: 82 additions & 0 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
################################################################################
#
# MIT License
#
# Copyright (c) 2023 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################

include(FetchContent)

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

set(GOOGLETEST_DIR "" CACHE STRING "Location of local GoogleTest repo to build against")

if(GOOGLETEST_DIR)
set(FETCHCONTENT_SOURCE_DIR_GOOGLETEST ${GOOGLETEST_DIR} CACHE STRING "GoogleTest source directory override")
endif()

set(BUILD_GMOCK OFF CACHE INTERNAL "")

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571
)

if(WIN32)
set(gtest_force_shared_crt ON CACHE INTERNAL "")
endif()

# Store the current value of BUILD_SHARED_LIBS
set(__build_shared_libs ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")

FetchContent_MakeAvailable(googletest)

# Restore the old value of BUILD_SHARED_LIBS
set(BUILD_SHARED_LIBS ${__build_shared_libs} CACHE BOOL "Type of libraries to build" FORCE)

set(GTEST_CMAKE_CXX_FLAGS
-Wno-undef
-Wno-reserved-identifier
-Wno-global-constructors
-Wno-missing-noreturn
-Wno-disabled-macro-expansion
-Wno-used-but-marked-unused
-Wno-switch-enum
-Wno-zero-as-null-pointer-constant
-Wno-unused-member-function
-Wno-comma
-Wno-old-style-cast
-Wno-deprecated
-Wno-unsafe-buffer-usage
-Wno-float-equal
-Wno-ignored-attributes
-Wno-incompatible-pointer-types
-Wno-enum-constexpr-conversion
-Wno-deprecated-builtins)

target_compile_options(gtest PRIVATE ${GTEST_CMAKE_CXX_FLAGS})
target_compile_options(gtest_main PRIVATE ${GTEST_CMAKE_CXX_FLAGS})

include(GoogleTest)
unset(GTEST_CMAKE_CXX_FLAGS)
11 changes: 4 additions & 7 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include(googletest) #include googletest.cmake
include(gtest) #include gtest.cmake
enable_testing()
include(GoogleTest)

find_package(rocblas)

set(SOURCES)
list(APPEND SOURCES
set(SOURCES
log.cpp
platform.cpp
)
Expand All @@ -26,10 +24,9 @@ function(add_gtest TEST_NAME)
target_include_directories(test_${TEST_NAME} SYSTEM PRIVATE $<BUILD_INTERFACE:${FDEEP_INCLUDE_DIR}>)
target_include_directories(test_${TEST_NAME} SYSTEM PRIVATE $<BUILD_INTERFACE:${EIGEN_INCLUDE_DIR}/eigen3>)
endif()
target_link_libraries(test_${TEST_NAME} gtest gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas>)
if(NOT MIOPEN_EMBED_DB STREQUAL "")
target_link_libraries(test_${TEST_NAME} gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas> $<BUILD_INTERFACE:miopen_data>)
else()
target_link_libraries(test_${TEST_NAME} gtest_main MIOpen ${Boost_LIBRARIES} hip::host $<BUILD_INTERFACE:roc::rocblas>)
target_link_libraries(test_${TEST_NAME} $<BUILD_INTERFACE:miopen_data>)
endif()
# Enable CMake to discover the test binary
gtest_discover_tests(test_${TEST_NAME} PROPERTIES ENVIRONMENT "MIOPEN_USER_DB_PATH=${CMAKE_CURRENT_BINARY_DIR};MIOPEN_TEST_FLOAT_ARG=${MIOPEN_TEST_FLOAT_ARG};MIOPEN_TEST_ALL=${MIOPEN_TEST_ALL};MIOPEN_TEST_MLIR=${MIOPEN_TEST_MLIR};MIOPEN_TEST_COMPOSABLEKERNEL=${MIOPEN_TEST_COMPOSABLEKERNEL}")
Expand Down

0 comments on commit 50cf4b1

Please sign in to comment.