pull in appropriate googletest via cmake ExternalProject
Summary: Do not rely on downloading it via wget in `build_helper.sh`
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -58,10 +58,15 @@ else()
endif()
list(APPEND
- _QUIC_COMMON_COMPILE_OPTIONS
+ _QUIC_BASE_COMPILE_OPTIONS
-std=c++14
-Wall
-Wextra
+)
+
+list(APPEND
+ _QUIC_COMMON_COMPILE_OPTIONS
+ ${_QUIC_BASE_COMPILE_OPTIONS}
# more strict options
-Werror=sign-compare
-Werror=bool-compare
@@ -70,16 +75,13 @@ list(APPEND
-Wnon-virtual-dtor
)
-include(QuicTest)
-
-add_subdirectory(quic)
-
if(BUILD_TESTS)
enable_testing()
- find_package(GTest REQUIRED)
- find_package(GMock REQUIRED)
+ include(QuicTest)
endif()
+add_subdirectory(quic)
+
install(
EXPORT mvfst-exports
FILE mvfst-targets.cmake

MODIFY
build_helper.sh
build_helper.sh
@@ -164,32 +164,6 @@ function setup_fizz() {
cd "$BWD" || exit
}
-function setup_googletest() {
- GTEST_DIR=$DEPS_DIR/googletest-release-1.8.0
- GTEST_BUILD_DIR=$GTEST_DIR/build
- # requires googletest-1.8
- if [ ! -d "$GTEST_DIR" ] ; then
- echo -e "${COLOR_GREEN}[ INFO ] Downloading gtest-1.8 ${COLOR_OFF}"
- TMP_DIR=$(mktemp -d)
- pushd .
- cd "$TMP_DIR"
- wget https://github.com/google/googletest/archive/release-1.8.0.zip -O "googletest.zip"
- unzip "googletest.zip" -d "$DEPS_DIR"
- popd
- fi
- echo -e "${COLOR_GREEN}Building Googletest ${COLOR_OFF}"
- mkdir -p "$GTEST_BUILD_DIR"
- cd "$GTEST_BUILD_DIR" || exit
- cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
- -DCMAKE_PREFIX_PATH="$GTEST_INSTALL_DIR" \
- -DCMAKE_INSTALL_PREFIX="$GTEST_INSTALL_DIR" \
- ..
- make -j "$(nproc)"
- make install
- echo -e "${COLOR_GREEN}Googletest is installed ${COLOR_OFF}"
- cd "$BWD" || exit
-}
-
function detect_platform() {
unameOut="$(uname -s)"
case "${unameOut}" in
@@ -201,7 +175,6 @@ function detect_platform() {
}
detect_platform
-setup_googletest
setup_folly
setup_fizz

MODIFY
cmake/QuicTest.cmake
cmake/QuicTest.cmake
include(CTest)
if(BUILD_TESTS)
include(GoogleTest)
- find_package(GMock MODULE REQUIRED)
+ find_package(GMock)
+ if(NOT LIBGMOCK_FOUND)
+ include(ExternalProject)
+
+ # Download and install GoogleMock
+ ExternalProject_Add(
+ googletest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.8.0
+ PREFIX googletest
+ # Disable install step
+ INSTALL_COMMAND ""
+ LOG_DOWNLOAD ON
+ LOG_UPDATE 1
+ LOG_CONFIGURE ON
+ LOG_BUILD ON
+ LOG_TEST 1
+ LOG_INSTALL 1
+ CMAKE_CACHE_ARGS
+ -DCMAKE_BUILD_TYPE:STRING=Release
+ -DBUILD_GMOCK:BOOL=ON
+ -DBUILD_GTEST:BOOL=ON
+ -Dgtest_force_shared_crt:BOOL=OFF
+ )
+
+ ExternalProject_Get_Property(googletest source_dir)
+ set(GTEST_SOURCE_DIR ${source_dir})
+ ExternalProject_Get_Property(googletest binary_dir)
+ set(GTEST_BINARY_DIR ${binary_dir})
+
+ # Setup gtest / gmock libraries and include dirs
+ set(LIBGTEST_LIBRARIES
+ "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/googlemock/gtest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}"
+ "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/googlemock/gtest/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
+)
+ set(LIBGMOCK_LIBRARIES
+ "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/googlemock/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}"
+ "${GTEST_BINARY_DIR}/${CMAKE_CFG_INTDIR}/googlemock/${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
+)
+ set(LIBGMOCK_INCLUDE_DIR "${source_dir}/googlemock/include")
+ set(LIBGTEST_INCLUDE_DIR "${source_dir}/googletest/include")
+ endif()
endif()
function(quic_add_test)
@@ -32,9 +73,10 @@ function(quic_add_test)
# implementation of 'main()' that calls folly::init
"${QUIC_FBCODE_ROOT}/quic/common/test/TestMain.cpp"
)
+ add_dependencies(${QUIC_TEST_TARGET} googletest) # make sure googletest is built first
target_compile_options(
${QUIC_TEST_TARGET} PRIVATE
- ${_QUIC_COMMON_COMPILE_OPTIONS}
+ ${_QUIC_BASE_COMPILE_OPTIONS}
)
target_link_libraries(${QUIC_TEST_TARGET} PRIVATE
"${QUIC_TEST_DEPENDS}"
@@ -51,9 +93,11 @@ function(quic_add_test)
target_link_libraries(${QUIC_TEST_TARGET} PRIVATE
${LIBGMOCK_LIBRARIES}
+ ${LIBGTEST_LIBRARIES}
)
target_include_directories(${QUIC_TEST_TARGET} PRIVATE
${LIBGMOCK_INCLUDE_DIR}
+ ${LIBGTEST_INCLUDE_DIR}
${QUIC_EXTRA_INCLUDE_DIRECTORIES}
)
target_compile_definitions(${QUIC_TEST_TARGET} PRIVATE ${LIBGMOCK_DEFINES})

MODIFY
quic/api/test/CMakeLists.txt
quic/api/test/CMakeLists.txt
@@ -16,7 +16,6 @@ quic_add_test(TARGET QuicTransportTest
mvfst_server
mvfst_state_stream_functions
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicTransportBaseTest
@@ -29,7 +28,6 @@ quic_add_test(TARGET QuicTransportBaseTest
mvfst_test_utils
mvfst_state_stream_functions
mvfst_server
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicTransportFunctionsTest
@@ -40,7 +38,6 @@ quic_add_test(TARGET QuicTransportFunctionsTest
mvfst_transport
mvfst_test_utils
mvfst_server
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicPacketSchedulerTest
@@ -53,7 +50,6 @@ quic_add_test(TARGET QuicPacketSchedulerTest
mvfst_transport
mvfst_test_utils
mvfst_server
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET IoBufQuicBatchTest

MODIFY
quic/codec/test/CMakeLists.txt
quic/codec/test/CMakeLists.txt
@@ -15,7 +15,6 @@ quic_add_test(TARGET QuicHeaderCodecTest
mvfst_exception
mvfst_codec
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicReadCodecTest
@@ -26,7 +25,6 @@ quic_add_test(TARGET QuicReadCodecTest
mvfst_codec
mvfst_exception
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicWriteCodecTest
@@ -39,7 +37,6 @@ quic_add_test(TARGET QuicWriteCodecTest
mvfst_codec_types
mvfst_exception
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicTypesTest
@@ -51,7 +48,6 @@ quic_add_test(TARGET QuicTypesTest
mvfst_codec_types
mvfst_exception
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET PacketNumberTest
@@ -60,7 +56,6 @@ quic_add_test(TARGET PacketNumberTest
DEPENDS
Folly::folly
mvfst_codec_types
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET PacketNumberCipherTest
@@ -69,7 +64,6 @@ quic_add_test(TARGET PacketNumberCipherTest
DEPENDS
Folly::folly
mvfst_codec_packet_number_cipher
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET DecodeTest
@@ -82,7 +76,6 @@ quic_add_test(TARGET DecodeTest
mvfst_codec_types
mvfst_exception
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicConnectionIdTest
@@ -91,7 +84,6 @@ quic_add_test(TARGET QuicConnectionIdTest
DEPENDS
Folly::folly
mvfst_codec_types
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicPacketBuilderTest
@@ -110,7 +102,6 @@ quic_add_test(TARGET QuicPacketBuilderTest
mvfst_state_machine
mvfst_state_stream_functions
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
@@ -121,5 +112,4 @@ quic_add_test(TARGET QuicIntegerTest
Folly::folly
mvfst_codec_types
mvfst_exception
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/common/test/CMakeLists.txt
quic/common/test/CMakeLists.txt
@@ -17,6 +17,8 @@ target_include_directories(
mvfst_test_utils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${FIZZ_PROJECT}>
+ ${LIBGMOCK_INCLUDE_DIR}
+ ${LIBGTEST_INCLUDE_DIR}
)
target_compile_options(
@@ -40,6 +42,8 @@ target_link_libraries(
mvfst_test_utils PUBLIC
Folly::folly
fizz::fizz
+ ${LIBGMOCK_LIBRARIES}
+ ${LIBGTEST_LIBRARIES}
mvfst_client
mvfst_codec_pktbuilder
mvfst_codec_types

MODIFY
quic/congestion_control/test/CMakeLists.txt
quic/congestion_control/test/CMakeLists.txt
@@ -21,5 +21,4 @@ quic_add_test(TARGET CongestionControllerTests
Folly::folly
mvfst_cc_algo
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/flowcontrol/test/CMakeLists.txt
quic/flowcontrol/test/CMakeLists.txt
@@ -15,5 +15,4 @@ quic_add_test(TARGET QuicFlowControlTest
mvfst_client
mvfst_flowcontrol
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/handshake/test/CMakeLists.txt
quic/handshake/test/CMakeLists.txt
@@ -14,7 +14,6 @@ quic_add_test(TARGET TransportParametersTest
Folly::folly
mvfst_handshake
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET HandshakeLayerTest
@@ -25,5 +24,4 @@ quic_add_test(TARGET HandshakeLayerTest
mvfst_codec_types
mvfst_handshake
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/logging/test/CMakeLists.txt
quic/logging/test/CMakeLists.txt
@@ -12,6 +12,5 @@ quic_add_test(TARGET MacroTest
QuicLoggingMacroTest.cpp
DEPENDS
Folly::folly
- ${LIBGTEST_LIBRARY}
mvfst_state_functions
)

MODIFY
quic/loss/test/CMakeLists.txt
quic/loss/test/CMakeLists.txt
@@ -18,5 +18,4 @@ quic_add_test(TARGET QuicLossFunctionsTest
mvfst_server
mvfst_test_utils
mvfst_transport
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/samples/CMakeLists.txt
quic/samples/CMakeLists.txt
@@ -31,5 +31,5 @@ target_link_libraries(
mvfst_test_utils
${GFLAGS_LIBRARIES}
${LIBGMOCK_LIBRARIES}
- ${LIBGTEST_LIBRARY}
+ ${LIBGTEST_LIBRARIES}
)

MODIFY
quic/server/handshake/test/CMakeLists.txt
quic/server/handshake/test/CMakeLists.txt
@@ -24,6 +24,4 @@ quic_add_test(TARGET ServerHandshakeTest
mvfst_server
mvfst_state_machine
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/server/test/CMakeLists.txt
quic/server/test/CMakeLists.txt
@@ -18,7 +18,6 @@ quic_add_test(TARGET QuicServerTest
mvfst_server
mvfst_test_utils
mvfst_transport
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicServerTransportTest
@@ -33,5 +32,4 @@ quic_add_test(TARGET QuicServerTransportTest
mvfst_state_stream_functions
mvfst_test_utils
mvfst_transport
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/state/stream/test/CMakeLists.txt
quic/state/stream/test/CMakeLists.txt
@@ -19,6 +19,4 @@ quic_add_test(TARGET StreamStateMachineTest
mvfst_state_stream_functions
mvfst_test_utils
mvfst_transport
- ${LIBGTEST_LIBRARIES}
- ${LIBGTEST_LIBRARY}
)

MODIFY
quic/state/test/CMakeLists.txt
quic/state/test/CMakeLists.txt
@@ -15,7 +15,6 @@ quic_add_test(TARGET StateMachineTest
Folly::folly
mvfst_state_machine
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicStreamFunctionsTest
@@ -26,7 +25,6 @@ quic_add_test(TARGET QuicStreamFunctionsTest
mvfst_server
mvfst_state_stream_functions
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET AckHandlersTest
@@ -37,7 +35,6 @@ quic_add_test(TARGET AckHandlersTest
mvfst_state_machine
mvfst_state_ack_handler
mvfst_test_utils
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicStateFunctionsTest
@@ -47,7 +44,6 @@ quic_add_test(TARGET QuicStateFunctionsTest
mvfst_server
mvfst_test_utils
mvfst_state_functions
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QuicPacingFunctionsTest
@@ -55,7 +51,6 @@ quic_add_test(TARGET QuicPacingFunctionsTest
QuicPacingFunctionsTest.cpp
DEPENDS
mvfst_state_pacing_functions
- ${LIBGTEST_LIBRARY}
)
quic_add_test(TARGET QPRFunctionsTest
@@ -64,5 +59,4 @@ quic_add_test(TARGET QPRFunctionsTest
DEPENDS
mvfst_server
mvfst_state_qpr_functions
- ${LIBGTEST_LIBRARY}
)

pull in appropriate googletest via cmake ExternalProject

Summary: Do not rely on downloading it via wget in `build_helper.sh`

Reviewed By: siyengar

Differential Revision: D15215226

fbshipit-source-id: aeef31b30964674d80346aa6a1480ce03fdf478d