if(FOUND)
message("-- Found library '${LIB${LIB}}'")
message("-- Found include '${${HEADER_CONST}_ROOT}'")
+ add_library(${NAME} INTERFACE IMPORTED)
+ set_target_properties(${NAME} PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES ${${HEADER_CONST}_ROOT}
+ INTERFACE_LINK_LIBRARIES ${LIB${LIB}})
else()
message("-- No library '${LIB}' found")
endif()
- set(${NAME} ${FOUND} PARENT_SCOPE)
- set(${NAME}_LIBRARIES ${LIB${LIB}} PARENT_SCOPE)
- set(${NAME}_INCLUDEDIR ${${HEADER_CONST}_ROOT} PARENT_SCOPE)
+ set(${NAME}_FOUND ${FOUND} PARENT_SCOPE)
endfunction()
function(check_dependency NAME LIB HEADER)
if(NOT ${NAME}_FOUND)
pkg_check_modules(${NAME} ${LIB}${ARGN})
endif()
- if(NOT ${NAME}_FOUND)
- check_dependency_basic(${NAME} ${LIB} ${HEADER})
- else()
- set(${NAME} ${${NAME}_FOUND} PARENT_SCOPE)
- set(${NAME}_LIBRARIES ${${NAME}_LDFLAGS} PARENT_SCOPE)
- set(${NAME}_INCLUDEDIR ${${NAME}_INCLUDEDIR} PARENT_SCOPE)
+ if(${NAME}_FOUND)
+ add_library(${NAME} ALIAS PkgConfig::${NAME})
+ endif()
+ endif()
+ if(NOT ${NAME}_FOUND)
+ check_dependency_basic(${NAME} ${LIB} ${HEADER})
+ endif()
- safe_string(${LIB} LIB_CONST)
- set(HAVE_${NAME} ${${NAME}_FOUND} PARENT_SCOPE)
- safe_string(${HEADER} HEADER_CONST)
- find_path(HAVE_${HEADER_CONST} ${HEADER} PATHS ${${NAME}_INCLUDEDIR})
- endif()
- else()
- check_dependency_basic(${NAME} ${LIB} ${HEADER})
+ set(HAVE_${NAME} ${${NAME}_FOUND} PARENT_SCOPE)
+ if(${NAME}_FOUND)
+ safe_string(${HEADER} HEADER_CONST)
+ find_path(HAVE_${HEADER_CONST} ${HEADER} PATHS ${${NAME}_INCLUDEDIR})
endif()
endfunction()
--- /dev/null
+function(CHECK_TBB)
+ check_header(execution)
+ # TBBConfig only sets TBB_FOUND to FALSE
+ if(HAVE_EXECUTION)
+ check_dependency(LIBTBB tbb tbb/task.h)
+ if(HAVE_LIBTBB)
+ cmake_push_check_state(RESET)
+ get_property(LIBTBB_INCLUDEDIR TARGET LIBTBB PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
+ get_property(LIBTBB_LIBRARIES TARGET LIBTBB PROPERTY INTERFACE_LINK_LIBRARIES)
+ set(CMAKE_REQUIRED_INCLUDES "${LIBTBB_INCLUDEDIR}")
+ set(CMAKE_REQUIRED_LIBRARIES "${LIBTBB_LIBRARIES}")
+ set(CMAKE_REQUIRED_FLAGS -std=c++17)
+ check_compiles(HAVE_TBB "std::vector<char> a={1,2,3}; std::all_of(std::execution::par,a.begin(),a.end(),[](char i){return i>0;});" vector algorithm execution)
+ cmake_pop_check_state(RESET)
+ if(HAVE_TBB)
+ set(HAVE_LIBTBB 1 PARENT_SCOPE)
+ endif()
+ endif()
+ endif()
+endfunction()
find_program(MEMCACHED_EXECUTABLE NAMES memcached
HINTS $ENV{MEMCACHED_DIR}
PATH_SUFFIXES bin
- DOC "memcached(), Memcached daemon"
+ DOC "memcached(1), Memcached daemon"
)
include(FindPackageHandleStandardArgs)
check_stdatomic()
check_dependency(LIBEVENT event event.h)
check_decl(getline stdio.h)
- if(LIBEVENT AND HAVE_C_STDATOMIC)
+ if(HAVE_LIBEVENT AND HAVE_C_STDATOMIC)
set(HAVE_MEMASLAP 1)
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()
find_package(Backtrace)
if(Backtrace_FOUND)
set(HAVE_BACKTRACE 1)
+ 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)
# modules
-set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
if(NOT BUILD_DOCSONLY)
include(CMake/_Include.cmake)
DESCRIPTION "libmemcached https://github.com/m6w6/libmemcached"
)
-set(CMAKE_CXX_STANDARD 11)
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(CMakeConfig.txt)
foreach(CLIENT IN LISTS CLIENTS)
add_executable(${CLIENT} ${CLIENT}.cc)
+ set_target_properties(${CLIENT} PROPERTIES CXX_STANDARD ${CXX_STANDARD})
target_include_directories(${CLIENT} PRIVATE ..)
target_link_libraries(${CLIENT} PRIVATE libclient_common)
if(CMAKE_INSTALL_RPATH)
memaslap/ms_task.c
memaslap/ms_thread.c)
target_include_directories(memaslap PRIVATE memaslap)
- target_link_libraries(memaslap PRIVATE libclient_common Threads::Threads)
- if(PKG_CONFIG_FOUND)
- target_link_libraries(memaslap PRIVATE PkgConfig::LIBEVENT)
- else()
- target_include_directories(memaslap PRIVATE ${LIBEVENT_INCLUDEDIR})
- target_link_libraries(memaslap PRIVATE ${LIBEVENT_LIBRARIES})
- endif()
+ target_link_libraries(memaslap PRIVATE libclient_common Threads::Threads LIBEVENT)
if(CMAKE_INSTALL_RPATH)
set_target_properties(${CLIENT} PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR})
)
add_library(hashkit ALIAS libhashkit)
set_target_properties(libhashkit PROPERTIES
+ CXX_STANDARD ${CXX_STANDARD}
LIBRARY_OUTPUT_NAME hashkit
LIBRARY_OUTPUT_NAME_DEBUG hashkit-dbg
SOVERSION ${LIBHASHKIT_SO_VERSION}
${LIBMEMCACHED_SOURCES})
add_library(memcached ALIAS libmemcached)
set_target_properties(libmemcached PROPERTIES
+ CXX_STANDARD ${CXX_STANDARD}
LIBRARY_OUTPUT_NAME memcached
LIBRARY_OUTPUT_NAME_DEBUG memcached-dbg
SOVERSION ${LIBMEMCACHED_SO_VERSION}
VERSION v${LIBMEMCACHED_VERSION})
target_compile_definitions(libmemcached PRIVATE -DBUILDING_LIBMEMCACHED)
-target_link_libraries(libmemcached PUBLIC libhashkit Threads::Threads ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
-if(LIBSASL_FOUND)
- if(PKG_CONFIG_FOUND)
- target_link_libraries(libmemcached PUBLIC PkgConfig::LIBSASL)
- else()
- target_link_libraries(libmemcached PUBLIC ${LIBSASL_LIBRARIES})
- target_include_directories(libmemcached PUBLIC ${LIBSASL_INCLUDEDIR})
- endif()
+target_link_libraries(libmemcached PUBLIC libhashkit Threads::Threads ${CMAKE_DL_LIBS})
+if(HAVE_BACKTRACE)
+ target_link_libraries(libmemcached PRIVATE BACKTRACE)
+endif()
+if(HAVE_LIBSASL)
+ target_link_libraries(libmemcached PUBLIC LIBSASL)
endif()
-target_include_directories(libmemcached PRIVATE ${Backtrace_INCLUDE_DIR})
target_include_directories(libmemcached PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
add_library(libmemcachedinternal STATIC
${LIBMEMCACHED_SOURCES})
add_library(memcachedinternal ALIAS libmemcachedinternal)
-set_target_properties(libmemcachedinternal PROPERTIES LIBRARY_OUTPUT_NAME memcachedinternal)
+set_target_properties(libmemcachedinternal PROPERTIES CXX_STANDARD ${CXX_STANDARD} LIBRARY_OUTPUT_NAME memcachedinternal)
target_compile_definitions(libmemcachedinternal PRIVATE -DBUILDING_LIBMEMCACHEDINTERNAL)
-target_link_libraries(libmemcachedinternal PUBLIC libhashkit Threads::Threads ${LIBSASL_LIBRARIES} ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
+target_link_libraries(libmemcachedinternal PUBLIC libhashkit Threads::Threads ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
+if(HAVE_LIBSASL)
+ target_link_libraries(libmemcachedinternal PUBLIC LIBSASL)
+endif()
target_include_directories(libmemcachedinternal PRIVATE ${Backtrace_INCLUDE_DIR})
target_include_directories(libmemcachedinternal PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
${CMAKE_BINARY_DIR})
-target_include_directories(libmemcachedinternal PUBLIC ${LIBSASL_INCLUDEDIR})
target_include_directories(libmemcachedinternal PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
)
add_library(memcachedprotocol ALIAS libmemcachedprotocol)
set_target_properties(libmemcachedprotocol PROPERTIES
+ CXX_STANDARD ${CXX_STANDARD}
LIBRARY_OUTPUT_NAME memcachedprotocol
LIBRARY_OUTPUT_NAME_DEBUG memcachedprotocol-dbg
SOVERSION ${LIBMEMCACHEDPROTOCOL_SO_VERSION}
)
add_library(memcachedutil ALIAS libmemcachedutil)
set_target_properties(libmemcachedutil PROPERTIES
+ CXX_STANDARD ${CXX_STANDARD}
LIBRARY_OUTPUT_NAME memcachedutil
LIBRARY_OUTPUT_NAME_DEBUG memcachedutil-dbg
SOVERSION ${LIBMEMCACHEDUTIL_SO_VERSION}
)
endif()
target_link_libraries(libmemcachedutil PUBLIC Threads::Threads)
+if(HAVE_LIBSASL)
+ target_link_libraries(libmemcachedutil PUBLIC LIBSASL)
+endif()
target_include_directories(libmemcachedutil PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
${CMAKE_BINARY_DIR})
-target_include_directories(libmemcachedutil PUBLIC ${LIBSASL_INCLUDEDIR})
target_include_directories(libmemcachedutil PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
return()
endif()
-include(CMake/Catch.cmake)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
+include(Catch)
+include(CheckTbb)
if(NOT MEMCACHED_BINARY)
message(SEND_ERROR "Could not find memcached(1) binary")
check_decl(SOCK_NONBLOCK sys/socket.h)
check_decl(SOCK_CLOEXEC sys/socket.h)
-check_header(execution)
-
-# TBBConfig only sets TBB_FOUND to FALSE
-set(TBB_FOUND TRUE)
-set(TBB_FIND_RELEASE_ONLY TRUE)
-find_package(TBB)
-
file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
set(TESTING_ROOT ${CMAKE_CURRENT_BINARY_DIR})
set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src)
target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcachedutil)
-if(TBB_FOUND AND HAVE_EXECUTION)
- target_link_libraries(runtests PRIVATE TBB::tbb)
-else()
- set(HAVE_EXECUTION 0)
+
+check_tbb()
+if(HAVE_TBB)
+ message("HAVE TBB")
+ target_link_libraries(runtests PRIVATE LIBTBB)
endif()
+
add_dependencies(runtests ${CLIENTS})
if(HAVE_MEMASLAP)
add_dependencies(runtests memaslap)
#cmakedefine HAVE_SOCK_NONBLOCK 1
#cmakedefine HAVE_SOCK_CLOEXEC 1
#cmakedefine HAVE_EXECUTION 1
+#cmakedefine HAVE_TBB 1
#cmakedefine TESTING_ROOT "@TESTING_ROOT@"
#cmakedefine MEMCACHED_BINARY getenv_else("MEMCACHED_BINARY", "@MEMCACHED_BINARY@")
#include "Retry.hpp"
#include <algorithm>
-#if HAVE_EXECUTION
+#if HAVE_EXECUTION && HAVE_TBB
# include <execution>
#endif
#include <sys/wait.h>
bool Cluster::isStopped() {
return none_of(
-#if HAVE_EXECUTION
+#if HAVE_EXECUTION && HAVE_TBB
execution::par,
#endif
cluster.begin(), cluster.end(), [](Server &s) {
bool Cluster::isListening() const {
return all_of(
-#if HAVE_EXECUTION
+#if HAVE_EXECUTION && HAVE_TBB
execution::par,
#endif
cluster.begin(), cluster.end(), [](const Server &s) {
return false;
}
auto listening = all_of(
-#if HAVE_EXECUTION
+#if HAVE_EXECUTION && HAVE_TBB
execution::par,
#endif
cluster.begin(), cluster.end(), [](Server &s) {