@ -2,11 +2,10 @@ function(add_c_defines)
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${ ARGN } )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS ${ ARGN } )
endfunction ( add_c_defines )
endfunction ( add_c_defines )
# # o s n a m e detection ( threadpool-test.cc needs this )
if ( CMAKE_SYSTEM_NAME MATCHES Darwin )
if ( APPLE )
add_c_defines ( DARWIN=1 _DARWIN_C_SOURCE )
add_c_defines ( DARWIN=1 _DARWIN_C_SOURCE )
elseif ( CMAKE_SYSTEM_NAME MATCHES Linux )
# add_c_defines ( __linux__=1 )
message ( WARNING "Setting TOKU_ALLOW_DEPRECATED on Darwin and with clang. TODO: find a portable way to deprecate, and remove this." )
add_c_defines ( TOKU_ALLOW_DEPRECATED )
endif ( )
endif ( )
# # p r e p r o c e s s o r d e f i n i t i o n s w e w a n t e v e r y w h e r e
# # p r e p r o c e s s o r d e f i n i t i o n s w e w a n t e v e r y w h e r e
@ -22,11 +21,6 @@ add_c_defines(
# # a d d T O K U _ P T H R E A D _ D E B U G f o r d e b u g b u i l d s
# # a d d T O K U _ P T H R E A D _ D E B U G f o r d e b u g b u i l d s
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG TOKU_PTHREAD_DEBUG )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG TOKU_PTHREAD_DEBUG )
if ( CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_CXX_COMPILER_ID MATCHES Clang )
message ( WARNING "Setting TOKU_ALLOW_DEPRECATED on Darwin and with clang. TODO: remove this." )
add_c_defines ( TOKU_ALLOW_DEPRECATED )
endif ( )
# # c o v e r a g e
# # c o v e r a g e
option ( USE_GCOV "Use gcov for test coverage." OFF )
option ( USE_GCOV "Use gcov for test coverage." OFF )
if ( USE_GCOV )
if ( USE_GCOV )
@ -39,11 +33,6 @@ endif (USE_GCOV)
include ( CheckCCompilerFlag )
include ( CheckCCompilerFlag )
include ( CheckCXXCompilerFlag )
include ( CheckCXXCompilerFlag )
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # X c o d e n e e d s t o h a v e t h i s s e t m a n u a l l y .
# # O t h e r generators ( makefiles ) i g n o r e t h i s s e t t i n g .
set ( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
# # a d d s a c o m p i l e r f l a g i f t h e c o m p i l e r s u p p o r t s i t
# # a d d s a c o m p i l e r f l a g i f t h e c o m p i l e r s u p p o r t s i t
macro ( set_cflags_if_supported_named flag flagname )
macro ( set_cflags_if_supported_named flag flagname )
check_c_compiler_flag ( "${flag}" HAVE_C_ ${ flagname } )
check_c_compiler_flag ( "${flag}" HAVE_C_ ${ flagname } )
@ -94,6 +83,7 @@ set_cflags_if_supported(
- f n o - r t t i
- f n o - r t t i
- f n o - e x c e p t i o n s
- f n o - e x c e p t i o n s
)
)
# # set_cflags_if_supported_named ( "-Weffc++" -Weffcpp )
# # C l a n g h a s s t r i c t e r P O D c h e c k s . S o , o n l y e n a b l e t h i s w a r n i n g o n o u r o t h e r builds ( Linux + GCC )
# # C l a n g h a s s t r i c t e r P O D c h e c k s . S o , o n l y e n a b l e t h i s w a r n i n g o n o u r o t h e r builds ( Linux + GCC )
if ( NOT CMAKE_CXX_COMPILER_ID MATCHES Clang )
if ( NOT CMAKE_CXX_COMPILER_ID MATCHES Clang )
@ -102,43 +92,28 @@ if (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)
)
)
endif ( )
endif ( )
# # set_cflags_if_supported_named ( "-Weffc++" -Weffcpp )
# # t h i s h i t s w i t h o p t i m i z e d b u i l d s s o m e w h e r e i n f t l e a f _ s p l i t , w e d o n ' t
# # k n o w w h y b u t w e d o n ' t t h i n k i t ' s a b i g d e a l
set_ldflags_if_supported (
set_ldflags_if_supported (
- W n o - e r r o r = s t r i c t - o v e r f l o w
- W n o - e r r o r = s t r i c t - o v e r f l o w
)
)
# # s e t e x t r a d e b u g g i n g f l a g s a n d p r e p r o c e s s o r d e f i n i t i o n s
# # s e t e x t r a d e b u g g i n g f l a g s a n d p r e p r o c e s s o r d e f i n i t i o n s
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -ggdb - O0" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -ggdb - O0" )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG FORTIFY_SOURCE=2 )
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -O0" )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _ FORTIFY_SOURCE=2)
# # s e t e x t r a r e l e a s e f l a g s , w e o v e r w r i t e t h i s b e c a u s e t h e d e f a u l t p a s s e s - D N D E B U G a n d w e d o n ' t w a n t t h a t
if ( CMAKE_CXX_COMPILER_ID STREQUAL Clang AND CMAKE_SYSTEM_NAME STREQUAL Darwin )
set ( CMAKE_C_FLAGS_RELEASE "-g -O4" )
set ( CMAKE_CXX_FLAGS_RELEASE "-g -O4" )
else ( )
# # s e t e x t r a r e l e a s e f l a g s
if ( APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang )
# h a v e t r i e d - f l t o a n d - O 4 , b o t h m a k e o u r s t a t i c a l l y l i n k e d e x e c u t a b l e s b r e a k a p p l e ' s l i n k e r
set ( CMAKE_C_FLAGS_RELEASE "-g -O3" )
set ( CMAKE_C_FLAGS_RELEASE "-g -O3" )
set ( CMAKE_CXX_FLAGS_RELEASE "-g -O3" )
set ( CMAKE_CXX_FLAGS_RELEASE "-g -O3" )
# # c h e c k h o w t o d o i n t e r - p r o c e d u r a l o p t i m i z a t i o n
check_c_compiler_flag ( -flto HAVE_C_FLAG_FLTO )
check_c_compiler_flag ( -ipo HAVE_C_FLAG_IPO )
if ( HAVE_C_FLAG_FLTO )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto -fuse-linker-plugin" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fuse-linker-plugin" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g -fuse-linker-plugin" )
elseif ( HAVE_C_FLAG_IPO )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ip -ipo1" )
endif ( )
check_cxx_compiler_flag ( -flto HAVE_CXX_FLAG_FLTO )
check_cxx_compiler_flag ( -ipo HAVE_CXX_FLAG_IPO )
if ( HAVE_CXX_FLAG_FLTO )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto -fuse-linker-plugin" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fuse-linker-plugin" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g -fuse-linker-plugin" )
elseif ( HAVE_CXX_FLAG_IPO )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ip -ipo1" )
endif ( )
else ( )
# w e o v e r w r i t e t h i s b e c a u s e t h e d e f a u l t p a s s e s - D N D E B U G a n d w e d o n ' t w a n t t h a t
set ( CMAKE_C_FLAGS_RELEASE "-g -O3 -flto -fuse-linker-plugin" )
set ( CMAKE_CXX_FLAGS_RELEASE "-g -O3 -flto -fuse-linker-plugin" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g -fuse-linker-plugin" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -g -fuse-linker-plugin" )
endif ( )
endif ( )
option ( USE_VALGRIND "Do not pass NVALGRIND to the compiler, because valgrind will be run on the generated executables." ON )
option ( USE_VALGRIND "Do not pass NVALGRIND to the compiler, because valgrind will be run on the generated executables." ON )
@ -146,80 +121,65 @@ if (NOT USE_VALGRIND)
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE NVALGRIND=1 )
set_property ( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE NVALGRIND=1 )
endif ( )
endif ( )
# # W e n e e d t o e x p l i c i t l y s e t t h i s s t a n d a r d l i b r a r y f o r X c o d e b u i l d s .
# # add_definitions ( -stdlib=libc++ )
if ( CMAKE_CXX_COMPILER_ID MATCHES Intel )
set ( CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}" )
# # m a k e s u r e i n t e l l i b s a r e l i n k e d s t a t i c a l l y
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel" )
# # s e t w a r n i n g s
set ( WARN_FLAGS
- W e x t r a
- 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
# # o t h e r f l a g s t o t r y :
# - W u n s a f e - l o o p - o p t i m i z a t i o n s
# - W p o i n t e r - a r i t h
# - W c + + - c o m p a t
# - W c + + 1 1 - c o m p a t
# - W w r i t e - s t r i n g s
# - W z e r o - a s - n u l l - p o i n t e r - c o n s t a n t
# - W l o g i c a l - o p
# - W v e c t o r - o p t i m i z a t i o n - p e r f o r m a n c e
)
# # d i s a b l e s o m e i n t e l - s p e c i f i c w a r n i n g s
set ( intel_warnings
9 4 # a l l o w a r r a y s o f l e n g t h 0
4 1 1 # a l l o w c o n s t s t r u c t m e m b e r s w i t h o u t a c o n s t r u c t o r
5 8 9 # d o n o t c o m p l a i n a b o u t g o t o t h a t s k i p s i n i t i a l i z a t i o n
1 2 9 2 # i c c lies ( it says it is "__GNUC__" , but it doesn't handle the resulting macroexpansions from glibc 2.15.37 ( which is designed for gcc 4.7, and appears in Fedora 17 )
2 2 5 9 # d o n o t c o m p l a i n a b o u t " n o n - p o i n t e r c o n v e r s i o n f r o m i n t t o u_int8_t ( and other small types ) m a y l o s e s i g n i f i c a n t b i t s " . t h i s p r o d u c e s t o o m a n y f a l s e p o s i t i v e s
1 1 0 0 0 # d o n o t r e m a r k a b o u t m u l t i - f i l e o p t i m i z a t i o n s , s i n g l e - f i l e o p t i m i z a t i o n s , a n d o b j e c t t e m p f i l e s
1 1 0 0 1
1 1 0 0 6
1 1 0 0 3 # d o n o t c o m p l a i n i f s o m e f i l e w a s c o m p i l e d w i t h o u t - i p o
)
string ( REGEX REPLACE ";" "," intel_warning_string "${intel_warnings}" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -diag-disable ${intel_warning_string}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-disable ${intel_warning_string}" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -diag-disable ${intel_warning_string}" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -diag-disable ${intel_warning_string}" )
option ( WARN_ABOUT_PACKED "Warn about useless __attribute__((packed)). This generates lots of warnings." OFF )
if ( WARN_ABOUT_PACKED )
list ( APPEND WARN_FLAGS -Wpacked -Wno-error=packed )
endif ( )
# # i c c d o e s - g d i f f e r e n t l y
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -debug all" )
set ( CMAKE_C_FLAGS "-Wcheck ${CMAKE_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -debug all" )
set ( CMAKE_CXX_FLAGS "-Wcheck ${CMAKE_CXX_FLAGS}" )
else ( )
set ( CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}" )
# # s e t g c c w a r n i n g s
set ( CMAKE_C_FLAGS "-Wextra ${CMAKE_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "-Wextra ${CMAKE_CXX_FLAGS}" )
set ( WARN_CFLAGS
- 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
)
if ( WARN_ABOUT_PACKED )
list ( APPEND WARN_CFLAGS -Wpacked -Wno-error=packed )
endif ( )
# # o t h e r f l a g s t o t r y :
# # - W u n s a f e - l o o p - o p t i m i z a t i o n s
# # - W p o i n t e r - a r i t h
# # - W c + + - c o m p a t
# # - W c + + 1 1 - c o m p a t
# # - W w r i t e - s t r i n g s
# # - W z e r o - a s - n u l l - p o i n t e r - c o n s t a n t
# # - W l o g i c a l - o p
# # - W v e c t o r - o p t i m i z a t i o n - p e r f o r m a n c e
if ( CMAKE_SYSTEM_NAME STREQUAL Darwin )
message ( WARNING "Disabling -Wcast-align and -Wshadow on osx. TODO: fix casting and shadowed declarations and re-enable them." )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL Clang )
message ( WARNING "Disabling -Wcast-align with clang. TODO: fix casting and re-enable it." )
list ( APPEND WARN_CFLAGS -Wshadow )
else ( )
list ( APPEND WARN_CFLAGS -Wcast-align -Wshadow )
endif ( )
endif ( )
if ( CMAKE_CXX_COMPILER_ID STREQUAL Clang )
message ( WARNING "Disabling -Wcast-align with clang. TODO: fix casting and re-enable it." )
else ( )
list ( APPEND WARN_FLAGS -Wcast-align )
endif ( )
set_cflags_if_supported ( ${ WARN_CFLAGS } )
set_cflags_if_supported ( ${ WARN_CFLAGS } )
# # a l w a y s w a n t t h e s e
# # a l w a y s w a n t t h e s e
set ( CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}" )
set ( CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}" )
set ( CMAKE_CXX_FLAGS "-Wall -Werror ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_CXX_FLAGS "-Wall -Werror ${CMAKE_CXX_FLAGS}" )
# # n e e d t o s e t - s t d l i b = l i b c + + t o g e t r e a l c + + 1 1 s u p p o r t o n d a r w i n
if ( APPLE )
if ( CMAKE_GENERATOR STREQUAL Xcode )
set ( CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
else ( )
set ( CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}" )
endif ( )
endif ( )
# p i c k l a n g u a g e d i a l e c t
set ( CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}" )
check_cxx_compiler_flag ( -std=c++11 HAVE_STDCXX11 )
check_cxx_compiler_flag ( -std=c++0x HAVE_STDCXX0X )
if ( HAVE_STDCXX11 )
set ( CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}" )
elseif ( HAVE_STDCXX0X )
set ( CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}" )
else ( )
message ( FATAL_ERROR "${CMAKE_CXX_COMPILER} doesn't support -std=c++11 or -std=c++0x, you need one that does." )
endif ( )
function ( add_space_separated_property type obj propname val )
function ( add_space_separated_property type obj propname val )
get_property ( oldval ${ type } ${ obj } PROPERTY ${ propname } )
get_property ( oldval ${ type } ${ obj } PROPERTY ${ propname } )
if ( oldval MATCHES NOTFOUND )
if ( oldval MATCHES NOTFOUND )
@ -229,14 +189,6 @@ function(add_space_separated_property type obj propname val)
endif ( )
endif ( )
endfunction ( add_space_separated_property )
endfunction ( add_space_separated_property )
function ( set_targets_need_intel_libs )
if ( CMAKE_CXX_COMPILER_ID STREQUAL Intel )
foreach ( tgt ${ ARGN } )
target_link_libraries ( ${ tgt } LINK_PUBLIC -Bstatic irc -Bdynamic stdc++ )
endforeach ( tgt )
endif ( )
endfunction ( set_targets_need_intel_libs )
# # t h i s f u n c t i o n m a k e s s u r e t h a t t h e l i b r a r i e s p a s s e d t o i t g e t c o m p i l e d
# # t h i s f u n c t i o n m a k e s s u r e t h a t t h e l i b r a r i e s p a s s e d t o i t g e t c o m p i l e d
# # w i t h g c o v - n e e d e d f l a g s , w e o n l y a d d t h o s e f l a g s t o o u r l i b r a r i e s
# # w i t h g c o v - n e e d e d f l a g s , w e o n l y a d d t h o s e f l a g s t o o u r l i b r a r i e s
# # b e c a u s e w e d o n ' t r e a l l y c a r e w h e t h e r o u r t e s t s g e t c o v e r e d
# # b e c a u s e w e d o n ' t r e a l l y c a r e w h e t h e r o u r t e s t s g e t c o v e r e d
@ -250,16 +202,10 @@ function(maybe_add_gcov_to_libraries)
endif ( USE_GCOV )
endif ( USE_GCOV )
endfunction ( maybe_add_gcov_to_libraries )
endfunction ( maybe_add_gcov_to_libraries )
# # a d d s - f v i s i b i l i t y = h i d d e n - f P I E t o c o m p i l e p h a s e
# # a d d s - pie ( or -Wl,-pie ) t o l i n k p h a s e
# # a d d s - f v i s i b i l i t y = h i d d e n
# # g o o d f o r b i n a r i e s
# # g o o d f o r b i n a r i e s
function ( add_common_options_to_binary_targets )
function ( add_common_options_to_binary_targets )
foreach ( tgt ${ ARGN } )
foreach ( tgt ${ ARGN } )
if ( CMAKE_C_COMPILER_ID STREQUAL Clang )
add_space_separated_property ( TARGET ${ tgt } COMPILE_FLAGS "-fvisibility=hidden" )
else ( )
add_space_separated_property ( TARGET ${ tgt } COMPILE_FLAGS "-fvisibility=hidden -fPIE" )
add_space_separated_property ( TARGET ${ tgt } LINK_FLAGS "-fPIE -pie" )
endif ( )
add_space_separated_property ( TARGET ${ tgt } COMPILE_FLAGS "-fvisibility=hidden" )
endforeach ( tgt )
endforeach ( tgt )
endfunction ( add_common_options_to_binary_targets )
endfunction ( add_common_options_to_binary_targets )