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 )
# If JVM_ARCH_DATA_MODEL is 32, compile all binaries as 32-bit.
# This variable is set by maven.
if ( JVM_ARCH_DATA_MODEL EQUAL 32 )
2012-07-01 22:47:48 +00:00
# force 32-bit code generation on amd64/x86_64, ppc64, sparc64
if ( CMAKE_COMPILER_IS_GNUCC AND CMAKE_SYSTEM_PROCESSOR MATCHES ".*64" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" )
set ( CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -m32" )
endif ( )
2012-06-11 18:34:40 +00:00
if ( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" )
set ( CMAKE_SYSTEM_PROCESSOR "i686" )
endif ( )
endif ( JVM_ARCH_DATA_MODEL EQUAL 32 )
# 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 )
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 )
find_package ( ZLIB REQUIRED )
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 )
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-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 } )
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
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 }
)
CONFIGURE_FILE ( ${ CMAKE_SOURCE_DIR } /config.h.cmake ${ CMAKE_BINARY_DIR } /config.h )
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
$ { 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
)
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 )