diff --git a/CMakeLists.txt b/CMakeLists.txt index b4677353da6..e37d1dbf992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -64,4 +64,4 @@ install( ) ## build tags -include(TokuBuildTagDatabases) +include(TokuBuildTagDatabases) \ No newline at end of file diff --git a/cmake_modules/TokuSetupCompiler.cmake b/cmake_modules/TokuSetupCompiler.cmake index 16b3b02d879..be236c528a6 100644 --- a/cmake_modules/TokuSetupCompiler.cmake +++ b/cmake_modules/TokuSetupCompiler.cmake @@ -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(set_targets_visibility_hidden) +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_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) diff --git a/db-benchmark-test/CMakeLists.txt b/db-benchmark-test/CMakeLists.txt index c6c14119b86..c5df415d0f0 100644 --- a/db-benchmark-test/CMakeLists.txt +++ b/db-benchmark-test/CMakeLists.txt @@ -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) diff --git a/ft/CMakeLists.txt b/ft/CMakeLists.txt index 5f7f291340a..fb3d3d19405 100644 --- a/ft/CMakeLists.txt +++ b/ft/CMakeLists.txt @@ -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. diff --git a/ft/tests/CMakeLists.txt b/ft/tests/CMakeLists.txt index c06a70ab9a7..90a9fd950ff 100644 --- a/ft/tests/CMakeLists.txt +++ b/ft/tests/CMakeLists.txt @@ -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") diff --git a/ft/tests/threadpool-test.c b/ft/tests/threadpool-test.c index 5fa550f148e..0860c734681 100644 --- a/ft/tests/threadpool-test.c +++ b/ft/tests/threadpool-test.c @@ -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