Skip to content

Commit

Permalink
Merge pull request #20 from cisco/paulej_fetch_gtest
Browse files Browse the repository at this point in the history
Fetch GoogleTest if not installed
  • Loading branch information
paulej authored Apr 3, 2023
2 parents ea2d82d + bb8b9fa commit 45ad0e2
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ project(libgse
DESCRIPTION "Game State Encoder Library"
LANGUAGES CXX)

add_subdirectory(dependencies)
add_subdirectory(src)

include(CTest)
Expand Down
8 changes: 8 additions & 0 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if(gse_BUILD_TESTS)
find_package(GTest)

if(NOT GTest_FOUND)
message(STATUS "Fetching GTest since it is not available on the system")
add_subdirectory(googletest)
endif()
endif()
22 changes: 22 additions & 0 deletions dependencies/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include(FetchContent)

FetchContent_Declare(GTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
OVERRIDE_FIND_PACKAGE)

if(WIN32)
# For Windows: Prevent overriding the parent project's
# compiler/linker settings
# (https://github.com/google/googletest/tree/v1.13.0/googletest)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()

# Prevent GTest from installing
set(INSTALL_GTEST OFF CACHE INTERNAL "Disable gtest installation")

FetchContent_MakeAvailable(GTest)

add_library(GTest::GTest INTERFACE IMPORTED GLOBAL)
add_library(GTest::Main INTERFACE IMPORTED GLOBAL)
target_link_libraries(GTest::GTest INTERFACE gtest_main)
2 changes: 0 additions & 2 deletions test/test_databuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_databuffer
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_databuffer PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_databuffer
Expand Down
2 changes: 0 additions & 2 deletions test/test_float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_float
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_float PRIVATE GTest::GTest GTest::Main)

add_test(NAME test_float
Expand Down
2 changes: 0 additions & 2 deletions test/test_gs_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_gs_api
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_gs_api PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_gs_api
Expand Down
2 changes: 0 additions & 2 deletions test/test_gs_decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_gs_decoder
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_gs_decoder PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_gs_decoder
Expand Down
2 changes: 0 additions & 2 deletions test/test_gs_deserializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ set_target_properties(test_gs_deserializer

target_include_directories(test_gs_deserializer PRIVATE ${CMAKE_SOURCE_DIR}/src/gse/src)

include(GoogleTest)

target_link_libraries(test_gs_deserializer PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_gs_deserializer
Expand Down
2 changes: 0 additions & 2 deletions test/test_gs_encoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_gs_encoder
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_gs_encoder PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_gs_encoder
Expand Down
2 changes: 0 additions & 2 deletions test/test_gs_serializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set_target_properties(test_gs_serializer
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

include(GoogleTest)

target_link_libraries(test_gs_serializer PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_gs_serializer
Expand Down
2 changes: 0 additions & 2 deletions test/test_half_float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ set_target_properties(test_half_float

target_include_directories(test_half_float PRIVATE ${libgse_SOURCE_DIR}/src)

include(GoogleTest)

target_link_libraries(test_half_float PRIVATE gse GTest::GTest GTest::Main)

add_test(NAME test_half_float
Expand Down

0 comments on commit 45ad0e2

Please sign in to comment.