Added find_package modules for MySQLClient and RabbitMQ and fixed an error in consumer.c
This commit is contained in:
parent
c3439027d4
commit
990de59241
@ -10,11 +10,13 @@ set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to in
|
||||
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/")
|
||||
find_package(Valgrind)
|
||||
|
||||
project(MaxScale)
|
||||
|
||||
check_deps()
|
||||
check_dirs()
|
||||
find_package(Valgrind)
|
||||
find_package(MySQLClient)
|
||||
|
||||
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules)
|
||||
|
||||
@ -93,7 +95,10 @@ add_subdirectory(log_manager)
|
||||
add_subdirectory(query_classifier)
|
||||
add_subdirectory(server)
|
||||
add_subdirectory(client)
|
||||
|
||||
if(BUILD_RABBITMQ)
|
||||
find_package(RabbitMQ)
|
||||
add_subdirectory(rabbitmq_consumer)
|
||||
endif()
|
||||
|
||||
# Install startup scripts and ldconfig files
|
||||
if( NOT ( (DEFINED INSTALL_SYSTEM_FILES) AND ( NOT ( INSTALL_SYSTEM_FILES ) ) ) )
|
||||
|
33
FindMySQLClient.cmake
Normal file
33
FindMySQLClient.cmake
Normal file
@ -0,0 +1,33 @@
|
||||
# This CMake file tries to find the the MySQL client library
|
||||
# The following variables are set:
|
||||
# MYSQLCLIENT_FOUND - System has MySQL client
|
||||
# MYSQLCLIENT_STATIC_FOUND - System has statically linked MySQL client
|
||||
# MYSQLCLIENT_LIBRARIES - The MySQL client library
|
||||
# MYSQLCLIENT_STATIC_LIBRARIES - The static MySQL client library
|
||||
# MYSQLCLIENT_HEADERS - The MySQL client headers
|
||||
|
||||
find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb)
|
||||
if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND")
|
||||
set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "")
|
||||
message(STATUS "Dynamic MySQL client library not found.")
|
||||
unset(MYSQLCLIENT_LIBRARIES)
|
||||
else()
|
||||
set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "")
|
||||
message(STATUS "Found dynamic MySQL client library: ${MYSQLCLIENT_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
set(OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
find_library(MYSQLCLIENT_STATIC_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES})
|
||||
|
||||
if(${MYSQLCLIENT_STATIC_LIBRARIES} MATCHES "NOTFOUND")
|
||||
set(MYSQLCLIENT_STATIC_FOUND FALSE CACHE INTERNAL "")
|
||||
message(STATUS "Static MySQL client library not found.")
|
||||
unset(MYSQLCLIENT_STATIC_LIBRARIES)
|
||||
else()
|
||||
set(MYSQLCLIENT_STATIC_FOUND TRUE CACHE INTERNAL "")
|
||||
message(STATUS "Found statc MySQL client library: ${MYSQLCLIENT_STATIC_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
find_path(MYSQLCLIENT_HEADERS mysql.h PATH_SUFFIXES mysql mariadb)
|
23
FindRabbitMQ.cmake
Normal file
23
FindRabbitMQ.cmake
Normal file
@ -0,0 +1,23 @@
|
||||
# This CMake file tries to find the the RabbitMQ library
|
||||
# The following variables are set:
|
||||
# RABBITMQ_FOUND - System has RabbitMQ client
|
||||
# RABBITMQ_LIBRARIES - The RabbitMQ client library
|
||||
# RABBITMQ_HEADERS - The RabbitMQ client headers
|
||||
include(CheckCSourceCompiles)
|
||||
find_library(RABBITMQ_LIBRARIES NAMES rabbitmq)
|
||||
find_path(RABBITMQ_HEADERS amqp.h PATH_SUFFIXES mysql mariadb)
|
||||
|
||||
if(${RABBITMQ_LIBRARIES} MATCHES "NOTFOUND")
|
||||
set(RABBITMQ_FOUND FALSE CACHE INTERNAL "")
|
||||
message(STATUS "RabbitMQ library not found.")
|
||||
unset(RABBITMQ_LIBRARIES)
|
||||
else()
|
||||
set(RABBITMQ_FOUND TRUE CACHE INTERNAL "")
|
||||
message(STATUS "Found RabbitMQ library: ${RABBITMQ_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_INCLUDES ${RABBITMQ_HEADERS})
|
||||
check_c_source_compiles("#include <amqp.h>\n int main(){if(AMQP_DELIVERY_PERSISTENT){return 0;}return 1;}" HAVE_RABBITMQ50)
|
||||
if(NOT HAVE_RABBITMQ50)
|
||||
message(FATAL_ERROR "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.")
|
||||
endif()
|
4
README
4
README
@ -221,8 +221,8 @@ DEPS_OK=[Y|N] Check dependencies, use N when you want to force a recheck of
|
||||
DEBUG_OUTPUT=[Y|N] Produce debugging output when configuring CMake
|
||||
RABBITMQ_LIB=<path> Path to RabbitMQ-C libraries
|
||||
RABBITMQ_HEADERS=<path> Path to RabbitMQ-C headers
|
||||
MYSQL_CLIENT_LIB=<path> Path to MySQL client libraries
|
||||
MYSQL_CLIENT_HEADERS=<path> Path to MySQL client headers
|
||||
MYSQLCLIENT_LIBRARIES=<path> Path to MySQL client libraries
|
||||
MYSQLCLIENT_HEADERS=<path> Path to MySQL client headers
|
||||
|
||||
\section Running Running MaxScale
|
||||
|
||||
|
84
macros.cmake
84
macros.cmake
@ -206,50 +206,52 @@ debugmsg("Search returned: ${MYSQL_DIR_LOC}")
|
||||
unset(RPM_FNC)
|
||||
|
||||
#Find the MySQL client library
|
||||
find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb)
|
||||
if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND")
|
||||
set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "")
|
||||
message(STATUS "Cannot find MySQL client library: Login tests disabled.")
|
||||
else()
|
||||
set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "")
|
||||
message(STATUS "Found MySQL client library: ${MYSQLCLIENT_LIBRARIES}")
|
||||
endif()
|
||||
# find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb)
|
||||
# if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND")
|
||||
# set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "")
|
||||
# message(STATUS "Cannot find MySQL client library: Login tests disabled.")
|
||||
# else()
|
||||
# set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "")
|
||||
# message(STATUS "Found MySQL client library: ${MYSQLCLIENT_LIBRARIES}")
|
||||
# endif()
|
||||
|
||||
#Check RabbitMQ headers and libraries
|
||||
if(BUILD_RABBITMQ)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
if(DEFINED RABBITMQ_LIB)
|
||||
find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH)
|
||||
else()
|
||||
find_library(RMQ_LIB rabbitmq)
|
||||
endif()
|
||||
if(RMQ_LIB MATCHES "NOTFOUND")
|
||||
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
|
||||
message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=<path>")
|
||||
else()
|
||||
set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE)
|
||||
message(STATUS "Using RabbitMQ libraries found at: ${RABBITMQ_LIB}")
|
||||
endif()
|
||||
|
||||
if(DEFINED RABBITMQ_HEADERS)
|
||||
find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH)
|
||||
else()
|
||||
find_file(RMQ_HEADERS amqp.h)
|
||||
endif()
|
||||
if(RMQ_HEADERS MATCHES "NOTFOUND")
|
||||
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
|
||||
message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=<path>")
|
||||
else()
|
||||
set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE)
|
||||
message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_INCLUDES ${RABBITMQ_HEADERS})
|
||||
check_c_source_compiles("#include <amqp.h>\n int main(){if(AMQP_DELIVERY_PERSISTENT){return 0;}return 1;}" HAVE_RMQ50)
|
||||
if(NOT HAVE_RMQ50)
|
||||
message(FATAL_ERROR "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.")
|
||||
endif()
|
||||
|
||||
find_package(RabbitMQ)
|
||||
# include(CheckCSourceCompiles)
|
||||
#
|
||||
# if(DEFINED RABBITMQ_LIB)
|
||||
# find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH)
|
||||
# else()
|
||||
# find_library(RMQ_LIB rabbitmq)
|
||||
# endif()
|
||||
# if(RMQ_LIB MATCHES "NOTFOUND")
|
||||
# set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
|
||||
# message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=<path>")
|
||||
# else()
|
||||
# set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE)
|
||||
# message(STATUS "Using RabbitMQ libraries found at: ${RABBITMQ_LIB}")
|
||||
# endif()
|
||||
#
|
||||
# if(DEFINED RABBITMQ_HEADERS)
|
||||
# find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH)
|
||||
# else()
|
||||
# find_file(RMQ_HEADERS amqp.h)
|
||||
# endif()
|
||||
# if(RMQ_HEADERS MATCHES "NOTFOUND")
|
||||
# set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
|
||||
# message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=<path>")
|
||||
# else()
|
||||
# set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE)
|
||||
# message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}")
|
||||
# endif()
|
||||
#
|
||||
# set(CMAKE_REQUIRED_INCLUDES ${RABBITMQ_HEADERS})
|
||||
# check_c_source_compiles("#include <amqp.h>\n int main(){if(AMQP_DELIVERY_PERSISTENT){return 0;}return 1;}" HAVE_RMQ50)
|
||||
# if(NOT HAVE_RMQ50)
|
||||
# message(FATAL_ERROR "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.")
|
||||
# endif()
|
||||
#
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
@ -1,19 +1,17 @@
|
||||
if (NOT ( DEFINED MYSQL_CLIENT_LIB ) )
|
||||
find_library(MYSQL_CLIENT_LIB NAMES mysqlclient PATHS /usr/lib /usr/lib64 PATH_SUFFIXES mysql mariadb)
|
||||
endif()
|
||||
if(RABBITMQ_FOUND AND MYSQLCLIENT_FOUND)
|
||||
|
||||
if (NOT ( DEFINED MYSQL_CLIENT_HEADERS ) )
|
||||
find_path(MYSQL_CLIENT_HEADERS NAMES mysql.h PATH_SUFFIXES mysql mariadb)
|
||||
endif()
|
||||
|
||||
if( ( RABBITMQ_LIB AND RABBITMQ_HEADERS ) AND ( NOT ( ${MYSQL_CLIENT_LIB} STREQUAL "MYSQL_CLIENT_LIB-NOTFOUND" ) ) AND ( NOT ( ${MYSQL_CLIENT_HEADERS} STREQUAL "MYSQL_CLIENT_HEADERS-NOTFOUND" ) ) )
|
||||
include_directories(${MYSQL_CLIENT_HEADERS})
|
||||
include_directories(${MYSQLCLIENT_HEADERS})
|
||||
add_executable (consumer consumer.c)
|
||||
target_link_libraries(consumer ${MYSQL_CLIENT_LIB} rabbitmq inih)
|
||||
|
||||
if(MYSQLCLIENT_FOUND)
|
||||
target_link_libraries(consumer ${MYSQLCLIENT_LIBRARIES} rabbitmq inih)
|
||||
elseif(MYSQLCLIENT_STATIC_FOUND)
|
||||
target_link_libraries(consumer ${MYSQLCLIENT_STATIC_LIBRARIES} rabbitmq inih)
|
||||
endif()
|
||||
|
||||
install(TARGETS consumer DESTINATION bin)
|
||||
install(FILES consumer.cnf DESTINATION etc)
|
||||
|
||||
|
||||
else()
|
||||
|
||||
message(FATAL_ERROR "Error: Can not find requred libraries and headers: librabbitmq libmysqlclient")
|
||||
|
@ -143,7 +143,7 @@ int connectToServer(MYSQL* server)
|
||||
}
|
||||
|
||||
memset(qstr,0,bsz);
|
||||
sprintf(qstr,DB_TABLE);
|
||||
sprintf(qstr,"%s",DB_TABLE);
|
||||
if(mysql_query(server,qstr)){
|
||||
fprintf(stderr,"Error: Could not send query MySQL server: %s\n",mysql_error(server));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user