summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 2f222719d365f86fed015a46aa6cce99d75f9644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#  cmake rules for eurephia - main file
#
#  GPLv2 only - Copyright (C) 2008-2009
#               David Sommerseth <dazo@users.sourceforge.net>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; version 2
#  of the License.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
PROJECT(eurephia C)
cmake_minimum_required(VERSION 2.6)

# Set the eurephia version
ADD_DEFINITIONS(-DEUREPHIAVERSION="0.9.4_beta")

# eurephia parameters - boolean values
OPTION(DEBUG "Add more verbose debug information" OFF)
OPTION(SHOW_SECRETS "Show passwords as clear text in logs." OFF)
OPTION(SQLITE3 "Build database driver for SQLite3" OFF)
OPTION(EUREPHIADM "Build command line based admin utility" OFF)
OPTION(PLUGIN "Build the eurephia plugin for OpenVPN" OFF)
OPTION(GCOV "Build eurephia with gcov features enabled" OFF)
OPTION(DOXYGEN "Compile Doxygen documentation" OFF)

# eurephia parameters - string values
SET(OPENVPN_SRC "" CACHE STRING "Path to OpenVPN source code")
SET(PREFIX "/usr/local" CACHE STRING "Install prefix for eurephia")
SET(BINDIR "/usr/local/bin" CACHE STRING "Directory for eurephia binaries")
SET(PLUGINDIR "/usr/local/lib/eurephia" CACHE STRING "Plug-in path for the eurephia modules")
SET(XSLTROOT "/usr/local/share/eurephia/xslt" CACHE STRING "Root path for the XSLT templates")

# Set install prefix
SET(CMAKE_INSTALL_PREFIX ${PREFIX})

# Default C compiler flags
SET(CMAKE_C_FLAGS "-fno-delete-null-pointer-checks -g -Wall")
IF(GCOV)
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
ENDIF(GCOV)

# Needed cmake modules
INCLUDE(CheckIncludeFile)
INCLUDE(CheckLibraryExists)
FIND_PACKAGE(PkgConfig)

#
# Add support for extra eurephia modules
#

# Database drivers
IF(SQLITE3)
        message(STATUS "Will build database interface for SQLite")
        SET(DATABASE ON)
        # Add the sqlite3 database driver to the build queue
        SET(subdirs ${subdirs} database/sqlite)
ENDIF(SQLITE3)

# Make sure we build at least one database driver
IF(NOT DATABASE AND (EUREPHIADM OR PLUGIN))
       message(FATAL_ERROR "Cannot build eurephia without any database drivers.")
ENDIF(NOT DATABASE AND (EUREPHIADM OR PLUGIN))


# eurephiadm - console based admin utility
IF(EUREPHIADM) 
        message(STATUS "Will build command line based admin utility")
        SET(ADMIN_ENABLED on)
        ADD_DEFINITIONS(-DENABLE_EUREPHIADM)
        # Add the eurephiadm utility to the build queue
        SET(subdirs ${subdirs} eurephiadm utils)
ENDIF(EUREPHIADM)

# Enable firewall features if iptables is enabled
IF(FW_IPTABLES)
        SET(FIREWALL on)
ENDIF(FW_IPTABLES)

# Extra checks when the openvpn plug-in is enabled
IF(PLUGIN)
        IF(NOT OPENVPN_SRC)
	       message(FATAL_ERROR "Missing path to OpenVPN source - try running ./configure again")
       ENDIF(NOT OPENVPN_SRC)
       message(STATUS "Building eurephia plug-in for OpenVPN")

       SET(CHECK_INCL_FILE "${OPENVPN_SRC}/openvpn-plugin.h")
       IF(NOT EXISTS ${CHECK_INCL_FILE})
              message(FATAL_ERROR "Missing openvpn-plugin.h ... Is the OpenVPN source code really located here? ${OPENVPN_SRC}")
       ENDIF(NOT EXISTS ${CHECK_INCL_FILE})

       INCLUDE_DIRECTORIES(BEFORE ${OPENVPN_SRC} .)
       # Add the openvpn plug-in to the build queue
       SET(subdirs ${subdirs} plugin)
ENDIF(PLUGIN)

#
# Check for some standard glibc functions which we need
#

# Check that we have dynamic loader available
CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_DLOPEN)
CHECK_LIBRARY_EXISTS(dl dlclose "" HAVE_DLCLOSE)
IF(NOT HAVE_DLOPEN OR NOT HAVE_DLCLOSE)
	message(FATAL_ERROR "Missing proper dl library")
