Cleaned up dependency checking

This commit is contained in:
Markus Makela 2014-09-24 15:39:06 +03:00
parent a85c3fe97a
commit e30f4b4b95
3 changed files with 38 additions and 38 deletions

View File

@ -10,12 +10,7 @@ set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to in
project(MaxScale)
if(NOT DEPS_OK)
check_deps()
else()
message(STATUS "Dependencies ok")
endif()
check_deps()
check_dirs()
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules)

2
README
View File

@ -203,7 +203,7 @@ All the variables that control the CMake build process:
INSTALL_DIR=<path> Installation directory
BUILD_TYPE=[None|Debug|Release] Type of the build, defaults to Release (optimized)
INSTALL_SYSTEM_FILES=[Y|N] Install startup scripts and ld configuration files
EMBEDDED_LIB=<path> Path to the embedded library (libmysqld.a or libmysqld.so)
EMBEDDED_LIB=<path> Path to the embedded library location (libmysqld.a for static and libmysqld.so for dynamic)
MYSQL_DIR=<path> Path to MySQL headers
ERRMSG=<path> Path to errmsg.sys file
STATIC_EMBEDDED=[Y|N] Whether to link the static or the dynamic verson of the library

View File

@ -60,26 +60,18 @@ macro(check_deps)
set(MAXSCALE_DEPS aio ssl crypt crypto z m dl rt pthread)
foreach(lib ${MAXSCALE_DEPS})
find_library(lib${lib} ${lib})
if((DEFINED lib${lib}) AND (${lib${lib}} STREQUAL "lib${lib}-NOTFOUND"))
set(DEPS_ERROR TRUE)
set(FAILED_DEPS "${FAILED_DEPS} lib${lib}")
if(${lib${lib}} MATCHES "NOTFOUND")
message(FATAL_ERROR "The required library ${lib${lib}} was not found.")
elseif(DEBUG_OUTPUT)
message(STATUS "Library was found at: ${lib${lib}}")
endif()
unset(lib${lib} CACHE)
endforeach()
if(DEPS_ERROR)
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
message(FATAL_ERROR "Cannot find dependencies: ${FAILED_DEPS}")
endif()
endmacro()
macro(check_dirs)
# This variable is used to prevent redundant checking of dependencies
set(DEPS_OK TRUE CACHE BOOL "If all the dependencies were found.")
# Find the MySQL headers if they were not defined
if(DEFINED MYSQL_DIR)
if(DEBUG_OUTPUT)
@ -92,13 +84,13 @@ macro(check_dirs)
message(STATUS "Search returned: ${MYSQL_DIR_LOC}")
endif()
if(${MYSQL_DIR_LOC} STREQUAL "MYSQL_DIR_LOC-NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
unset(MYSQL_DIR CACHE)
message(FATAL_ERROR "Fatal Error: MySQL headers were not found.")
else()
message(STATUS "Using MySQL headers found at: ${MYSQL_DIR}")
set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE)
endif()
set(MYSQL_DIR_LOC "" INTERNAL)
unset(MYSQL_DIR_LOC CACHE)
# Find the errmsg.sys file if it was not defied
if( DEFINED ERRMSG )
@ -106,13 +98,13 @@ macro(check_dirs)
endif()
find_file(ERRMSG_FILE errmsg.sys PATHS /usr/share/mysql /usr/local/share/mysql PATH_SUFFIXES english)
if(${ERRMSG_FILE} MATCHES "ERRMSG_FILE-NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
unset(ERRMSG CACHE)
message(FATAL_ERROR "Fatal Error: The errmsg.sys file was not found, please define the path to it by using -DERRMSG=<path>")
else()
message(STATUS "Using errmsg.sys found at: ${ERRMSG_FILE}")
endif()
set(ERRMSG ${ERRMSG_FILE} CACHE FILEPATH "Path to the errmsg.sys file." FORCE)
set(ERRMSG_FILE "" INTERNAL)
unset(ERRMSG_FILE CACHE)
# Find the embedded mysql library
if(STATIC_EMBEDDED)
@ -123,6 +115,10 @@ macro(check_dirs)
if(DEBUG_OUTPUT)
message(STATUS "Searching for libmysqld.a at: ${EMBEDDED_LIB}")
endif()
get_filename_component(EMBEDDED_LIB_PATH ${EMBEDDED_LIB} REALPATH CACHE)
set(EMBEDDED_LIB ${EMBEDDED_LIB_PATH} CACHE PATH "Path to libmysqld" FORCE)
unset(EMBEDDED_LIB_PATH CACHE)
message(STATUS "provided path:${EMBEDDED_LIB}")
find_library(EMBEDDED_LIB_STATIC libmysqld.a PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH)
else()
find_library(EMBEDDED_LIB_STATIC libmysqld.a PATH_SUFFIXES mysql mariadb)
@ -132,13 +128,16 @@ macro(check_dirs)
endif()
set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES})
set(OLD_SUFFIXES "" INTERNAL)
unset(OLD_SUFFIXES CACHE)
else()
else()
if (DEFINED EMBEDDED_LIB)
if(DEBUG_OUTPUT)
message(STATUS "Searching for libmysqld.so at: ${EMBEDDED_LIB}")
endif()
get_filename_component(EMBEDDED_LIB_PATH ${EMBEDDED_LIB} REALPATH CACHE)
set(EMBEDDED_LIB ${EMBEDDED_LIB_PATH} CACHE PATH "Path to libmysqld" FORCE)
unset(EMBEDDED_LIB_PATH CACHE)
find_library(EMBEDDED_LIB_DYNAMIC mysqld PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH)
else()
find_library(EMBEDDED_LIB_DYNAMIC mysqld PATH_SUFFIXES mysql mariadb)
@ -149,12 +148,14 @@ macro(check_dirs)
set(EMBEDDED_LIB ${EMBEDDED_LIB_DYNAMIC} CACHE FILEPATH "Path to libmysqld" FORCE)
endif()
set(EMBEDDED_LIB_DYNAMIC "" INTERNAL)
set(EMBEDDED_LIB_STATIC "" INTERNAL)
unset(EMBEDDED_LIB_DYNAMIC CACHE)
unset(EMBEDDED_LIB_STATIC CACHE)
# Inform the user about the embedded library
if( (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_STATIC-NOTFOUND") OR (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_DYNAMIC-NOTFOUND"))
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
if(EMBEDDED_LIB MATCHES "NOTFOUND")
message(STATUS "${EMBEDDED_LIB}")
unset(EMBEDDED_LIB CACHE)
message(FATAL_ERROR "Library not found: libmysqld. If your install of MySQL is in a non-default location, please provide the location with -DEMBEDDED_LIB=<path to library>")
else()
get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH)
@ -167,26 +168,27 @@ macro(check_dirs)
if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND")
find_file(DEB_FNC init-functions PATHS /lib/lsb)
if(${DEB_FNC} MATCHES "DEB_FNC-NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
unset(DEB_BASED CACHE)
message(FATAL_ERROR "Cannot find required init-functions in /lib/lsb/ or /etc/rc.d/init.d/, please confirm that your system files are OK.")
else()
set(DEB_BASED TRUE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.")
set(DEB_BASED TRUE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions." FORCE)
endif()
else()
set(DEB_BASED FALSE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions.")
set(DEB_BASED FALSE CACHE BOOL "If init.d script uses /lib/lsb/init-functions instead of /etc/rc.d/init.d/functions." FORCE)
endif()
set(DEB_FNC "" INTERNAL)
set(RPM_FNC "" INTERNAL)
unset(DEB_FNC CACHE)
unset(RPM_FNC CACHE)
#Check RabbitMQ headers and libraries
if(BUILD_RABBITMQ)
if(DEFINED RABBITMQ_LIB)
get_filename_component(RABBITMQ_LIB ${RABBITMQ_LIB} DIRECTORY CACHE)
find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH)
endif()
find_library(RMQ_LIB rabbitmq)
if(RMQ_LIB STREQUAL "RMQ_LIB-NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
if(RMQ_LIB MATCHES NOTFOUND)
unset(RABBITMQ_LIB)
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)
@ -194,17 +196,20 @@ macro(check_dirs)
endif()
if(DEFINED RABBITMQ_HEADERS)
get_filename_component(RABBITMQ_HEADERS ${RABBITMQ_HEADERS} DIRECTORY CACHE)
find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH)
endif()
find_file(RMQ_HEADERS amqp.h)
if(RMQ_HEADERS STREQUAL "RMQ_HEADERS-NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
if(RMQ_HEADERS MATCHES NOTFOUND)
unset(RABBITMQ_HEADERS)
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()
unset(RMQ_HEADERS CACHE)
unset(RMQ_LIB CACHE)
endif()
endmacro()