Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Utilize globally installed gtest if available #151

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions cpp/cmake/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,48 @@ if(TESTING)
include(FetchContent)

FetchContent_Declare(
googletest
GTest
GIT_REPOSITORY https://github.com/google/googletest.git
# Version 1.12.1 is not compatible with WASI-SDK 12
GIT_TAG release-1.10.0
GIT_TAG release-1.10.0
FIND_PACKAGE_ARGS
)

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled")

# Disable all warning when compiling gtest
target_compile_options(
gtest
PRIVATE
-w
)
FetchContent_MakeAvailable(GTest)

if(WASM)
target_compile_definitions(
if (NOT GTest_FOUND)
# FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful
# so these variables will be available if we reach this case
set_property(DIRECTORY ${gtest_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL)
set_property(DIRECTORY ${gtest_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL)

# Disable all warning when compiling gtest
target_compile_options(
gtest
PRIVATE
-DGTEST_HAS_EXCEPTIONS=0
-DGTEST_HAS_STREAM_REDIRECTION=0)
endif()
-w
)

mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)
if(WASM)
target_compile_definitions(
gtest
PRIVATE
-DGTEST_HAS_EXCEPTIONS=0
-DGTEST_HAS_STREAM_REDIRECTION=0
)
endif()

mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)

add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()

enable_testing()
endif()
6 changes: 3 additions & 3 deletions cpp/cmake/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function(barretenberg_module MODULE_NAME)
target_link_libraries(
${MODULE_NAME}_test_objects
PRIVATE
gtest
GTest::gtest
${TBB_IMPORTED_TARGETS}
)

Expand Down Expand Up @@ -93,8 +93,8 @@ function(barretenberg_module MODULE_NAME)
PRIVATE
${MODULE_LINK_NAME}
${ARGN}
gtest
gtest_main
GTest::gtest
GTest::gtest_main
${TBB_IMPORTED_TARGETS}
)

Expand Down