2013-09-28 17:59:50 +08:00
# Main CMake file for the ZoneMinder project.
# Created by mastertheknife (Kfir Itzhak)
# The goal is to ease up the installation of zoneminder.
# Our current installation method (using autotools) is outdated, slow and breaks now and then.
# The CMake installation method will require no parameters at all, default should sufficient and reliable.
# It will be still possible to install ZoneMinder using autotools, they don't conflict with each other. The cmake way is a complete re-write (different syntax) and aims to be identical to the autotools way,
# by having options using the same name and leaving ZM totally unmodified, while providing exactly the same things that ZM expects (config.h, configuration in *.in files, etc).
#
# For more information and installation, see the INSTALL file
#
cmake_minimum_required ( VERSION 2.6 )
2013-10-09 20:41:14 +08:00
project ( zoneminder )
2013-12-14 02:39:23 +08:00
set ( zoneminder_VERSION "1.26.5" )
2013-10-09 20:41:14 +08:00
2013-11-01 00:10:00 +08:00
# CMake does not allow out-of-source build if CMakeCache.exists in the source folder. Abort and notify the user to save him from headache why it doesn't work.
if ( ( NOT ( CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR ) ) AND ( EXISTS "${CMAKE_SOURCE_DIR}/CMakeCache.txt" ) )
message ( FATAL_ERROR " You are attempting to do an out-of-source build, but a cmake cache file for an in-source build exists. Please delete the file CMakeCache.txt from the source folder to proceed." )
endif ( ( NOT ( CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR ) ) AND ( EXISTS "${CMAKE_SOURCE_DIR}/CMakeCache.txt" ) )
2013-09-28 17:59:50 +08:00
# Default build type. To change the build type, use the CMAKE_BUILD_TYPE configuration option.
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Release or Debug" FORCE )
endif ( NOT CMAKE_BUILD_TYPE )
2013-10-09 20:41:14 +08:00
# Can assist in troubleshooting
2013-09-28 17:59:50 +08:00
#set(CMAKE_VERBOSE_MAKEFILE ON)
#set(CMAKE_INSTALL_ALWAYS ON)
# Default CLFAGS and CXXFLAGS:
set ( CMAKE_C_FLAGS_RELEASE "-Wall -D__STDC_CONSTANT_MACROS -O2" )
set ( CMAKE_CXX_FLAGS_RELEASE "-Wall -D__STDC_CONSTANT_MACROS -O2" )
set ( CMAKE_C_FLAGS_DEBUG "-Wall -D__STDC_CONSTANT_MACROS -g" )
set ( CMAKE_CXX_FLAGS_DEBUG "-Wall -D__STDC_CONSTANT_MACROS -g" )
2013-11-17 21:10:35 +08:00
set ( CMAKE_INCLUDE_CURRENT_DIR ON )
2013-09-28 17:59:50 +08:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR}/cmake/Modules/" )
2013-10-09 20:41:14 +08:00
2013-09-28 17:59:50 +08:00
# Modules that we need:
include ( GNUInstallDirs )
include ( CheckIncludeFile )
include ( CheckIncludeFiles )
include ( CheckFunctionExists )
2013-10-09 20:41:14 +08:00
include ( CheckPrototypeDefinition_fixed )
2013-09-28 17:59:50 +08:00
include ( CheckTypeSize )
include ( CheckStructHasMember )
2013-10-09 20:41:14 +08:00
# Configuration options
2013-10-21 21:11:37 +08:00
mark_as_advanced ( FORCE ZM_EXTRA_LIBS ZM_MYSQL_ENGINE ZM_NO_MMAP CMAKE_INSTALL_FULL_BINDIR ZM_PERL_SUBPREFIX ZM_PERL_USE_PATH ZM_TARGET_DISTRO )
2013-09-28 17:59:50 +08:00
set ( ZM_RUNDIR "/var/run/zm" CACHE PATH "Location of transient process files, default: /var/run/zm" )
set ( ZM_TMPDIR "/tmp/zm" CACHE PATH "Location of temporary files, default: /tmp/zm" )
set ( ZM_LOGDIR "/var/log/zm" CACHE PATH "Location of generated log files, default: /var/log/zm" )
set ( ZM_WEBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/zoneminder/www" CACHE PATH "Location of the web files, default: <prefix>/${CMAKE_INSTALL_DATADIR}/zoneminder/www" )
set ( ZM_CGIDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/zoneminder/cgi-bin" CACHE PATH "Location of the cgi-bin files, default: <prefix>/${CMAKE_INSTALL_LIBEXECDIR}/zoneminder/cgi-bin" )
set ( ZM_CONTENTDIR "/var/lib/zoneminder" CACHE PATH "Location of dynamic content (events and images), default: /var/lib/zoneminder" )
set ( ZM_DB_HOST "localhost" CACHE STRING "Hostname where ZoneMinder database located, default: localhost" )
set ( ZM_DB_NAME "zm" CACHE STRING "Name of ZoneMinder database, default: zm" )
set ( ZM_DB_USER "zmuser" CACHE STRING "Name of ZoneMinder database user, default: zmuser" )
set ( ZM_DB_PASS "zmpass" CACHE STRING "Password of ZoneMinder database user, default: zmpass" )
set ( ZM_WEB_USER "" CACHE STRING "The user apache or the local web server runs on. Leave empty for automatic detection. If that fails, you can use this variable to force" )
set ( ZM_WEB_GROUP "" CACHE STRING "The group apache or the local web server runs on, Leave empty to be the same as the web user" )
# Advanced
2013-09-30 19:31:36 +08:00
set ( ZM_EXTRA_LIBS "" CACHE STRING "A list of optional libraries, separated by semicolons, e.g. ssl;theora" )
2013-09-28 17:59:50 +08:00
set ( ZM_MYSQL_ENGINE "InnoDB" CACHE STRING "MySQL engine to use with database, default: InnoDB" )
set ( ZM_NO_MMAP "OFF" CACHE BOOL "Set to ON to not use mmap shared memory. Shouldn't be enabled unless you experience problems with the shared memory. default: OFF" )
2013-10-09 20:58:14 +08:00
set ( ZM_NO_FFMPEG "OFF" CACHE BOOL "Set to ON to skip ffmpeg checks and force building ZM without ffmpeg. default: OFF" )
2013-10-21 21:11:37 +08:00
set ( ZM_NO_X10 "OFF" CACHE BOOL "Set to ON to build ZoneMinder without X10 support. default: OFF" )
2013-11-15 17:12:33 +08:00
set ( ZM_PERL_SUBPREFIX "${CMAKE_INSTALL_LIBDIR}/perl5" CACHE PATH "Use a different directory for the zm perl modules. NOTE: This is a subprefix, e.g. lib will be turned into <prefix>/lib, default: <libdir>/perl5" )
2013-10-21 21:11:37 +08:00
set ( ZM_PERL_USE_PATH "${CMAKE_INSTALL_PREFIX}/${ZM_PERL_SUBPREFIX}" CACHE PATH "Override the include path for zm perl modules. Useful if you are moving the perl modules without using the ZM_PERL_SUBPREFIX option. default: <prefix>/<zmperlsubprefix>" )
2013-10-19 22:38:58 +08:00
set ( ZM_TARGET_DISTRO "" CACHE STRING "Build ZoneMinder for a specific distribution. Currently, valid names are: f19, el6" )
2013-09-28 17:59:50 +08:00
# Required for certain checks to work
set ( CMAKE_EXTRA_INCLUDE_FILES ${ CMAKE_EXTRA_INCLUDE_FILES } stdio.h stdlib.h math.h signal.h )
# Required for including headers from the this folder
2013-11-03 05:44:50 +08:00
include_directories ( "${CMAKE_BINARY_DIR}" )
2013-09-28 17:59:50 +08:00
# This is required to enable searching in lib64 (if exists), do not change
set_property ( GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON )
2013-10-09 20:41:14 +08:00
# System checks
2013-09-28 17:59:50 +08:00
check_include_file ( "linux/videodev.h" HAVE_LINUX_VIDEODEV_H )
check_include_file ( "linux/videodev2.h" HAVE_LINUX_VIDEODEV2_H )
check_include_file ( "execinfo.h" HAVE_EXECINFO_H )
2013-10-06 23:26:33 +08:00
check_include_file ( "ucontext.h" HAVE_UCONTEXT_H )
2013-09-28 17:59:50 +08:00
check_include_file ( "sys/sendfile.h" HAVE_SYS_SENDFILE_H )
check_include_file ( "sys/syscall.h" HAVE_SYS_SYSCALL_H )
2013-10-03 20:08:09 +08:00
check_function_exists ( "syscall" HAVE_SYSCALL )
2013-09-28 17:59:50 +08:00
check_function_exists ( "sendfile" HAVE_SENDFILE )
check_function_exists ( "backtrace" HAVE_DECL_BACKTRACE )
2013-10-06 23:26:33 +08:00
check_function_exists ( "backtrace_symbols" HAVE_DECL_BACKTRACE_SYMBOLS )
2013-09-28 17:59:50 +08:00
check_function_exists ( "posix_memalign" HAVE_POSIX_MEMALIGN )
2013-10-06 23:23:00 +08:00
check_type_size ( "siginfo_t" HAVE_SIGINFO_T )
check_type_size ( "ucontext_t" HAVE_UCONTEXT_T )
2013-09-28 17:59:50 +08:00
# *** LIBRARY CHECKS ***
# zlib
find_package ( ZLIB )
if ( ZLIB_FOUND )
set ( HAVE_LIBZLIB 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${ZLIB_LIBRARIES}" )
include_directories ( "${ZLIB_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${ZLIB_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_include_file ( "zlib.h" HAVE_ZLIB_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} zlib" )
2013-10-14 12:58:21 +08:00
else ( ZLIB_FOUND )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} zlib" )
2013-09-28 17:59:50 +08:00
endif ( ZLIB_FOUND )
# jpeg
find_package ( JPEG )
if ( JPEG_FOUND )
set ( HAVE_LIBJPEG 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${JPEG_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
#link_directories(${JPEG_LIBRARY})
2013-11-15 17:12:33 +08:00
include_directories ( "${JPEG_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_include_files ( "stdio.h;jpeglib.h" HAVE_JPEGLIB_H )
2013-10-09 20:41:14 +08:00
if ( NOT HAVE_JPEGLIB_H )
message ( FATAL_ERROR " zm requires libjpeg headers - check that libjpeg development packages are installed" )
endif ( NOT HAVE_JPEGLIB_H )
2013-09-28 17:59:50 +08:00
else ( JPEG_FOUND )
message ( FATAL_ERROR "zm requires jpeg but it was not found on your system" )
endif ( JPEG_FOUND )
# OpenSSL
find_package ( OpenSSL )
if ( OPENSSL_FOUND )
set ( HAVE_LIBOPENSSL 1 )
2013-10-09 20:41:14 +08:00
set ( HAVE_LIBCRYPTO 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${OPENSSL_LIBRARIES}" )
include_directories ( "${OPENSSL_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_include_file ( "openssl/md5.h" HAVE_OPENSSL_MD5_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} OpenSSL" )
2013-10-14 12:58:21 +08:00
else ( OPENSSL_FOUND )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} OpenSSL" )
2013-09-28 17:59:50 +08:00
endif ( OPENSSL_FOUND )
2013-10-09 20:41:14 +08:00
# pthread (using find_library and find_path)
2013-09-28 17:59:50 +08:00
find_library ( PTHREAD_LIBRARIES pthread )
if ( PTHREAD_LIBRARIES )
set ( HAVE_LIBPTHREAD 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${PTHREAD_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
find_path ( PTHREAD_INCLUDE_DIR pthread.h )
if ( PTHREAD_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${PTHREAD_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${PTHREAD_INCLUDE_DIR}" )
2013-10-09 20:41:14 +08:00
endif ( PTHREAD_INCLUDE_DIR )
mark_as_advanced ( FORCE PTHREAD_LIBRARIES PTHREAD_INCLUDE_DIR )
2013-09-28 17:59:50 +08:00
check_include_file ( "pthread.h" HAVE_PTHREAD_H )
2013-10-09 20:41:14 +08:00
if ( NOT HAVE_PTHREAD_H )
message ( FATAL_ERROR " zm requires pthread headers - check that pthread development packages are installed" )
endif ( NOT HAVE_PTHREAD_H )
2013-09-28 17:59:50 +08:00
else ( PTHREAD_LIBRARIES )
message ( FATAL_ERROR "zm requires pthread but it was not found on your system" )
endif ( PTHREAD_LIBRARIES )
2013-10-09 20:41:14 +08:00
# pcre (using find_library and find_path)
2013-09-28 17:59:50 +08:00
find_library ( PCRE_LIBRARIES pcre )
if ( PCRE_LIBRARIES )
set ( HAVE_LIBPCRE 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${PCRE_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
find_path ( PCRE_INCLUDE_DIR pcre.h )
if ( PCRE_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${PCRE_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${PCRE_INCLUDE_DIR}" )
2013-10-09 20:41:14 +08:00
endif ( PCRE_INCLUDE_DIR )
mark_as_advanced ( FORCE PCRE_LIBRARIES PCRE_INCLUDE_DIR )
2013-09-28 17:59:50 +08:00
check_include_file ( "pcre.h" HAVE_PCRE_H )
2013-10-14 12:58:21 +08:00
set ( optlibsfound "${optlibsfound} PCRE" )
else ( PCRE_LIBRARIES )
set ( optlibsnotfound "${optlibsnotfound} PCRE" )
2013-09-28 17:59:50 +08:00
endif ( PCRE_LIBRARIES )
2013-10-09 20:41:14 +08:00
# gcrypt (using find_library and find_path)
2013-09-28 17:59:50 +08:00
find_library ( GCRYPT_LIBRARIES gcrypt )
if ( GCRYPT_LIBRARIES )
set ( HAVE_LIBGCRYPT 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${GCRYPT_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
find_path ( GCRYPT_INCLUDE_DIR gcrypt.h )
if ( GCRYPT_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${GCRYPT_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${GCRYPT_INCLUDE_DIR}" )
2013-10-09 20:41:14 +08:00
endif ( GCRYPT_INCLUDE_DIR )
mark_as_advanced ( FORCE GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR )
2013-09-28 17:59:50 +08:00
check_include_file ( "gcrypt.h" HAVE_GCRYPT_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} GCrypt" )
2013-10-14 12:58:21 +08:00
else ( GCRYPT_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} GCrypt" )
2013-09-28 17:59:50 +08:00
endif ( GCRYPT_LIBRARIES )
2013-10-09 20:41:14 +08:00
# gnutls (using find_library and find_path)
2013-09-28 17:59:50 +08:00
find_library ( GNUTLS_LIBRARIES gnutls )
if ( GNUTLS_LIBRARIES )
set ( HAVE_LIBGNUTLS 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${GNUTLS_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
find_path ( GNUTLS_INCLUDE_DIR gnutls/gnutls.h )
if ( GNUTLS_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${GNUTLS_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${GNUTLS_INCLUDE_DIR}" )
2013-10-09 20:41:14 +08:00
endif ( GNUTLS_INCLUDE_DIR )
mark_as_advanced ( FORCE GNUTLS_LIBRARIES GNUTLS_INCLUDE_DIR )
2013-09-28 17:59:50 +08:00
check_include_file ( "gnutls/openssl.h" HAVE_GNUTLS_OPENSSL_H )
check_include_file ( "gnutls/gnutls.h" HAVE_GNUTLS_GNUTLS_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} GnuTLS" )
2013-10-14 12:58:21 +08:00
else ( GNUTLS_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} GnuTLS" )
2013-09-28 17:59:50 +08:00
endif ( GNUTLS_LIBRARIES )
2013-10-09 20:41:14 +08:00
# mysqlclient (using find_library and find_path)
2013-09-28 17:59:50 +08:00
find_library ( MYSQLCLIENT_LIBRARIES mysqlclient PATH_SUFFIXES mysql )
if ( MYSQLCLIENT_LIBRARIES )
set ( HAVE_LIBMYSQLCLIENT 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${MYSQLCLIENT_LIBRARIES}" )
2013-10-09 20:41:14 +08:00
find_path ( MYSQLCLIENT_INCLUDE_DIR mysql/mysql.h )
if ( MYSQLCLIENT_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${MYSQLCLIENT_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${MYSQLCLIENT_INCLUDE_DIR}" )
2013-10-09 20:41:14 +08:00
endif ( MYSQLCLIENT_INCLUDE_DIR )
mark_as_advanced ( FORCE MYSQLCLIENT_LIBRARIES MYSQLCLIENT_INCLUDE_DIR )
2013-09-28 17:59:50 +08:00
check_include_file ( "mysql/mysql.h" HAVE_MYSQL_H )
2013-10-09 20:41:14 +08:00
if ( NOT HAVE_MYSQL_H )
message ( FATAL_ERROR "zm requires MySQL headers - check that MySQL development packages are installed" )
endif ( NOT HAVE_MYSQL_H )
2013-09-28 17:59:50 +08:00
else ( MYSQLCLIENT_LIBRARIES )
message ( FATAL_ERROR "zm requires mysqlclient but it was not found on your system" )
endif ( MYSQLCLIENT_LIBRARIES )
2013-12-20 00:38:07 +08:00
# x264 (using find_library and find_path)
find_library ( X264_LIBRARIES x264 )
if ( X264_LIBRARIES )
set ( HAVE_LIBX264 1 )
list ( APPEND ZM_BIN_LIBS "${X264_LIBRARIES}" )
find_path ( X264_INCLUDE_DIR x264.h )
if ( X264_INCLUDE_DIR )
include_directories ( "${X264_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${X264_INCLUDE_DIR}" )
endif ( X264_INCLUDE_DIR )
mark_as_advanced ( FORCE X264_LIBRARIES X264_INCLUDE_DIR )
check_include_files ( "stdint.h;x264.h" HAVE_X264_H )
set ( optlibsfound "${optlibsfound} x264" )
else ( X264_LIBRARIES )
set ( optlibsnotfound "${optlibsnotfound} x264" )
endif ( X264_LIBRARIES )
# mp4v2 (using find_library and find_path)
find_library ( MP4V2_LIBRARIES mp4v2 )
if ( MP4V2_LIBRARIES )
set ( HAVE_LIBMP4V2 1 )
list ( APPEND ZM_BIN_LIBS "${MP4V2_LIBRARIES}" )
find_path ( MP4V2_INCLUDE_DIR mp4.h )
if ( MP4V2_INCLUDE_DIR )
include_directories ( "${MP4V2_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${MP4V2_INCLUDE_DIR}" )
endif ( MP4V2_INCLUDE_DIR )
mark_as_advanced ( FORCE MP4V2_LIBRARIES MP4V2_INCLUDE_DIR )
check_include_file ( "mp4.h" HAVE_MP4_H )
set ( optlibsfound "${optlibsfound} mp4v2" )
else ( MP4V2_LIBRARIES )
set ( optlibsnotfound "${optlibsnotfound} mp4v2" )
endif ( MP4V2_LIBRARIES )
2013-11-15 17:11:33 +08:00
set ( PATH_FFMPEG "" )
set ( OPT_FFMPEG "no" )
2013-10-09 20:58:14 +08:00
# Do not check for ffmpeg if ZM_NO_FFMPEG is on
if ( NOT ZM_NO_FFMPEG )
# avformat (using find_library and find_path)
find_library ( AVFORMAT_LIBRARIES avformat )
if ( AVFORMAT_LIBRARIES )
set ( HAVE_LIBAVFORMAT 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${AVFORMAT_LIBRARIES}" )
2013-10-09 20:58:14 +08:00
find_path ( AVFORMAT_INCLUDE_DIR "libavformat/avformat.h" )
if ( AVFORMAT_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${AVFORMAT_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${AVFORMAT_INCLUDE_DIR}" )
2013-10-09 20:58:14 +08:00
endif ( AVFORMAT_INCLUDE_DIR )
mark_as_advanced ( FORCE AVFORMAT_LIBRARIES AVFORMAT_INCLUDE_DIR )
check_include_file ( "libavformat/avformat.h" HAVE_LIBAVFORMAT_AVFORMAT_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} AVFormat" )
2013-10-14 12:58:21 +08:00
else ( AVFORMAT_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} AVFormat" )
2013-10-09 20:58:14 +08:00
endif ( AVFORMAT_LIBRARIES )
2013-09-28 17:59:50 +08:00
2013-10-09 20:58:14 +08:00
# avcodec (using find_library and find_path)
find_library ( AVCODEC_LIBRARIES avcodec )
if ( AVCODEC_LIBRARIES )
set ( HAVE_LIBAVCODEC 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${AVCODEC_LIBRARIES}" )
2013-10-09 20:58:14 +08:00
find_path ( AVCODEC_INCLUDE_DIR "libavcodec/avcodec.h" )
if ( AVCODEC_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${AVCODEC_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${AVCODEC_INCLUDE_DIR}" )
2013-10-09 20:58:14 +08:00
endif ( AVCODEC_INCLUDE_DIR )
mark_as_advanced ( FORCE AVCODEC_LIBRARIES AVCODEC_INCLUDE_DIR )
check_include_file ( "libavcodec/avcodec.h" HAVE_LIBAVCODEC_AVCODEC_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} AVCodec" )
2013-10-14 12:58:21 +08:00
else ( AVCODEC_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} AVCodec" )
2013-10-09 20:58:14 +08:00
endif ( AVCODEC_LIBRARIES )
2013-09-28 17:59:50 +08:00
2013-10-09 20:58:14 +08:00
# avdevice (using find_library and find_path)
find_library ( AVDEVICE_LIBRARIES avdevice )
if ( AVDEVICE_LIBRARIES )
set ( HAVE_LIBAVDEVICE 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${AVDEVICE_LIBRARIES}" )
2013-10-09 20:58:14 +08:00
find_path ( AVDEVICE_INCLUDE_DIR "libavdevice/avdevice.h" )
if ( AVDEVICE_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${AVDEVICE_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${AVDEVICE_INCLUDE_DIR}" )
2013-10-09 20:58:14 +08:00
endif ( AVDEVICE_INCLUDE_DIR )
mark_as_advanced ( FORCE AVDEVICE_LIBRARIES AVDEVICE_INCLUDE_DIR )
check_include_file ( "libavdevice/avdevice.h" HAVE_LIBAVDEVICE_AVDEVICE_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} AVDevice" )
2013-10-14 12:58:21 +08:00
else ( AVDEVICE_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} AVDevice" )
2013-10-09 20:58:14 +08:00
endif ( AVDEVICE_LIBRARIES )
2013-09-28 17:59:50 +08:00
2013-10-09 20:58:14 +08:00
# avutil (using find_library and find_path)
find_library ( AVUTIL_LIBRARIES avutil )
if ( AVUTIL_LIBRARIES )
set ( HAVE_LIBAVUTIL 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${AVUTIL_LIBRARIES}" )
2013-10-09 20:58:14 +08:00
find_path ( AVUTIL_INCLUDE_DIR "libavutil/avutil.h" )
if ( AVUTIL_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${AVUTIL_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${AVUTIL_INCLUDE_DIR}" )
2013-10-09 20:58:14 +08:00
endif ( AVUTIL_INCLUDE_DIR )
mark_as_advanced ( FORCE AVUTIL_LIBRARIES AVUTIL_INCLUDE_DIR )
check_include_file ( "libavutil/avutil.h" HAVE_LIBAVUTIL_AVUTIL_H )
check_include_file ( "libavutil/mathematics.h" HAVE_LIBAVUTIL_MATHEMATICS_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} AVUtil" )
2013-10-14 12:58:21 +08:00
else ( AVUTIL_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} AVUtil" )
2013-10-09 20:58:14 +08:00
endif ( AVUTIL_LIBRARIES )
2013-09-28 17:59:50 +08:00
2013-10-09 20:58:14 +08:00
# swscale (using find_library and find_path)
find_library ( SWSCALE_LIBRARIES swscale )
if ( SWSCALE_LIBRARIES )
set ( HAVE_LIBSWSCALE 1 )
2013-11-15 17:12:33 +08:00
list ( APPEND ZM_BIN_LIBS "${SWSCALE_LIBRARIES}" )
2013-10-09 20:58:14 +08:00
find_path ( SWSCALE_INCLUDE_DIR "libswscale/swscale.h" )
if ( SWSCALE_INCLUDE_DIR )
2013-11-15 17:12:33 +08:00
include_directories ( "${SWSCALE_INCLUDE_DIR}" )
set ( CMAKE_REQUIRED_INCLUDES "${SWSCALE_INCLUDE_DIR}" )
2013-10-09 20:58:14 +08:00
endif ( SWSCALE_INCLUDE_DIR )
mark_as_advanced ( FORCE SWSCALE_LIBRARIES SWSCALE_INCLUDE_DIR )
check_include_file ( "libswscale/swscale.h" HAVE_LIBSWSCALE_SWSCALE_H )
2013-10-21 22:13:07 +08:00
set ( optlibsfound "${optlibsfound} SWScale" )
2013-10-14 12:58:21 +08:00
else ( SWSCALE_LIBRARIES )
2013-10-21 22:13:07 +08:00
set ( optlibsnotfound "${optlibsnotfound} SWScale" )
2013-10-09 20:58:14 +08:00
endif ( SWSCALE_LIBRARIES )
2013-11-15 17:11:33 +08:00
# Find the path to the ffmpeg executable
find_program ( FFMPEG_EXECUTABLE ffmpeg PATH_SUFFIXES ffmpeg )
if ( FFMPEG_EXECUTABLE )
set ( PATH_FFMPEG "${FFMPEG_EXECUTABLE}" )
set ( OPT_FFMPEG "yes" )
mark_as_advanced ( FFMPEG_EXECUTABLE )
endif ( FFMPEG_EXECUTABLE )
2013-10-09 20:58:14 +08:00
endif ( NOT ZM_NO_FFMPEG )
2013-09-28 17:59:50 +08:00
# *** END OF LIBRARY CHECKS ***
# Check for gnutls or crypto
if ( ( NOT HAVE_LIBCRYPTO ) AND ( NOT HAVE_LIBGNUTLS ) )
message ( FATAL_ERROR " zm requires crypto or gnutls but none were found on your system" )
endif ( ( NOT HAVE_LIBCRYPTO ) AND ( NOT HAVE_LIBGNUTLS ) )
# Check for V4L header files and enable ZM_HAS_V4L, ZM_HAS_V4L1, ZM_HAS_V4L2 accordingly
2013-10-09 21:05:56 +08:00
# Setting to zeros first is required because ZM uses #define for these
set ( ZM_HAS_V4L 0 )
set ( ZM_HAS_V4L1 0 )
set ( ZM_HAS_V4L2 0 )
2013-09-28 17:59:50 +08:00
if ( HAVE_LINUX_VIDEODEV_H )
set ( ZM_HAS_V4L 1 )
set ( ZM_HAS_V4L1 1 )
endif ( HAVE_LINUX_VIDEODEV_H )
if ( HAVE_LINUX_VIDEODEV2_H )
set ( ZM_HAS_V4L 1 )
set ( ZM_HAS_V4L2 1 )
endif ( HAVE_LINUX_VIDEODEV2_H )
if ( ( NOT HAVE_LINUX_VIDEODEV_H ) AND ( NOT HAVE_LINUX_VIDEODEV2_H ) )
message ( AUTHOR_WARNING " Video 4 Linux headers weren't found - Analog and USB camera support will not be available" )
endif ( ( NOT HAVE_LINUX_VIDEODEV_H ) AND ( NOT HAVE_LINUX_VIDEODEV2_H ) )
# Check for PCRE and enable ZM_PCRE accordingly
2013-10-09 21:05:56 +08:00
set ( ZM_PCRE 0 )
2013-09-28 17:59:50 +08:00
if ( HAVE_LIBPCRE AND HAVE_PCRE_H )
set ( ZM_PCRE 1 )
endif ( HAVE_LIBPCRE AND HAVE_PCRE_H )
2013-10-09 21:05:56 +08:00
# Check for mmap and enable in all components
set ( ZM_MEM_MAPPED 0 )
2013-10-09 20:41:14 +08:00
set ( ENABLE_MMAP no )
if ( NOT ZM_NO_MMAP )
set ( ZM_MEM_MAPPED 1 )
set ( ENABLE_MMAP yes )
set ( ZM_MMAP_PERLPACKAGE "Sys::Mmap" )
endif ( NOT ZM_NO_MMAP )
2013-09-28 17:59:50 +08:00
# Check for authenication functions
if ( HAVE_OPENSSL_MD5_H )
2013-11-15 17:12:33 +08:00
set ( CMAKE_REQUIRED_LIBRARIES "${OPENSSL_LIBRARIES}" )
set ( CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_prototype_definition ( MD5 "unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)" "NULL" "openssl/md5.h" HAVE_MD5_OPENSSL )
endif ( HAVE_OPENSSL_MD5_H )
if ( HAVE_GNUTLS_OPENSSL_H )
2013-11-15 17:12:33 +08:00
set ( CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARIES}" )
set ( CMAKE_REQUIRED_INCLUDES "${GNUTLS_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_prototype_definition ( MD5 "unsigned char *MD5 (const unsigned char *buf, unsigned long len, unsigned char *md)" "NULL" "gnutls/openssl.h" HAVE_MD5_GNUTLS )
endif ( HAVE_GNUTLS_OPENSSL_H )
if ( HAVE_GNUTLS_GNUTLS_H )
2013-11-15 17:12:33 +08:00
set ( CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARIES}" )
set ( CMAKE_REQUIRED_INCLUDES "${GNUTLS_INCLUDE_DIR}" )
2013-09-28 17:59:50 +08:00
check_prototype_definition ( gnutls_fingerprint "int gnutls_fingerprint (gnutls_digest_algorithm_t algo, const gnutls_datum_t * data, void *result, size_t * result_size)" "0" "stdlib.h;gnutls/gnutls.h" HAVE_DECL_GNUTLS_FINGERPRINT )
endif ( HAVE_GNUTLS_GNUTLS_H )
if ( HAVE_MD5_OPENSSL OR HAVE_MD5_GNUTLS )
set ( HAVE_DECL_MD5 1 )
else ( HAVE_MD5_OPENSSL OR HAVE_MD5_GNUTLS )
message ( AUTHOR_WARNING " ZM requires a working MD5 function for hashed authenication but none were found - hashed authenication will not be available" )
endif ( HAVE_MD5_OPENSSL OR HAVE_MD5_GNUTLS )
# Dirty fix for zm_user only using openssl's md5 if gnutls and gcrypt are not available.
# This needs to be fixed in zm_user.[h,cpp] but such fix will also require changes to configure.ac
if ( HAVE_LIBCRYPTO AND HAVE_OPENSSL_MD5_H AND HAVE_MD5_OPENSSL )
set ( HAVE_GCRYPT_H 0 )
set ( HAVE_GNUTLS_OPENSSL_H 0 )
endif ( HAVE_LIBCRYPTO AND HAVE_OPENSSL_MD5_H AND HAVE_MD5_OPENSSL )
2013-10-09 20:41:14 +08:00
# Check for Perl
2013-09-28 17:59:50 +08:00
find_package ( Perl )
if ( NOT PERL_FOUND )
message ( FATAL_ERROR "zm requires Perl 5.6.0 or newer but it was not found on your system" )
endif ( NOT PERL_FOUND )
2013-10-09 20:41:14 +08:00
2013-09-28 17:59:50 +08:00
# Checking for perl modules requires FindPerlModules.cmake
# Check all required modules at once
# TODO: Add checking for the optional modules
find_package ( PerlModules COMPONENTS Sys::Syslog DBI DBD::mysql Getopt::Long Time::HiRes Date::Manip LWP::UserAgent ExtUtils::MakeMaker ${ ZM_MMAP_PERLPACKAGE } )
if ( NOT PERLMODULES_FOUND )
message ( FATAL_ERROR "Not all required perl modules were found on your system" )
endif ( NOT PERLMODULES_FOUND )
# Attempt to check which user apache (or other web server) runs on by searching for a user beginning with apache or www and then cutting the user from the first matching user line
if ( ZM_WEB_USER STREQUAL "" )
# Check for a user matching ^apache and cut the username from the userline in the first match
file ( STRINGS "/etc/passwd" userline_apache REGEX "^apache" )
file ( STRINGS "/etc/passwd" userline_www REGEX "^www" )
if ( NOT ( userline_apache STREQUAL "" ) )
execute_process ( COMMAND echo ${ userline_apache } COMMAND cut -d: -f1 OUTPUT_VARIABLE ZM_WEB_USER OUTPUT_STRIP_TRAILING_WHITESPACE )
elseif ( NOT ( userline_www STREQUAL "" ) )
execute_process ( COMMAND echo ${ userline_www } COMMAND cut -d: -f1 OUTPUT_VARIABLE ZM_WEB_USER OUTPUT_STRIP_TRAILING_WHITESPACE )
endif ( NOT ( userline_apache STREQUAL "" ) )
message ( STATUS "Detected web server user: ${ZM_WEB_USER}" )
endif ( ZM_WEB_USER STREQUAL "" )
# Check if webgroup contains anything. If not, use the web user as the web group
if ( NOT ZM_WEB_GROUP )
set ( ZM_WEB_GROUP ${ ZM_WEB_USER } )
endif ( NOT ZM_WEB_GROUP )
message ( STATUS "Using web user: ${ZM_WEB_USER}" )
message ( STATUS "Using web group: ${ZM_WEB_GROUP}" )
# Some variables that zm expects
set ( ZM_PID "${ZM_RUNDIR}/zm.pid" )
set ( ZM_CONFIG "/${CMAKE_INSTALL_SYSCONFDIR}/zm.conf" )
2013-10-09 20:41:14 +08:00
set ( VERSION "${zoneminder_VERSION}" )
2013-10-06 22:12:02 +08:00
set ( PKGDATADIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/zoneminder" )
2013-09-28 17:59:50 +08:00
set ( BINDIR "${CMAKE_INSTALL_FULL_BINDIR}" )
set ( LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}" )
set ( SYSCONFDIR "/${CMAKE_INSTALL_SYSCONFDIR}" )
set ( WEB_PREFIX "${ZM_WEBDIR}" )
set ( CGI_PREFIX "${ZM_CGIDIR}" )
set ( WEB_USER "${ZM_WEB_USER}" )
set ( WEB_GROUP "${ZM_WEB_GROUP}" )
2013-11-05 04:38:21 +08:00
set ( ZM_DB_TYPE "mysql" )
2013-10-09 20:41:14 +08:00
set ( EXTRA_PERL_LIB "use lib '${ZM_PERL_USE_PATH}';" )
2013-09-28 17:59:50 +08:00
2013-10-19 22:38:58 +08:00
# Reassign some variables if a target distro has been specified
if ( ( ZM_TARGET_DISTRO STREQUAL "f19" ) OR ( ZM_TARGET_DISTRO STREQUAL "el6" ) )
2013-10-21 21:11:37 +08:00
set ( ZM_RUNDIR "/var/run/zoneminder" )
set ( ZM_TMPDIR "/var/lib/zoneminder/temp" )
set ( ZM_LOGDIR "/var/log/zoneminder" )
2013-10-19 22:38:58 +08:00
endif ( ( ZM_TARGET_DISTRO STREQUAL "f19" ) OR ( ZM_TARGET_DISTRO STREQUAL "el6" ) )
2013-09-28 17:59:50 +08:00
# Generate files from the .in files
2013-11-04 15:56:40 +08:00
configure_file ( zm.conf.in "${CMAKE_CURRENT_BINARY_DIR}/zm.conf" @ONLY )
configure_file ( zoneminder-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY )
configure_file ( zmconfgen.pl.in "${CMAKE_CURRENT_BINARY_DIR}/zmconfgen.pl" @ONLY )
configure_file ( zmlinkcontent.sh.in "${CMAKE_CURRENT_BINARY_DIR}/zmlinkcontent.sh" @ONLY )
2013-09-28 17:59:50 +08:00
# Process subdirectories
add_subdirectory ( src )
add_subdirectory ( scripts )
add_subdirectory ( db )
add_subdirectory ( web )
2013-10-21 21:11:37 +08:00
# Process misc subdirectories
2013-10-19 22:38:58 +08:00
if ( ZM_TARGET_DISTRO STREQUAL "f19" )
2013-10-21 21:11:37 +08:00
add_subdirectory ( distros/fedora )
2013-10-19 22:38:58 +08:00
elseif ( ZM_TARGET_DISTRO STREQUAL "el6" )
2013-10-21 21:11:37 +08:00
add_subdirectory ( distros/redhat )
2013-10-19 22:38:58 +08:00
else ( ZM_TARGET_DISTRO STREQUAL "el6" )
2013-10-21 21:11:37 +08:00
add_subdirectory ( misc )
2013-10-19 22:38:58 +08:00
endif ( ZM_TARGET_DISTRO STREQUAL "f19" )
2013-09-28 17:59:50 +08:00
2013-10-14 12:58:21 +08:00
# Print optional libraries detection status
message ( STATUS "Optional libraries found:${optlibsfound}" )
message ( STATUS "Optional libraries not found:${optlibsnotfound}" )
2013-09-28 17:59:50 +08:00
# Run ZM configuration generator
message ( STATUS "Running ZoneMinder configuration generator" )
execute_process ( COMMAND perl ./zmconfgen.pl RESULT_VARIABLE zmconfgen_result )
if ( zmconfgen_result EQUAL 0 )
message ( STATUS "ZoneMinder configuration generator completed successfully" )
else ( zmconfgen_result EQUAL 0 )
message ( FATAL_ERROR "ZoneMinder configuration generator failed. Exit code: ${zmconfgen_result}" )
endif ( zmconfgen_result EQUAL 0 )
# Install zm.conf
2013-11-04 15:56:40 +08:00
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/zm.conf" DESTINATION "/${CMAKE_INSTALL_SYSCONFDIR}" )
2013-09-28 17:59:50 +08:00
2013-10-21 21:11:37 +08:00
# Uninstall target
configure_file (
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c m a k e / c m a k e _ u n i n s t a l l . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / c m a k e _ u n i n s t a l l . c m a k e "
I M M E D I A T E @ O N L Y )
add_custom_target ( uninstall
C O M M A N D $ { C M A K E _ C O M M A N D } - P $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / c m a k e _ u n i n s t a l l . c m a k e )