From 6a3c5e0abd38beffff622e6ab656045d7f5b4e22 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 6 Nov 2026 16:52:29 +0800 Subject: [PATCH 1/2] ORC-2235: [C++] Preserve CMAKE_MODULE_PATH when dependency discovery fails --- c++/orcConfig.cmake.in | 25 +++------ c++/test/CMakeLists.txt | 12 ++++ c++/test/cmake/CMakeLists.txt | 100 ++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 17 deletions(-) create mode 100644 c++/test/cmake/CMakeLists.txt diff --git a/c++/orcConfig.cmake.in b/c++/orcConfig.cmake.in index c794822569..91d346d28f 100644 --- a/c++/orcConfig.cmake.in +++ b/c++/orcConfig.cmake.in @@ -35,24 +35,15 @@ set(ORC_SYSTEM_DEPENDENCIES "@ORC_SYSTEM_DEPENDENCIES@") -if(DEFINED CMAKE_MODULE_PATH) - set(ORC_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH}) -else() - unset(ORC_CMAKE_MODULE_PATH_OLD) -endif() -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - include(CMakeFindDependencyMacro) -foreach(dependency ${ORC_SYSTEM_DEPENDENCIES}) - find_dependency(${dependency}) -endforeach() - -if(DEFINED ORC_CMAKE_MODULE_PATH_OLD) - set(CMAKE_MODULE_PATH ${ORC_CMAKE_MODULE_PATH_OLD}) - unset(ORC_CMAKE_MODULE_PATH_OLD) -else() - unset(CMAKE_MODULE_PATH) -endif() +# find_dependency() returns from this file when a dependency is not found. +# Keep changes to CMAKE_MODULE_PATH local even on that early return. +block(SCOPE_FOR VARIABLES PROPAGATE orc_FOUND orc_NOT_FOUND_MESSAGE) + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + foreach(dependency ${ORC_SYSTEM_DEPENDENCIES}) + find_dependency(${dependency}) + endforeach() +endblock() include("${CMAKE_CURRENT_LIST_DIR}/orcTargets.cmake") diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt index 6d23e70839..db94f69dc6 100644 --- a/c++/test/CMakeLists.txt +++ b/c++/test/CMakeLists.txt @@ -97,3 +97,15 @@ if (WIN32) ENVIRONMENT "TZDIR=${TZDATA_DIR}" ) endif () + +foreach (dependency_found IN ITEMS TRUE FALSE) + foreach (module_path_state IN ITEMS UNSET EMPTY SET) + add_test (NAME orc-config-${dependency_found}-${module_path_state} + COMMAND ${CMAKE_COMMAND} + -DDEPENDENCY_FOUND=${dependency_found} + -DMODULE_PATH_STATE=${module_path_state} + -S "${CMAKE_CURRENT_SOURCE_DIR}/cmake" + -B "${CMAKE_CURRENT_BINARY_DIR}/cmake/${dependency_found}-${module_path_state}" + ) + endforeach () +endforeach () diff --git a/c++/test/cmake/CMakeLists.txt b/c++/test/cmake/CMakeLists.txt new file mode 100644 index 0000000000..25a478ef17 --- /dev/null +++ b/c++/test/cmake/CMakeLists.txt @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +cmake_minimum_required (VERSION 3.25.0) +project (orc-config-test NONE) + +include(CMakePackageConfigHelpers) + +set(package_dir "${CMAKE_CURRENT_BINARY_DIR}/package") +file(MAKE_DIRECTORY "${package_dir}/include") +set(ORC_SYSTEM_DEPENDENCIES OrcConfigTestPresent OrcConfigTestDependency) +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/../../orcConfig.cmake.in" + "${package_dir}/orcConfig.cmake" + INSTALL_DESTINATION .) + +# Use mock dependencies so the tests do not depend on installed libraries. +file(WRITE "${package_dir}/FindOrcConfigTestPresent.cmake" [=[ +set(OrcConfigTestPresent_FOUND TRUE) +add_library(OrcConfigTest::Present INTERFACE IMPORTED) +]=]) +file(WRITE "${package_dir}/FindOrcConfigTestDependency.cmake" [=[ +set(OrcConfigTestDependency_FOUND "${DEPENDENCY_FOUND}") +]=]) +file(WRITE "${package_dir}/orcTargets.cmake" [=[ +add_library(orc::orc UNKNOWN IMPORTED) +set_target_properties(orc::orc PROPERTIES + IMPORTED_CONFIGURATIONS RELEASE + IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/liborc.a" + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/include" + INTERFACE_LINK_LIBRARIES OrcConfigTest::Present) +]=]) + +if(MODULE_PATH_STATE STREQUAL "UNSET") + unset(CMAKE_MODULE_PATH) +elseif(MODULE_PATH_STATE STREQUAL "EMPTY") + set(CMAKE_MODULE_PATH "") +elseif(MODULE_PATH_STATE STREQUAL "SET") + set(caller_module_dir "${CMAKE_CURRENT_BINARY_DIR}/caller modules") + file(MAKE_DIRECTORY "${caller_module_dir}") + file(WRITE "${caller_module_dir}/FindOrcConfigTestCaller.cmake" + "set(OrcConfigTestCaller_FOUND TRUE)\n") + set(CMAKE_MODULE_PATH "${caller_module_dir};${CMAKE_CURRENT_BINARY_DIR}/other modules") +else() + message(FATAL_ERROR "Unknown module path state: ${MODULE_PATH_STATE}") +endif() +set(module_path_before "${CMAKE_MODULE_PATH}") + +find_package(orc CONFIG QUIET PATHS "${package_dir}" NO_DEFAULT_PATH) + +if(NOT "${CMAKE_MODULE_PATH}" STREQUAL "${module_path_before}") + message(FATAL_ERROR "orcConfig.cmake changed CMAKE_MODULE_PATH") +endif() +if(MODULE_PATH_STATE STREQUAL "UNSET") + if(DEFINED CMAKE_MODULE_PATH) + message(FATAL_ERROR "orcConfig.cmake defined CMAKE_MODULE_PATH") + endif() +elseif(NOT DEFINED CMAKE_MODULE_PATH) + message(FATAL_ERROR "orcConfig.cmake undefined CMAKE_MODULE_PATH") +endif() + +if(NOT TARGET OrcConfigTest::Present) + message(FATAL_ERROR "The dependency's imported target is not visible") +endif() +if(DEPENDENCY_FOUND) + if(NOT orc_FOUND OR NOT ORC_FOUND OR NOT TARGET orc::orc) + message(FATAL_ERROR "ORC was not found with all dependencies available") + endif() + if(NOT ORC_STATIC_LIB OR NOT ORC_INCLUDE_DIR OR NOT ORC_INCLUDE_DIRS) + message(FATAL_ERROR "ORC compatibility variables were not set") + endif() +else() + if(orc_FOUND) + message(FATAL_ERROR "ORC was found with a missing dependency") + endif() + if(NOT orc_NOT_FOUND_MESSAGE MATCHES "OrcConfigTestDependency") + message(FATAL_ERROR "The missing dependency diagnostic was not propagated") + endif() + if(TARGET orc::orc) + message(FATAL_ERROR "ORC targets were included despite a missing dependency") + endif() +endif() + +if(MODULE_PATH_STATE STREQUAL "SET") + find_package(OrcConfigTestCaller REQUIRED MODULE) +endif() From e02428ff649c088eae754c6fc065aa64fdeeca48 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 6 Nov 2026 17:03:48 +0800 Subject: [PATCH 2/2] ORC-2235: Remove CMake test infrastructure changes --- c++/test/CMakeLists.txt | 12 ---- c++/test/cmake/CMakeLists.txt | 100 ---------------------------------- 2 files changed, 112 deletions(-) delete mode 100644 c++/test/cmake/CMakeLists.txt diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt index db94f69dc6..6d23e70839 100644 --- a/c++/test/CMakeLists.txt +++ b/c++/test/CMakeLists.txt @@ -97,15 +97,3 @@ if (WIN32) ENVIRONMENT "TZDIR=${TZDATA_DIR}" ) endif () - -foreach (dependency_found IN ITEMS TRUE FALSE) - foreach (module_path_state IN ITEMS UNSET EMPTY SET) - add_test (NAME orc-config-${dependency_found}-${module_path_state} - COMMAND ${CMAKE_COMMAND} - -DDEPENDENCY_FOUND=${dependency_found} - -DMODULE_PATH_STATE=${module_path_state} - -S "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - -B "${CMAKE_CURRENT_BINARY_DIR}/cmake/${dependency_found}-${module_path_state}" - ) - endforeach () -endforeach () diff --git a/c++/test/cmake/CMakeLists.txt b/c++/test/cmake/CMakeLists.txt deleted file mode 100644 index 25a478ef17..0000000000 --- a/c++/test/cmake/CMakeLists.txt +++ /dev/null @@ -1,100 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -cmake_minimum_required (VERSION 3.25.0) -project (orc-config-test NONE) - -include(CMakePackageConfigHelpers) - -set(package_dir "${CMAKE_CURRENT_BINARY_DIR}/package") -file(MAKE_DIRECTORY "${package_dir}/include") -set(ORC_SYSTEM_DEPENDENCIES OrcConfigTestPresent OrcConfigTestDependency) -configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/../../orcConfig.cmake.in" - "${package_dir}/orcConfig.cmake" - INSTALL_DESTINATION .) - -# Use mock dependencies so the tests do not depend on installed libraries. -file(WRITE "${package_dir}/FindOrcConfigTestPresent.cmake" [=[ -set(OrcConfigTestPresent_FOUND TRUE) -add_library(OrcConfigTest::Present INTERFACE IMPORTED) -]=]) -file(WRITE "${package_dir}/FindOrcConfigTestDependency.cmake" [=[ -set(OrcConfigTestDependency_FOUND "${DEPENDENCY_FOUND}") -]=]) -file(WRITE "${package_dir}/orcTargets.cmake" [=[ -add_library(orc::orc UNKNOWN IMPORTED) -set_target_properties(orc::orc PROPERTIES - IMPORTED_CONFIGURATIONS RELEASE - IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/liborc.a" - INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/include" - INTERFACE_LINK_LIBRARIES OrcConfigTest::Present) -]=]) - -if(MODULE_PATH_STATE STREQUAL "UNSET") - unset(CMAKE_MODULE_PATH) -elseif(MODULE_PATH_STATE STREQUAL "EMPTY") - set(CMAKE_MODULE_PATH "") -elseif(MODULE_PATH_STATE STREQUAL "SET") - set(caller_module_dir "${CMAKE_CURRENT_BINARY_DIR}/caller modules") - file(MAKE_DIRECTORY "${caller_module_dir}") - file(WRITE "${caller_module_dir}/FindOrcConfigTestCaller.cmake" - "set(OrcConfigTestCaller_FOUND TRUE)\n") - set(CMAKE_MODULE_PATH "${caller_module_dir};${CMAKE_CURRENT_BINARY_DIR}/other modules") -else() - message(FATAL_ERROR "Unknown module path state: ${MODULE_PATH_STATE}") -endif() -set(module_path_before "${CMAKE_MODULE_PATH}") - -find_package(orc CONFIG QUIET PATHS "${package_dir}" NO_DEFAULT_PATH) - -if(NOT "${CMAKE_MODULE_PATH}" STREQUAL "${module_path_before}") - message(FATAL_ERROR "orcConfig.cmake changed CMAKE_MODULE_PATH") -endif() -if(MODULE_PATH_STATE STREQUAL "UNSET") - if(DEFINED CMAKE_MODULE_PATH) - message(FATAL_ERROR "orcConfig.cmake defined CMAKE_MODULE_PATH") - endif() -elseif(NOT DEFINED CMAKE_MODULE_PATH) - message(FATAL_ERROR "orcConfig.cmake undefined CMAKE_MODULE_PATH") -endif() - -if(NOT TARGET OrcConfigTest::Present) - message(FATAL_ERROR "The dependency's imported target is not visible") -endif() -if(DEPENDENCY_FOUND) - if(NOT orc_FOUND OR NOT ORC_FOUND OR NOT TARGET orc::orc) - message(FATAL_ERROR "ORC was not found with all dependencies available") - endif() - if(NOT ORC_STATIC_LIB OR NOT ORC_INCLUDE_DIR OR NOT ORC_INCLUDE_DIRS) - message(FATAL_ERROR "ORC compatibility variables were not set") - endif() -else() - if(orc_FOUND) - message(FATAL_ERROR "ORC was found with a missing dependency") - endif() - if(NOT orc_NOT_FOUND_MESSAGE MATCHES "OrcConfigTestDependency") - message(FATAL_ERROR "The missing dependency diagnostic was not propagated") - endif() - if(TARGET orc::orc) - message(FATAL_ERROR "ORC targets were included despite a missing dependency") - endif() -endif() - -if(MODULE_PATH_STATE STREQUAL "SET") - find_package(OrcConfigTestCaller REQUIRED MODULE) -endif()