Skip to content

Commit

Permalink
Fix find_package and linking for 'gtest' library (facebookincubator#1…
Browse files Browse the repository at this point in the history
…0422)

Summary:
Fixes facebookincubator#10421

1. Use "GTest"(not `"gtest"` or `"GTEST"`) in `find_package` to solve
   the following warning:

```
CMake Warning at CMake/ResolveDependency.cmake:70 (find_package):
  By not providing "Findgtest.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "gtest", but
  CMake did not find one.

  Could not find a package configuration file provided by "gtest" with any of
  the following names:

    gtestConfig.cmake
    gtest-config.cmake

  Add the installation prefix of "gtest" to CMAKE_PREFIX_PATH or set
  "gtest_DIR" to a directory containing one of the above files.  If "gtest"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  CMakeLists.txt:542 (resolve_dependency)
```

2. Use `GTest::gtest` and `Gtest::gtest_main` in the
   `target_link_libraries` to solve the following error when 'gtest' is
   pre-installed(not using the BUNDLED way). See [1]

```
ld: library not found for -gtest
```

3. Finally, because the compilation error of the precompiled 'gtest'
library has been solved, we can pre-install the 'gtest' library
in setup-macos.sh.

[1] https://cmake.org/cmake/help/v3.30/module/FindGTest.html

Pull Request resolved: facebookincubator#10422

Reviewed By: pedroerp

Differential Revision: D61135221

Pulled By: xiaoxmeng

fbshipit-source-id: 4963efcbb154e06cd413c707158255804a23c271
  • Loading branch information
lingbin authored and facebook-github-bot committed Aug 12, 2024
1 parent 23c862e commit a6ca103
Show file tree
Hide file tree
Showing 78 changed files with 246 additions and 245 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ jobs:
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "TRUE"
run: |
brew install \
bison boost ccache double-conversion flex fmt gflags glog \
icu4c libevent libsodium lz4 lzo ninja openssl protobuf@21 \
range-v3 simdjson snappy thrift xz xsimd zstd
source scripts/setup-macos.sh
brew install $MACOS_BUILD_DEPS $MACOS_VELOX_DEPS
echo "NJOBS=`sysctl -n hw.ncpu`" >> $GITHUB_ENV
brew unlink protobuf || echo "protobuf not installed"
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ include_directories(SYSTEM velox/external)

# these were previously vendored in third-party/
if(NOT VELOX_DISABLE_GOOGLETEST)
set(gtest_SOURCE AUTO)
resolve_dependency(gtest)
set(GTest_SOURCE AUTO)
resolve_dependency(GTest)
set(VELOX_GTEST_INCUDE_DIR
"${gtest_SOURCE_DIR}/googletest/include"
PARENT_SCOPE)
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PYTHON_VENV=${PYHTON_VENV:-"${SCRIPTDIR}/../.venv"}
NPROC=$(getconf _NPROCESSORS_ONLN)

DEPENDENCY_DIR=${DEPENDENCY_DIR:-$(pwd)}
MACOS_VELOX_DEPS="flex bison protobuf@21 icu4c boost gflags glog libevent lz4 lzo snappy xz zstd openssl libsodium"
MACOS_VELOX_DEPS="bison boost double-conversion flex fmt gflags glog googletest icu4c libevent libsodium lz4 lzo openssl protobuf@21 simdjson snappy thrift xz xsimd zstd"
MACOS_BUILD_DEPS="ninja cmake ccache"
FB_OS_VERSION="v2024.05.20.00"
FMT_VERSION="10.1.1"
Expand Down
2 changes: 1 addition & 1 deletion velox/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ target_link_libraries(
velox_benchmark_builder ${velox_benchmark_deps})
# This is a workaround for the use of VectorTestBase.h which includes gtest.h
target_link_libraries(
velox_benchmark_builder gtest)
velox_benchmark_builder GTest::gtest)

if(${VELOX_ENABLE_BENCHMARKS})
add_subdirectory(tpch)
Expand Down
6 changes: 3 additions & 3 deletions velox/buffer/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ target_link_libraries(
velox_memory
velox_buffer
velox_test_util
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
glog::glog
gflags::gflags
pthread)
10 changes: 5 additions & 5 deletions velox/common/base/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ target_link_libraries(
Folly::folly
fmt::fmt
gflags::gflags
gtest
gmock
gtest_main)
GTest::gtest
GTest::gmock
GTest::gtest_main)

