Skip to content

Commit

Permalink
Fix for GTEST on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ihedvall committed Jan 25, 2024
1 parent da3e031 commit 3b0e31d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ jobs:
with:
platform: ${{ matrix.env.ninja_platform }}

- name: MSVC dev
uses: ilammy/msvc-dev-cmd@v1

- name: GTEST Install
uses: Bacondish2023/setup-googletest@main

- name: PYTEST Install
run: pip install pytest

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if (wxWidgets_FOUND AND DBC_TOOLS)
add_subdirectory(dbcviewer)
endif ()

if (GTEST_FOUND AND DBC_TEST)
if (DBC_TEST)
enable_testing()
add_subdirectory(test)
endif ()
Expand Down
26 changes: 14 additions & 12 deletions script/googletest.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright 2021 Ingemar Hedvall
# SPDX-License-Identifier: MIT

if (NOT GTest_FOUND)
set(GTEST_MSVC_SEARCH MT)
if (COMP_DIR)
set(GTEST_ROOT ${COMP_DIR}/googletest/master)
endif()
include (FetchContent)

message(STATUS "GTest Fetching: " ${GTest_FOUND})
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG HEAD
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
message(STATUS "googletest Populated: " ${googletest_POPULATED})
message(STATUS "googletest Source: " ${googletest_SOURCE_DIR})
message(STATUS "googletest Binary: " ${googletest_BINARY_DIR})

find_package(GTest)
message(STATUS "GTest Found: " ${GTest_FOUND})
message(STATUS "GTest Include Dirs: " ${GTEST_INCLUDE_DIRS})
message(STATUS "GTest Libraries: " ${GTEST_LIBRARIES})
message(STATUS "GTest Main Libraries: " ${GTEST_MAIN_LIBRARIES})
message(STATUS "GTest Both Libraries: " ${GTEST_BOTH_LIBRARIES})
endif()
9 changes: 2 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ add_executable(test_dbc
test_dbchelper.cpp)

target_include_directories(test_dbc PRIVATE
../src # dbchelper.h
${GTEST_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS})
../src )

if (MINGW)
target_link_options(test_dbc PRIVATE -static -fstack-protector)
Expand All @@ -23,10 +21,7 @@ elseif (MSVC)
endif ()

target_link_libraries(test_dbc PRIVATE dbc)
target_link_libraries(test_dbc PRIVATE ${GTEST_BOTH_LIBRARIES})

if (WIN32)
endif ()
target_link_libraries(test_dbc PRIVATE GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(test_dbc)
Expand Down

0 comments on commit 3b0e31d

Please sign in to comment.