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) project(MaxScale)
if(NOT DEPS_OK) check_deps()
check_deps()
else()
message(STATUS "Dependencies ok")
endif()
check_dirs() check_dirs()
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/modules) 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 INSTALL_DIR=<path> Installation directory
BUILD_TYPE=[None|Debug|Release] Type of the build, defaults to Release (optimized) 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 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 MYSQL_DIR=<path> Path to MySQL headers
ERRMSG=<path> Path to errmsg.sys file ERRMSG=<path> Path to errmsg.sys file
STATIC_EMBEDDED=[Y|N] Whether to link the static or the dynamic verson of the library 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) set(MAXSCALE_DEPS aio ssl crypt crypto z m dl rt pthread)
foreach(lib ${MAXSCALE_DEPS}) foreach(lib ${MAXSCALE_DEPS})
find_library(lib${lib} ${lib}) find_library(lib${lib} ${lib})
if((DEFINED lib${lib}) AND (${lib${lib}} STREQUAL "lib${lib}-NOTFOUND")) if(${lib${lib}} MATCHES "NOTFOUND")
set(DEPS_ERROR TRUE) message(FATAL_ERROR "The required library ${lib${lib}} was not found.")
set(FAILED_DEPS "${FAILED_DEPS} lib${lib}")
elseif(DEBUG_OUTPUT) elseif(DEBUG_OUTPUT)
message(STATUS "Library was found at: ${lib${lib}}") message(STATUS "Library was found at: ${lib${lib}}")
endif() endif()
unset(lib${lib} CACHE)
endforeach() 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() endmacro()
macro(check_dirs) 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 # Find the MySQL headers if they were not defined
if(DEFINED MYSQL_DIR) if(DEFINED MYSQL_DIR)
if(DEBUG_OUTPUT) if(DEBUG_OUTPUT)
@ -92,13 +84,13 @@ macro(check_dirs)
message(STATUS "Search returned: ${MYSQL_DIR_LOC}") message(STATUS "Search returned: ${MYSQL_DIR_LOC}")
endif() endif()
if(${MYSQL_DIR_LOC} STREQUAL "MYSQL_DIR_LOC-NOTFOUND") 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.") message(FATAL_ERROR "Fatal Error: MySQL headers were not found.")
else() else()
message(STATUS "Using MySQL headers found at: ${MYSQL_DIR}") message(STATUS "Using MySQL headers found at: ${MYSQL_DIR}")
set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE) set(MYSQL_DIR ${MYSQL_DIR_LOC} CACHE PATH "Path to MySQL headers" FORCE)
endif() endif()
set(MYSQL_DIR_LOC "" INTERNAL) unset(MYSQL_DIR_LOC CACHE)
# Find the errmsg.sys file if it was not defied # Find the errmsg.sys file if it was not defied
if( DEFINED ERRMSG ) if( DEFINED ERRMSG )
@ -106,13 +98,13 @@ macro(check_dirs)
endif() endif()
find_file(ERRMSG_FILE errmsg.sys PATHS /usr/share/mysql /usr/local/share/mysql PATH_SUFFIXES english) find_file(ERRMSG_FILE errmsg.sys PATHS /usr/share/mysql /usr/local/share/mysql PATH_SUFFIXES english)
if(${ERRMSG_FILE} MATCHES "ERRMSG_FILE-NOTFOUND") 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>") message(FATAL_ERROR "Fatal Error: The errmsg.sys file was not found, please define the path to it by using -DERRMSG=<path>")
else() else()
message(STATUS "Using errmsg.sys found at: ${ERRMSG_FILE}") message(STATUS "Using errmsg.sys found at: ${ERRMSG_FILE}")
endif() endif()
set(ERRMSG ${ERRMSG_FILE} CACHE FILEPATH "Path to the errmsg.sys file." FORCE) 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 # Find the embedded mysql library
if(STATIC_EMBEDDED) if(STATIC_EMBEDDED)
@ -123,6 +115,10 @@ macro(check_dirs)
if(DEBUG_OUTPUT) if(DEBUG_OUTPUT)
message(STATUS "Searching for libmysqld.a at: ${EMBEDDED_LIB}") message(STATUS "Searching for libmysqld.a at: ${EMBEDDED_LIB}")
endif() 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) find_library(EMBEDDED_LIB_STATIC libmysqld.a PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH)
else() else()
find_library(EMBEDDED_LIB_STATIC libmysqld.a PATH_SUFFIXES mysql mariadb) find_library(EMBEDDED_LIB_STATIC libmysqld.a PATH_SUFFIXES mysql mariadb)
@ -132,13 +128,16 @@ macro(check_dirs)
endif() endif()
set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE) set(EMBEDDED_LIB ${EMBEDDED_LIB_STATIC} CACHE FILEPATH "Path to libmysqld" FORCE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES})
set(OLD_SUFFIXES "" INTERNAL) unset(OLD_SUFFIXES CACHE)
else() else()
if (DEFINED EMBEDDED_LIB) if (DEFINED EMBEDDED_LIB)
if(DEBUG_OUTPUT) if(DEBUG_OUTPUT)
message(STATUS "Searching for libmysqld.so at: ${EMBEDDED_LIB}") message(STATUS "Searching for libmysqld.so at: ${EMBEDDED_LIB}")
endif() 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) find_library(EMBEDDED_LIB_DYNAMIC mysqld PATHS ${EMBEDDED_LIB} PATH_SUFFIXES mysql mariadb NO_DEFAULT_PATH)
else() else()
find_library(EMBEDDED_LIB_DYNAMIC mysqld PATH_SUFFIXES mysql mariadb) 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) set(EMBEDDED_LIB ${EMBEDDED_LIB_DYNAMIC} CACHE FILEPATH "Path to libmysqld" FORCE)
endif() endif()
set(EMBEDDED_LIB_DYNAMIC "" INTERNAL) unset(EMBEDDED_LIB_DYNAMIC CACHE)
set(EMBEDDED_LIB_STATIC "" INTERNAL) unset(EMBEDDED_LIB_STATIC CACHE)
# Inform the user about the embedded library # Inform the user about the embedded library
if( (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_STATIC-NOTFOUND") OR (${EMBEDDED_LIB} STREQUAL "EMBEDDED_LIB_DYNAMIC-NOTFOUND")) if(EMBEDDED_LIB MATCHES "NOTFOUND")
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.")
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>") 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() else()
get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH) get_filename_component(EMBEDDED_LIB ${EMBEDDED_LIB} REALPATH)
@ -167,26 +168,27 @@ macro(check_dirs)
if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND") if(${RPM_FNC} MATCHES "RPM_FNC-NOTFOUND")
find_file(DEB_FNC init-functions PATHS /lib/lsb) find_file(DEB_FNC init-functions PATHS /lib/lsb)
if(${DEB_FNC} MATCHES "DEB_FNC-NOTFOUND") 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.") 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() 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() endif()
else() 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() endif()
set(DEB_FNC "" INTERNAL) unset(DEB_FNC CACHE)
set(RPM_FNC "" INTERNAL) unset(RPM_FNC CACHE)
#Check RabbitMQ headers and libraries #Check RabbitMQ headers and libraries
if(BUILD_RABBITMQ) if(BUILD_RABBITMQ)
if(DEFINED RABBITMQ_LIB) if(DEFINED RABBITMQ_LIB)
get_filename_component(RABBITMQ_LIB ${RABBITMQ_LIB} DIRECTORY CACHE)
find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH) find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH)
endif() endif()
find_library(RMQ_LIB rabbitmq) find_library(RMQ_LIB rabbitmq)
if(RMQ_LIB STREQUAL "RMQ_LIB-NOTFOUND") if(RMQ_LIB MATCHES NOTFOUND)
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") unset(RABBITMQ_LIB)
message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=<path>") message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=<path>")
else() else()
set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE) set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE)
@ -194,17 +196,20 @@ macro(check_dirs)
endif() endif()
if(DEFINED RABBITMQ_HEADERS) 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) find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH)
endif() endif()
find_file(RMQ_HEADERS amqp.h) find_file(RMQ_HEADERS amqp.h)
if(RMQ_HEADERS STREQUAL "RMQ_HEADERS-NOTFOUND") if(RMQ_HEADERS MATCHES NOTFOUND)
set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") unset(RABBITMQ_HEADERS)
message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=<path>") message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=<path>")
else() else()
set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE) set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE)
message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}") message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}")
endif() endif()
unset(RMQ_HEADERS CACHE)
unset(RMQ_LIB CACHE)
endif() endif()
endmacro() endmacro()