2013-04-17 00:00:25 -04:00
## set c99 dialect
add_definitions ( "-std=c99" )
function ( add_c_defines )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${ ARGN } )
endfunction ( add_c_defines )
## os name detection (threadpool-test.c needs this)
2013-04-17 00:00:27 -04:00
if ( CMAKE_SYSTEM_NAME MATCHES Darwin )
2013-04-17 00:00:25 -04:00
add_c_defines ( DARWIN=1 _DARWIN_C_SOURCE )
2013-04-17 00:00:27 -04:00
elseif ( CMAKE_SYSTEM_NAME MATCHES Linux )
2013-04-17 00:00:25 -04:00
add_c_defines ( __linux__=1 )
2013-04-17 00:00:27 -04:00
endif ( )
2013-04-17 00:00:25 -04:00
## preprocessor definitions we want everywhere
add_c_defines (
_ S V I D _ S O U R C E
_ X O P E N _ S O U R C E = 6 0 0
_ F I L E _ O F F S E T _ B I T S = 6 4
_ L A R G E F I L E 6 4 _ S O U R C E
)
2013-04-17 00:00:27 -04:00
if ( CMAKE_SYSTEM_NAME MATCHES Darwin )
2013-04-17 00:00:25 -04:00
message ( WARNING "Setting TOKU_ALLOW_DEPRECATED on Darwin. TODO: remove this." )
add_c_defines ( TOKU_ALLOW_DEPRECATED )
2013-04-17 00:00:27 -04:00
endif ( )
2013-04-17 00:00:25 -04:00
## coverage
option ( USE_GCOV "Use gcov for test coverage." OFF )
if ( USE_GCOV )
if ( NOT CMAKE_C_COMPILER_ID MATCHES GNU )
message ( FATAL_ERROR "Must use the GNU compiler to compile for test coverage." )
endif ( )
endif ( USE_GCOV )
2013-04-17 00:00:27 -04:00
## this function makes sure that the libraries passed to it get compiled
## with gcov-needed flags, we only add those flags to our libraries
## because we don't really care whether our tests get covered
2013-04-17 00:00:25 -04:00
function ( maybe_add_gcov_to_libraries )
if ( USE_GCOV )
foreach ( lib ${ ARGN } )
get_target_property ( lib_compile_flags ${ lib } COMPILE_FLAGS )
if ( lib_compile_flags MATCHES lib_compile_flags-NOTFOUND )
set ( lib_compile_flags "" )
endif ( )
get_target_property ( lib_link_flags ${ lib } LINK_FLAGS )
if ( lib_link_flags MATCHES lib_link_flags-NOTFOUND )
set ( lib_link_flags "" )
endif ( )
set_target_properties ( ${ lib } PROPERTIES
C O M P I L E _ F L A G S " $ { l i b _ c o m p i l e _ f l a g s } - - c o v e r a g e "
L I N K _ F L A G S " $ { l i b _ l i n k _ f l a g s } - - c o v e r a g e "
)
target_link_libraries ( ${ lib } gcov )
endforeach ( lib )
endif ( USE_GCOV )
endfunction ( maybe_add_gcov_to_libraries )
include ( CheckCCompilerFlag )
2013-04-17 00:00:27 -04:00
## adds a compiler flag if the compiler supports it
function ( set_cflags_if_supported )
foreach ( flag ${ ARGN } )
check_c_compiler_flag ( ${ flag } HAVE_ ${ flag } )
if ( HAVE_ ${ flag } )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" )
endif ( )
endforeach ( flag )
2013-04-17 00:00:27 -04:00
endfunction ( set_cflags_if_supported )
2013-04-17 00:00:25 -04:00
2013-04-17 00:00:27 -04:00
## disable some warnings
set_cflags_if_supported (
- W n o - s e l f - a s s i g n
- W n o - m i s s i n g - f i e l d - i n i t i a l i z e r s
- W n o - m a y b e - u n i n i t i a l i z e d
)
2013-04-17 00:00:25 -04:00
## set extra debugging flags and preprocessor definitions
2013-04-17 00:00:27 -04:00
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -ggdb -O0" )
2013-04-17 00:00:25 -04:00
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG FORTIFY_SOURCE=2 )
## set extra release flags
2013-04-17 00:00:27 -04:00
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3" )
2013-04-17 00:00:25 -04:00
## check how to do inter-procedural optimization
check_c_compiler_flag ( -flto HAVE_CC_FLAG_FLTO )
check_c_compiler_flag ( -ipo HAVE_CC_FLAG_IPO )
## add inter-procedural optimization flags
2013-04-17 00:00:27 -04:00
if ( HAVE_CC_FLAG_FLTO )
2013-04-17 00:00:25 -04:00
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto" )
2013-04-17 00:00:27 -04:00
elseif ( HAVE_CC_FLAG_IPO )
2013-04-17 00:00:25 -04:00
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ip -ipo1" )
2013-04-17 00:00:27 -04:00
endif ( )
2013-04-17 00:00:25 -04:00
2013-04-17 00:00:27 -04:00
if ( CMAKE_C_COMPILER_ID MATCHES Intel )
## make sure intel libs are linked statically
2013-04-17 00:00:26 -04:00
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel" )
2013-04-17 00:00:27 -04:00
## disable some intel-specific warnings
2013-04-17 00:00:25 -04:00
set ( intel_warnings
9 4 # allow arrays of length 0
5 8 9 # do not complain about goto that skips initialization
2 2 5 9 # do not complain about "non-pointer conversion from int to u_int8_t (and other small types) may lose significant bits". this produces too many false positives
1 1 0 0 0 # do not remark about multi-file optimizations, single-file optimizations, and object temp files
1 1 0 0 1
1 1 0 0 6
1 1 0 0 3 # do not complain if some file was compiled without -ipo
)
string ( REGEX REPLACE ";" "," intel_warning_string "${intel_warnings}" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -diag-disable ${intel_warning_string}" )
2013-04-17 00:00:27 -04:00
## icc does -g differently
2013-04-17 00:00:26 -04:00
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -debug all" )
2013-04-17 00:00:25 -04:00
2013-04-17 00:00:27 -04:00
## set icc warnings
set ( WARN_CFLAGS
- W a l l
- W c h e c k ## icc version of -Wextra
)
2013-04-17 00:00:26 -04:00
else ( )
2013-04-17 00:00:27 -04:00
## set gcc warnings
set ( WARN_CFLAGS
- W a l l
- W e x t r a
- W c a s t - a l i g n
- W b a d - f u n c t i o n - c a s t
- W n o - m i s s i n g - n o r e t u r n
- W s t r i c t - p r o t o t y p e s
- W m i s s i n g - p r o t o t y p e s
- W m i s s i n g - d e c l a r a t i o n s
- W p o i n t e r - a r i t h
- W m i s s i n g - f o r m a t - a t t r i b u t e
- W s h a d o w
)
2013-04-17 00:00:25 -04:00
endif ( )
2013-04-17 00:00:26 -04:00
2013-04-17 00:00:27 -04:00
set_cflags_if_supported ( ${ WARN_CFLAGS } )
2013-04-17 00:00:26 -04:00
## function for adding -fvisibility=hidden to targets
function ( set_targets_visibility_hidden )
if ( NOT CMAKE_C_COMPILER_ID STREQUAL "Intel" )
foreach ( target ${ ARGN } )
get_target_property ( flags ${ target } COMPILE_FLAGS )
set_target_properties ( ${ target } PROPERTIES
C O M P I L E _ F L A G S " $ { C O M P I L E _ F L A G S } - f v i s i b i l i t y = h i d d e n " )
endforeach ( target )
endif ( )
endfunction ( set_targets_visibility_hidden )