cmake: add missing headers; add dtrace
authorMichael Wallner <mike@php.net>
Wed, 19 Aug 2020 14:21:01 +0000 (16:21 +0200)
committerMichael Wallner <mike@php.net>
Wed, 19 Aug 2020 14:21:01 +0000 (16:21 +0200)
CMake/CheckDebug.cmake
CMake/FindDTrace.cmake [new file with mode: 0644]
CMake/InstallPublicHeaders.cmake
CMake/_Include.cmake
include/libhashkit-1.0/CMakeLists.txt
include/libmemcached-1.0/CMakeLists.txt
src/libmemcached/CMakeLists.txt

index cc91da979171d09e23d5f375ecf7445808c00e13..2701bdfd0ab3107c5cdf4b11364acb5b4eb93bff 100644 (file)
@@ -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 (file)
index 0000000..4e7b379
--- /dev/null
@@ -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)
index 70cfe3d02c092864373daf4d63ce1076e11681ed..c25c5cf03776fe83099a6ad9d966b67345721281 100644 (file)
@@ -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()
index 67963844d64bc70531a2e096a732b6494aa6be63..00da54f9a46b0012a4bc9a0cb71759ea61be09b7 100644 (file)
@@ -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})
 
index 13e836f62758852959f866b133f3e8ee5e8dbc51..24fefd5757477eafa282c24f920ff76843b5e9b6 100644 (file)
@@ -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
index f288c13ef7ab06d4bf4bca00dda53268e4ad4f73..c9b4f7c1f0adce916f2ae45273679b46decd471d 100644 (file)
@@ -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
index a5c80f43eb481e22d9bc43acf749983e51421b2e..ebb0d83bb4c0abd603033bf19e4235a8e298f972 100644 (file)
@@ -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)