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

[t:4814] clean up and comment the CMakeLists.txts


git-svn-id: file:///svn/toku/tokudb@43367 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8586fccb
cmake_minimum_required(VERSION 2.8.8) cmake_minimum_required(VERSION 2.8.8)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
## this needs to happen before calling project(), when cmake detects some
## basic things about the compiler
include(TokuSetupIntelCompiler) include(TokuSetupIntelCompiler)
project(TOKUDB) project(TokuDB)
include(TokuFeatureDetection) include(TokuFeatureDetection)
include(TokuSetupCompiler) include(TokuSetupCompiler)
include(TokuSetupCTest) include(TokuSetupCTest)
## lzma ## add lzma with an external project
include(ExternalProject) include(ExternalProject)
set(xz_configure_opts --with-pic) set(xz_configure_opts --with-pic)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") if (CMAKE_SYSTEM_NAME MATCHES Darwin)
## lzma has some assembly that doesn't work on osx
list(APPEND xz_configure_opts --disable-assembler) list(APPEND xz_configure_opts --disable-assembler)
endif() endif ()
if(${CMAKE_BUILD_TYPE} MATCHES "Release") if (CMAKE_BUILD_TYPE MATCHES Release)
if(CMAKE_C_COMPILER_ID MATCHES "Intel") if (CMAKE_C_COMPILER_ID MATCHES Intel)
list(APPEND xz_configure_opts CC=icc "CFLAGS=-O2 -g -ip -ipo1" AR=xiar) list(APPEND xz_configure_opts CC=icc "CFLAGS=-O2 -g -ip -ipo1" AR=xiar)
endif() endif ()
else() else ()
list(APPEND xz_configure_opts --enable-debug) list(APPEND xz_configure_opts --enable-debug)
endif() endif ()
if (CMAKE_GENERATOR STREQUAL "Ninja") if (CMAKE_GENERATOR STREQUAL Ninja)
## ninja doesn't understand "$(MAKE)"
ExternalProject_Add(ep_lzma ExternalProject_Add(ep_lzma
PREFIX xz PREFIX xz
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xz-4.999.9beta SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xz-4.999.9beta
...@@ -37,6 +41,8 @@ if (CMAKE_GENERATOR STREQUAL "Ninja") ...@@ -37,6 +41,8 @@ if (CMAKE_GENERATOR STREQUAL "Ninja")
make -C src/liblzma install make -C src/liblzma install
) )
else () else ()
## use "$(MAKE)" for submakes so they can use the jobserver, doesn't
## seem to break Xcode...
ExternalProject_Add(ep_lzma ExternalProject_Add(ep_lzma
PREFIX xz PREFIX xz
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xz-4.999.9beta SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xz-4.999.9beta
...@@ -55,9 +61,20 @@ add_library(lzma STATIC IMPORTED) ...@@ -55,9 +61,20 @@ add_library(lzma STATIC IMPORTED)
set_target_properties(lzma PROPERTIES IMPORTED_LOCATION set_target_properties(lzma PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/xz/lib/liblzma.a") "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/xz/lib/liblzma.a")
## 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(LIBTOKUPORTABILITY "tokuportability" CACHE STRING "Name of libtokuportability.so")
set(LIBTOKUDB "tokudb" CACHE STRING "Name of libtokudb.so") set(LIBTOKUDB "tokudb" CACHE STRING "Name of libtokudb.so")
## add an option for cilk
option(USE_CILK "Use cilk in tokudb." OFF)
## can't use cilk without icc
if (USE_CILK AND (NOT CMAKE_C_COMPILER_ID MATCHES Intel))
message(FATAL_ERROR "You specified USE_CILK=ON so you need INTEL_CC=ON.")
endif ()
## default includes and libraries ## default includes and libraries
include_directories(SYSTEM include_directories(SYSTEM
/usr/local/include /usr/local/include
...@@ -67,15 +84,12 @@ include_directories( ...@@ -67,15 +84,12 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/toku_include ${CMAKE_CURRENT_SOURCE_DIR}/toku_include
${CMAKE_CURRENT_SOURCE_DIR}/portability ${CMAKE_CURRENT_SOURCE_DIR}/portability
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ## so you can include <newbrt/brt.h> from inside src/
) )
## include where config.h will be ## include where config.h will be generated
include_directories( include_directories(${CMAKE_CURRENT_BINARY_DIR}/toku_include)
${CMAKE_CURRENT_BINARY_DIR}/toku_include
)
link_libraries(dl pthread z)
## build db.h and include that directory ## build db.h and include where it will be generated
add_subdirectory(buildheader) add_subdirectory(buildheader)
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/buildheader) include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/buildheader)
...@@ -96,6 +110,7 @@ install( ...@@ -96,6 +110,7 @@ install(
DESTINATION . DESTINATION .
) )
## set up lists of sources and headers for tags
file(GLOB_RECURSE all_srcs file(GLOB_RECURSE all_srcs
include/*.c include/*.c
toku_include/*.c toku_include/*.c
...@@ -117,4 +132,5 @@ file(GLOB_RECURSE all_hdrs ...@@ -117,4 +132,5 @@ file(GLOB_RECURSE all_hdrs
db-benchmark-test/*.h db-benchmark-test/*.h
) )
## build tags
include(TokuBuildTagDatabases) include(TokuBuildTagDatabases)
find_program(CTAGS "ctags") option(USE_CTAGS "Build the ctags database." ON)
if(NOT CTAGS MATCHES "CTAGS-NOTFOUND") if (USE_CTAGS)
add_custom_command( find_program(CTAGS "ctags")
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/tags" if (NOT CTAGS MATCHES NOTFOUND)
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ctags-stamp" add_custom_command(
COMMAND ${CTAGS} -o tags ${all_srcs} ${all_hdrs} OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/tags"
COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/ctags-stamp" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ctags-stamp"
DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h COMMAND ${CTAGS} -o tags ${all_srcs} ${all_hdrs}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/ctags-stamp"
add_custom_target(build_ctags ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tags" ctags-stamp) DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h
endif() WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_target(build_ctags ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tags" ctags-stamp)
endif ()
endif ()
find_program(ETAGS "etags") option(USE_ETAGS "Build the etags database." ON)
if(NOT ETAGS MATCHES "ETAGS-NOTFOUND") if (USE_ETAGS)
add_custom_command( find_program(ETAGS "etags")
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/TAGS" if (NOT ETAGS MATCHES NOTFOUND)
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/etags-stamp" add_custom_command(
COMMAND ${ETAGS} -o TAGS ${all_srcs} ${all_hdrs} OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/TAGS"
COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/etags-stamp" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/etags-stamp"
DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h COMMAND ${ETAGS} -o TAGS ${all_srcs} ${all_hdrs}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/etags-stamp"
add_custom_target(build_etags ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/TAGS" etags-stamp) DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h
endif() WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_target(build_etags ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/TAGS" etags-stamp)
endif ()
endif ()
find_program(CSCOPE "cscope") option(USE_CSCOPE "Build the cscope database." ON)
if(NOT CSCOPE MATCHES "CSCOPE-NOTFOUND") if (USE_CSCOPE)
add_custom_command( find_program(CSCOPE "cscope")
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.out" if (NOT CSCOPE MATCHES NOTFOUND)
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.in.out" add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.po.out" OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.out"
COMMAND ${CSCOPE} -b -q -R OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.in.out"
DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/cscope.po.out"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") COMMAND ${CSCOPE} -b -q -R
add_custom_target(build_cscope.out ALL DEPENDS DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h
"${CMAKE_CURRENT_SOURCE_DIR}/cscope.out" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
"${CMAKE_CURRENT_SOURCE_DIR}/cscope.in.out" add_custom_target(build_cscope.out ALL DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/cscope.po.out") "${CMAKE_CURRENT_SOURCE_DIR}/cscope.out"
endif() "${CMAKE_CURRENT_SOURCE_DIR}/cscope.in.out"
"${CMAKE_CURRENT_SOURCE_DIR}/cscope.po.out")
endif ()
endif ()
find_program(GTAGS "gtags") option(USE_GTAGS "Build the gtags database." ON)
if(NOT GTAGS MATCHES "GTAGS-NOTFOUND") if (USE_GTAGS)
add_custom_command( find_program(GTAGS "gtags")
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GTAGS" if (NOT GTAGS MATCHES NOTFOUND)
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GRTAGS" ## todo: use global -u instead of gtags each time
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GPATH" add_custom_command(
COMMAND ${GTAGS} --gtagsconf "${CMAKE_CURRENT_SOURCE_DIR}/.globalrc" OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GTAGS"
DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GRTAGS"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/GPATH"
add_custom_target(build_GTAGS ALL DEPENDS COMMAND ${GTAGS} --gtagsconf "${CMAKE_CURRENT_SOURCE_DIR}/.globalrc"
"${CMAKE_CURRENT_SOURCE_DIR}/GTAGS" DEPENDS ${all_srcs} ${all_hdrs} install_tdb_h generate_logging_code generate_config_h
"${CMAKE_CURRENT_SOURCE_DIR}/GRTAGS" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
"${CMAKE_CURRENT_SOURCE_DIR}/GPATH") add_custom_target(build_GTAGS ALL DEPENDS
endif() "${CMAKE_CURRENT_SOURCE_DIR}/GTAGS"
"${CMAKE_CURRENT_SOURCE_DIR}/GRTAGS"
"${CMAKE_CURRENT_SOURCE_DIR}/GPATH")
endif ()
endif ()
\ No newline at end of file
## some functions for getting system info to build BUILDNAME ## some functions for getting system info so we can construct BUILDNAME
## given an executable, follows symlinks and resolves paths until it runs ## given an executable, follows symlinks and resolves paths until it runs
## out of symlinks, then gives you the basename ## out of symlinks, then gives you the basename
...@@ -85,18 +85,19 @@ endmacro(get_svn_wc_status) ...@@ -85,18 +85,19 @@ endmacro(get_svn_wc_status)
## gather machine info ## gather machine info
uname("-m" machine_type) uname("-m" machine_type)
real_executable_name("${CMAKE_C_COMPILER}" real_c_compiler) real_executable_name("${CMAKE_C_COMPILER}" real_c_compiler)
get_svn_revision("${CMAKE_CURRENT_SOURCE_DIR}" svn_revision) get_svn_revision("${CMAKE_CURRENT_SOURCE_DIR}" svn_revision) ## unused since it confuses cdash about history
get_svn_wc_status("${CMAKE_CURRENT_SOURCE_DIR}" wc_status) get_svn_wc_status("${CMAKE_CURRENT_SOURCE_DIR}" wc_status) ## unused since it confuses cdash about history
get_filename_component(branchname "${CMAKE_CURRENT_SOURCE_DIR}" NAME) get_filename_component(branchname "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
## construct BUILDNAME ## construct BUILDNAME, seems to have to happen before include(CTest)
set(BUILDNAME "${branchname} ${CMAKE_BUILD_TYPE} ${CMAKE_SYSTEM} ${machine_type} ${CMAKE_C_COMPILER_ID} ${real_c_compiler} ${CMAKE_C_COMPILER_VERSION}" CACHE STRING "CTest build name" FORCE) set(BUILDNAME "${branchname} ${CMAKE_BUILD_TYPE} ${CMAKE_SYSTEM} ${machine_type} ${CMAKE_C_COMPILER_ID} ${real_c_compiler} ${CMAKE_C_COMPILER_VERSION}" CACHE STRING "CTest build name" FORCE)
include(CTest) include(CTest)
if(BUILD_TESTING) if (BUILD_TESTING)
## set up full valgrind suppressions file (concatenate the suppressions files) ## set up full valgrind suppressions file (concatenate the suppressions files)
file(COPY newbrt/valgrind.suppressions DESTINATION .) file(READ newbrt/valgrind.suppressions valgrind_suppressions)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/valgrind.suppressions" "${valgrind_suppressions}")
file(READ src/tests/bdb.suppressions bdb_suppressions) file(READ src/tests/bdb.suppressions bdb_suppressions)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/valgrind.suppressions" "${bdb_suppressions}") file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/valgrind.suppressions" "${bdb_suppressions}")
file(READ bash.suppressions bash_suppressions) file(READ bash.suppressions bash_suppressions)
...@@ -106,8 +107,11 @@ if(BUILD_TESTING) ...@@ -106,8 +107,11 @@ if(BUILD_TESTING)
set(CMAKE_HELGRIND_COMMAND_STRING "valgrind --quiet --tool=helgrind --error-exitcode=1 --suppressions=${TOKUDB_SOURCE_DIR}/src/tests/helgrind.suppressions --trace-children=yes --trace-children-skip=sh,*/sh,basename,*/basename,dirname,*/dirname,rm,*/rm,cp,*/cp,mv,*/mv,cat,*/cat,diff,*/diff,test,*/tokudb_dump* --trace-children-skip-by-arg=--only_create,--test,--no-shutdown") set(CMAKE_HELGRIND_COMMAND_STRING "valgrind --quiet --tool=helgrind --error-exitcode=1 --suppressions=${TOKUDB_SOURCE_DIR}/src/tests/helgrind.suppressions --trace-children=yes --trace-children-skip=sh,*/sh,basename,*/basename,dirname,*/dirname,rm,*/rm,cp,*/cp,mv,*/mv,cat,*/cat,diff,*/diff,test,*/tokudb_dump* --trace-children-skip-by-arg=--only_create,--test,--no-shutdown")
function(add_helgrind_test name) function(add_helgrind_test name)
if (CMAKE_SYSTEM_NAME MATCHES Darwin OR if (CMAKE_SYSTEM_NAME MATCHES Darwin OR
CMAKE_C_COMPILER_ID MATCHES Intel OR ((CMAKE_C_COMPILER_ID MATCHES Intel) AND
(CMAKE_BUILD_TYPE MATCHES Release)) OR
USE_GCOV) USE_GCOV)
## can't use helgrind on osx or with optimized intel, no point in
## using it if we're doing coverage
add_test( add_test(
NAME ${name} NAME ${name}
COMMAND ${ARGN} COMMAND ${ARGN}
...@@ -125,19 +129,22 @@ if(BUILD_TESTING) ...@@ -125,19 +129,22 @@ if(BUILD_TESTING)
set(CMAKE_DRD_COMMAND_STRING "valgrind --quiet --tool=drd --error-exitcode=1 --suppressions=${TOKUDB_SOURCE_DIR}/src/tests/drd.suppressions --trace-children=yes --trace-children-skip=sh,*/sh,basename,*/basename,dirname,*/dirname,rm,*/rm,cp,*/cp,mv,*/mv,cat,*/cat,diff,*/diff,test,*/tokudb_dump* --trace-children-skip-by-arg=--only_create,--test,--no-shutdown") set(CMAKE_DRD_COMMAND_STRING "valgrind --quiet --tool=drd --error-exitcode=1 --suppressions=${TOKUDB_SOURCE_DIR}/src/tests/drd.suppressions --trace-children=yes --trace-children-skip=sh,*/sh,basename,*/basename,dirname,*/dirname,rm,*/rm,cp,*/cp,mv,*/mv,cat,*/cat,diff,*/diff,test,*/tokudb_dump* --trace-children-skip-by-arg=--only_create,--test,--no-shutdown")
function(add_drd_test name) function(add_drd_test name)
if (CMAKE_SYSTEM_NAME MATCHES Darwin OR if (CMAKE_SYSTEM_NAME MATCHES Darwin OR
CMAKE_C_COMPILER_ID MATCHES Intel OR ((CMAKE_C_COMPILER_ID MATCHES Intel) AND
(CMAKE_BUILD_TYPE MATCHES Release)) OR
USE_GCOV) USE_GCOV)
## can't use drd on osx or with optimized intel, no point in
## using it if we're doing coverage
add_test( add_test(
NAME ${name} NAME ${name}
COMMAND ${ARGN} COMMAND ${ARGN}
) )
else() else ()
separate_arguments(CMAKE_DRD_COMMAND_STRING) separate_arguments(CMAKE_DRD_COMMAND_STRING)
add_test( add_test(
NAME ${name} NAME ${name}
COMMAND ${CMAKE_DRD_COMMAND_STRING} ${ARGN} COMMAND ${CMAKE_DRD_COMMAND_STRING} ${ARGN}
) )
endif() endif ()
endfunction(add_drd_test) endfunction(add_drd_test)
option(RUN_LONG_TESTS "If set, run all tests, even the ones that take a long time to complete." OFF) option(RUN_LONG_TESTS "If set, run all tests, even the ones that take a long time to complete." OFF)
...@@ -145,4 +152,4 @@ if(BUILD_TESTING) ...@@ -145,4 +152,4 @@ if(BUILD_TESTING)
option(RUN_PERF_TESTS "If set, run the perf tests." OFF) option(RUN_PERF_TESTS "If set, run the perf tests." OFF)
configure_file(CTestCustom.cmake . @ONLY) configure_file(CTestCustom.cmake . @ONLY)
endif(BUILD_TESTING) endif (BUILD_TESTING)
...@@ -6,11 +6,11 @@ function(add_c_defines) ...@@ -6,11 +6,11 @@ function(add_c_defines)
endfunction(add_c_defines) endfunction(add_c_defines)
## os name detection (threadpool-test.c needs this) ## os name detection (threadpool-test.c needs this)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin") if (CMAKE_SYSTEM_NAME MATCHES Darwin)
add_c_defines(DARWIN=1 _DARWIN_C_SOURCE) add_c_defines(DARWIN=1 _DARWIN_C_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") elseif (CMAKE_SYSTEM_NAME MATCHES Linux)
add_c_defines(__linux__=1) add_c_defines(__linux__=1)
endif() endif ()
## preprocessor definitions we want everywhere ## preprocessor definitions we want everywhere
add_c_defines( add_c_defines(
...@@ -20,10 +20,10 @@ add_c_defines( ...@@ -20,10 +20,10 @@ add_c_defines(
_LARGEFILE64_SOURCE _LARGEFILE64_SOURCE
) )
if(CMAKE_SYSTEM_NAME MATCHES Darwin) if (CMAKE_SYSTEM_NAME MATCHES Darwin)
message(WARNING "Setting TOKU_ALLOW_DEPRECATED on Darwin. TODO: remove this.") message(WARNING "Setting TOKU_ALLOW_DEPRECATED on Darwin. TODO: remove this.")
add_c_defines(TOKU_ALLOW_DEPRECATED) add_c_defines(TOKU_ALLOW_DEPRECATED)
endif() endif ()
## coverage ## coverage
option(USE_GCOV "Use gcov for test coverage." OFF) option(USE_GCOV "Use gcov for test coverage." OFF)
...@@ -33,6 +33,9 @@ if (USE_GCOV) ...@@ -33,6 +33,9 @@ if (USE_GCOV)
endif () endif ()
endif (USE_GCOV) 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) function(maybe_add_gcov_to_libraries)
if (USE_GCOV) if (USE_GCOV)
foreach(lib ${ARGN}) foreach(lib ${ARGN})
...@@ -55,41 +58,46 @@ endfunction(maybe_add_gcov_to_libraries) ...@@ -55,41 +58,46 @@ endfunction(maybe_add_gcov_to_libraries)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
## disable some warnings, if we can ## adds a compiler flag if the compiler supports it
function(set_flag_if_exists flag) function(set_cflags_if_supported)
check_c_compiler_flag(${flag} HAVE_${flag}) foreach(flag ${ARGN})
if(HAVE_${flag}) check_c_compiler_flag(${flag} HAVE_${flag})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") if (HAVE_${flag})
endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endif ()
endforeach(flag)
endfunction(set_flag_if_exists) endfunction(set_flag_if_exists)
foreach(flag -Wno-self-assign -Wno-missing-field-initializers -Wno-maybe-uninitialized) ## disable some warnings
set_flag_if_exists(${flag}) set_cflags_if_supported(
endforeach(flag) -Wno-self-assign
-Wno-missing-field-initializers
-Wno-maybe-uninitialized
)
## set extra debugging flags and preprocessor definitions ## set extra debugging flags and preprocessor definitions
set(CMAKE_C_FLAGS_DEBUG "-g3 -ggdb -O0") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -ggdb -O0")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG FORTIFY_SOURCE=2) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG FORTIFY_SOURCE=2)
## set extra release flags ## set extra release flags
set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
## check how to do inter-procedural optimization ## check how to do inter-procedural optimization
check_c_compiler_flag(-flto HAVE_CC_FLAG_FLTO) check_c_compiler_flag(-flto HAVE_CC_FLAG_FLTO)
check_c_compiler_flag(-ipo HAVE_CC_FLAG_IPO) check_c_compiler_flag(-ipo HAVE_CC_FLAG_IPO)
## add inter-procedural optimization flags ## add inter-procedural optimization flags
if(HAVE_CC_FLAG_FLTO) if (HAVE_CC_FLAG_FLTO)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
elseif(HAVE_CC_FLAG_IPO) elseif (HAVE_CC_FLAG_IPO)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ip -ipo1") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ip -ipo1")
endif() endif ()
if(CMAKE_C_COMPILER_ID MATCHES "^Intel$") if (CMAKE_C_COMPILER_ID MATCHES Intel)
# make sure intel libs are linked statically ## make sure intel libs are linked statically
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-intel")
# disable some intel-specific warnings ## disable some intel-specific warnings
set(intel_warnings set(intel_warnings
94 # allow arrays of length 0 94 # allow arrays of length 0
589 # do not complain about goto that skips initialization 589 # do not complain about goto that skips initialization
...@@ -101,15 +109,33 @@ if(CMAKE_C_COMPILER_ID MATCHES "^Intel$") ...@@ -101,15 +109,33 @@ if(CMAKE_C_COMPILER_ID MATCHES "^Intel$")
) )
string(REGEX REPLACE ";" "," intel_warning_string "${intel_warnings}") string(REGEX REPLACE ";" "," intel_warning_string "${intel_warnings}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -diag-disable ${intel_warning_string}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -diag-disable ${intel_warning_string}")
## icc does -g differently
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -debug all") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -debug all")
set(EXTRA_CFLAGS "-Wall -Wcheck") ## set icc warnings
set(WARN_CFLAGS
-Wall
-Wcheck ## icc version of -Wextra
)
else() else()
set(EXTRA_CFLAGS "-Wall -Wextra -Wcast-align -Wbad-function-cast -Wno-missing-noreturn -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wmissing-format-attribute -Wshadow") ## set gcc warnings
set(WARN_CFLAGS
-Wall
-Wextra
-Wcast-align
-Wbad-function-cast
-Wno-missing-noreturn
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
-Wpointer-arith
-Wmissing-format-attribute
-Wshadow
)
endif() endif()
## default warning levels set_cflags_if_supported(${WARN_CFLAGS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
## function for adding -fvisibility=hidden to targets ## function for adding -fvisibility=hidden to targets
function(set_targets_visibility_hidden) function(set_targets_visibility_hidden)
......
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
option(USE_CILK "Use cilk in tokudb." OFF)
## can't use cilk without icc
if(USE_CILK AND NOT(CMAKE_C_COMPILER_ID MATCHES Intel))
message(FATAL_ERROR "You specified USE_CILK=ON so you need to use an Intel compiler.")
endif()
## generate log_code.c, log_print.c, log_header.c ## generate log_code.c, log_print.c, log_header.c
## TODO: generate these in the build directory instead
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_code.c PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_code.c PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_print.c PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_print.c PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_header.h PROPERTIES GENERATED TRUE) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/log_header.h PROPERTIES GENERATED TRUE)
...@@ -78,6 +72,7 @@ set(BRT_SOURCES ...@@ -78,6 +72,7 @@ set(BRT_SOURCES
add_library(newbrt SHARED ${BRT_SOURCES}) add_library(newbrt SHARED ${BRT_SOURCES})
add_library(newbrt_static STATIC ${BRT_SOURCES}) add_library(newbrt_static STATIC ${BRT_SOURCES})
## we're going to link this into libtokudb.so so it needs to have PIC
set_property(TARGET newbrt_static APPEND PROPERTY COMPILE_FLAGS "-fPIC") set_property(TARGET newbrt_static APPEND PROPERTY COMPILE_FLAGS "-fPIC")
maybe_add_gcov_to_libraries(newbrt newbrt_static) maybe_add_gcov_to_libraries(newbrt newbrt_static)
...@@ -85,11 +80,14 @@ maybe_add_gcov_to_libraries(newbrt newbrt_static) ...@@ -85,11 +80,14 @@ maybe_add_gcov_to_libraries(newbrt newbrt_static)
add_dependencies(newbrt install_tdb_h build_lzma) add_dependencies(newbrt install_tdb_h build_lzma)
add_dependencies(newbrt_static install_tdb_h build_lzma) add_dependencies(newbrt_static install_tdb_h build_lzma)
## link with lzma (which should be static) ## link with tokuportability, and lzma (which should be static)
target_link_libraries(newbrt ${LIBTOKUPORTABILITY} lzma) target_link_libraries(newbrt ${LIBTOKUPORTABILITY} lzma)
target_link_libraries(newbrt_static ${LIBTOKUPORTABILITY} lzma) target_link_libraries(newbrt_static ${LIBTOKUPORTABILITY} lzma)
if (CMAKE_C_COMPILER_ID STREQUAL "Intel") 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(newbrt -nodefaultlibs c -Bstatic irc -Bdynamic) target_link_libraries(newbrt -nodefaultlibs c -Bstatic irc -Bdynamic)
endif () endif ()
......
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE)
if(BUILD_TESTING) if(BUILD_TESTING)
## get a list of the sources in this directory
file(GLOB srcs RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.c) file(GLOB srcs RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.c)
## these are generated by some tests, we need to remember to clean them
## up
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
foo1.brt foo2.brt foo3.brt foo4.brt foo1.brt foo2.brt foo3.brt foo4.brt
bar1.brt bar2.brt bar3.brt bar4.brt bar1.brt bar2.brt bar3.brt bar4.brt
test-dump-brt.out) test-dump-brt.out)
## this macro will remove the test from the list of source files so it
## doesn't end up getting the default test rule applied to it
macro(declare_custom_tests) macro(declare_custom_tests)
foreach(source ${ARGN}) foreach(source ${ARGN})
list(REMOVE_ITEM srcs ${source}) list(REMOVE_ITEM srcs ${source})
...@@ -19,7 +24,7 @@ if(BUILD_TESTING) ...@@ -19,7 +24,7 @@ if(BUILD_TESTING)
add_test(logcursor-bw echo "logcursor-bw must be run manually (needs logs to iterate over).") add_test(logcursor-bw echo "logcursor-bw must be run manually (needs logs to iterate over).")
foreach(src ${srcs}) foreach(src ${srcs})
if(NOT "${src}" MATCHES "dir[.].*[.]c") if(NOT "${src}" MATCHES "dir[.].*[.]c") ## annoying
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} newbrt ${LIBTOKUPORTABILITY}) target_link_libraries(${base} newbrt ${LIBTOKUPORTABILITY})
...@@ -28,10 +33,16 @@ if(BUILD_TESTING) ...@@ -28,10 +33,16 @@ if(BUILD_TESTING)
file(GLOB log_tests RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" log-test*.c) file(GLOB log_tests RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" log-test*.c)
foreach(src ${log_tests}) foreach(src ${log_tests})
## these tests use -Ddname=foo to decide where to put their data, if
## we don't specify it, it defaults to "dir."__FILE__ which with cmake
## is going to be an absolute path with "dir." in front, and that's
## not a valid path
set_property(SOURCE ${src} APPEND PROPERTY set_property(SOURCE ${src} APPEND PROPERTY
COMPILE_DEFINITIONS "dname=\"${src}\"") COMPILE_DEFINITIONS "dname=\"${src}\"")
endforeach(src) endforeach(src)
## declare some tests that should be run with specific options
declare_custom_tests(test-assert.c) declare_custom_tests(test-assert.c)
add_test(test-assertA test-assert) add_test(test-assertA test-assert)
add_test(test-assertB test-assert notok) add_test(test-assertB test-assert notok)
...@@ -93,6 +104,7 @@ if(BUILD_TESTING) ...@@ -93,6 +104,7 @@ if(BUILD_TESTING)
foreach(src ${srcs}) foreach(src ${srcs})
if(NOT "${src}" MATCHES "dir[.].*[.]c") if(NOT "${src}" MATCHES "dir[.].*[.]c")
## add a default test rule that runs with no options
get_filename_component(base ${src} NAME_WE) get_filename_component(base ${src} NAME_WE)
add_test(${base} ${base}) add_test(${base} ${base})
endif() endif()
......
...@@ -19,24 +19,31 @@ set(tokudb_srcs ...@@ -19,24 +19,31 @@ set(tokudb_srcs
elocks.c elocks.c
) )
## make the shared library
add_library(${LIBTOKUDB} SHARED ${tokudb_srcs}) add_library(${LIBTOKUDB} SHARED ${tokudb_srcs})
add_dependencies(${LIBTOKUDB} generate_logging_code install_tdb_h) add_dependencies(${LIBTOKUDB} generate_logging_code install_tdb_h)
target_link_libraries(${LIBTOKUDB} lock_tree_static range_tree_static newbrt_static) target_link_libraries(${LIBTOKUDB} lock_tree_static range_tree_static newbrt_static)
## make the static library
add_library(${LIBTOKUDB}_static STATIC ${tokudb_srcs})
add_dependencies(${LIBTOKUDB}_static generate_logging_code install_tdb_h)
target_link_libraries(${LIBTOKUDB}_static lock_tree_static range_tree_static newbrt_static)
## 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) get_target_property(link_flags ${LIBTOKUDB} LINK_FLAGS)
set_target_properties(${LIBTOKUDB} PROPERTIES set_target_properties(${LIBTOKUDB} PROPERTIES
LINK_FLAGS "${LINK_FLAGS} -Wl,--version-script=export.map") LINK_FLAGS "${LINK_FLAGS} -Wl,--version-script=export.map")
set_targets_visibility_hidden(${LIBTOKUDB})
add_library(${LIBTOKUDB}_static STATIC ${tokudb_srcs}) ## add gcov and define _GNU_SOURCE
add_dependencies(${LIBTOKUDB}_static generate_logging_code install_tdb_h)
target_link_libraries(${LIBTOKUDB}_static lock_tree_static range_tree_static newbrt_static)
set_targets_visibility_hidden(${LIBTOKUDB} ${LIBTOKUDB}_static)
maybe_add_gcov_to_libraries(${LIBTOKUDB} ${LIBTOKUDB}_static) maybe_add_gcov_to_libraries(${LIBTOKUDB} ${LIBTOKUDB}_static)
set_property(TARGET ${LIBTOKUDB} ${LIBTOKUDB}_static APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE) set_property(TARGET ${LIBTOKUDB} ${LIBTOKUDB}_static APPEND PROPERTY COMPILE_DEFINITIONS _GNU_SOURCE)
if (CMAKE_C_COMPILER_ID STREQUAL "Intel") 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) target_link_libraries(${LIBTOKUDB} -nodefaultlibs c -Bstatic irc -Bdynamic)
endif () endif ()
......
...@@ -2,17 +2,18 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) ...@@ -2,17 +2,18 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(lock_tree_srcs locktree.c idlth.c lth.c rth.c txnid_set.c wfg.c) set(lock_tree_srcs locktree.c idlth.c lth.c rth.c txnid_set.c wfg.c)
## make the linear library
add_library(lock_tree_lin_static STATIC ${lock_tree_srcs}) add_library(lock_tree_lin_static STATIC ${lock_tree_srcs})
set_property(TARGET lock_tree_lin_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
add_dependencies(lock_tree_lin_static install_tdb_h) add_dependencies(lock_tree_lin_static install_tdb_h)
## make the log library
add_library(lock_tree_tlog_static STATIC ${lock_tree_srcs}) add_library(lock_tree_tlog_static STATIC ${lock_tree_srcs})
set_property(TARGET lock_tree_tlog_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
set_property(TARGET lock_tree_tlog_static APPEND PROPERTY set_property(TARGET lock_tree_tlog_static APPEND PROPERTY
COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS) COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS)
add_dependencies(lock_tree_tlog_static install_tdb_h) 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_library(lock_tree_static STATIC ${lock_tree_srcs})
set_property(TARGET lock_tree_static APPEND PROPERTY set_property(TARGET lock_tree_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC") COMPILE_FLAGS "-fPIC")
......
...@@ -4,6 +4,8 @@ if(BUILD_TESTING) ...@@ -4,6 +4,8 @@ if(BUILD_TESTING)
get_filename_component(base ${src} NAME_WE) get_filename_component(base ${src} NAME_WE)
foreach(impl lin tlog) foreach(impl lin tlog)
## each source file test_foo.c creates binaries lt_test_foo.lin and
## lt_test_foo.tlog
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}\"")
...@@ -22,6 +24,9 @@ if(BUILD_TESTING) ...@@ -22,6 +24,9 @@ if(BUILD_TESTING)
COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS) COMPILE_DEFINITIONS TOKU_RT_NOOVERLAPS)
endforeach(src) endforeach(src)
## run test_footprint_point_write.c and test_footprint_range_write.c in
## a bunch of different ways.
## TODO: add lt_ prefix to test names
foreach(impl lin tlog) foreach(impl lin tlog)
foreach(type point range) foreach(type point range)
foreach(i 1 2) foreach(i 1 2)
......
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
## make the linear library
add_library(range_tree_lin_static STATIC linear.c) add_library(range_tree_lin_static STATIC linear.c)
set_property(TARGET range_tree_lin_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
add_dependencies(range_tree_lin_static install_tdb_h) add_dependencies(range_tree_lin_static install_tdb_h)
## make the log library
add_library(range_tree_tlog_static STATIC log_nooverlap.c) add_library(range_tree_tlog_static STATIC log_nooverlap.c)
set_property(TARGET range_tree_tlog_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC")
add_dependencies(range_tree_tlog_static install_tdb_h) 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_library(range_tree_static STATIC log_nooverlap.c)
set_property(TARGET range_tree_static APPEND PROPERTY set_property(TARGET range_tree_static APPEND PROPERTY
COMPILE_FLAGS "-fPIC") COMPILE_FLAGS "-fPIC")
set_property(SOURCE log_nooverlap.c APPEND PROPERTY LABELS RUN_GCOV)
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)
......
...@@ -4,6 +4,8 @@ if(BUILD_TESTING) ...@@ -4,6 +4,8 @@ if(BUILD_TESTING)
get_filename_component(base ${src} NAME_WE) get_filename_component(base ${src} NAME_WE)
foreach(impl lin tlog) foreach(impl lin tlog)
## each source file test_foo.c creates binaries rt_test_foo.lin and
## rt_test_foo.tlog
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}\"")
......
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