2014-07-17 17:44:55 +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 )
include ( JNIFlags.cmake NO_POLICY_SCOPE )
# 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 )
#
# This macro alters the behavior of find_package and find_library.
2014-07-22 19:55:03 +00:00
# It does this by setting the CMAKE_FIND_LIBRARY_SUFFIXES global variable.
2014-07-17 17:44:55 +00:00
# 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 "FreeBSD" )
# FreeBSD has always .so installed.
SET ( CMAKE_FIND_LIBRARY_SUFFIXES ".so" )
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 )
2014-07-22 19:55:03 +00:00
#Must identify where the generated headers have been placed
MESSAGE ( FATAL_ERROR "You must set the cmake variable GENERATED_JAVAH" )
2014-07-17 17:44:55 +00:00
endif ( NOT GENERATED_JAVAH )
find_package ( JNI REQUIRED )
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
# primitive configs
set ( PRFLAGS "-DSIMPLE_MEMCPY" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PRFLAGS} -Wall" )
2014-07-22 19:55:03 +00:00
set ( CMAKE_LD_FLAGS " ${ CMAKE_LD_FLAGS } -no-undefined -version-info 0:1:0
- L $ { _ J A V A _ H O M E } / j r e / l i b / a m d 6 4 / s e r v e r - l j v m " )
2014-07-17 17:44:55 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -g -O2 -DNDEBUG -fPIC" )
set ( D main/native/ )
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckCSourceCompiles )
#INCLUDE(CheckLibraryExists)
INCLUDE ( CheckIncludeFiles )
#CHECK_FUNCTION_EXISTS(sync_file_range HAVE_SYNC_FILE_RANGE)
#CHECK_FUNCTION_EXISTS(posix_fadvise HAVE_POSIX_FADVISE)
#CHECK_LIBRARY_EXISTS(dl dlopen "" NEED_LINK_DL)
CHECK_INCLUDE_FILES ( fcntl.h HAVE_FCNTL_H )
CHECK_INCLUDE_FILES ( malloc.h HAVE_MALLOC_H )
CHECK_INCLUDE_FILES ( mach/mach.h HAVE_MACH_MACH_H )
CHECK_INCLUDE_FILES ( memory.h HAVE_MEMORY_H )
CHECK_INCLUDE_FILES ( stddef.h HAVE_STDDEF_H )
CHECK_INCLUDE_FILES ( stdint.h HAVE_STDINT_H )
CHECK_INCLUDE_FILES ( stdlib.h HAVE_STDLIB_H )
CHECK_INCLUDE_FILES ( string.h HAVE_STRING_H )
CHECK_INCLUDE_FILES ( unistd.h HAVE_UNITSTD_H )
CHECK_FUNCTION_EXISTS ( clock_gettime HAVE_CLOCK_GETTIME )
CHECK_FUNCTION_EXISTS ( localtime_r HAVE_LOCALTIME_R )
CHECK_FUNCTION_EXISTS ( memset HAVE_MEMSET )
CHECK_FUNCTION_EXISTS ( strchr HAVE_STRCHR )
CHECK_FUNCTION_EXISTS ( strtoul HAVE_STRTOUL )
SET ( STORED_CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_LIBRARY_SUFFIXES )
set_find_shared_library_version ( "1" )
2014-07-22 19:55:03 +00:00
find_library ( SNAPPY_LIBRARY
2014-07-17 17:44:55 +00:00
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 } )
SET ( CMAKE_FIND_LIBRARY_SUFFIXES STORED_CMAKE_FIND_LIBRARY_SUFFIXES )
2014-07-22 19:55:03 +00:00
find_path ( SNAPPY_INCLUDE_DIR
2014-07-17 17:44:55 +00:00
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 )
GET_FILENAME_COMPONENT ( HADOOP_SNAPPY_LIBRARY ${ SNAPPY_LIBRARY } NAME )
set ( SNAPPY_SOURCE_FILES
" $ { D } / s r c / c o d e c / S n a p p y C o d e c . c c " )
else ( SNAPPY_LIBRARY AND SNAPPY_INCLUDE_DIR )
2014-08-06 07:32:49 +00:00
set ( SNAPPY_LIBRARY "" )
2014-07-17 17:44:55 +00:00
set ( SNAPPY_INCLUDE_DIR "" )
set ( SNAPPY_SOURCE_FILES "" )
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 )
2014-08-06 07:32:49 +00:00
CONFIGURE_FILE ( ${ CMAKE_SOURCE_DIR } /config.h.cmake ${ CMAKE_BINARY_DIR } /config.h )
2014-07-17 17:44:55 +00:00
include_directories (
2014-07-22 19:55:03 +00:00
$ { G E N E R A T E D _ J A V A H }
$ { D }
2014-07-17 17:44:55 +00:00
$ { D } / s r c
2014-07-22 19:55:03 +00:00
$ { D } / s r c / u t i l
$ { D } / s r c / l i b
$ { D } / t e s t
2014-07-17 17:44:55 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
2014-08-06 06:01:12 +00:00
$ { C M A K E _ B I N A R Y _ D I R }
2014-07-17 17:44:55 +00:00
$ { J N I _ 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 }
)
SET ( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE )
2014-07-22 19:55:03 +00:00
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
# macosx does not have -lrt
set ( NT_DEPEND_LIBRARY dl pthread z ${ SNAPPY_LIBRARY } ${ JAVA_JVM_LIBRARY } )
else ( ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
set ( NT_DEPEND_LIBRARY dl rt pthread z ${ SNAPPY_LIBRARY } ${ JAVA_JVM_LIBRARY } )
endif ( ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
2014-07-17 17:44:55 +00:00
add_dual_library ( nativetask
2014-08-06 06:01:12 +00:00
$ { C M A K E _ B I N A R Y _ D I R } / l z 4 . c
2014-07-17 17:44:55 +00:00
$ { D } / c i t y h a s h / c i t y . c c
$ { D } / s r c / c o d e c / B l o c k C o d e c . c c
$ { D } / s r c / c o d e c / G z i p C o d e c . c c
$ { D } / s r c / c o d e c / L z 4 C o d e c . c c
$ { S N A P P Y _ S O U R C E _ F I L E S }
$ { D } / s r c / h a n d l e r / B a t c h H a n d l e r . c c
$ { D } / s r c / h a n d l e r / M C o l l e c t o r O u t p u t H a n d l e r . c c
$ { D } / s r c / h a n d l e r / A b s t r a c t M a p H a n d l e r . c c
$ { D } / s r c / h a n d l e r / C o m b i n e H a n d l e r . c c
$ { D } / s r c / l i b / B u f f e r s . c c
$ { D } / s r c / l i b / B u f f e r S t r e a m . c c
$ { D } / s r c / l i b / C o m p r e s s i o n s . c c
$ { D } / s r c / l i b / P a r t i t i o n B u c k e t . c c
$ { D } / s r c / l i b / P a r t i t i o n B u c k e t I t e r a t o r . c c
$ { D } / s r c / l i b / F i l e S y s t e m . c c
$ { D } / s r c / l i b / I F i l e . c c
$ { D } / s r c / l i b / j n i u t i l s . c c
$ { D } / s r c / l i b / L o g . c c
$ { D } / s r c / l i b / M a p O u t p u t C o l l e c t o r . c c
$ { D } / s r c / l i b / M a p O u t p u t S p e c . c c
$ { D } / s r c / l i b / M e m o r y B l o c k . c c
$ { D } / s r c / l i b / M e r g e . c c
$ { D } / s r c / l i b / N a t i v e L i b r a r y . c c
$ { D } / s r c / l i b / I t e r a t o r . c c
$ { D } / s r c / l i b / N a t i v e O b j e c t F a c t o r y . c c
$ { D } / s r c / l i b / N a t i v e R u n t i m e J n i I m p l . c c
$ { D } / s r c / l i b / N a t i v e T a s k . c c
$ { D } / s r c / l i b / S p i l l I n f o . c c
$ { D } / s r c / l i b / P a t h . c c
$ { D } / s r c / l i b / S t r e a m s . c c
$ { D } / s r c / l i b / C o m b i n e r . c c
$ { D } / s r c / l i b / T a s k C o u n t e r s . c c
$ { D } / s r c / u t i l / C h e c k s u m . c c
$ { D } / s r c / u t i l / H a s h . c c
$ { D } / s r c / u t i l / R a n d o m . c c
$ { D } / s r c / u t i l / S t r i n g U t i l . c c
$ { D } / s r c / u t i l / S y n c U t i l s . c c
$ { D } / s r c / u t i l / T i m e r . c c
$ { D } / s r c / u t i l / W r i t a b l e U t i l s . c c
)
2014-07-22 19:55:03 +00:00
target_link_libraries ( nativetask ${ NT_DEPEND_LIBRARY } )
add_executable ( nttest
2014-07-17 17:44:55 +00:00
$ { D } / g t e s t / g t e s t - a l l . c c
2014-07-22 19:55:03 +00:00
$ { D } / t e s t / l i b / T e s t B y t e A r r a y . c c
$ { D } / t e s t / l i b / T e s t B y t e B u f f e r . c c
$ { D } / t e s t / l i b / T e s t C o m p a r a t o r F o r D u a l P i v o t Q u i c k S o r t . c c
$ { D } / t e s t / l i b / T e s t C o m p a r a t o r F o r S t d S o r t . c c
$ { D } / t e s t / l i b / T e s t F i x S i z e C o n t a i n e r . c c
$ { D } / t e s t / l i b / T e s t M e m o r y P o o l . c c
$ { D } / t e s t / l i b / T e s t I t e r a t o r . c c
$ { D } / t e s t / l i b / T e s t K V B u f f e r . c c
$ { D } / t e s t / l i b / T e s t M e m B l o c k I t e r a t o r . c c
$ { D } / t e s t / l i b / T e s t M e m o r y B l o c k . c c
$ { D } / t e s t / l i b / T e s t P a r t i t i o n B u c k e t . c c
$ { D } / t e s t / l i b / T e s t R e a d B u f f e r . c c
$ { D } / t e s t / l i b / T e s t R e a d W r i t e B u f f e r . c c
$ { D } / t e s t / l i b / T e s t T r a c k i n g C o l l e c t o r . c c
$ { D } / t e s t / u t i l / T e s t C h e c k s u m . c c
$ { D } / t e s t / u t i l / T e s t H a s h . c c
$ { D } / t e s t / u t i l / T e s t S t r i n g U t i l . c c
$ { D } / t e s t / u t i l / T e s t S y n c U t i l s . c c
$ { D } / t e s t / u t i l / T e s t W r i t a b l e U t i l s . c c
$ { D } / t e s t / T e s t C o m m a n d . c c
$ { D } / t e s t / T e s t C o n f i g . c c
$ { D } / t e s t / T e s t C o u n t e r . c c
$ { D } / t e s t / T e s t C o m p r e s s i o n s . c c
$ { D } / t e s t / T e s t F i l e S y s t e m . c c
$ { D } / t e s t / T e s t I F i l e . c c
$ { D } / t e s t / T e s t P r i m i t i v e s . c c
$ { D } / t e s t / T e s t S o r t . c c
$ { D } / t e s t / T e s t M a i n . c c
2014-07-17 17:44:55 +00:00
$ { D } / t e s t / t e s t _ c o m m o n s . c c )
2014-07-22 19:55:03 +00:00
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
# macos clang with libc++ does not have tr1/tuple, just tuple
SET_TARGET_PROPERTIES ( nttest PROPERTIES COMPILE_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1" )
ENDIF ( )
target_link_libraries ( nttest
n a t i v e t a s k _ s t a t i c
$ { N T _ D E P E N D _ L I B R A R Y }
2014-07-17 17:44:55 +00:00
)
IF ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
#
# By embedding '$ORIGIN' into the RPATH of libnativetask.so,
# dlopen will look in the directory containing libnativetask.so.
# However, $ORIGIN is not supported by all operating systems.
#
SET_TARGET_PROPERTIES ( nativetask
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 ( )
SET ( LIBNATIVETASK_VERSION "1.0.0" )
SET_TARGET_PROPERTIES ( nativetask PROPERTIES SOVERSION ${ LIBNATIVETASK_VERSION } )
dual_output_directory ( nativetask target/usr/local/lib )
output_directory ( nttest test )