From 8a84f4f9b26b3268df4b9bdd5f58f4dc44d55d79 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 21 Apr 2023 09:03:40 +0900 Subject: [PATCH] GH-35252: [C++] Use FindGTestAlt.cmake by ArrowTesting (#35253) ### Rationale for this change `find_package(Arrow)` is failed when a project doesn't set `CMAKE_CXX_STANDARD`. ### What changes are included in this PR? * `find_package(Arrow)` doesn't need to use `FindGTestAlt.cmake`. `find_package(ArrowTesting)` needs it. * `FindGTestAlt.cmake` doesn't need to run availability check when it's called from `find_package(ArrowTesting)`. Because it's already done when Apache Arrow C++ is built. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * Closes: #35252 Authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- cpp/cmake_modules/FindGTestAlt.cmake | 2 +- cpp/cmake_modules/ThirdpartyToolchain.cmake | 17 ++++++++++++++--- cpp/src/arrow/ArrowTestingConfig.cmake.in | 18 ++++++++++++++++++ cpp/src/arrow/CMakeLists.txt | 10 ++++++++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/cpp/cmake_modules/FindGTestAlt.cmake b/cpp/cmake_modules/FindGTestAlt.cmake index 86aa262641858..77d4f39d9e0bf 100644 --- a/cpp/cmake_modules/FindGTestAlt.cmake +++ b/cpp/cmake_modules/FindGTestAlt.cmake @@ -36,7 +36,7 @@ endif() find_package(GTest ${find_package_args}) set(GTestAlt_FOUND ${GTest_FOUND}) -if(GTestAlt_FOUND) +if(GTestAlt_FOUND AND GTestAlt_NEED_CXX_STANDARD_CHECK) set(KEEP_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE) set(GTestAlt_CXX_STANDARD_TEST_SOURCE diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 8bd02a8672815..b5f9716722d0f 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -229,6 +229,7 @@ endmacro() macro(resolve_dependency DEPENDENCY_NAME) set(options) set(one_value_args + ARROW_CMAKE_PACKAGE_NAME FORCE_ANY_NEWER_VERSION HAVE_ALT IS_RUNTIME_DEPENDENCY @@ -290,8 +291,15 @@ macro(resolve_dependency DEPENDENCY_NAME) endif() endif() if(${DEPENDENCY_NAME}_SOURCE STREQUAL "SYSTEM" AND ARG_IS_RUNTIME_DEPENDENCY) - provide_find_module(${PACKAGE_NAME} "Arrow") - list(APPEND ARROW_SYSTEM_DEPENDENCIES ${PACKAGE_NAME}) + if(NOT ARG_ARROW_CMAKE_PACKAGE_NAME) + set(ARG_ARROW_CMAKE_PACKAGE_NAME "Arrow") + endif() + if(ARG_ARROW_CMAKE_PACKAGE_NAME STREQUAL "Arrow") + provide_find_module(${PACKAGE_NAME} "Arrow") + list(APPEND ARROW_SYSTEM_DEPENDENCIES ${PACKAGE_NAME}) + else() + provide_find_module(${PACKAGE_NAME} ${ARG_ARROW_CMAKE_PACKAGE_NAME}) + endif() if(ARROW_BUILD_STATIC) find_package(PkgConfig QUIET) foreach(ARG_PC_PACKAGE_NAME ${ARG_PC_PACKAGE_NAMES}) @@ -2220,11 +2228,14 @@ macro(build_gtest) endmacro() if(ARROW_TESTING) + set(GTestAlt_NEED_CXX_STANDARD_CHECK TRUE) resolve_dependency(GTest HAVE_ALT TRUE REQUIRED_VERSION - 1.10.0) + 1.10.0 + ARROW_CMAKE_PACKAGE_NAME + "ArrowTesting") if(GTest_SOURCE STREQUAL "SYSTEM") find_package(PkgConfig QUIET) diff --git a/cpp/src/arrow/ArrowTestingConfig.cmake.in b/cpp/src/arrow/ArrowTestingConfig.cmake.in index 87ee9e755e145..b65f6ef0d58b0 100644 --- a/cpp/src/arrow/ArrowTestingConfig.cmake.in +++ b/cpp/src/arrow/ArrowTestingConfig.cmake.in @@ -26,9 +26,27 @@ @PACKAGE_INIT@ +set(ARROW_GTEST_SOURCE "@GTest_SOURCE@") + include(CMakeFindDependencyMacro) find_dependency(Arrow) +if(DEFINED CMAKE_MODULE_PATH) + set(ARROW_TESTING_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH}) +else() + unset(ARROW_TESTING_CMAKE_MODULE_PATH_OLD) +endif() +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +if("${ARROW_GTEST_SOURCE}" STREQUAL "SYSTEM") + find_dependency(GTestAlt) +endif() +if(DEFINED ARROW_TESTING_CMAKE_MODULE_PATH_OLD) + set(CMAKE_MODULE_PATH ${ARROW_TESTING_CMAKE_MODULE_PATH_OLD}) + unset(ARROW_TESTING_CMAKE_MODULE_PATH_OLD) +else() + unset(CMAKE_MODULE_PATH) +endif() + include("${CMAKE_CURRENT_LIST_DIR}/ArrowTestingTargets.cmake") arrow_keep_backward_compatibility(ArrowTesting arrow_testing) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index fc1841a7ed767..f5a3bc407244b 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -702,6 +702,12 @@ endif() if(ARROW_TESTING) # that depend on gtest + set(ARROW_TESTING_SHARED_INSTALL_INTERFACE_LIBS Arrow::arrow_shared) + set(ARROW_TESTING_STATIC_INSTALL_INTERFACE_LIBS Arrow::arrow_static) + if(GTest_SOURCE STREQUAL "SYSTEM") + list(APPEND ARROW_TESTING_SHARED_INSTALL_INTERFACE_LIBS ${ARROW_GTEST_GTEST}) + list(APPEND ARROW_TESTING_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_GTEST_GTEST}) + endif() add_arrow_lib(arrow_testing CMAKE_PACKAGE_NAME ArrowTesting @@ -721,14 +727,14 @@ if(ARROW_TESTING) arrow_shared ${ARROW_GTEST_GTEST} SHARED_INSTALL_INTERFACE_LIBS - Arrow::arrow_shared + ${ARROW_TESTING_SHARED_INSTALL_INTERFACE_LIBS} STATIC_LINK_LIBS arrow::flatbuffers rapidjson::rapidjson arrow_static ${ARROW_GTEST_GTEST} STATIC_INSTALL_INTERFACE_LIBS - Arrow::arrow_static) + ${ARROW_TESTING_STATIC_INSTALL_INTERFACE_LIBS}) add_custom_target(arrow_testing) add_dependencies(arrow_testing ${ARROW_TESTING_LIBRARIES})