bin: move memaslap to contrib
[m6w6/libmemcached] / CMake / _Include.cmake
index 67963844d64bc70531a2e096a732b6494aa6be63..67917c8e10b6720c83ae4bf5586133fbeb7fd013 100644 (file)
@@ -1,10 +1,19 @@
-set(THREADS_PREFER_PTHREAD_FLAG ON)
 
 # globals
-include(CTest)
+if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+    include(CTest)
+endif()
 include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
 
+if(CMAKE_HOST_SYSTEM_NAME MATCHES "BSD")
+    find_program(PKGCONF pkgconf)
+    if(PKGCONF)
+        set(PKG_CONFIG_EXECUTABLE ${PKGCONF})
+    endif()
+endif()
 find_package(PkgConfig)
+set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
 
 # locals
@@ -17,6 +26,8 @@ include(CheckHeader)
 include(CheckCompiles)
 include(CheckType)
 include(CheckStdatomic)
+include(TestBigEndian)
+include(CheckByteswap)
 
 # configuration
 
@@ -27,23 +38,36 @@ check_debug()
 if(ENABLE_MEMASLAP)
     check_stdatomic()
     check_dependency(LIBEVENT event event.h)
+    check_dependency(LIBMATH m math.h)
     check_decl(getline stdio.h)
+    if(HAVE_LIBEVENT AND HAVE_C_STDATOMIC)
+        set(HAVE_MEMASLAP 1)
+    endif()
 endif()
 
 ## dtrace
+include(EnableDtrace)
 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
 if(BUILD_TESTING)
-    check_dependency(LIBUUID uuid uuid/uuid.h)
+    if(NOT MEMCACHED_BINARY)
+        find_package(Memcached)
+        set(MEMCACHED_BINARY ${MEMCACHED_EXECUTABLE})
+    endif()
 endif()
 
 ## sasl
 if(ENABLE_SASL)
     check_dependency(LIBSASL sasl2 sasl/sasl.h)
-    if(LIBSASL)
+    if(HAVE_LIBSASL)
         set(LIBMEMCACHED_WITH_SASL_SUPPORT 1)
     endif()
 endif()
@@ -61,10 +85,13 @@ endif()
 
 # system checks
 
+test_big_endian(WORDS_BIGENDIAN)
+check_byteswap()
+
+check_header(alloca.h)
 check_header(arpa/inet.h)
 check_header(dlfcn.h)
 check_header(errno.h)
-check_header(execinfo.h)
 check_header(fcntl.h)
 check_header(io.h)
 check_header(limits.h)
@@ -89,13 +116,25 @@ check_decl(htonll arpa/inet.h)
 check_decl(MSG_DONTWAIT sys/socket.h)
 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(SO_RCVTIMEO sys/socket.h)
+check_decl(SO_SNDTIMEO sys/socket.h)
+check_decl(setenv stdlib.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})
+
+find_package(Backtrace)
+if(Backtrace_FOUND)
+    set(HAVE_BACKTRACE 1)
+    set(BACKTRACE BACKTRACE)
+    add_library(BACKTRACE INTERFACE IMPORTED)
+    set_target_properties(BACKTRACE PROPERTIES
+            INTERFACE_LINK_LIBRARIES "${Backtrace_LIBRARIES}"
+            INTERFACE_INCLUDE_DIRECTORIES "${Backtrace_INCLUDE_DIR}")
+endif()
 
 check_type(in_port_t netinet/in.h)