Skip to content

Commit cbe2618

Browse files
jonkeanekou
andauthored
GH-49369: [C++][R] Deal with validating libtool again (#49370)
### Rationale for this change Deal with bespoke frameworks on CRAN machines, ensure we can detect Apple-provided `libtool` as opposed to GNU `libtool`. Modernize cmake. ### What changes are included in this PR? Use `VALIDATOR` to validate `libtool`, a slightly more flexible regex ### Are these changes tested? Yes ### Are there any user-facing changes? No, well just one. * GitHub Issue: #49369 Lead-authored-by: Jonathan Keane <jkeane@gmail.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org> Signed-off-by: Jonathan Keane <jkeane@gmail.com>
1 parent 61741aa commit cbe2618

1 file changed

Lines changed: 43 additions & 16 deletions

File tree

cpp/cmake_modules/BuildUtils.cmake

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,55 @@ function(arrow_create_merged_static_lib output_target)
9191
endforeach()
9292

9393
if(APPLE)
94+
# Get the version string from a libtool binary.
95+
function(get_libtool_version item result_var)
96+
execute_process(COMMAND "${item}" -V
97+
OUTPUT_VARIABLE _version
98+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
99+
set(${result_var}
100+
"${_version}"
101+
PARENT_SCOPE)
102+
endfunction()
103+
104+
# Validator function to confirm that the libtool is Apple's libtool.
105+
# The apple-distributed libtool is what we want for bundling, but there is
106+
# a GNU libtool that has a name collision (and happens to be bundled with R, too).
107+
# We are not compatible with GNU libtool, so we need to avoid it.
108+
function(validate_apple_libtool result_var item)
109+
get_libtool_version("${item}" libtool_version)
110+
if(NOT "${libtool_version}" MATCHES ".*cctools.+([0-9.]+).*")
111+
set(${result_var}
112+
FALSE
113+
PARENT_SCOPE)
114+
endif()
115+
endfunction()
116+
94117
if(CMAKE_LIBTOOL)
95118
set(LIBTOOL_MACOS ${CMAKE_LIBTOOL})
119+
# Validate that CMAKE_LIBTOOL is Apple's libtool
120+
validate_apple_libtool(is_apple_libtool "${LIBTOOL_MACOS}")
121+
if(NOT is_apple_libtool)
122+
get_libtool_version("${LIBTOOL_MACOS}" _libtool_version_output)
123+
message(FATAL_ERROR "CMAKE_LIBTOOL does not appear to be Apple's libtool: ${LIBTOOL_MACOS}\nlibtool -V output: ${_libtool_version_output}"
124+
)
125+
endif()
96126
else()
97-
# The apple-distributed libtool is what we want for bundling, but there is
98-
# a GNU libtool that has a namecollision (and happens to be bundled with R, too).
99-
# We are not compatible with GNU libtool, so we need to avoid it.
100-
101-
# check in the obvious places first to find Apple's libtool
127+
# Check in the obvious places first to find Apple's libtool
102128
# HINTS is used before system paths and before PATHS, so we use that
103129
# even though hard coded paths should go in PATHS
104-
# TODO: use a VALIDATOR when we require cmake >= 3.25
105130
find_program(LIBTOOL_MACOS libtool
106-
HINTS /usr/bin /Library/Developer/CommandLineTools/usr/bin)
107-
endif()
108-
109-
# confirm that the libtool we found is Apple's libtool
110-
execute_process(COMMAND ${LIBTOOL_MACOS} -V
111-
OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
112-
OUTPUT_STRIP_TRAILING_WHITESPACE)
113-
if(NOT "${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
114-
message(FATAL_ERROR "libtool found appears not to be Apple's libtool: ${LIBTOOL_MACOS}"
115-
)
131+
HINTS /usr/bin /Library/Developer/CommandLineTools/usr/bin VALIDATOR
132+
validate_apple_libtool)
133+
if(NOT LIBTOOL_MACOS)
134+
# Find any libtool (without validation) to show its version in the error
135+
find_program(_any_libtool libtool)
136+
if(_any_libtool)
137+
get_libtool_version("${_any_libtool}" _libtool_version_output)
138+
endif()
139+
message(FATAL_ERROR "Could not find Apple's libtool. GNU libtool is not compatible."
140+
"\nFound libtool: ${_any_libtool}"
141+
"\nlibtool -V output: ${_libtool_version_output}")
142+
endif()
116143
endif()
117144

118145
set(BUNDLE_COMMAND ${LIBTOOL_MACOS} "-no_warning_for_no_symbols" "-static" "-o"

0 commit comments

Comments
 (0)