Skip to content

Commit

Permalink
GH-35252: [C++] Use FindGTestAlt.cmake by ArrowTesting (#35253)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
kou authored and raulcd committed Apr 21, 2023
1 parent 897c37d commit 8a84f4f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cpp/cmake_modules/FindGTestAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions cpp/src/arrow/ArrowTestingConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down

0 comments on commit 8a84f4f

Please sign in to comment.