add_executable(velox_id_map_test IdMapTest.cpp)

Expand All @@ -67,8 +67,8 @@ target_link_libraries(
Boost::headers
gflags::gflags
glog::glog
gtest
gtest_main
GTest::gtest
GTest::gtest_main
pthread)

add_executable(velox_memcpy_meter Memcpy.cpp)
Expand Down
12 changes: 6 additions & 6 deletions velox/common/caching/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ target_link_libraries(
Folly::folly
velox_time
glog::glog
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(
velox_cache_test
Expand All @@ -40,8 +40,8 @@ target_link_libraries(
velox_temp_path
Folly::folly
glog::glog
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(cached_factory_test CachedFactoryTest.cpp)
add_test(cached_factory_test cached_factory_test)
Expand All @@ -52,5 +52,5 @@ target_link_libraries(
Folly::folly
velox_time
glog::glog
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
3 changes: 2 additions & 1 deletion velox/common/compression/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ add_test(velox_common_compression_test velox_common_compression_test)
target_link_libraries(
velox_common_compression_test
PUBLIC velox_link_libs
PRIVATE velox_common_compression velox_exception gtest gtest_main)
PRIVATE velox_common_compression velox_exception GTest::gtest
GTest::gtest_main)
2 changes: 1 addition & 1 deletion velox/common/encode/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ add_test(velox_common_encode_test velox_common_encode_test)
target_link_libraries(
velox_common_encode_test
PUBLIC Folly::folly
PRIVATE velox_encode velox_exception gtest gtest_main)
PRIVATE velox_encode velox_exception GTest::gtest GTest::gtest_main)
6 changes: 3 additions & 3 deletions velox/common/file/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ target_link_libraries(
velox_file
velox_file_test_utils
velox_temp_path
gmock
gtest
gtest_main)
GTest::gmock
GTest::gtest
GTest::gtest_main)
2 changes: 1 addition & 1 deletion velox/common/hyperloglog/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ add_test(NAME velox_common_hyperloglog_test

target_link_libraries(
velox_common_hyperloglog_test
PRIVATE velox_common_hyperloglog velox_encode gtest gtest_main)
PRIVATE velox_common_hyperloglog velox_encode GTest::gtest GTest::gtest_main)
6 changes: 3 additions & 3 deletions velox/common/memory/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ target_link_libraries(
fmt::fmt
gflags::gflags
glog::glog
gmock
gtest
gtest_main
GTest::gmock
GTest::gtest
GTest::gtest_main
re2::re2)

gtest_add_tests(velox_memory_test "" AUTO)
Expand Down
4 changes: 2 additions & 2 deletions velox/common/process/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ target_link_libraries(
PRIVATE
velox_process
fmt::fmt
gtest
velox_time
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/common/serialization/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ target_link_libraries(
velox_serialization
Folly::folly
glog::glog
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/common/testutil/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ target_link_libraries(
velox_exception
velox_exec
velox_time
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
2 changes: 1 addition & 1 deletion velox/common/time/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ add_executable(velox_time_test CpuWallTimerTest.cpp)

target_link_libraries(
velox_time_test
PRIVATE velox_time glog::glog gtest gtest_main)
PRIVATE velox_time glog::glog GTest::gtest GTest::gtest_main)

gtest_add_tests(velox_time_test "" AUTO)
4 changes: 2 additions & 2 deletions velox/connectors/fuzzer/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ target_link_libraries(
velox_vector_test_lib
velox_exec_test_lib
velox_aggregates
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/connectors/hive/iceberg/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if(NOT VELOX_DISABLE_GOOGLETEST)
velox_exec_test_lib
Folly::folly
${FOLLY_BENCHMARK}
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

endif()
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ target_link_libraries(
velox_hive_connector
velox_dwio_common_exception
velox_exec
gtest
gtest_main
GTest::gtest
GTest::gtest_main
Azure::azure-storage-blobs
Azure::azure-storage-files-datalake)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ target_link_libraries(
velox_hive_connector
velox_dwio_common_exception
velox_exec
gmock
gtest
gtest_main)
GTest::gmock
GTest::gtest
GTest::gtest_main)
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ target_link_libraries(
velox_hive_connector
velox_dwio_common_exception
velox_exec
gtest
gtest_main
gmock)
GTest::gtest
GTest::gtest_main
GTest::gmock)

target_compile_options(velox_hdfs_file_test
PRIVATE -Wno-deprecated-declarations)
24 changes: 12 additions & 12 deletions velox/connectors/hive/storage_adapters/s3fs/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ target_link_libraries(
velox_exec_test_lib
velox_dwio_common_exception
velox_exec
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_s3registration_test S3FileSystemRegistrationTest.cpp)
add_test(velox_s3registration_test velox_s3registration_test)
Expand All @@ -37,8 +37,8 @@ target_link_libraries(
velox_exec_test_lib
velox_dwio_common_exception
velox_exec
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_s3finalize_test S3FileSystemFinalizeTest.cpp)
add_test(velox_s3finalize_test velox_s3finalize_test)
Expand All @@ -48,8 +48,8 @@ target_link_libraries(
velox_hive_config
velox_file
velox_core
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_s3insert_test S3InsertTest.cpp)
add_test(velox_s3insert_test velox_s3insert_test)
Expand All @@ -62,8 +62,8 @@ target_link_libraries(
velox_exec_test_lib
velox_dwio_common_exception
velox_exec
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_s3read_test S3ReadTest.cpp)
add_test(
Expand All @@ -79,8 +79,8 @@ target_link_libraries(
velox_exec_test_lib
velox_dwio_common_exception
velox_exec
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_s3multiendpoints_test S3MultipleEndpointsTest.cpp)
add_test(velox_s3multiendpoints_test velox_s3multiendpoints_test)
Expand All @@ -93,5 +93,5 @@ target_link_libraries(
velox_exec_test_lib
velox_dwio_common_exception
velox_exec
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/connectors/hive/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ target_link_libraries(
velox_vector_test_lib
velox_exec
velox_exec_test_lib
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/connectors/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ add_test(velox_connector_test velox_connector_test)
target_link_libraries(
velox_connector_test
velox_connector
gtest
gtest_main
GTest::gtest
GTest::gtest_main
glog::glog
gflags::gflags
Folly::folly)
4 changes: 2 additions & 2 deletions velox/connectors/tpch/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ target_link_libraries(
velox_vector_test_lib
velox_exec_test_lib
velox_aggregates
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)

add_executable(velox_tpch_speed_test SpeedTest.cpp)

Expand Down
4 changes: 2 additions & 2 deletions velox/core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ target_link_libraries(
velox_presto_types
velox_type
velox_vector_test_lib
gtest
gtest_main)
GTest::gtest
GTest::gtest_main)
4 changes: 2 additions & 2 deletions velox/duckdb/conversion/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ target_link_libraries(
velox_functions_prestosql
velox_functions_lib
velox_functions_test_lib
gtest
gtest_main
GTest::gtest
GTest::gtest_main
gflags::gflags)
6 changes: 3 additions & 3 deletions velox/dwio/catalog/fbhive/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ target_link_libraries(
file_utils_test
velox_dwio_catalog_fbhive
velox_dwio_common_exception
gtest
gtest_main
gmock)
GTest::gtest
GTest::gtest_main
GTest::gmock)
6 changes: 3 additions & 3 deletions velox/dwio/common/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ target_link_libraries(
Folly::folly
${TEST_LINK_LIBS}
gflags::gflags
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
glog::glog
fmt::fmt
protobuf::libprotobuf)
Expand Down
2 changes: 1 addition & 1 deletion velox/dwio/common/tests/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target_link_libraries(
fmt::fmt
glog::glog
gflags::gflags
gtest
GTest::gtest
velox_dwio_common
velox_dwio_common_exception
velox_exception
Expand Down
6 changes: 3 additions & 3 deletions velox/dwio/dwrf/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ set(TEST_LINK_LIBS
velox_dwio_dwrf_reader
velox_dwio_dwrf_writer
gflags::gflags
gtest
gtest_main
gmock
GTest::gtest
GTest::gtest_main
GTest::gmock
glog::glog
${FILESYSTEM})

Expand Down
Loading

0 comments on commit a6ca103

Please sign in to comment.