]> git.ipfire.org Git - thirdparty/sarg.git/blob - CMakeLists.txt
Change the release date.
[thirdparty/sarg.git] / CMakeLists.txt
1 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
2 PROJECT(sarg C)
3 SET(sarg_VERSION 2)
4 SET(sarg_REVISION "3.1-pre1")
5 SET(sarg_BUILD "")
6 SET(sarg_BUILDDATE "Jul-19-2010")
7
8 INCLUDE(AddFileDependencies)
9 INCLUDE(CheckIncludeFile)
10 INCLUDE(CheckLibraryExists)
11 INCLUDE(CheckFunctionExists)
12 INCLUDE(CheckTypeSize)
13 INCLUDE(CheckSymbolExists)
14 INCLUDE(CheckCCompilerFlag)
15
16 DEFINE_PROPERTY(GLOBAL PROPERTY enable-htmldir BRIEF_DOCS "--enable-htmldir=htmldir"
17 FULL_DOCS "Select htmldir as the root of your WWW documents")
18
19 SET(PACKAGE_NAME "sarg")
20 SET(PACKAGE_VERSION "${sarg_VERSION}.${sarg_REVISION}${sarg_BUILD}")
21
22 MACRO(SET_ABS_SOURCE VAR DOC)
23 IF(${VAR} AND NOT ${VAR}_SOURCE)
24 SET(PATH "${${VAR}}")
25 IF(NOT IS_ABSOLUTE ${PATH})
26 SET(PATH "${CMAKE_INSTALL_PREFIX}/${PATH}")
27 ENDIF(NOT IS_ABSOLUTE ${PATH})
28 GET_FILENAME_COMPONENT(SOURCE_PATH "${PATH}" ABSOLUTE)
29 SET(${VAR}_SOURCE "${SOURCE_PATH}" CACHE PATH "${DOC}")
30 ENDIF(${VAR} AND NOT ${VAR}_SOURCE)
31 ENDMACRO(SET_ABS_SOURCE VAR DOC)
32
33 SET_ABS_SOURCE(SYSCONFDIR "The full path of the configuration directory to be compiled in the program")
34 SET_ABS_SOURCE(LANGDIR "The full path of the language directory to be compiled in the program")
35 SET_ABS_SOURCE(FONTDIR "The full path of the fonts directory to be compiled in the program")
36 SET_ABS_SOURCE(IMAGEDIR "The full path of the images directory to be compiled in the program")
37
38 SET(SYSCONFDIR "etc/sarg" CACHE PATH "The configuration directory relative to the install directory")
39 SET(BINDIR "bin" CACHE PATH "The directory to install the exec relative to the install directory")
40 SET(MANDIR "share/man" CACHE PATH "The directory to copy the man page relative to the install directory")
41 SET(LANGDIR "share/sarg/languages" CACHE PATH "The directory to copy the languages files relative to the install directory")
42 SET(FONTDIR "share/sarg/fonts" CACHE PATH "The directory to copy the fonts relative to the install directory")
43 SET(IMAGEDIR "share/sarg/images" CACHE PATH "The directory to copy the images files relative to the install directory")
44 SET(SARGPHPDIR "share/sarg/sarg-php" CACHE PATH "The directory to copy sarg-php relative to the install directory")
45
46 # Sources to compile
47 INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}") #Make it find this config.h before the one in src/include
48 INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include")
49 SET(SRC util.c log.c report.c topuser.c email.c sort.c html.c
50 totger.c index.c getconf.c usage.c decomp.c ip2name.c
51 useragent.c exclude.c convlog.c totday.c repday.c datafile.c
52 indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c
53 smartfilter.c denied.c authfail.c charset.c
54 squidguard_log.c squidguard_report.c auth.c download.c grepday.c
55 dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c
56 usertab.c userinfo.c longline.c)
57
58 FOREACH(f ${SRC})
59 ADD_FILE_DEPENDENCIES(${f} ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/include/conf.h ${CMAKE_SOURCE_DIR}/include/info.h ${CMAKE_SOURCE_DIR}/include/defs.h)
60 ENDFOREACH(f)
61
62 ADD_EXECUTABLE(sarg ${SRC})
63
64 SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}")
65
66 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wno-sign-compare")
67 SET_TARGET_PROPERTIES(sarg PROPERTIES LINK_FLAGS "$ENV{LDFLAGS}")
68
69 CHECK_C_COMPILER_FLAG("-Wextra" HAVE_WEXTRA)
70 IF(HAVE_WEXTRA)
71 # Not supported by gcc 3.3
72 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
73 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Wextra -Wno-unused-parameter")
74 ENDIF(HAVE_WEXTRA)
75
76 CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION)
77 IF(HAVE_WERROR_IMPLICIT_FUNCTION)
78 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
79 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=implicit-function-declaration")
80 ENDIF(HAVE_WERROR_IMPLICIT_FUNCTION)
81
82 CHECK_C_COMPILER_FLAG("-Werror=format" HAVE_WERROR_FORMAT)
83 IF(HAVE_WERROR_FORMAT)
84 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
85 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Werror=format")
86 ENDIF(HAVE_WERROR_FORMAT)
87
88 # Required header files
89 CHECK_INCLUDE_FILE(stdio.h HAVE_STDIO_H)
90 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
91 CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
92 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
93 CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H)
94 CHECK_INCLUDE_FILE(time.h HAVE_TIME_H)
95 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
96 CHECK_INCLUDE_FILE(sys/dirent.h HAVE_SYS_DIRENT_H)
97 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
98 CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
99 CHECK_INCLUDE_FILE(netdb.h HAVE_NETDB_H)
100 CHECK_INCLUDE_FILE(arpa/inet.h HAVE_ARPA_INET_H)
101 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
102 CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_H)
103 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
104 CHECK_INCLUDE_FILE(ctype.h HAVE_CTYPE_H)
105 CHECK_INCLUDE_FILE(errno.h HAVE_ERRNO_H)
106 CHECK_INCLUDE_FILE(sys/resource.h HAVE_SYS_RESOURCE_H)
107 CHECK_INCLUDE_FILE(sys/wait.h HAVE_SYS_WAIT_H)
108 CHECK_INCLUDE_FILE(stdarg.h HAVE_STDARG_H)
109 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
110 CHECK_INCLUDE_FILE(limits.h HAVE_LIMITS_H)
111 CHECK_INCLUDE_FILE(math.h HAVE_MATH_H)
112 CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H)
113 CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H)
114 CHECK_INCLUDE_FILE(libintl.h HAVE_LIBINTL_H)
115 CHECK_INCLUDE_FILE(libgen.h HAVE_LIBGEN_H)
116 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
117 CHECK_INCLUDE_FILE(getopt.h HAVE_GETOPT_H)
118
119 IF(!HAVE_GETOPT_H)
120 MESSAGE(SEND_ERROR "getopt.h is required to compile sarg")
121 ENDIF(!HAVE_GETOPT_H)
122
123 # Windows need lib wsock32 and ws2_32
124 IF(CMAKE_SYSTEM_NAME STREQUAL "Windows")
125 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
126 CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H)
127 CHECK_INCLUDE_FILE(ws2tcpip.h HAVE_WS2TCPIP_H)
128
129 FIND_LIBRARY(WSOCK_LIB NAMES wsock32 DOC "The winsock library")
130 IF(WSOCK_LIB)
131 TARGET_LINK_LIBRARIES(sarg wsock32)
132 LIST(APPEND CMAKE_REQUIRED_LIBRARIES wsock32)
133 ENDIF(WSOCK_LIB)
134
135 FIND_LIBRARY(WSOCK2_LIB NAMES ws2_32 DOC "The winsock 2 library")
136 IF(WSOCK2_LIB)
137 TARGET_LINK_LIBRARIES(sarg ws2_32)
138 LIST(APPEND CMAKE_REQUIRED_LIBRARIES ws2_32)
139 ENDIF(WSOCK2_LIB)
140
141 ADD_DEFINITIONS(-DWINDOWS)
142 ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Windows")
143
144 CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO)
145 CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE)
146 CHECK_FUNCTION_EXISTS(symlink HAVE_SYMLINK)
147 CHECK_FUNCTION_EXISTS(lstat HAVE_LSTAT)
148 CHECK_FUNCTION_EXISTS(getnameinfo HAVE_GETNAMEINFO)
149 CHECK_FUNCTION_EXISTS(inet_aton HAVE_INET_ATON)
150
151 # Find gd
152 CHECK_INCLUDE_FILE(gd.h HAVE_GD_H)
153 IF(HAVE_GD_H)
154 CHECK_INCLUDE_FILE(gdfontl.h HAVE_GDFONTL_H)
155 CHECK_INCLUDE_FILE(gdfontt.h HAVE_GDFONTT_H)
156 CHECK_INCLUDE_FILE(gdfonts.h HAVE_GDFONTS_H)
157 CHECK_INCLUDE_FILE(gdfontmb.h HAVE_GDFONTMB_H)
158 CHECK_INCLUDE_FILE(gdfontg.h HAVE_GDFONTG_H)
159 FIND_LIBRARY(GD_LIBRARY NAMES gd bgd DOC "The GD library")
160 IF(GD_LIBRARY)
161 #CHECK_LIBRARY_EXISTS(gd gdImagePng "." HAVE_GD_LIB)
162 TARGET_LINK_LIBRARIES(sarg ${GD_LIBRARY})
163 SET(HAVE_GD_LIB GD_LIBRARY CACHE PATH DOC "True IF GD was found")
164 SET(HAVE_GD_LIB CACHE BOOL DOC "True IF must use GD")
165 ENDIF(GD_LIBRARY)
166 ENDIF(HAVE_GD_H)
167
168 # Find iconv
169 OPTION(ENABLE_ICONV "Enable the usage of iconv" ON)
170 IF(ENABLE_ICONV)
171 CHECK_INCLUDE_FILE(iconv.h HAVE_ICONV_H)
172 IF(HAVE_ICONV_H)
173 FIND_PATH(ICONV_INCLUDE_PATH NAMES iconv.h)
174 FIND_LIBRARY(ICONV_LIBRARY NAMES iconv DOC "The ICONV library")
175 IF(ICONV_LIBRARY)
176 TARGET_LINK_LIBRARIES(sarg ${ICONV_LIBRARY})
177 ENDIF(ICONV_LIBRARY)
178 CHECK_FUNCTION_EXISTS(iconv_open HAVE_ICONV)
179
180 IF(NOT USE_CONST_ICONV)
181 SET(ICONV_CONST_FILE ${CMAKE_BINARY_DIR}/consticonv.c)
182 FILE(WRITE ${ICONV_CONST_FILE} "
183 #include <iconv.h>
184 #ifdef __CLASSIC_C__
185 int main(){
186 int ac;
187 char*av[];
188 #else
189 int main(int ac, char*av[]){
190 #endif
191 iconv_t localtoutf=(iconv_t)-1;
192 const char *str=\"\";
193 char *sstr=\"\";
194 size_t slen=0, sslen=0;
195
196 iconv (localtoutf, (const char **)&str, &slen, &sstr, &sslen);
197 if(ac > 1000)
198 {
199 return *av[0];
200 }
201 return 0;
202 }
203 ")
204 TRY_COMPILE(USE_CONST_ICONV ${CMAKE_BINARY_DIR} ${ICONV_CONST_FILE} CMAKE_FLAGS -DLINK_LIBRARIES="iconv")
205 FILE(REMOVE ${ICONV_CONST_FILE})
206 IF(USE_CONST_ICONV)
207 SET(ICONV_CONST "const" CACHE STRING "The type of char to use with iconv")
208 MESSAGE(STATUS "iconv requires const char **")
209 ELSEIF(USE_CONST_ICONV)
210 SET(ICONV_CONST "" CACHE STRING "The type of char to use with iconv")
211 MESSAGE(STATUS "iconv requires char **")
212 ENDIF(USE_CONST_ICONV)
213 SET(USE_CONST_ICONV TRUE CACHE BOOL "Use const char ** with iconv")
214 ENDIF(NOT USE_CONST_ICONV)
215 ENDIF(HAVE_ICONV_H)
216 ENDIF(ENABLE_ICONV)
217
218 # Find ldap
219 CHECK_INCLUDE_FILE(ldap.h HAVE_LDAP_H)
220 IF(HAVE_LDAP_H)
221 FIND_LIBRARY(LDAP_LIBRARY NAMES ldap DOC "The ldap library")
222 IF(LDAP_LIBRARY)
223 TARGET_LINK_LIBRARIES(sarg ${LDAP_LIBRARY})
224 SET(HAVE_LDAP LDAP_LIBRARY CACHE PATH DOC "True if LDAP was found")
225 SET(HAVE_LDAP CACHE BOOL DOC "True if must use LDAP")
226 ENDIF(LDAP_LIBRARY)
227 ENDIF(HAVE_LDAP_H)
228
229 # Support for large files
230 OPTION(ENABLE_LARGEFILE "Enable the usage of large files" ON)
231 IF(ENABLE_LARGEFILE)
232 IF(LFS_SEARCHED MATCHES "^LFS_SEARCHED$")
233 SET(SEARCH_LARGEFILE TRUE)
234 ENDIF(LFS_SEARCHED MATCHES "^LFS_SEARCHED$")
235 ENDIF(ENABLE_LARGEFILE)
236
237 IF(SEARCH_LARGEFILE)
238 SET(LFS_SEARCHED TRUE CACHE INTERNAL "LFS has been searched")
239 MESSAGE(STATUS "Looking for large file support")
240 SET(LFS_FILE "${CMAKE_BINARY_DIR}/lfsfopen64.c")
241 FILE(WRITE ${LFS_FILE} "
242 #include <stdio.h>
243 int main(void)
244 {
245 FILE *f = fopen64 (\"/tmp/foo\",\"r\");
246 return(0);
247 }
248 ")
249 TRY_COMPILE(HAVE_FOPEN64 ${CMAKE_BINARY_DIR} ${LFS_FILE} COMPILE_DEFINITIONS "-Wall -Werror")
250 IF(HAVE_FOPEN64)
251 MESSAGE(STATUS "Looking for large file support - found")
252 ELSE(HAVE_FOPEN64)
253 SET(LFS_NEED_DEFINE FALSE CACHE BOOL "Does LFS require _LARGEFILE64_SOURCE ?")
254 MESSAGE(STATUS "Looking for large file support with _LARGEFILE64_SOURCE")
255 FILE(WRITE ${LFS_FILE} "
256 #define _LARGEFILE64_SOURCE
257 #include <stdio.h>
258 int main(void)
259 {
260 FILE *f = fopen64 (\"/tmp/foo\",\"r\");
261 return(0);
262 }
263 ")
264 TRY_COMPILE(HAVE_FOPEN64 ${CMAKE_BINARY_DIR} ${LFS_FILE} OUTPUT_VARIABLE LFS_OUTPUT)
265 IF(HAVE_FOPEN64)
266 MESSAGE(STATUS "Looking for large file support with _LARGEFILE64_SOURCE - found")
267 SET(LFS_NEED_DEFINE TRUE CACHE BOOL "Does LFS require _LARGEFILE64_SOURCE ?" FORCE)
268 ELSE(HAVE_FOPEN64)
269 MESSAGE("Failed with output ${LFS_OUTPUT}")
270 ENDIF(HAVE_FOPEN64)
271 ENDIF(HAVE_FOPEN64)
272 FILE(REMOVE ${LFS_FILE})
273 ENDIF(SEARCH_LARGEFILE)
274
275 IF(LFS_NEED_DEFINE)
276 ADD_DEFINITIONS(-D_LARGEFILE64_SOURCE)
277 ENDIF(LFS_NEED_DEFINE)
278
279 # Find rlim_t
280 IF(HAVE_SYS_RESOURCE_H)
281 SET(CMAKE_EXTRA_INCLUDE_FILES "sys/resource.h")
282 ENDIF(HAVE_SYS_RESOURCE_H)
283 CHECK_TYPE_SIZE(rlim_t RLIM_T)
284 IF(HAVE_RLIM_T)
285 IF(RLIM_T STREQUAL 4)
286 SET(RLIM_STRING "%d")
287 ELSEIF(RLIM_T STREQUAL 8)
288 SET(RLIM_STRING "%lli")
289 ELSE(RLIM_T STREQUAL 4)
290 MESSAGE("Unknown rlim_t size")
291 ENDIF(RLIM_T STREQUAL 4)
292 #ELSE(HAVE_RLIM_T)
293 # MESSAGE("Cannot detect the size of your system's rlim_t type")
294 ENDIF(HAVE_RLIM_T)
295
296 CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
297 IF(NOT HAVE_MKSTEMP)
298 # MingW provide mkstemps in libiberty but doesn't declare it in any header file
299 FIND_LIBRARY(IBERTY_LIB NAMES iberty DOC "The library of mingw containing mkstemps")
300 IF(IBERTY_LIB)
301 TARGET_LINK_LIBRARIES(sarg iberty)
302 ENDIF(IBERTY_LIB)
303 ENDIF(NOT HAVE_MKSTEMP)
304
305 # Gettext and friends
306 IF(NOT HAVE_LC_MESSAGES)
307 SET(FILES)
308 IF(HAVE_LOCALE_H)
309 LIST(APPEND FILES "locale.h")
310 ENDIF(HAVE_LOCALE_H)
311 IF(HAVE_LIBINTL_H)
312 LIST(APPEND FILES "libintl.h")
313 ENDIF(HAVE_LIBINTL_H)
314 LIST(LENGTH FILES NFILES)
315 IF(NFILES GREATER 0)
316 CHECK_SYMBOL_EXISTS(LC_MESSAGES "${FILES}" HAVE_LC_MESSAGES)
317 ENDIF(NFILES GREATER 0)
318 ENDIF(NOT HAVE_LC_MESSAGES)
319
320 # System particularities
321 IF(CMAKE_SYSTEM_NAME STREQUAL "solaris")
322 TARGET_LINK_LIBRARIES(sarg socket nsl)
323 #SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_DEFINITIONS="-DSOLARIS ${COMPILE_DEFINITIONS}")
324 ADD_DEFINITIONS(-DSOLARIS)
325 ENDIF(CMAKE_SYSTEM_NAME STREQUAL "solaris")
326
327 OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF)
328 IF(ENABLE_EXTRA_PROTECT)
329 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
330 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror")
331 CHECK_C_COMPILER_FLAG("-Wformat -Werror=format-security" HAVE_WERROR_FORMAT_SECURITY)
332 IF(HAVE_WERROR_FORMAT_SECURITY)
333 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
334 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -Wformat -Werror=format-security")
335 ENDIF(HAVE_WERROR_FORMAT_SECURITY)
336 ENDIF(ENABLE_EXTRA_PROTECT)
337
338 # Compile sarg for debugging
339 OPTION(ENABLE_DEBUG "Compile sarg with debugging symbols" OFF)
340 IF(ENABLE_DEBUG)
341 GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS)
342 SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -g")
343 ENDIF(ENABLE_DEBUG)
344
345 # Save the configuration for the project
346 CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/include/config.h.in" "${CMAKE_BINARY_DIR}/config.h" @ONLY)
347
348 # Installation of the project
349 INSTALL(TARGETS sarg DESTINATION "${BINDIR}")
350 INSTALL(FILES sarg.conf DESTINATION "${SYSCONFDIR}" RENAME sarg.conf.exemple)
351 INSTALL(FILES exclude_codes user_limit_block css.tpl DESTINATION "${SYSCONFDIR}")
352 INSTALL(FILES sarg.1 DESTINATION "${MANDIR}")
353 INSTALL(DIRECTORY languages/ DESTINATION "${LANGDIR}" PATTERN ".svn" EXCLUDE)
354 INSTALL(DIRECTORY images/ DESTINATION "${IMAGEDIR}" PATTERN ".svn" EXCLUDE)
355 INSTALL(DIRECTORY fonts/ DESTINATION "${FONTDIR}" FILES_MATCHING PATTERN "*.ttf" PATTERN ".svn" EXCLUDE)
356 INSTALL(DIRECTORY sarg-php/ DESTINATION "${SARGPHPDIR}" PATTERN ".svn" EXCLUDE)
357
358 # Package creation
359 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Squid Analysis Report Generator")
360 SET(CPACK_PACKAGE_VERSION_MAJOR "${sarg_VERSION}")
361 SET(CPACK_PACKAGE_VERSION_MINOR "${sarg_REVISION}")
362 SET(CPACK_PACKAGE_VERSION_PATCH "${sarg_BUILD}")
363 SET(CPACK_GENERATOR TGZ)
364 SET(CPACK_SOURCE_GENERATOR TGZ)
365 SET(CPACK_SOURCE_IGNORE_FILES "/.svn/" "/debian/" "/html/" "Makefile$" "config\\\\.log$" "config\\\\.status$" ".*~$" "\\\\.o$")
366 INCLUDE(CPack)