ENDIF(NOT HAVE_DLOPEN OR NOT HAVE_DLCLOSE)

# Check that we have some pthread functions
CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
CHECK_LIBRARY_EXISTS(pthread pthread_mutex_lock "" HAVE_PTHREAD_MUTEX_LOCK)
CHECK_LIBRARY_EXISTS(pthread pthread_mutex_unlock "" HAVE_PTHREAD_MUTEX_UNLOCK)
IF(NOT HAVE_PTHREAD_MUTEX_LOCK OR NOT HAVE_PTHREAD_MUTEX_UNLOCK)
	message(FATAL_ERROR "Missing proper pthread_mutex support")
ENDIF(NOT HAVE_PTHREAD_MUTEX_LOCK OR NOT HAVE_PTHREAD_MUTEX_UNLOCK)

#
# Check for other needed modules
#

# Check for openssl ... needed for gathering safe random data
pkg_search_module(OPENSSL REQUIRED openssl)
CHECK_LIBRARY_EXISTS(crypto RAND_load_file "" HAVE_OPENSSL_RAND_LOAD_FILE)
CHECK_LIBRARY_EXISTS(crypto RAND_pseudo_bytes "" HAVE_OPENSSL_RAND_PSEUDO_BYTES)
IF(NOT HAVE_OPENSSL_RAND_LOAD_FILE OR NOT HAVE_OPENSSL_RAND_PSEUDO_BYTES)
	message(FATAL_ERROR "Missing OpenSSL crypto support")
ENDIF(NOT HAVE_OPENSSL_RAND_LOAD_FILE OR NOT HAVE_OPENSSL_RAND_PSEUDO_BYTES)


# Generic checks when administration utilities are enabled
IF(ADMIN_ENABLED)
       # Check for libxml2
       pkg_search_module(LIBXML2 REQUIRED libxml-2.0 libxml2 libxml>=2.6)
       INCLUDE_DIRECTORIES(BEFORE  ${LIBXML2_INCLUDE_DIRS})
       ADD_DEFINITIONS(-DHAVE_LIBXML2)
       SET(EXTRA_LIBS ${EXTRA_LIBS} ${LIBXML2_LIBRARIES})

       # Check for libxslt
       pkg_search_module(LIBXSLT REQUIRED libxslt)
       INCLUDE_DIRECTORIES(BEFORE  ${LIBXSLT_INCLUDE_DIRS})
       ADD_DEFINITIONS(-DHAVE_LIBXSLT)
       SET(EXTRA_LIBS ${EXTRA_LIBS} ${LIBXSLT_LIBRARIES})

       # Find optional package for eurephiadm - OpenSSL.
       # Used for parsing certificate files, and we need a fairly
       # new openssl version.
       pkg_search_module(OPENSSL OPTIONAL openssl>=0.9.8)
       IF(OPENSSL_FOUND)
              ADD_DEFINITIONS(-DHAVE_OPENSSL)
              SET(EXTRA_LIBS ${EXTRA_LIBS} ${OPENSSL_LIBRARIES})
       ENDIF(OPENSSL_FOUND)
ENDIF(ADMIN_ENABLED)

# Export our internal common library
ADD_LIBRARY(common STATIC IMPORTED)
SET_PROPERTY(TARGET common PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/common/libeurephiacommon.a)

# Start the building.  First build the common library, and then the requested eurephia modules
IF(DATABASE OR PLUGIN OR FIREWALL OR EUREPHIADM)
        SUBDIRS(common ${subdirs})
ENDIF(DATABASE OR PLUGIN OR FIREWALL OR EUREPHIADM)

# Compile Doxygen docs at the end if requested
IF(DOXYGEN)
        SUBDIRS(doxygen)
ENDIF(DOXYGEN)

#  Give warning if DEBUG is enabled
IF(DEBUG)
        message(STATUS "***** DEBUG enabled ***** might be a security issue")
	ADD_DEFINITIONS(-DENABLE_DEBUG)
	IF(SHOW_SECRETS)
                message(STATUS "SHOW_SECRETS ENABLED -- THIS WILL LOG PASSWORDS IN CLEAR TEXT")
		ADD_DEFINITIONS(-DSHOW_SECRETS)
	ENDIF(SHOW_SECRETS)
ENDIF(DEBUG)