From 73e9366510d9778f8aa829d72adc14cca669dc5e Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Mon, 15 Oct 2012 17:44:02 +0000 Subject: [PATCH] HADOOP-8901. GZip and Snappy support may not work without unversioned libraries. Contributed by Colin Patrick McCabe. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1398416 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../hadoop-common/src/CMakeLists.txt | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index a49e7632fa..afc1eabfad 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -352,6 +352,9 @@ Release 2.0.3-alpha - Unreleased (Arpit Gupta via suresh) + HADOOP-8901. GZip and Snappy support may not work without unversioned + libraries (Colin Patrick McCabe via todd) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/CMakeLists.txt b/hadoop-common-project/hadoop-common/src/CMakeLists.txt index bff64d95a4..68c63abae3 100644 --- a/hadoop-common-project/hadoop-common/src/CMakeLists.txt +++ b/hadoop-common-project/hadoop-common/src/CMakeLists.txt @@ -50,12 +50,41 @@ function(dual_output_directory TGT DIR) output_directory(${TGT}_static "${DIR}") endfunction(dual_output_directory TGT DIR) +# +# This macro alters the behavior of find_package and find_library. +# It does this by setting the CMAKE_FIND_LIBRARY_SUFFIXES global variable. +# You should save that variable before calling this function and restore it +# after you have accomplished your goal. +# +# The behavior is altered in two ways: +# 1. We always find shared libraries, never static; +# 2. We find shared libraries with the given version number. +# +# On Windows this function is a no-op. Windows does not encode +# version number information information into library path names. +# +macro(set_find_shared_library_version LVERS) + IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + # Mac OS uses .dylib + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".${LVERS}.dylib") + ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # Windows doesn't support finding shared libraries by version. + ELSE() + # Most UNIX variants use .so + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so.${LVERS}") + ENDIF() +endmacro(set_find_shared_library_version LVERS) + if (NOT GENERATED_JAVAH) # Must identify where the generated headers have been placed MESSAGE(FATAL_ERROR "You must set the cmake variable GENERATED_JAVAH") endif (NOT GENERATED_JAVAH) find_package(JNI REQUIRED) + +SET(STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES) +set_find_shared_library_version("1") find_package(ZLIB REQUIRED) +SET(CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_FILE_OFFSET_BITS=64") @@ -69,10 +98,13 @@ INCLUDE(CheckCSourceCompiles) CHECK_FUNCTION_EXISTS(sync_file_range HAVE_SYNC_FILE_RANGE) CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE) +SET(STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES) +set_find_shared_library_version("1") find_library(SNAPPY_LIBRARY NAMES snappy PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/lib ${CUSTOM_SNAPPY_PREFIX}/lib64 ${CUSTOM_SNAPPY_LIB}) +SET(CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES) find_path(SNAPPY_INCLUDE_DIR NAMES snappy.h PATHS ${CUSTOM_SNAPPY_PREFIX} ${CUSTOM_SNAPPY_PREFIX}/include