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" )
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 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
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
2012-06-11 14:44:57 -04:00
find_package ( ZLIB REQUIRED )
2012-10-15 13:44:08 -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" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_REENTRANT -D_FILE_OFFSET_BITS=64" )
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 )
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckCSourceCompiles )
CHECK_FUNCTION_EXISTS ( sync_file_range HAVE_SYNC_FILE_RANGE )
CHECK_FUNCTION_EXISTS ( posix_fadvise HAVE_POSIX_FADVISE )
2012-10-15 13:44:08 -04:00
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
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 } )
2012-10-15 13:44:08 -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
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 }
$ { S N A P P Y _ 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
)
set_property ( SOURCE main.cpp PROPERTY INCLUDE_DIRECTORIES "\" -Werror\ " \" -Wall\ "" )
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
$ { 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
$ { S N A P P Y _ S O U R C E _ F I L E S }
$ { 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
$ { 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
$ { 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
$ { D } / s e c u r i t y / g e t G r o u p . 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-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
d l
$ { 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 )