2012-06-11 18:34:40 +00: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 21:58:21 +00:00
include ( JNIFlags.cmake NO_POLICY_SCOPE )
2012-06-11 18:34:40 +00: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 17:44:02 +00: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 15:32:25 +00:00
ELSEIF ( ${ CMAKE_SYSTEM_NAME } MATCHES "FreeBSD" )
# FreeBSD has always .so installed.
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ".so" )
2012-10-15 17:44:02 +00: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 )
2012-06-11 18:34:40 +00: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 17:44:02 +00:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
2012-06-11 18:34:40 +00:00
find_package ( ZLIB REQUIRED )
2012-10-15 17:44:02 +00:00
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
2012-06-11 18:34:40 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2" )
2013-02-25 22:07:45 +00: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 18:34:40 +00:00
set ( D main/native/src/org/apache/hadoop )
2012-09-05 22:19:40 +00:00
set ( T main/native/src/test/org/apache/hadoop )
2012-06-11 18:34:40 +00:00
GET_FILENAME_COMPONENT ( HADOOP_ZLIB_LIBRARY ${ ZLIB_LIBRARIES } NAME )
2013-03-06 23:10:12 +00:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
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 )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
2012-06-11 18:34:40 +00:00
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckCSourceCompiles )
2012-10-23 15:32:25 +00:00
INCLUDE ( CheckLibraryExists )
2012-06-11 18:34:40 +00:00
CHECK_FUNCTION_EXISTS ( sync_file_range HAVE_SYNC_FILE_RANGE )
CHECK_FUNCTION_EXISTS ( posix_fadvise HAVE_POSIX_FADVISE )
2012-10-23 15:32:25 +00:00
CHECK_LIBRARY_EXISTS ( dl dlopen "" NEED_LINK_DL )
2012-06-11 18:34:40 +00:00
2012-10-15 17:44:02 +00:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
2012-08-01 21:23:10 +00: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 } )
2012-10-15 17:44:02 +00:00
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
2012-08-01 21:23:10 +00: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 18:34:40 +00: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 21:23:10 +00:00
else ( SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR )
2012-06-11 18:34:40 +00:00
set ( SNAPPY_INCLUDE_DIR "" )
set ( SNAPPY_SOURCE_FILES "" )
2012-08-01 21:23:10 +00: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 18:34:40 +00:00
2014-07-03 23:40:31 +00:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1.0.0" )
SET ( OPENSSL_NAME "crypto" )
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Windows" )
SET ( OPENSSL_NAME "eay32" )
ENDIF ( )
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 )
find_library ( OPENSSL_LIBRARY
N A M E S $ { O P E N S S L _ N A M E } )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
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 )
find_path ( OPENSSL_INCLUDE_DIR
N A M E S o p e n s s l / e v p . h )
if ( OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR )
GET_FILENAME_COMPONENT ( HADOOP_OPENSSL_LIBRARY ${ OPENSSL_LIBRARY } NAME )
SET ( OPENSSL_SOURCE_FILES
2014-07-12 01:29:26 +00:00
" $ { 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-07-03 23:40:31 +00:00
else ( OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR )
SET ( OPENSSL_INCLUDE_DIR "" )
SET ( OPENSSL_SOURCE_FILES "" )
IF ( REQUIRE_OPENSSL )
MESSAGE ( FATAL_ERROR "Required openssl library could not be found. OPENSSL_LIBRARY=${OPENSSL_LIBRARY}, OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}, CUSTOM_OPENSSL_INCLUDE_DIR=${CUSTOM_OPENSSL_INCLUDE_DIR}, CUSTOM_OPENSSL_PREFIX=${CUSTOM_OPENSSL_PREFIX}, CUSTOM_OPENSSL_INCLUDE=${CUSTOM_OPENSSL_INCLUDE}" )
ENDIF ( REQUIRE_OPENSSL )
endif ( OPENSSL_LIBRARY AND OPENSSL_INCLUDE_DIR )
2012-06-11 18:34:40 +00: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 23:10:12 +00:00
$ { B Z I P 2 _ I N C L U D E _ D I R }
2012-06-11 18:34:40 +00:00
$ { S N A P P Y _ I N C L U D E _ D I R }
2014-07-03 23:40:31 +00:00
$ { O P E N S S L _ I N C L U D E _ D I R }
2012-09-05 22:19:40 +00:00
$ { D } / u t i l
2012-06-11 18:34:40 +00:00
)
CONFIGURE_FILE ( ${ CMAKE_SOURCE_DIR } /config.h.cmake ${ CMAKE_BINARY_DIR } /config.h )
2012-09-05 22:19:40 +00: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 19:30:07 +00:00
SET ( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
2012-06-11 18:34:40 +00:00
add_dual_library ( hadoop
2013-01-09 21:37:34 +00: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 18:34:40 +00: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 21:10:54 +00:00
$ { D } / i o / c o m p r e s s / l z 4 / l z 4 h c . c
2012-06-11 18:34:40 +00:00
$ { S N A P P Y _ S O U R C E _ F I L E S }
2014-07-03 23:40:31 +00:00
$ { O P E N S S L _ S O U R C E _ F I L E S }
2012-06-11 18:34:40 +00: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 23:10:12 +00:00
$ { B Z I P 2 _ S O U R C E _ F I L E S }
2012-06-11 18:34:40 +00: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-02-01 02:25:33 +00: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-01-09 21:37:34 +00:00
$ { D } / n e t / u n i x / D o m a i n S o c k e t . c
2014-02-01 02:25:33 +00: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 18:34:40 +00: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 16:21:18 +00: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-03 00:06:39 +00: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 18:34:40 +00: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 15:32:25 +00:00
if ( NEED_LINK_DL )
set ( LIB_DL dl )
endif ( NEED_LINK_DL )
2012-09-17 19:30:07 +00: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 18:34:40 +00:00
target_link_dual_libraries ( hadoop
2012-10-23 15:32:25 +00:00
$ { L I B _ D L }
2012-06-11 18:34:40 +00: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 )