2012-06-11 14:44:57 -04:00
#
# 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 2.6 FATAL_ERROR )
# Default to release builds
set ( CMAKE_BUILD_TYPE, Release )
2012-08-09 17:58:29 -04:00
include ( JNIFlags.cmake NO_POLICY_SCOPE )
2012-06-11 14:44:57 -04:00
# Compile a library with both shared and static variants
function ( add_dual_library LIBNAME )
add_library ( ${ LIBNAME } SHARED ${ ARGN } )
add_library ( ${ LIBNAME } _static STATIC ${ ARGN } )
set_target_properties ( ${ LIBNAME } _static PROPERTIES OUTPUT_NAME ${ LIBNAME } )
endfunction ( add_dual_library )
# Link both a static and a dynamic target against some libraries
function ( target_link_dual_libraries LIBNAME )
target_link_libraries ( ${ LIBNAME } ${ ARGN } )
target_link_libraries ( ${ LIBNAME } _static ${ ARGN } )
endfunction ( target_link_dual_libraries )
function ( output_directory TGT DIR )
SET_TARGET_PROPERTIES ( ${ TGT } PROPERTIES
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / $ { D I R } " )
SET_TARGET_PROPERTIES ( ${ TGT } PROPERTIES
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / $ { D I R } " )
SET_TARGET_PROPERTIES ( ${ TGT } PROPERTIES
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / $ { D I R } " )
endfunction ( output_directory TGT DIR )
function ( dual_output_directory TGT DIR )
output_directory ( ${ TGT } "${DIR}" )
output_directory ( ${ TGT } _static "${DIR}" )
endfunction ( dual_output_directory TGT DIR )
2012-10-15 13:44:08 -04:00
#
# 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" )
2012-10-23 11:37:38 -04:00
ELSEIF ( ${ CMAKE_SYSTEM_NAME } MATCHES "FreeBSD" )
# FreeBSD has always .so installed.
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ".so" )
2012-10-15 13:44:08 -04:00
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 )
2014-10-29 22:38:52 -04:00
#
# Alter the behavior of find_package and find_library so that we find only
# shared libraries without any version suffix. You should save
# CMAKE_FIND_LIBRARY_SUFFIXES before calling this function and restore it
# afterwards.
#
macro ( set_find_shared_library_without_version )
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
# Mac OS uses .dylib
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" )
ELSEIF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )
# No effect
ELSE ( )
# Most UNIX variants use .so
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ".so" )
ENDIF ( )
2014-10-30 13:37:24 -04:00
endmacro ( set_find_shared_library_without_version )
2014-10-29 22:38:52 -04:00
2012-06-11 14:44:57 -04:00
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 )
2012-10-15 13:44:08 -04:00
2014-10-29 22:38:52 -04:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_FIND_LIBRARY_SUFFIXES } )
2012-10-15 13:44:08 -04:00
set_find_shared_library_version ( "1" )
2012-06-11 14:44:57 -04:00
find_package ( ZLIB REQUIRED )
2014-10-29 22:38:52 -04:00
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ${ STORED_CMAKE_FIND_LIBRARY_SUFFIXES } )
2012-06-11 14:44:57 -04:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2" )
2013-02-25 17:08:33 -05:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_GNU_SOURCE" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" )
2012-06-11 14:44:57 -04:00
set ( D main/native/src/org/apache/hadoop )
2012-09-05 18:24:44 -04:00
set ( T main/native/src/test/org/apache/hadoop )
2012-06-11 14:44:57 -04:00
GET_FILENAME_COMPONENT ( HADOOP_ZLIB_LIBRARY ${ ZLIB_LIBRARIES } NAME )
2014-10-29 22:38:52 -04:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_FIND_LIBRARY_SUFFIXES } )
2013-03-06 18:16:33 -05:00
set_find_shared_library_version ( "1" )
find_package ( BZip2 QUIET )
if ( BZIP2_INCLUDE_DIR AND BZIP2_LIBRARIES )
GET_FILENAME_COMPONENT ( HADOOP_BZIP2_LIBRARY ${ BZIP2_LIBRARIES } NAME )
set ( BZIP2_SOURCE_FILES
" $ { D } / i o / c o m p r e s s / b z i p 2 / B z i p 2 C o m p r e s s o r . c "
" $ { D } / i o / c o m p r e s s / b z i p 2 / B z i p 2 D e c o m p r e s s o r . c " )
else ( BZIP2_INCLUDE_DIR AND BZIP2_LIBRARIES )
set ( BZIP2_SOURCE_FILES "" )
set ( BZIP2_INCLUDE_DIR "" )
IF ( REQUIRE_BZIP2 )
MESSAGE ( FATAL_ERROR "Required bzip2 library and/or header files could not be found." )
ENDIF ( REQUIRE_BZIP2 )
endif ( BZIP2_INCLUDE_DIR AND BZIP2_LIBRARIES )
2014-10-29 22:38:52 -04:00
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ${ STORED_CMAKE_FIND_LIBRARY_SUFFIXES } )
2013-03-06 18:16:33 -05:00
2012-06-11 14:44:57 -04:00
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckCSourceCompiles )
2012-10-23 11:37:38 -04:00
INCLUDE ( CheckLibraryExists )
2012-06-11 14:44:57 -04:00
CHECK_FUNCTION_EXISTS ( sync_file_range HAVE_SYNC_FILE_RANGE )
CHECK_FUNCTION_EXISTS ( posix_fadvise HAVE_POSIX_FADVISE )
2012-10-23 11:37:38 -04:00
CHECK_LIBRARY_EXISTS ( dl dlopen "" NEED_LINK_DL )
2012-06-11 14:44:57 -04:00
2014-10-29 22:38:52 -04:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_FIND_LIBRARY_SUFFIXES } )
2012-10-15 13:44:08 -04:00
set_find_shared_library_version ( "1" )
2012-08-01 17:27:12 -04:00
find_library ( SNAPPY_LIBRARY
N A M E S s n a p p y
P A T H S $ { C U S T O M _ S N A P P Y _ P R E F I X } $ { C U S T O M _ S N A P P Y _ P R E F I X } / l i b
$ { C U S T O M _ S N A P P Y _ P R E F I X } / l i b 6 4 $ { C U S T O M _ S N A P P Y _ L I B } )
2014-10-29 22:38:52 -04:00
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ${ STORED_CMAKE_FIND_LIBRARY_SUFFIXES } )
2012-08-01 17:27:12 -04:00
find_path ( SNAPPY_INCLUDE_DIR
N A M E S s n a p p y . h
P A T H S $ { C U S T O M _ S N A P P Y _ P R E F I X } $ { C U S T O M _ S N A P P Y _ P R E F I X } / i n c l u d e
$ { C U S T O M _ S N A P P Y _ I N C L U D E } )
if ( SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR )
2012-06-11 14:44:57 -04:00
GET_FILENAME_COMPONENT ( HADOOP_SNAPPY_LIBRARY ${ SNAPPY_LIBRARY } NAME )
set ( SNAPPY_SOURCE_FILES
" $ { D } / i o / c o m p r e s s / s n a p p y / S n a p p y C o m p r e s s o r . c "
" $ { D } / i o / c o m p r e s s / s n a p p y / S n a p p y D e c o m p r e s s o r . c " )
2012-08-01 17:27:12 -04:00
else ( SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR )
2012-06-11 14:44:57 -04:00
set ( SNAPPY_INCLUDE_DIR "" )
set ( SNAPPY_SOURCE_FILES "" )
2012-08-01 17:27:12 -04:00
IF ( REQUIRE_SNAPPY )
MESSAGE ( FATAL_ERROR "Required snappy library could not be found. SNAPPY_LIBRARY=${SNAPPY_LIBRARY}, SNAPPY_INCLUDE_DIR=${SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_INCLUDE_DIR=${CUSTOM_SNAPPY_INCLUDE_DIR}, CUSTOM_SNAPPY_PREFIX=${CUSTOM_SNAPPY_PREFIX}, CUSTOM_SNAPPY_INCLUDE=${CUSTOM_SNAPPY_INCLUDE}" )
ENDIF ( REQUIRE_SNAPPY )
endif ( SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR )
2012-06-11 14:44:57 -04:00
2014-10-29 22:38:52 -04:00
# Find the no-suffix version of libcrypto.
# See HADOOP-11216 for details.
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_FIND_LIBRARY_SUFFIXES } )
set_find_shared_library_without_version ( )
2014-08-26 13:38:28 -04:00
SET ( OPENSSL_NAME "crypto" )
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )
SET ( OPENSSL_NAME "eay32" )
ENDIF ( )
2014-10-29 22:38:52 -04:00
MESSAGE ( "CUSTOM_OPENSSL_PREFIX = ${CUSTOM_OPENSSL_PREFIX}" )
2014-08-26 13:38:28 -04:00
find_library ( OPENSSL_LIBRARY
N A M E S $ { O P E N S S L _ N A M E }
P A T H S $ { C U S T O M _ O P E N S S L _ P R E F I X } $ { C U S T O M _ O P E N S S L _ P R E F I X } / l i b
$ { C U S T O M _ O P E N S S L _ P R E F I X } / l i b 6 4 $ { C U S T O M _ O P E N S S L _ L I B } N O _ D E F A U L T _ P A T H )
2014-10-29 22:38:52 -04:00
find_library ( OPENSSL_LIBRARY NAMES ${ OPENSSL_NAME } )
2014-08-26 13:38:28 -04:00
find_path ( OPENSSL_INCLUDE_DIR
N A M E S o p e n s s l / e v p . h
P A T H S $ { C U S T O M _ O P E N S S L _ P R E F I X } $ { C U S T O M _ O P E N S S L _ P R E F I X } / i n c l u d e
$ { C U S T O M _ O P E N S S L _ I N C L U D E } N O _ D E F A U L T _ P A T H )
2014-10-29 22:38:52 -04:00
find_path ( OPENSSL_INCLUDE_DIR NAMES openssl/evp.h )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ${ STORED_CMAKE_FIND_LIBRARY_SUFFIXES } )
SET ( USABLE_OPENSSL 0 )
2014-08-26 13:38:28 -04:00
if ( OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR )
GET_FILENAME_COMPONENT ( HADOOP_OPENSSL_LIBRARY ${ OPENSSL_LIBRARY } NAME )
2014-10-29 22:38:52 -04:00
INCLUDE ( CheckCSourceCompiles )
SET ( OLD_CMAKE_REQUIRED_INCLUDES ${ CMAKE_REQUIRED_INCLUDES } )
SET ( CMAKE_REQUIRED_INCLUDES ${ OPENSSL_INCLUDE_DIR } )
CHECK_C_SOURCE_COMPILES ( "#include \" ${ OPENSSL_INCLUDE_DIR } /openssl/evp.h\ "\nint main(int argc, char **argv) { return !EVP_aes_256_ctr; }" HAS_NEW_ENOUGH_OPENSSL )
SET ( CMAKE_REQUIRED_INCLUDES ${ OLD_CMAKE_REQUIRED_INCLUDES } )
if ( NOT HAS_NEW_ENOUGH_OPENSSL )
MESSAGE ( "The OpenSSL library installed at ${OPENSSL_LIBRARY} is too old. You need a version at least new enough to have EVP_aes_256_ctr." )
else ( NOT HAS_NEW_ENOUGH_OPENSSL )
SET ( USABLE_OPENSSL 1 )
endif ( NOT HAS_NEW_ENOUGH_OPENSSL )
endif ( OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR )
if ( USABLE_OPENSSL )
2014-08-26 13:38:28 -04:00
SET ( OPENSSL_SOURCE_FILES
" $ { D } / c r y p t o / O p e n s s l C i p h e r . c "
" $ { D } / c r y p t o / r a n d o m / O p e n s s l S e c u r e R a n d o m . c " )
2014-10-29 22:38:52 -04:00
else ( USABLE_OPENSSL )
2014-12-04 15:51:42 -05:00
MESSAGE ( "Cannot find a usable OpenSSL library. OPENSSL_LIBRARY=${OPENSSL_LIBRARY}, OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}, CUSTOM_OPENSSL_LIB=${CUSTOM_OPENSSL_LIB}, CUSTOM_OPENSSL_PREFIX=${CUSTOM_OPENSSL_PREFIX}, CUSTOM_OPENSSL_INCLUDE=${CUSTOM_OPENSSL_INCLUDE}" )
2014-08-26 13:38:28 -04:00
IF ( REQUIRE_OPENSSL )
2014-10-29 22:38:52 -04:00
MESSAGE ( FATAL_ERROR "Terminating build because require.openssl was specified." )
2014-08-26 13:38:28 -04:00
ENDIF ( REQUIRE_OPENSSL )
2014-10-29 22:38:52 -04:00
SET ( OPENSSL_LIBRARY "" )
SET ( OPENSSL_INCLUDE_DIR "" )
SET ( OPENSSL_SOURCE_FILES "" )
endif ( USABLE_OPENSSL )
2014-08-26 13:38:28 -04:00
2012-06-11 14:44:57 -04:00
include_directories (
$ { G E N E R A T E D _ J A V A H }
m a i n / n a t i v e / s r c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c
$ { C M A K E _ B I N A R Y _ D I R }
$ { J N I _ I N C L U D E _ D I R S }
$ { Z L I B _ I N C L U D E _ D I R S }
2013-03-06 18:16:33 -05:00
$ { B Z I P 2 _ I N C L U D E _ D I R }
2012-06-11 14:44:57 -04:00
$ { S N A P P Y _ I N C L U D E _ D I R }
2014-08-26 13:38:28 -04:00
$ { O P E N S S L _ I N C L U D E _ D I R }
2012-09-05 18:24:44 -04:00
$ { D } / u t i l
2012-06-11 14:44:57 -04:00
)
CONFIGURE_FILE ( ${ CMAKE_SOURCE_DIR } /config.h.cmake ${ CMAKE_BINARY_DIR } /config.h )
2012-09-05 18:24:44 -04:00
add_executable ( test_bulk_crc32
$ { D } / u t i l / b u l k _ c r c 3 2 . c
$ { T } / u t i l / t e s t _ b u l k _ c r c 3 2 . c
)
2012-09-17 15:30:40 -04:00
SET ( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
2012-06-11 14:44:57 -04:00
add_dual_library ( hadoop
2013-05-16 03:02:57 -04:00
m a i n / n a t i v e / s r c / e x c e p t i o n . c
2012-06-11 14:44:57 -04:00
$ { D } / i o / c o m p r e s s / l z 4 / L z 4 C o m p r e s s o r . c
$ { D } / i o / c o m p r e s s / l z 4 / L z 4 D e c o m p r e s s o r . c
$ { D } / i o / c o m p r e s s / l z 4 / l z 4 . c
2013-08-05 17:12:23 -04:00
$ { D } / i o / c o m p r e s s / l z 4 / l z 4 h c . c
2012-06-11 14:44:57 -04:00
$ { S N A P P Y _ S O U R C E _ F I L E S }
2014-08-26 13:38:28 -04:00
$ { O P E N S S L _ S O U R C E _ F I L E S }
2012-06-11 14:44:57 -04:00
$ { D } / i o / c o m p r e s s / z l i b / Z l i b C o m p r e s s o r . c
$ { D } / i o / c o m p r e s s / z l i b / Z l i b D e c o m p r e s s o r . c
2013-03-06 18:16:33 -05:00
$ { B Z I P 2 _ S O U R C E _ F I L E S }
2012-06-11 14:44:57 -04:00
$ { D } / i o / n a t i v e i o / N a t i v e I O . c
$ { D } / i o / n a t i v e i o / e r r n o _ e n u m . c
$ { D } / i o / n a t i v e i o / f i l e _ d e s c r i p t o r . c
2014-01-31 21:31:14 -05:00
$ { D } / i o / n a t i v e i o / S h a r e d F i l e D e s c r i p t o r F a c t o r y . c
2013-05-16 03:02:57 -04:00
$ { D } / n e t / u n i x / D o m a i n S o c k e t . c
2014-01-31 21:31:14 -05:00
$ { D } / n e t / u n i x / D o m a i n S o c k e t W a t c h e r . c
2012-06-11 14:44:57 -04:00
$ { D } / s e c u r i t y / J n i B a s e d U n i x G r o u p s M a p p i n g . c
$ { D } / s e c u r i t y / J n i B a s e d U n i x G r o u p s N e t g r o u p M a p p i n g . c
2013-06-24 12:25:52 -04:00
$ { D } / s e c u r i t y / h a d o o p _ g r o u p _ i n f o . c
$ { D } / s e c u r i t y / h a d o o p _ u s e r _ i n f o . c
2012-10-02 20:10:22 -04:00
$ { D } / u t i l / N a t i v e C o d e L o a d e r . c
2012-06-11 14:44:57 -04:00
$ { D } / u t i l / N a t i v e C r c 3 2 . c
$ { D } / u t i l / b u l k _ c r c 3 2 . c
)
2012-10-23 11:37:38 -04:00
if ( NEED_LINK_DL )
set ( LIB_DL dl )
endif ( NEED_LINK_DL )
2012-09-17 15:30:40 -04:00
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
#
# By embedding '$ORIGIN' into the RPATH of libhadoop.so,
# dlopen will look in the directory containing libhadoop.so.
# However, $ORIGIN is not supported by all operating systems.
#
SET_TARGET_PROPERTIES ( hadoop
P R O P E R T I E S I N S T A L L _ R P A T H " \ $ O R I G I N / " )
ENDIF ( )
2012-06-11 14:44:57 -04:00
target_link_dual_libraries ( hadoop
2012-10-23 11:37:38 -04:00
$ { L I B _ D L }
2012-06-11 14:44:57 -04:00
$ { J A V A _ J V M _ L I B R A R Y }
)
SET ( LIBHADOOP_VERSION "1.0.0" )
SET_TARGET_PROPERTIES ( hadoop PROPERTIES
S O V E R S I O N $ { L I B H A D O O P _ V E R S I O N } )
dual_output_directory ( hadoop target/usr/local/lib )