include(CMakePushCheckState)
include(CheckCXXCompilerFlag)
+function(check_flag FLAG DEFAULT)
+ unset(FLAG_CONSTANT)
+ string(MAKE_C_IDENTIFIER CXX${FLAG} FLAG_CONSTANT)
+ check_cxx_compiler_flag(${FLAG} ${FLAG_CONSTANT})
+ if(${FLAG_CONSTANT})
+ add_compile_options(${FLAG})
+ elseif(DEFAULT)
+ add_compile_options(${DEFAULT})
+ endif()
+endfunction()
+
function(check_debug)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
- add_compile_options(-O1)
+ check_flag(-Og -O0)
+ check_flag(-ggdb -g)
add_definitions(-DDEBUG=1)
foreach(FLAG IN ITEMS
-fno-inline
-fno-eliminate-unused-debug-types
-funsafe-loop-optimizations
- -g3
-
-Wall
-Wextra
-Wunknown-pragmas
-Wunsafe-loop-optimizations
)
- unset(FLAG_CONSTANT)
- string(MAKE_C_IDENTIFIER CXX${FLAG} FLAG_CONSTANT)
- check_cxx_compiler_flag(${FLAG} ${FLAG_CONSTANT})
- if(${FLAG_CONSTANT})
- add_compile_options(${FLAG})
- endif()
+ check_flag(${FLAG} IGNORE)
endforeach()
if(ENABLE_SANITIZERS)
--- /dev/null
+find_program(DTRACE_EXECUTABLE NAMES dtrace
+ HINTS $ENV{DTRACE_DIR}
+ PATH_SUFFIXES bin
+ DOC "DTrace static probe generator"
+ )
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(DTrace DEFAULT_MSG DTRACE_EXECUTABLE)
+
+mark_as_advanced(DTRACE_EXECUTABLE)
# change local includes to system includes
foreach(HEADER IN LISTS ARGN)
- file(READ ${HEADER} HEADER_IN)
- string(REGEX REPLACE "include *\"([^\"]+)\"" "include <\\1>" HEADER_OUT "${HEADER_IN}")
- file(GENERATE
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${HEADER}
- CONTENT "${HEADER_OUT}"
- )
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${HEADER}
+ if(HEADER MATCHES "^@")
+ string(SUBSTRING ${HEADER} 1 -1 HEADER)
+ configure_file(${HEADER}.in ${HEADER})
+ string(PREPEND HEADER ${CMAKE_CURRENT_BINARY_DIR}/)
+ endif()
+ install(FILES ${HEADER}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIRECTORY}
)
endforeach()
## dtrace
if(ENABLE_DTRACE)
- set(HAVE_DTRACE 1)
+ find_package(DTrace)
+ if(DTRACE_EXECUTABLE)
+ set(HAVE_DTRACE 1)
+ else()
+ message(WARNING "The dtrace command is required to enable dtrace/systemtap support.")
+ endif()
endif()
## uuid
check_decl(MSG_NOSIGNAL sys/socket.h)
check_decl(rcvtimeo sys/socket.h)
check_decl(sndtimeo sys/socket.h)
+check_decl(strerror string.h)
check_decl(strerror_r string.h)
check_compiles(HAVE_STRERROR_R_CHAR_P "char x, y = *strerror_r(0,&x,1);" string.h)
-check_decl(strerror string.h)
check_decl(abi::__cxa_demangle cxxabi.h)
set(HAVE_GCC_ABI_DEMANGLE ${HAVE_ABI____CXA_DEMANGLE})
-configure_file(configure.h.in configure.h @ONLY)
-
install_public_headers(libhashkit-1.0
+ @configure.h
algorithm.h
basic_string.h
behavior.h
-configure_file(configure.h.in configure.h @ONLY)
-
add_subdirectory(struct)
add_subdirectory(types)
install_public_headers(
libmemcached-1.0
+ @configure.h
alloc.h
allocators.h
analyze.h
)
add_flex_bison_dependency(CSL_SCANNER CSL_PARSER)
+if(HAVE_DTRACE)
+ add_custom_command(
+ OUTPUT dtrace_probes.h
+ COMMAND ${DTRACE_EXECUTABLE}
+ ARGS -h -o dtrace_probes.h -s ${CMAKE_CURRENT_SOURCE_DIR}/libmemcached_probes.d
+ MAIN_DEPENDENCY libmemcached_probes.d
+ )
+ add_custom_command(
+ OUTPUT libmemcached_probes.o
+ COMMAND ${DTRACE_EXECUTABLE}
+ ARGS -o libmemcached_probes.o -G -s ${CMAKE_CURRENT_SOURCE_DIR}/libmemcached_probes.d
+ MAIN_DEPENDENCY dtrace_probes.h
+ )
+ set(DTRACE_GENERATED_OUTPUT libmemcached_probes.o)
+endif()
+
set(LIBMEMCACHED_SOURCES
csl/context.cc
${BISON_CSL_PARSER_OUTPUTS}
${FLEX_CSL_SCANNER_OUTPUTS}
+ ${DTRACE_GENERATED_OUTPUT}
allocators.cc
analyze.cc
array.c
util.h
)
-# FIXME: dtrace
-
add_library(libmemcachedinternal STATIC
${LIBMEMCACHED_SOURCES})
add_library(memcachedinternal ALIAS libmemcachedinternal)
target_link_libraries(libmemcachedinternal libhashkit Threads::Threads ${LIBSASL_LIBRARIES} ${CMAKE_DL_LIBS})
target_include_directories(libmemcachedinternal PRIVATE ${LIBSASL_INCLUDEDIR})
target_compile_definitions(libmemcachedinternal PRIVATE -DBUILDING_LIBMEMCACHEDINTERNAL)
+
+# let libmemcached depend on libmemcachedinternal to ensure that they do not
+# compete for the same generated dependencies
+add_dependencies(libmemcached libmemcachedinternal)