Commit e26f2532 authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

[t:4871] implement binary compilation options in a nicer way in cmake,

only do it for release builds, play nicer with multi-configuration
generators like vs and xcode


git-svn-id: file:///svn/toku/tokudb@44535 c7de825b-a66e-492c-adef-691d508d4ae1
parent 1a26abb9
...@@ -147,3 +147,17 @@ function(maybe_add_gcov_to_libraries) ...@@ -147,3 +147,17 @@ function(maybe_add_gcov_to_libraries)
endforeach(lib) endforeach(lib)
endif (USE_GCOV) endif (USE_GCOV)
endfunction(maybe_add_gcov_to_libraries) endfunction(maybe_add_gcov_to_libraries)
## adds -fvisibility=hidden -fPIE to compile phase
## adds -pie (or -Wl,-pie) to link phase
## good for binaries
function(add_common_options_to_binary_targets)
foreach(tgt ${ARGN})
add_space_separated_property(TARGET ${tgt} COMPILE_FLAGS_RELEASE "-fvisibility=hidden -fPIE")
if (CMAKE_C_COMPILER_ID STREQUAL Clang)
add_space_separated_property(TARGET ${tgt} LINK_FLAGS_RELEASE "-Wl,-pie")
else ()
add_space_separated_property(TARGET ${tgt} LINK_FLAGS_RELEASE "-pie")
endif ()
endforeach(tgt)
endfunction(add_common_options_to_binary_targets)
\ No newline at end of file
...@@ -23,6 +23,7 @@ if(BDB_FOUND) ...@@ -23,6 +23,7 @@ if(BDB_FOUND)
set_target_properties(${bdb_bin}-bdb PROPERTIES set_target_properties(${bdb_bin}-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}/..") 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(${bdb_bin}-bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES}) target_link_libraries(${bdb_bin}-bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
add_common_options_to_binary_targets(${bdb_bin}-bdb)
endforeach(bdb_bin) endforeach(bdb_bin)
endif() endif()
...@@ -30,7 +31,6 @@ foreach(tokudb_bin ${both_bins} ${tokudbonly_bins}) ...@@ -30,7 +31,6 @@ foreach(tokudb_bin ${both_bins} ${tokudbonly_bins})
add_executable(${tokudb_bin}-tokudb ${tokudb_bin}.c) add_executable(${tokudb_bin}-tokudb ${tokudb_bin}.c)
set_property(TARGET ${tokudb_bin}-tokudb APPEND PROPERTY set_property(TARGET ${tokudb_bin}-tokudb APPEND PROPERTY
COMPILE_DEFINITIONS "TOKUDB;ENVDIR=\"${tokudb_bin}.c.tdb\"") 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 ${LIBTOKUDB} ${LIBTOKUPORTABILITY}) target_link_libraries(${tokudb_bin}-tokudb ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
add_common_options_to_binary_targets(${tokudb_bin}-tokudb)
endforeach(tokudb_bin) endforeach(tokudb_bin)
...@@ -8,8 +8,7 @@ set_source_files_properties( ...@@ -8,8 +8,7 @@ set_source_files_properties(
PROPERTIES GENERATED TRUE) PROPERTIES GENERATED TRUE)
add_executable(logformat logformat.c) add_executable(logformat logformat.c)
add_space_separated_property(TARGET logformat COMPILE_FLAGS "-fvisibility=hidden -fPIE") add_common_options_to_binary_targets(logformat)
add_space_separated_property(TARGET logformat LINK_FLAGS -pie)
target_link_libraries(logformat ${LIBTOKUPORTABILITY}) target_link_libraries(logformat ${LIBTOKUPORTABILITY})
add_custom_command( add_custom_command(
...@@ -117,15 +116,13 @@ set(bins ...@@ -117,15 +116,13 @@ set(bins
foreach(bin ${bins}) foreach(bin ${bins})
add_executable(${bin} ${bin}.c) add_executable(${bin} ${bin}.c)
add_dependencies(${bin} install_tdb_h) 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}) target_link_libraries(${bin} ft ${LIBTOKUPORTABILITY})
add_executable(${bin}_static ${bin}.c) add_executable(${bin}_static ${bin}.c)
add_dependencies(${bin}_static install_tdb_h) 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 z ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl) target_link_libraries(${bin}_static ft_static z ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl)
add_common_options_to_binary_targets(${bin} ${bin}_static)
endforeach(bin) endforeach(bin)
# link in math.h library just for this tool. # link in math.h library just for this tool.
......
...@@ -30,8 +30,7 @@ if(BUILD_TESTING) ...@@ -30,8 +30,7 @@ if(BUILD_TESTING)
get_filename_component(base ${src} NAME_WE) get_filename_component(base ${src} NAME_WE)
add_executable(${base} ${src}) add_executable(${base} ${src})
target_link_libraries(${base} ft ${LIBTOKUPORTABILITY}) target_link_libraries(${base} ft ${LIBTOKUPORTABILITY})
add_space_separated_property(TARGET ${base} COMPILE_FLAGS "-fvisibility=hidden -fPIE") add_common_options_to_binary_targets(${base})
add_space_separated_property(TARGET ${base} LINK_FLAGS -pie)
set_property(TARGET ${base} APPEND PROPERTY set_property(TARGET ${base} APPEND PROPERTY
COMPILE_DEFINITIONS "__SRCFILE__=\"${src}\";TOKUSVNROOT=\"${toku_svn_root}\"") COMPILE_DEFINITIONS "__SRCFILE__=\"${src}\";TOKUSVNROOT=\"${toku_svn_root}\"")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${src}.ft_handle") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${src}.ft_handle")
......
...@@ -20,8 +20,7 @@ if(BUILD_TESTING) ...@@ -20,8 +20,7 @@ if(BUILD_TESTING)
add_executable(${test} ${src}) add_executable(${test} ${src})
target_link_libraries(${test} ${LIBTOKUPORTABILITY}) target_link_libraries(${test} ${LIBTOKUPORTABILITY})
add_space_separated_property(TARGET ${test} COMPILE_FLAGS "-fvisibility=hidden -fPIE") add_common_options_to_binary_targets(${test})
add_space_separated_property(TARGET ${test} LINK_FLAGS -pie)
if(HAVE_CLOCK_REALTIME) if(HAVE_CLOCK_REALTIME)
target_link_libraries(${test} rt) target_link_libraries(${test} rt)
else() else()
......
...@@ -37,10 +37,9 @@ endif () ...@@ -37,10 +37,9 @@ endif ()
## add a version script and set -fvisibility=hidden for the shared library ## add a version script and set -fvisibility=hidden for the shared library
configure_file(export.map . COPYONLY) configure_file(export.map . COPYONLY)
get_target_property(link_flags ${LIBTOKUDB} LINK_FLAGS)
if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_space_separated_property(TARGET ${LIBTOKUDB} COMPILE_FLAGS -fvisibility=hidden) add_space_separated_property(TARGET ${LIBTOKUDB} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
add_space_separated_property(TARGET ${LIBTOKUDB} LINK_FLAGS "-Wl,--version-script=export.map") add_space_separated_property(TARGET ${LIBTOKUDB} LINK_FLAGS_RELEASE "-Wl,--version-script=export.map")
endif () endif ()
## add gcov and define _GNU_SOURCE ## add gcov and define _GNU_SOURCE
......
...@@ -15,7 +15,8 @@ add_dependencies(lock_tree_tlog_static install_tdb_h) ...@@ -15,7 +15,8 @@ add_dependencies(lock_tree_tlog_static install_tdb_h)
## make the real library, it's going to go into libtokudb.so so it needs ## make the real library, it's going to go into libtokudb.so so it needs
## to be PIC ## to be PIC
add_library(lock_tree_static STATIC ${lock_tree_srcs}) add_library(lock_tree_static STATIC ${lock_tree_srcs})
add_space_separated_property(TARGET lock_tree_static COMPILE_FLAGS "-fvisibility=hidden -fPIC") add_space_separated_property(TARGET lock_tree_static COMPILE_FLAGS -fPIC)
add_space_separated_property(TARGET lock_tree_static COMPILE_FLAGS_RELEASE -fvisibility=hidden)
set_property(TARGET lock_tree_static APPEND PROPERTY set_property(TARGET lock_tree_static APPEND PROPERTY
COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS) COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS)
add_dependencies(lock_tree_static install_tdb_h) add_dependencies(lock_tree_static install_tdb_h)
......
...@@ -9,7 +9,7 @@ if(BUILD_TESTING) ...@@ -9,7 +9,7 @@ if(BUILD_TESTING)
add_executable(lt_${base}.${impl} ${src}) add_executable(lt_${base}.${impl} ${src})
set_property(TARGET lt_${base}.${impl} APPEND PROPERTY set_property(TARGET lt_${base}.${impl} APPEND PROPERTY
COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"") COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"")
add_space_separated_property(TARGET lt_${base}.${impl} COMPILE_FLAGS -fvisibility=hidden) add_space_separated_property(TARGET lt_${base}.${impl} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
target_link_libraries(lt_${base}.${impl} target_link_libraries(lt_${base}.${impl}
lock_tree_${impl}_static lock_tree_${impl}_static
range_tree_${impl}_static range_tree_${impl}_static
......
...@@ -11,7 +11,8 @@ add_dependencies(range_tree_tlog_static install_tdb_h) ...@@ -11,7 +11,8 @@ add_dependencies(range_tree_tlog_static install_tdb_h)
## make the real library, it's going to go into libtokudb.so so it needs ## make the real library, it's going to go into libtokudb.so so it needs
## to be PIC ## to be PIC
add_library(range_tree_static STATIC log_nooverlap.c) add_library(range_tree_static STATIC log_nooverlap.c)
add_space_separated_property(TARGET range_tree_static COMPILE_FLAGS "-fvisibility=hidden -fPIC") add_space_separated_property(TARGET range_tree_static COMPILE_FLAGS -fPIC)
add_space_separated_property(TARGET range_tree_static COMPILE_FLAGS_RELEASE -fvisibility=hidden)
add_dependencies(range_tree_static install_tdb_h) add_dependencies(range_tree_static install_tdb_h)
maybe_add_gcov_to_libraries(range_tree_lin_static range_tree_tlog_static range_tree_static) maybe_add_gcov_to_libraries(range_tree_lin_static range_tree_tlog_static range_tree_static)
......
...@@ -9,7 +9,7 @@ if(BUILD_TESTING) ...@@ -9,7 +9,7 @@ if(BUILD_TESTING)
add_executable(rt_${base}.${impl} ${src}) add_executable(rt_${base}.${impl} ${src})
set_property(TARGET rt_${base}.${impl} APPEND PROPERTY set_property(TARGET rt_${base}.${impl} APPEND PROPERTY
COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"") COMPILE_DEFINITIONS "TESTDIR=\"dir.${base}.c.${impl}\"")
add_space_separated_property(TARGET rt_${base}.${impl} COMPILE_FLAGS -fvisibility=hidden) add_space_separated_property(TARGET rt_${base}.${impl} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
target_link_libraries(rt_${base}.${impl} target_link_libraries(rt_${base}.${impl}
range_tree_${impl}_static range_tree_${impl}_static
ft ft
......
...@@ -319,8 +319,7 @@ if(BUILD_TESTING) ...@@ -319,8 +319,7 @@ if(BUILD_TESTING)
set_property(TARGET ${base}.tdb APPEND PROPERTY set_property(TARGET ${base}.tdb APPEND PROPERTY
COMPILE_DEFINITIONS "ENVDIR=\"dir.${src}.tdb\";USE_TDB;IS_TDB=1;TOKUDB=1") 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") 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_common_options_to_binary_targets(${base}.tdb)
add_space_separated_property(TARGET ${base}.tdb COMPILE_FLAGS -pie)
endforeach(bin) endforeach(bin)
if(BDB_FOUND) if(BDB_FOUND)
...@@ -335,6 +334,7 @@ if(BUILD_TESTING) ...@@ -335,6 +334,7 @@ if(BUILD_TESTING)
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}/../..") 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(${base}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES}) target_link_libraries(${base}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${src}.bdb") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${src}.bdb")
add_common_options_to_binary_targets(${base}.bdb)
endforeach(bin) endforeach(bin)
endif() endif()
...@@ -355,8 +355,7 @@ if(BUILD_TESTING) ...@@ -355,8 +355,7 @@ if(BUILD_TESTING)
set_target_properties(${prefix}_${binary} PROPERTIES set_target_properties(${prefix}_${binary} PROPERTIES
COMPILE_DEFINITIONS "ENVDIR=\"dir.${prefix}_${source}.tdb\";USE_TDB;IS_TDB=1;TOKUDB=1") 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") 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_common_options_to_binary_targets(${prefix}_${binary})
add_space_separated_property(TARGET ${prefix}_${binary} COMPILE_FLAGS -pie)
endfunction(add_custom_executable) endfunction(add_custom_executable)
declare_custom_tests(test1426.tdb) declare_custom_tests(test1426.tdb)
......
...@@ -5,18 +5,16 @@ foreach(util ${utils}) ...@@ -5,18 +5,16 @@ foreach(util ${utils})
add_executable(${util} ${util}.c) add_executable(${util} ${util}.c)
set_target_properties(${util} PROPERTIES set_target_properties(${util} PROPERTIES
COMPILE_DEFINITIONS "IS_TDB=1;USE_TDB=1;TDB_IS_STATIC=0") 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}) target_link_libraries(${util} ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
add_executable(${util}_static ${util}.c) add_executable(${util}_static ${util}.c)
set_target_properties(${util}_static PROPERTIES set_target_properties(${util}_static PROPERTIES
COMPILE_DEFINITIONS "IS_TDB=1;USE_TDB=1;TDB_IS_STATIC=1") COMPILE_DEFINITIONS "IS_TDB=1;USE_TDB=1;TDB_IS_STATIC=1")
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 lock_tree_static range_tree_static ft_static z ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl) target_link_libraries(${util}_static ${LIBTOKUDB}_static lock_tree_static range_tree_static ft_static z ${LIBTOKUPORTABILITY}_static ${CMAKE_THREAD_LIBS_INIT} dl)
set_targets_need_intel_libs(${util}_static) set_targets_need_intel_libs(${util}_static)
add_common_options_to_binary_targets(${util} ${util}_static)
if(BDB_FOUND) if(BDB_FOUND)
add_executable(${util}.bdb ${util}.c) add_executable(${util}.bdb ${util}.c)
set_property(TARGET ${util}.bdb APPEND PROPERTY set_property(TARGET ${util}.bdb APPEND PROPERTY
...@@ -25,5 +23,6 @@ foreach(util ${utils}) ...@@ -25,5 +23,6 @@ foreach(util ${utils})
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}/..") 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}) target_link_libraries(${util}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
set_targets_need_intel_libs(${util}.bdb) set_targets_need_intel_libs(${util}.bdb)
add_common_options_to_binary_targets(${util}.bdb)
endif() endif()
endforeach(util) 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