Commit dc4776a7 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 11f07aa6
......@@ -147,3 +147,17 @@ function(maybe_add_gcov_to_libraries)
endforeach(lib)
endif (USE_GCOV)
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)
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}/..")
target_link_libraries(${bdb_bin}-bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
add_common_options_to_binary_targets(${bdb_bin}-bdb)
endforeach(bdb_bin)
endif()
......@@ -30,7 +31,6 @@ 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 ${LIBTOKUDB} ${LIBTOKUPORTABILITY})
add_common_options_to_binary_targets(${tokudb_bin}-tokudb)
endforeach(tokudb_bin)
......@@ -8,8 +8,7 @@ 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)
add_common_options_to_binary_targets(logformat)
target_link_libraries(logformat ${LIBTOKUPORTABILITY})
add_custom_command(
......@@ -117,15 +116,13 @@ 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}_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)
add_common_options_to_binary_targets(${bin} ${bin}_static)
endforeach(bin)
# link in math.h library just for this tool.
......
......@@ -30,8 +30,7 @@ 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)
add_common_options_to_binary_targets(${base})
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")
......
......@@ -20,8 +20,7 @@ if(BUILD_TESTING)
add_executable(${test} ${src})
target_link_libraries(${test} ${LIBTOKUPORTABILITY})
add_space_separated_property(TARGET ${test} COMPILE_FLAGS "-fvisibility=hidden -fPIE")
add_space_separated_property(TARGET ${test} LINK_FLAGS -pie)
add_common_options_to_binary_targets(${test})
if(HAVE_CLOCK_REALTIME)
target_link_libraries(${test} rt)
else()
......
......@@ -37,10 +37,9 @@ 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)
add_space_separated_property(TARGET ${LIBTOKUDB} COMPILE_FLAGS -fvisibility=hidden)
add_space_separated_property(TARGET ${LIBTOKUDB} LINK_FLAGS "-Wl,--version-script=export.map")
add_space_separated_property(TARGET ${LIBTOKUDB} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
add_space_separated_property(TARGET ${LIBTOKUDB} LINK_FLAGS_RELEASE "-Wl,--version-script=export.map")
endif ()
## add gcov and define _GNU_SOURCE
......
......@@ -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
## to be PIC
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
COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS)
add_dependencies(lock_tree_static install_tdb_h)
......
......@@ -9,7 +9,7 @@ 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)
add_space_separated_property(TARGET lt_${base}.${impl} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
target_link_libraries(lt_${base}.${impl}
lock_tree_${impl}_static
range_tree_${impl}_static
......
......@@ -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
## to be PIC
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)
maybe_add_gcov_to_libraries(range_tree_lin_static range_tree_tlog_static range_tree_static)
......
......@@ -9,7 +9,7 @@ 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)
add_space_separated_property(TARGET rt_${base}.${impl} COMPILE_FLAGS_RELEASE -fvisibility=hidden)
target_link_libraries(rt_${base}.${impl}
range_tree_${impl}_static
ft
......
......@@ -319,8 +319,7 @@ 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)
add_common_options_to_binary_targets(${base}.tdb)
endforeach(bin)
if(BDB_FOUND)
......@@ -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}/../..")
target_link_libraries(${base}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "dir.${src}.bdb")
add_common_options_to_binary_targets(${base}.bdb)
endforeach(bin)
endif()
......@@ -355,8 +355,7 @@ if(BUILD_TESTING)
set_target_properties(${prefix}_${binary} PROPERTIES
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)
add_common_options_to_binary_targets(${prefix}_${binary})
endfunction(add_custom_executable)
declare_custom_tests(test1426.tdb)
......
......@@ -5,18 +5,16 @@ 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")
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)
set_targets_need_intel_libs(${util}_static)
add_common_options_to_binary_targets(${util} ${util}_static)
if(BDB_FOUND)
add_executable(${util}.bdb ${util}.c)
set_property(TARGET ${util}.bdb APPEND PROPERTY
......@@ -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}/..")
target_link_libraries(${util}.bdb ${LIBTOKUPORTABILITY} ${BDB_LIBRARIES})
set_targets_need_intel_libs(${util}.bdb)
add_common_options_to_binary_targets(${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