Commit 36dc39a0 authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

[t:4871] clean up compilation flags across the board

git-svn-id: file:///svn/toku/tokudb@44507 c7de825b-a66e-492c-adef-691d508d4ae1
parent c9a54f1f
......@@ -7,14 +7,14 @@ include(TokuSetupIntelCompiler)
project(TokuDB)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
include(TokuFeatureDetection)
include(TokuSetupCompiler)
include(TokuSetupCTest)
include(TokuThirdParty)
## everything needs these libraries
link_libraries(dl pthread z)
## need a way to change the name of libs we build
set(LIBTOKUPORTABILITY "tokuportability" CACHE STRING "Name of libtokuportability.so")
set(LIBTOKUDB "tokudb" CACHE STRING "Name of libtokudb.so")
......
......@@ -9,7 +9,7 @@ endfunction(add_c_defines)
if (CMAKE_SYSTEM_NAME MATCHES Darwin)
add_c_defines(DARWIN=1 _DARWIN_C_SOURCE)
elseif (CMAKE_SYSTEM_NAME MATCHES Linux)
add_c_defines(__linux__=1)
# add_c_defines(__linux__=1)
endif ()
## preprocessor definitions we want everywhere
......@@ -33,29 +33,6 @@ if (USE_GCOV)
endif ()
endif (USE_GCOV)
## 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
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
COMPILE_FLAGS "${lib_compile_flags} --coverage"
LINK_FLAGS "${lib_link_flags} --coverage"
)
target_link_libraries(${lib} gcov)
endforeach(lib)
endif (USE_GCOV)
endfunction(maybe_add_gcov_to_libraries)
include(CheckCCompilerFlag)
## adds a compiler flag if the compiler supports it
......@@ -138,13 +115,32 @@ set_cflags_if_supported(${WARN_CFLAGS})
## always want these
set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}")
## 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
COMPILE_FLAGS "${COMPILE_FLAGS} -fvisibility=hidden")
endforeach(target)
function(add_space_separated_property type obj propname val)
get_property(oldval ${type} ${obj} PROPERTY ${propname})
if (oldval MATCHES NOTFOUND)
set_property(${type} ${obj} PROPERTY ${propname} "${val}")
else ()
set_property(${type} ${obj} PROPERTY ${propname} "${oldval} ${val}")
endif ()
endfunction(add_space_separated_property)
function(set_targets_need_intel_libs)
if (CMAKE_C_COMPILER_ID STREQUAL Intel)
foreach(tgt ${ARGN})
target_link_libraries(${tgt} LINK_PUBLIC -Bstatic irc -Bdynamic c)
endforeach(tgt)
endif ()
endfunction(set_targets_visibility_hidden)
endfunction(set_targets_need_intel_libs)
## 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
function(maybe_add_gcov_to_libraries)
if (USE_GCOV)
foreach(lib ${ARGN})
add_space_separated_property(TARGET ${lib} COMPILE_FLAGS --coverage)
add_space_separated_property(TARGET ${lib} LINK_FLAGS --coverage)
target_link_libraries(${lib} gcov)
endforeach(lib)
endif (USE_GCOV)
endfunction(maybe_add_gcov_to_libraries)
......@@ -30,5 +30,7 @@ foreach(tokudb_bin ${both_bins} ${tokudbonly_bins})
add_executable(${tokudb_bin}-tokudb ${tokudb_bin}.c)
set_property(TARGET ${tokudb_bin}-tokudb APPEND PROPERTY
COMPILE_DEFINITIONS "TOKUDB;ENVDIR=\"${tokudb_bin}.c.tdb\"")
add_space_separated_property(TARGET ${tokudb_bin}-tokudb COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${tokudb_bin}-tokudb LINK_FLAGS -pie)
target_link_libraries(${tokudb_bin}-tokudb ${LIBTOKUPORTABILITY} ${LIBTOKUDB})
endforeach(tokudb_bin)
......@@ -8,6 +8,8 @@ set_source_files_properties(
PROPERTIES GENERATED TRUE)
add_executable(logformat logformat.c)
add_space_separated_property(TARGET logformat COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET logformat LINK_FLAGS -pie)
target_link_libraries(logformat ${LIBTOKUPORTABILITY})
add_custom_command(
......@@ -81,22 +83,20 @@ set(FT_SOURCES
add_library(ft SHARED ${FT_SOURCES})
add_library(ft_static STATIC ${FT_SOURCES})
## we're going to link this into libtokudb.so so it needs to have PIC
set_property(TARGET ft_static APPEND PROPERTY COMPILE_FLAGS "-fPIC")
add_space_separated_property(TARGET ft_static COMPILE_FLAGS -fPIC)
maybe_add_gcov_to_libraries(ft ft_static)
## depend on other generated targets
add_dependencies(ft install_tdb_h build_lzma)
add_dependencies(ft_static install_tdb_h build_lzma)
## link with tokuportability, and lzma (which should be static)
target_link_libraries(ft ${LIBTOKUPORTABILITY} lzma)
target_link_libraries(ft_static ${LIBTOKUPORTABILITY} lzma)
## link with lzma (which should be static) and link dependers with zlib
target_link_libraries(ft LINK_PRIVATE lzma)
target_link_libraries(ft LINK_INTERFACE_LIBRARIES ${ZLIB_LIBRARIES})
target_link_libraries(ft_static LINK_PRIVATE lzma)
if (CMAKE_C_COMPILER_ID STREQUAL Intel)
## don't link with default libs, those come with tokuportability, but we
## do need libc and we need the intel libirc (and it should be static to
## be redistributable)
target_link_libraries(ft -nodefaultlibs c -Bstatic irc -Bdynamic)
target_link_libraries(ft LINK_PRIVATE -nodefaultlibs)
endif ()
## conditionally use cilk
......@@ -117,11 +117,15 @@ set(bins
foreach(bin ${bins})
add_executable(${bin} ${bin}.c)
add_dependencies(${bin} install_tdb_h)
add_space_separated_property(TARGET ${bin} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${bin} LINK_FLAGS -pie)
target_link_libraries(${bin} ft ${LIBTOKUPORTABILITY})
add_executable(${bin}_static ${bin}.c)
add_dependencies(${bin} install_tdb_h)
target_link_libraries(${bin}_static ft_static ${LIBTOKUPORTABILITY_STATIC})
add_dependencies(${bin}_static install_tdb_h)
add_space_separated_property(TARGET ${bin}_static COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${bin}_static LINK_FLAGS -pie)
target_link_libraries(${bin}_static ft_static ${ZLIB_LIBRARIES} ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl)
endforeach(bin)
# link in math.h library just for this tool.
......
......@@ -30,6 +30,8 @@ if(BUILD_TESTING)
get_filename_component(base ${src} NAME_WE)
add_executable(${base} ${src})
target_link_libraries(${base} ft ${LIBTOKUPORTABILITY})
add_space_separated_property(TARGET ${base} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${base} LINK_FLAGS -pie)
set_property(TARGET ${base} APPEND PROPERTY
COMPILE_DEFINITIONS "__SRCFILE__=\"${src}\";TOKUSVNROOT=\"${toku_svn_root}\"")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${src}.ft_handle")
......
......@@ -84,9 +84,7 @@ usage (void) {
int
test_main (int argc, const char *argv[]) {
int max_threads = 1;
#if defined(__linux__) || defined(DARWIN)
int do_malloc_fail = 0;
#endif
int i;
for (i=1; i<argc; i++) {
......@@ -99,11 +97,9 @@ test_main (int argc, const char *argv[]) {
} else if (strcmp(arg, "-q") == 0) {
verbose = 0;
continue;
#if defined(__linux__) || defined(DARWIN)
} else if (strcmp(arg, "-malloc-fail") == 0) {
do_malloc_fail = 1;
continue;
#endif
} else
max_threads = atoi(arg);
}
......
......@@ -14,16 +14,13 @@ add_library(${LIBTOKUPORTABILITY} SHARED ${tokuportability_srcs})
add_library(${LIBTOKUPORTABILITY}_static STATIC ${tokuportability_srcs})
maybe_add_gcov_to_libraries(${LIBTOKUPORTABILITY} ${LIBTOKUPORTABILITY}_static)
set_property(TARGET ${LIBTOKUPORTABILITY} ${LIBTOKUPORTABILITY}_static APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE)
add_space_separated_property(TARGET ${LIBTOKUPORTABILITY}_static COMPILE_FLAGS -fPIC)
target_link_libraries(${LIBTOKUPORTABILITY} LINK_INTERFACE_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} dl)
if (INTEL_CC)
if (CMAKE_C_COMPILER_ID STREQUAL Intel)
## ignore warning about cilkrts linking dynamically
get_target_property(link_flags ${LIBTOKUPORTABILITY} LINK_FLAGS)
if (link_flags STREQUAL link_flags-NOTFOUND)
set(link_flags "")
endif ()
set_target_properties(${LIBTOKUPORTABILITY} PROPERTIES
LINK_FLAGS "${link_flags} -diag-disable 10237")
endif (INTEL_CC)
add_space_separated_property(TARGET ${LIBTOKUPORTABILITY} LINK_FLAGS "-diag-disable 10237")
endif ()
foreach(src file.c memory.c os_malloc.c portability.c toku_assert.c toku_rwlock.c)
set_property(SOURCE ${src} APPEND PROPERTY COMPILE_DEFINITIONS TOKU_ALLOW_DEPRECATED=1)
......
......@@ -12,14 +12,16 @@ if(BUILD_TESTING)
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wno-unused-result HAVE_WNO_UNUSED_RESULT)
if (HAVE_WNO_UNUSED_RESULT)
set_property(SOURCE try-leak-lost.c APPEND PROPERTY COMPILE_FLAGS -Wno-unused-result)
add_space_separated_property(SOURCE try-leak-lost.c COMPILE_FLAGS -Wno-unused-result)
endif ()
foreach(src ${srcs})
get_filename_component(test ${src} NAME_WE)
add_executable(${test} ${src})
target_link_libraries(${test} ${LIBTOKUPORTABILITY})
target_link_libraries(${test} ${LIBTOKUPORTABILITY} ${CMAKE_THREAD_LIBS_INIT})
add_space_separated_property(TARGET ${test} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${test} LINK_FLAGS -pie)
if(HAVE_CLOCK_REALTIME)
target_link_libraries(${test} rt)
else()
......
......@@ -21,32 +21,33 @@ set(tokudb_srcs
## make the shared library
add_library(${LIBTOKUDB} SHARED ${tokudb_srcs})
add_dependencies(${LIBTOKUDB} install_tdb_h)
target_link_libraries(${LIBTOKUDB} lock_tree_static range_tree_static ft_static)
target_link_libraries(${LIBTOKUDB} LINK_PRIVATE lock_tree_static range_tree_static ft_static)
target_link_libraries(${LIBTOKUDB} LINK_INTERFACE_LIBRARIES ${ZLIB_LIBRARIES})
## make the static library
add_library(${LIBTOKUDB}_static STATIC ${tokudb_srcs})
add_dependencies(${LIBTOKUDB}_static install_tdb_h)
target_link_libraries(${LIBTOKUDB}_static lock_tree_static range_tree_static ft_static)
add_space_separated_property(TARGET ${LIBTOKUDB}_static COMPILE_FLAGS -fPIC)
target_link_libraries(${LIBTOKUDB}_static LINK_PRIVATE lock_tree_static range_tree_static ft_static)
if (CMAKE_C_COMPILER_ID STREQUAL Intel)
target_link_libraries(${LIBTOKUDB} LINK_PRIVATE -nodefaultlibs)
target_link_libraries(${LIBTOKUDB}_static LINK_PRIVATE -nodefaultlibs)
endif ()
## add a version script and set -fvisibility=hidden for the shared library
configure_file(export.map . COPYONLY)
get_target_property(link_flags ${LIBTOKUDB} LINK_FLAGS)
if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
set_target_properties(${LIBTOKUDB} PROPERTIES
LINK_FLAGS "${LINK_FLAGS} -Wl,--version-script=export.map")
set_targets_visibility_hidden(${LIBTOKUDB})
add_space_separated_property(TARGET ${LIBTOKUDB} COMPILE_FLAGS -fvisibility=hidden)
add_space_separated_property(TARGET ${LIBTOKUDB} LINK_FLAGS "-Wl,--version-script=export.map")
endif ()
## add gcov and define _GNU_SOURCE
maybe_add_gcov_to_libraries(${LIBTOKUDB} ${LIBTOKUDB}_static)
set_property(TARGET ${LIBTOKUDB} ${LIBTOKUDB}_static APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE)
if (CMAKE_C_COMPILER_ID STREQUAL Intel)
## don't link with default libs, those come with tokuportability, but we
## do need libc and we need the intel libirc (and it should be static to
## be redistributable)
target_link_libraries(${LIBTOKUDB} -nodefaultlibs c -Bstatic irc -Bdynamic)
endif ()
set_targets_need_intel_libs(${LIBTOKUDB})
install(
TARGETS ${LIBTOKUDB}
......
......@@ -15,8 +15,7 @@ add_dependencies(lock_tree_tlog_static install_tdb_h)
## make the real library, it's going to go into libtokudb.so so it needs
## to be PIC
add_library(lock_tree_static STATIC ${lock_tree_srcs})
set_property(TARGET lock_tree_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
add_space_separated_property(TARGET lock_tree_static COMPILE_FLAGS "-fvisibility=hidden -fPIC")
set_property(TARGET lock_tree_static APPEND PROPERTY
COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS)
add_dependencies(lock_tree_static install_tdb_h)
......
......@@ -9,10 +9,12 @@ if(BUILD_TESTING)
add_executable(lt_${base}.${impl} ${src})
set_property(TARGET lt_${base}.${impl} APPEND PROPERTY
COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"")
add_space_separated_property(TARGET lt_${base}.${impl} COMPILE_FLAGS -fvisibility=hidden)
target_link_libraries(lt_${base}.${impl}
lock_tree_${impl}_static
range_tree_${impl}_static
ft
${ZLIB_LIBRARIES}
${LIBTOKUPORTABILITY}
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${base}.c.${impl}")
......
......@@ -11,8 +11,7 @@ add_dependencies(range_tree_tlog_static install_tdb_h)
## make the real library, it's going to go into libtokudb.so so it needs
## to be PIC
add_library(range_tree_static STATIC log_nooverlap.c)
set_property(TARGET range_tree_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
add_space_separated_property(TARGET range_tree_static COMPILE_FLAGS "-fvisibility=hidden -fPIC")
add_dependencies(range_tree_static install_tdb_h)
maybe_add_gcov_to_libraries(range_tree_lin_static range_tree_tlog_static range_tree_static)
......
......@@ -9,9 +9,11 @@ if(BUILD_TESTING)
add_executable(rt_${base}.${impl} ${src})
set_property(TARGET rt_${base}.${impl} APPEND PROPERTY
COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"")
add_space_separated_property(TARGET rt_${base}.${impl} COMPILE_FLAGS -fvisibility=hidden)
target_link_libraries(rt_${base}.${impl}
range_tree_${impl}_static
ft
${ZLIB_LIBRARIES}
${LIBTOKUPORTABILITY}
)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${base}.c.${impl}")
......
......@@ -319,6 +319,8 @@ if(BUILD_TESTING)
set_property(TARGET ${base}.tdb APPEND PROPERTY
COMPILE_DEFINITIONS "ENVDIR=\"dir.${src}.tdb\";USE_TDB;IS_TDB=1;TOKUDB=1")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${src}.tdb")
add_space_separated_property(TARGET ${base}.tdb COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${base}.tdb COMPILE_FLAGS -pie)
endforeach(bin)
if(BDB_FOUND)
......@@ -351,8 +353,10 @@ if(BUILD_TESTING)
add_executable(${prefix}_${binary} ${source})
target_link_libraries(${prefix}_${binary} ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
set_target_properties(${prefix}_${binary} PROPERTIES
COMPILE_DEFINITIONS "ENVDIR=\"dir.${prefix}_${source}.tdb\";USE_TDB;IS_TDB")
COMPILE_DEFINITIONS "ENVDIR=\"dir.${prefix}_${source}.tdb\";USE_TDB;IS_TDB=1;TOKUDB=1")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${prefix}_${source}.tdb")
add_space_separated_property(TARGET ${prefix}_${binary} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${prefix}_${binary} COMPILE_FLAGS -pie)
endfunction(add_custom_executable)
declare_custom_tests(test1426.tdb)
......
......@@ -5,12 +5,17 @@ foreach(util ${utils})
add_executable(${util} ${util}.c)
set_target_properties(${util} PROPERTIES
COMPILE_DEFINITIONS "IS_TDB=1;USE_TDB=1;TDB_IS_STATIC=0")
add_space_separated_property(TARGET ${util} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${util} LINK_FLAGS -pie)
target_link_libraries(${util} ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
add_executable(${util}_static ${util}.c)
set_target_properties(${util}_static PROPERTIES
COMPILE_DEFINITIONS "IS_TDB=1;USE_TDB=1;TDB_IS_STATIC=1")
target_link_libraries(${util}_static ${LIBTOKUDB}_static ${LIBTOKUPORTABILITY}_static)
add_space_separated_property(TARGET ${util}_static COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${util}_static LINK_FLAGS -pie)
target_link_libraries(${util}_static ${LIBTOKUDB}_static ${ZLIB_LIBRARIES} ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl)
set_targets_need_intel_libs(${util}_static)
if(BDB_FOUND)
add_executable(${util}.bdb ${util}.c)
......@@ -19,5 +24,6 @@ foreach(util ${utils})
set_target_properties(${util}.bdb PROPERTIES
INCLUDE_DIRECTORIES "${BDB_INCLUDE_DIR};${CMAKE_CURRENT_BINARY_DIR}/../toku_include;${CMAKE_CURRENT_SOURCE_DIR}/../toku_include;${CMAKE_CURRENT_SOURCE_DIR}/../portability;${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(${util}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
set_targets_need_intel_libs(${util}.bdb)
endif()
endforeach(util)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment