From: Michael Wallner Date: Wed, 19 Aug 2020 14:21:01 +0000 (+0200) Subject: cmake: add missing headers; add dtrace X-Git-Tag: 1.1.0-beta1~241 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d3ccb3a18e065b270a58b628482d1ca06f58766c;p=m6w6%2Flibmemcached cmake: add missing headers; add dtrace --- diff --git a/CMake/CheckDebug.cmake b/CMake/CheckDebug.cmake index cc91da97..2701bdfd 100644 --- a/CMake/CheckDebug.cmake +++ b/CMake/CheckDebug.cmake @@ -1,9 +1,21 @@ 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 @@ -11,8 +23,6 @@ function(check_debug) -fno-eliminate-unused-debug-types -funsafe-loop-optimizations - -g3 - -Wall -Wextra @@ -27,12 +37,7 @@ function(check_debug) -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) diff --git a/CMake/FindDTrace.cmake b/CMake/FindDTrace.cmake new file mode 100644 index 00000000..4e7b3790 --- /dev/null +++ b/CMake/FindDTrace.cmake @@ -0,0 +1,10 @@ +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) diff --git a/CMake/InstallPublicHeaders.cmake b/CMake/InstallPublicHeaders.cmake index 70cfe3d0..c25c5cf0 100644 --- a/CMake/InstallPublicHeaders.cmake +++ b/CMake/InstallPublicHeaders.cmake @@ -31,13 +31,12 @@ function(install_public_headers DIRECTORY) # 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() diff --git a/CMake/_Include.cmake b/CMake/_Include.cmake index 67963844..00da54f9 100644 --- a/CMake/_Include.cmake +++ b/CMake/_Include.cmake @@ -32,7 +32,12 @@ endif() ## 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 @@ -91,9 +96,9 @@ check_decl(MSG_MORE sys/socket.h) 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}) diff --git a/include/libhashkit-1.0/CMakeLists.txt b/include/libhashkit-1.0/CMakeLists.txt index 13e836f6..24fefd57 100644 --- a/include/libhashkit-1.0/CMakeLists.txt +++ b/include/libhashkit-1.0/CMakeLists.txt @@ -1,7 +1,6 @@ -configure_file(configure.h.in configure.h @ONLY) - install_public_headers(libhashkit-1.0 + @configure.h algorithm.h basic_string.h behavior.h diff --git a/include/libmemcached-1.0/CMakeLists.txt b/include/libmemcached-1.0/CMakeLists.txt index f288c13e..c9b4f7c1 100644 --- a/include/libmemcached-1.0/CMakeLists.txt +++ b/include/libmemcached-1.0/CMakeLists.txt @@ -1,12 +1,11 @@ -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 diff --git a/src/libmemcached/CMakeLists.txt b/src/libmemcached/CMakeLists.txt index a5c80f43..ebb0d83b 100644 --- a/src/libmemcached/CMakeLists.txt +++ b/src/libmemcached/CMakeLists.txt @@ -16,10 +16,27 @@ flex_target(CSL_SCANNER csl/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/csl/scanner.cc ) 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 @@ -91,8 +108,6 @@ install_public_headers( util.h ) -# FIXME: dtrace - add_library(libmemcachedinternal STATIC ${LIBMEMCACHED_SOURCES}) add_library(memcachedinternal ALIAS libmemcachedinternal) @@ -100,3 +115,7 @@ set_target_properties(libmemcachedinternal PROPERTIES LIBRARY_OUTPUT_NAME memcac 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)