/[pcre]/code/trunk/CMakeLists.txt
ViewVC logotype

Contents of /code/trunk/CMakeLists.txt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 939 - (show annotations) (download)
Sun Feb 26 17:21:43 2012 UTC (2 years, 4 months ago) by ph10
File MIME type: text/plain
File size: 29420 byte(s)
CMake support for linking pcretest with libedit.

1 # CMakeLists.txt
2 #
3 #
4 # This file allows building PCRE with the CMake configuration and build
5 # tool. Download CMake in source or binary form from http://www.cmake.org/
6 #
7 # Original listfile by Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
8 # Refined and expanded by Daniel Richard G. <skunk@iSKUNK.ORG>
9 # 2007-09-14 mod by Sheri so 7.4 supported configuration options can be entered
10 # 2007-09-19 Adjusted by PH to retain previous default settings
11 # 2007-12-26 (a) On UNIX, use names libpcre instead of just pcre
12 # (b) Ensure pcretest and pcregrep link with the local library,
13 # not a previously-installed one.
14 # (c) Add PCRE_SUPPORT_LIBREADLINE, PCRE_SUPPORT_LIBZ, and
15 # PCRE_SUPPORT_LIBBZ2.
16 # 2008-01-20 Brought up to date to include several new features by Christian
17 # Ehrlicher.
18 # 2008-01-22 Sheri added options for backward compatibility of library names
19 # when building with minGW:
20 # if "ON", NON_STANDARD_LIB_PREFIX causes shared libraries to
21 # be built without "lib" as prefix. (The libraries will be named
22 # pcre.dll, pcreposix.dll and pcrecpp.dll).
23 # if "ON", NON_STANDARD_LIB_SUFFIX causes shared libraries to
24 # be built with suffix of "-0.dll". (The libraries will be named
25 # libpcre-0.dll, libpcreposix-0.dll and libpcrecpp-0.dll - same names
26 # built by default with Configure and Make.
27 # 2008-01-23 PH removed the automatic build of pcredemo.
28 # 2008-04-22 PH modified READLINE support so it finds NCURSES when needed.
29 # 2008-07-03 PH updated for revised UCP property support (change of files)
30 # 2009-03-23 PH applied Steven Van Ingelgem's patch to change the name
31 # CMAKE_BINARY_DIR to PROJECT_BINARY_DIR so that it works when PCRE
32 # is included within another project.
33 # 2009-03-23 PH applied a modified version of Steven Van Ingelgem's patches to
34 # add options to stop the building of pcregrep and the tests, and
35 # to disable the final configuration report.
36 # 2009-04-11 PH applied Christian Ehrlicher's patch to show compiler flags that
37 # are set by specifying a release type.
38 # 2010-01-02 PH added test for stdint.h
39 # 2010-03-02 PH added test for inttypes.h
40 # 2011-08-01 PH added PCREGREP_BUFSIZE
41 # 2011-08-22 PH added PCRE_SUPPORT_JIT
42 # 2011-09-06 PH modified WIN32 ADD_TEST line as suggested by Sergey Cherepanov
43 # 2011-09-06 PH added PCRE_SUPPORT_PCREGREP_JIT
44 # 2011-10-04 Sheri added support for including coff data in windows shared libraries
45 # compiled with MINGW if pcre.rc and/or pcreposix.rc are placed in
46 # the source dir by the user prior to building
47 # 2011-10-04 Sheri changed various add_test's to use exes' location built instead
48 # of DEBUG location only (likely only matters in MSVC)
49 # 2011-10-04 Sheri added scripts to provide needed variables to RunTest and
50 # RunGrepTest (used for UNIX and Msys)
51 # 2011-10-04 Sheri added scripts to provide needed variables and to execute
52 # RunTest.bat in Win32 (for effortless testing with "make test")
53 # 2011-10-04 Sheri Increased minimum required cmake version
54 # 2012-01-06 PH removed pcre_info.c and added pcre_string_utils.c
55 # 2012-01-10 Zoltan Herczeg added libpcre16 support
56 # 2012-01-13 Stephen Kelly added out of source build support
57 # 2012-01-17 PH applied Stephen Kelly's patch to parse the version data out
58 # of the configure.ac file
59 # 2012-02-26 PH added support for libedit
60
61 PROJECT(PCRE C CXX)
62
63 # Increased minimum to 2.8.0 to support newer add_test features
64
65 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
66
67 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # for FindReadline.cmake
68
69 # external packages
70 FIND_PACKAGE( BZip2 )
71 FIND_PACKAGE( ZLIB )
72 FIND_PACKAGE( Readline )
73 FIND_PACKAGE( Editline )
74
75 # Configuration checks
76
77 INCLUDE(CheckIncludeFile)
78 INCLUDE(CheckIncludeFileCXX)
79 INCLUDE(CheckFunctionExists)
80 INCLUDE(CheckTypeSize)
81
82 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
83 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
84 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
85 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
86 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
87 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
88 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
89
90 CHECK_INCLUDE_FILE_CXX(type_traits.h HAVE_TYPE_TRAITS_H)
91 CHECK_INCLUDE_FILE_CXX(bits/type_traits.h HAVE_BITS_TYPE_TRAITS_H)
92
93 CHECK_FUNCTION_EXISTS(bcopy HAVE_BCOPY)
94 CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
95 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
96 CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
97 CHECK_FUNCTION_EXISTS(strtoq HAVE_STRTOQ)
98 CHECK_FUNCTION_EXISTS(_strtoi64 HAVE__STRTOI64)
99
100 CHECK_TYPE_SIZE("long long" LONG_LONG)
101 CHECK_TYPE_SIZE("unsigned long long" UNSIGNED_LONG_LONG)
102
103 # User-configurable options
104 #
105 # (Note: CMakeSetup displays these in alphabetical order, regardless of
106 # the order we use here)
107
108 SET(BUILD_SHARED_LIBS OFF CACHE BOOL
109 "Build shared libraries instead of static ones.")
110
111 OPTION(PCRE_BUILD_PCRE8 "Build 8 bit PCRE library" ON)
112
113 OPTION(PCRE_BUILD_PCRE16 "Build 16 bit PCRE library" OFF)
114
115 OPTION(PCRE_BUILD_PCRECPP "Build the PCRE C++ library (pcrecpp)." ON)
116
117 SET(PCRE_EBCDIC OFF CACHE BOOL
118 "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems)")
119
120 SET(PCRE_LINK_SIZE "2" CACHE STRING
121 "Internal link size (2, 3 or 4 allowed). See LINK_SIZE in config.h.in for details.")
122
123 SET(PCRE_MATCH_LIMIT "10000000" CACHE STRING
124 "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.")
125
126 SET(PCRE_MATCH_LIMIT_RECURSION "MATCH_LIMIT" CACHE STRING
127 "Default limit on internal recursion. See MATCH_LIMIT_RECURSION in config.h.in for details.")
128
129 SET(PCREGREP_BUFSIZE "20480" CACHE STRING
130 "Buffer size parameter for pcregrep. See PCREGREP_BUFSIZE in config.h.in for details.")
131
132 SET(PCRE_NEWLINE "LF" CACHE STRING
133 "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF).")
134
135 SET(PCRE_NO_RECURSE OFF CACHE BOOL
136 "If ON, then don't use stack recursion when matching. See NO_RECURSE in config.h.in for details.")
137
138 SET(PCRE_POSIX_MALLOC_THRESHOLD "10" CACHE STRING
139 "Threshold for malloc() usage. See POSIX_MALLOC_THRESHOLD in config.h.in for details.")
140
141 SET(PCRE_SUPPORT_JIT OFF CACHE BOOL
142 "Enable support for Just-in-time compiling.")
143
144 SET(PCRE_SUPPORT_PCREGREP_JIT ON CACHE BOOL
145 "Enable use of Just-in-time compiling in pcregrep.")
146
147 SET(PCRE_SUPPORT_UTF OFF CACHE BOOL
148 "Enable support for Unicode Transformation Format (UTF-8 and/or UTF-16) encoding.")
149
150 SET(PCRE_SUPPORT_UNICODE_PROPERTIES OFF CACHE BOOL
151 "Enable support for Unicode properties (if set, UTF support will be enabled as well).")
152
153 SET(PCRE_SUPPORT_BSR_ANYCRLF OFF CACHE BOOL
154 "ON=Backslash-R matches only LF CR and CRLF, OFF=Backslash-R matches all Unicode Linebreaks")
155
156 OPTION(PCRE_SHOW_REPORT "Show the final configuration report" ON)
157 OPTION(PCRE_BUILD_PCREGREP "Build pcregrep" ON)
158 OPTION(PCRE_BUILD_TESTS "Build the tests" ON)
159
160 IF (MINGW)
161 OPTION(NON_STANDARD_LIB_PREFIX
162 "ON=Shared libraries built in mingw will be named pcre.dll, etc., instead of libpcre.dll, etc."
163 OFF)
164
165 OPTION(NON_STANDARD_LIB_SUFFIX
166 "ON=Shared libraries built in mingw will be named libpcre-0.dll, etc., instead of libpcre.dll, etc."
167 OFF)
168 ENDIF(MINGW)
169
170 # bzip2 lib
171 IF(BZIP2_FOUND)
172 OPTION (PCRE_SUPPORT_LIBBZ2 "Enable support for linking pcregrep with libbz2." ON)
173 ENDIF(BZIP2_FOUND)
174 IF(PCRE_SUPPORT_LIBBZ2)
175 INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
176 ENDIF(PCRE_SUPPORT_LIBBZ2)
177
178 # zlib
179 IF(ZLIB_FOUND)
180 OPTION (PCRE_SUPPORT_LIBZ "Enable support for linking pcregrep with libz." ON)
181 ENDIF(ZLIB_FOUND)
182 IF(PCRE_SUPPORT_LIBZ)
183 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
184 ENDIF(PCRE_SUPPORT_LIBZ)
185
186 # editline lib
187 IF(EDITLINE_FOUND)
188 OPTION (PCRE_SUPPORT_LIBEDIT "Enable support for linking pcretest with libedit." OFF)
189 ENDIF(EDITLINE_FOUND)
190 IF(PCRE_SUPPORT_LIBEDIT)
191 INCLUDE_DIRECTORIES(${EDITLINE_INCLUDE_DIR})
192 ENDIF(PCRE_SUPPORT_LIBEDIT)
193
194 # readline lib
195 IF(READLINE_FOUND)
196 OPTION (PCRE_SUPPORT_LIBREADLINE "Enable support for linking pcretest with libreadline." ON)
197 ENDIF(READLINE_FOUND)
198 IF(PCRE_SUPPORT_LIBREADLINE)
199 INCLUDE_DIRECTORIES(${READLINE_INCLUDE_DIR})
200 ENDIF(PCRE_SUPPORT_LIBREADLINE)
201
202 # Prepare build configuration
203
204 SET(pcre_have_type_traits 0)
205 SET(pcre_have_bits_type_traits 0)
206
207 IF(HAVE_TYPE_TRAITS_H)
208 SET(pcre_have_type_traits 1)
209 ENDIF(HAVE_TYPE_TRAITS_H)
210
211 IF(HAVE_BITS_TYPE_TRAITS_H)
212 SET(pcre_have_bits_type_traits 1)
213 ENDIF(HAVE_BITS_TYPE_TRAITS_H)
214
215 SET(pcre_have_long_long 0)
216 SET(pcre_have_ulong_long 0)
217
218 IF(HAVE_LONG_LONG)
219 SET(pcre_have_long_long 1)
220 ENDIF(HAVE_LONG_LONG)
221
222 IF(HAVE_UNSIGNED_LONG_LONG)
223 SET(pcre_have_ulong_long 1)
224 ENDIF(HAVE_UNSIGNED_LONG_LONG)
225
226 IF(NOT BUILD_SHARED_LIBS)
227 SET(PCRE_STATIC 1)
228 ENDIF(NOT BUILD_SHARED_LIBS)
229
230 IF(NOT PCRE_BUILD_PCRE8 AND NOT PCRE_BUILD_PCRE16)
231 MESSAGE(FATAL_ERROR "Either PCRE_BUILD_PCRE8 or PCRE_BUILD_PCRE16 must be enabled")
232 ENDIF(NOT PCRE_BUILD_PCRE8 AND NOT PCRE_BUILD_PCRE16)
233
234 IF(PCRE_BUILD_PCRE8)
235 SET(SUPPORT_PCRE8 1)
236 ENDIF(PCRE_BUILD_PCRE8)
237
238 IF(PCRE_BUILD_PCRE16)
239 SET(SUPPORT_PCRE16 1)
240 ENDIF(PCRE_BUILD_PCRE16)
241
242 IF(PCRE_BUILD_PCRECPP AND NOT PCRE_BUILD_PCRE8)
243 MESSAGE(STATUS "** PCRE_BUILD_PCRE8 must be enabled for the C++ library support")
244 SET(PCRE_BUILD_PCRECPP OFF)
245 ENDIF(PCRE_BUILD_PCRECPP AND NOT PCRE_BUILD_PCRE8)
246
247 IF(PCRE_BUILD_PCREGREP AND NOT PCRE_BUILD_PCRE8)
248 MESSAGE(STATUS "** PCRE_BUILD_PCRE8 must be enabled for the pcregrep program")
249 SET(PCRE_BUILD_PCREGREP OFF)
250 ENDIF(PCRE_BUILD_PCREGREP AND NOT PCRE_BUILD_PCRE8)
251
252 IF(PCRE_SUPPORT_LIBREADLINE AND PCRE_SUPPORT_LIBEDIT)
253 MESSAGE(FATAL_ERROR "Only one of libreadline or libeditline can be specified")
254 ENDIF(PCRE_SUPPORT_LIBREADLINE AND PCRE_SUPPORT_LIBEDIT)
255
256 IF(PCRE_SUPPORT_BSR_ANYCRLF)
257 SET(BSR_ANYCRLF 1)
258 ENDIF(PCRE_SUPPORT_BSR_ANYCRLF)
259
260 IF(PCRE_SUPPORT_UTF OR PCRE_SUPPORT_UNICODE_PROPERTIES)
261 SET(SUPPORT_UTF 1)
262 SET(PCRE_SUPPORT_UTF ON)
263 ENDIF(PCRE_SUPPORT_UTF OR PCRE_SUPPORT_UNICODE_PROPERTIES)
264
265 IF(PCRE_SUPPORT_UNICODE_PROPERTIES)
266 SET(SUPPORT_UCP 1)
267 ENDIF(PCRE_SUPPORT_UNICODE_PROPERTIES)
268
269 IF(PCRE_SUPPORT_JIT)
270 SET(SUPPORT_JIT 1)
271 ENDIF(PCRE_SUPPORT_JIT)
272
273 IF(PCRE_SUPPORT_PCREGREP_JIT)
274 SET(SUPPORT_PCREGREP_JIT 1)
275 ENDIF(PCRE_SUPPORT_PCREGREP_JIT)
276
277 # This next one used to contain
278 # SET(PCRETEST_LIBS ${READLINE_LIBRARY})
279 # but I was advised to add the NCURSES test as well, along with
280 # some modifications to cmake/FindReadline.cmake which should
281 # make it possible to override the default if necessary. PH
282
283 IF(PCRE_SUPPORT_LIBREADLINE)
284 SET(SUPPORT_LIBREADLINE 1)
285 SET(PCRETEST_LIBS ${READLINE_LIBRARY} ${NCURSES_LIBRARY})
286 ENDIF(PCRE_SUPPORT_LIBREADLINE)
287
288 # libedit is a plug-compatible alternative to libreadline
289
290 IF(PCRE_SUPPORT_LIBEDIT)
291 SET(SUPPORT_LIBEDIT 1)
292 SET(PCRETEST_LIBS ${EDITLINE_LIBRARY} ${NCURSES_LIBRARY})
293 ENDIF(PCRE_SUPPORT_LIBEDIT)
294
295 IF(PCRE_SUPPORT_LIBZ)
296 SET(SUPPORT_LIBZ 1)
297 SET(PCREGREP_LIBS ${PCREGREP_LIBS} ${ZLIB_LIBRARIES})
298 ENDIF(PCRE_SUPPORT_LIBZ)
299
300 IF(PCRE_SUPPORT_LIBBZ2)
301 SET(SUPPORT_LIBBZ2 1)
302 SET(PCREGREP_LIBS ${PCREGREP_LIBS} ${BZIP2_LIBRARIES})
303 ENDIF(PCRE_SUPPORT_LIBBZ2)
304
305 SET(NEWLINE "")
306
307 IF(PCRE_NEWLINE STREQUAL "LF")
308 SET(NEWLINE "10")
309 ENDIF(PCRE_NEWLINE STREQUAL "LF")
310 IF(PCRE_NEWLINE STREQUAL "CR")
311 SET(NEWLINE "13")
312 ENDIF(PCRE_NEWLINE STREQUAL "CR")
313 IF(PCRE_NEWLINE STREQUAL "CRLF")
314 SET(NEWLINE "3338")
315 ENDIF(PCRE_NEWLINE STREQUAL "CRLF")
316 IF(PCRE_NEWLINE STREQUAL "ANY")
317 SET(NEWLINE "-1")
318 ENDIF(PCRE_NEWLINE STREQUAL "ANY")
319 IF(PCRE_NEWLINE STREQUAL "ANYCRLF")
320 SET(NEWLINE "-2")
321 ENDIF(PCRE_NEWLINE STREQUAL "ANYCRLF")
322
323 IF(NEWLINE STREQUAL "")
324 MESSAGE(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".")
325 ENDIF(NEWLINE STREQUAL "")
326
327 IF(PCRE_EBCDIC)
328 SET(EBCDIC 1)
329 ENDIF(PCRE_EBCDIC)
330
331 IF(PCRE_NO_RECURSE)
332 SET(NO_RECURSE 1)
333 ENDIF(PCRE_NO_RECURSE)
334
335 # Output files
336 CONFIGURE_FILE(config-cmake.h.in
337 ${PROJECT_BINARY_DIR}/config.h
338 @ONLY)
339
340 # Parse version numbers and date out of configure.ac
341
342 file(STRINGS ${PROJECT_SOURCE_DIR}/configure.ac
343 configure_lines
344 LIMIT_COUNT 50 # Read only the first 50 lines of the file
345 )
346
347 set(SEARCHED_VARIABLES "pcre_major" "pcre_minor" "pcre_prerelease" "pcre_date")
348 foreach(configure_line ${configure_lines})
349 foreach(_substitution_variable ${SEARCHED_VARIABLES})
350 string(TOUPPER ${_substitution_variable} _substitution_variable_upper)
351 if (NOT ${_substitution_variable_upper})
352 string(REGEX MATCH "m4_define\\(${_substitution_variable}, \\[(.*)\\]" MACTHED_STRING ${configure_line})
353 if (CMAKE_MATCH_1)
354 set(${_substitution_variable_upper} ${CMAKE_MATCH_1})
355 endif()
356 endif()
357 endforeach()
358 endforeach()
359
360 CONFIGURE_FILE(pcre.h.in
361 ${PROJECT_BINARY_DIR}/pcre.h
362 @ONLY)
363
364 # What about pcre-config and libpcre.pc?
365
366 IF(PCRE_BUILD_PCRECPP)
367 CONFIGURE_FILE(pcre_stringpiece.h.in
368 ${PROJECT_BINARY_DIR}/pcre_stringpiece.h
369 @ONLY)
370
371 CONFIGURE_FILE(pcrecpparg.h.in
372 ${PROJECT_BINARY_DIR}/pcrecpparg.h
373 @ONLY)
374 ENDIF(PCRE_BUILD_PCRECPP)
375
376 # Character table generation
377
378 OPTION(PCRE_REBUILD_CHARTABLES "Rebuild char tables" OFF)
379 IF(PCRE_REBUILD_CHARTABLES)
380 ADD_EXECUTABLE(dftables dftables.c)
381
382 GET_TARGET_PROPERTY(DFTABLES_EXE dftables LOCATION)
383
384 ADD_CUSTOM_COMMAND(
385 COMMENT "Generating character tables (pcre_chartables.c) for current locale"
386 DEPENDS dftables
387 COMMAND ${DFTABLES_EXE}
388 ARGS ${PROJECT_BINARY_DIR}/pcre_chartables.c
389 OUTPUT ${PROJECT_BINARY_DIR}/pcre_chartables.c
390 )
391 ELSE(PCRE_REBUILD_CHARTABLES)
392 CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/pcre_chartables.c.dist
393 ${PROJECT_BINARY_DIR}/pcre_chartables.c
394 COPYONLY)
395 ENDIF(PCRE_REBUILD_CHARTABLES)
396
397 # Source code
398
399 SET(PCRE_HEADERS ${PROJECT_BINARY_DIR}/pcre.h)
400
401 IF(PCRE_BUILD_PCRE8)
402 SET(PCRE_SOURCES
403 pcre_byte_order.c
404 pcre_chartables.c
405 pcre_compile.c
406 pcre_config.c
407 pcre_dfa_exec.c
408 pcre_exec.c
409 pcre_fullinfo.c
410 pcre_get.c
411 pcre_globals.c
412 pcre_jit_compile.c
413 pcre_maketables.c
414 pcre_newline.c
415 pcre_ord2utf8.c
416 pcre_refcount.c
417 pcre_string_utils.c
418 pcre_study.c
419 pcre_tables.c
420 pcre_ucd.c
421 pcre_valid_utf8.c
422 pcre_version.c
423 pcre_xclass.c
424 )
425
426 SET(PCREPOSIX_HEADERS pcreposix.h)
427
428 SET(PCREPOSIX_SOURCES pcreposix.c)
429
430 ENDIF(PCRE_BUILD_PCRE8)
431
432 IF(PCRE_BUILD_PCRE16)
433 SET(PCRE16_SOURCES
434 pcre16_byte_order.c
435 pcre16_chartables.c
436 pcre16_compile.c
437 pcre16_config.c
438 pcre16_dfa_exec.c
439 pcre16_exec.c
440 pcre16_fullinfo.c
441 pcre16_get.c
442 pcre16_globals.c
443 pcre16_jit_compile.c
444 pcre16_maketables.c
445 pcre16_newline.c
446 pcre16_ord2utf16.c
447 pcre16_refcount.c
448 pcre16_string_utils.c
449 pcre16_study.c
450 pcre16_tables.c
451 pcre16_ucd.c
452 pcre16_utf16_utils.c
453 pcre16_valid_utf16.c
454 pcre16_version.c
455 pcre16_xclass.c
456 )
457 ENDIF(PCRE_BUILD_PCRE16)
458
459 IF(MINGW AND NOT PCRE_STATIC)
460 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcre.rc)
461 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcre.o
462 PRE-LINK
463 COMMAND windres ARGS pcre.rc pcre.o
464 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
465 COMMENT Using pcre coff info in mingw build)
466 SET(PCRE_SOURCES
467 ${PCRE_SOURCES} ${PROJECT_SOURCE_DIR}/pcre.o
468 )
469 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcre.rc)
470 IF (EXISTS ${PROJECT_SOURCE_DIR}/pcreposix.rc)
471 ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/pcreposix.o
472 PRE-LINK
473 COMMAND windres ARGS pcreposix.rc pcreposix.o
474 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
475 COMMENT Using pcreposix coff info in mingw build)
476 SET(PCREPOSIX_SOURCES
477 ${PCREPOSIX_SOURCES} ${PROJECT_SOURCE_DIR}/pcreposix.o
478 )
479 ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/pcreposix.rc)
480 ENDIF(MINGW AND NOT PCRE_STATIC)
481
482 SET(PCRECPP_HEADERS
483 pcrecpp.h
484 pcre_scanner.h
485 ${PROJECT_BINARY_DIR}/pcrecpparg.h
486 ${PROJECT_BINARY_DIR}/pcre_stringpiece.h
487 )
488
489 SET(PCRECPP_SOURCES
490 pcrecpp.cc
491 pcre_scanner.cc
492 pcre_stringpiece.cc
493 )
494
495 # Build setup
496
497 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
498
499 IF(MSVC)
500 ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
501 ENDIF(MSVC)
502
503 SET(CMAKE_INCLUDE_CURRENT_DIR 1)
504 # needed to make sure to not link debug libs
505 # against release libs and vice versa
506 IF(WIN32)
507 SET(CMAKE_DEBUG_POSTFIX "d")
508 ENDIF(WIN32)
509
510 SET(targets)
511
512 # Libraries
513 # pcre
514 IF(PCRE_BUILD_PCRE8)
515 ADD_LIBRARY(pcre ${PCRE_HEADERS} ${PCRE_SOURCES} ${PROJECT_BINARY_DIR}/config.h)
516 SET(targets ${targets} pcre)
517 ADD_LIBRARY(pcreposix ${PCREPOSIX_HEADERS} ${PCREPOSIX_SOURCES})
518 SET(targets ${targets} pcreposix)
519 TARGET_LINK_LIBRARIES(pcreposix pcre)
520
521 IF(MINGW AND NOT PCRE_STATIC)
522 IF(NON_STANDARD_LIB_PREFIX)
523 SET_TARGET_PROPERTIES(pcre pcreposix
524 PROPERTIES PREFIX ""
525 )
526 ENDIF(NON_STANDARD_LIB_PREFIX)
527
528 IF(NON_STANDARD_LIB_SUFFIX)
529 SET_TARGET_PROPERTIES(pcre pcreposix
530 PROPERTIES SUFFIX "-0.dll"
531 )
532 ENDIF(NON_STANDARD_LIB_SUFFIX)
533 ENDIF(MINGW AND NOT PCRE_STATIC)
534
535 ENDIF(PCRE_BUILD_PCRE8)
536
537 IF(PCRE_BUILD_PCRE16)
538 ADD_LIBRARY(pcre16 ${PCRE_HEADERS} ${PCRE16_SOURCES} ${PROJECT_BINARY_DIR}/config.h)
539 SET(targets ${targets} pcre16)
540
541 IF(MINGW AND NOT PCRE_STATIC)
542 IF(NON_STANDARD_LIB_PREFIX)
543 SET_TARGET_PROPERTIES(pcre16
544 PROPERTIES PREFIX ""
545 )
546 ENDIF(NON_STANDARD_LIB_PREFIX)
547
548 IF(NON_STANDARD_LIB_SUFFIX)
549 SET_TARGET_PROPERTIES(pcre16
550 PROPERTIES SUFFIX "-0.dll"
551 )
552 ENDIF(NON_STANDARD_LIB_SUFFIX)
553 ENDIF(MINGW AND NOT PCRE_STATIC)
554
555 ENDIF(PCRE_BUILD_PCRE16)
556
557 # pcrecpp
558 IF(PCRE_BUILD_PCRECPP)
559 ADD_LIBRARY(pcrecpp ${PCRECPP_HEADERS} ${PCRECPP_SOURCES})
560 SET(targets ${targets} pcrecpp)
561 TARGET_LINK_LIBRARIES(pcrecpp pcre)
562
563 IF(MINGW AND NOT PCRE_STATIC)
564 IF(NON_STANDARD_LIB_PREFIX)
565 SET_TARGET_PROPERTIES(pcrecpp
566 PROPERTIES PREFIX ""
567 )
568 ENDIF(NON_STANDARD_LIB_PREFIX)
569
570 IF(NON_STANDARD_LIB_SUFFIX)
571 SET_TARGET_PROPERTIES(pcrecpp
572 PROPERTIES SUFFIX "-0.dll"
573 )
574 ENDIF(NON_STANDARD_LIB_SUFFIX)
575 ENDIF(MINGW AND NOT PCRE_STATIC)
576 ENDIF(PCRE_BUILD_PCRECPP)
577
578
579 # Executables
580
581 # Removed by PH (2008-01-23) because pcredemo shouldn't really be built
582 # automatically, and it gave trouble in some environments anyway.
583 # ADD_EXECUTABLE(pcredemo pcredemo.c)
584 # TARGET_LINK_LIBRARIES(pcredemo pcreposix)
585 # IF(NOT BUILD_SHARED_LIBS)
586 # # make sure to not use declspec(dllimport) in static mode on windows
587 # SET_TARGET_PROPERTIES(pcredemo PROPERTIES COMPILE_FLAGS "-DPCRE_STATIC")
588 # ENDIF(NOT BUILD_SHARED_LIBS)
589
590 IF(PCRE_BUILD_PCREGREP)
591 ADD_EXECUTABLE(pcregrep pcregrep.c)
592 SET(targets ${targets} pcregrep)
593 TARGET_LINK_LIBRARIES(pcregrep pcreposix ${PCREGREP_LIBS})
594 ENDIF(PCRE_BUILD_PCREGREP)
595
596 # Testing
597 IF(PCRE_BUILD_TESTS)
598 ENABLE_TESTING()
599
600 SET(PCRETEST_SOURCES pcretest.c)
601 IF(PCRE_BUILD_PCRE8)
602 LIST(APPEND PCRETEST_SOURCES pcre_printint.c)
603 ENDIF(PCRE_BUILD_PCRE8)
604 IF(PCRE_BUILD_PCRE16)
605 LIST(APPEND PCRETEST_SOURCES pcre16_printint.c)
606 ENDIF(PCRE_BUILD_PCRE16)
607
608 ADD_EXECUTABLE(pcretest ${PCRETEST_SOURCES})
609 SET(targets ${targets} pcretest)
610 IF(PCRE_BUILD_PCRE8)
611 LIST(APPEND PCRETEST_LIBS pcreposix pcre)
612 ENDIF(PCRE_BUILD_PCRE8)
613 IF(PCRE_BUILD_PCRE16)
614 LIST(APPEND PCRETEST_LIBS pcre16)
615 ENDIF(PCRE_BUILD_PCRE16)
616 TARGET_LINK_LIBRARIES(pcretest ${PCRETEST_LIBS})
617
618 IF(PCRE_SUPPORT_JIT)
619 ADD_EXECUTABLE(pcre_jit_test pcre_jit_test.c)
620 SET(targets ${targets} pcre_jit_test)
621 SET(PCRE_JIT_TEST_LIBS )
622 IF(PCRE_BUILD_PCRE8)
623 LIST(APPEND PCRE_JIT_TEST_LIBS pcre)
624 ENDIF(PCRE_BUILD_PCRE8)
625 IF(PCRE_BUILD_PCRE16)
626 LIST(APPEND PCRE_JIT_TEST_LIBS pcre16)
627 ENDIF(PCRE_BUILD_PCRE16)
628 TARGET_LINK_LIBRARIES(pcre_jit_test ${PCRE_JIT_TEST_LIBS})
629 ENDIF(PCRE_SUPPORT_JIT)
630
631 IF(PCRE_BUILD_PCRECPP)
632 ADD_EXECUTABLE(pcrecpp_unittest pcrecpp_unittest.cc)
633 SET(targets ${targets} pcrecpp_unittest)
634 TARGET_LINK_LIBRARIES(pcrecpp_unittest pcrecpp)
635 IF(MINGW AND NON_STANDARD_LIB_NAMES AND NOT PCRE_STATIC)
636 SET_TARGET_PROPERTIES(pcrecpp
637 PROPERTIES PREFIX ""
638 )
639 ENDIF(MINGW AND NON_STANDARD_LIB_NAMES AND NOT PCRE_STATIC)
640
641 ADD_EXECUTABLE(pcre_scanner_unittest pcre_scanner_unittest.cc)
642 SET(targets ${targets} pcre_scanner_unittest)
643 TARGET_LINK_LIBRARIES(pcre_scanner_unittest pcrecpp)
644
645 ADD_EXECUTABLE(pcre_stringpiece_unittest pcre_stringpiece_unittest.cc)
646 SET(targets ${targets} pcre_stringpiece_unittest)
647 TARGET_LINK_LIBRARIES(pcre_stringpiece_unittest pcrecpp)
648 ENDIF(PCRE_BUILD_PCRECPP)
649
650 # exes in Debug location tested by the RunTest shell script
651 # via "make test"
652 IF(PCRE_BUILD_PCREGREP)
653 GET_TARGET_PROPERTY(PCREGREP_EXE pcregrep DEBUG_LOCATION)
654 ENDIF(PCRE_BUILD_PCREGREP)
655
656 GET_TARGET_PROPERTY(PCRETEST_EXE pcretest DEBUG_LOCATION)
657
658 # =================================================
659 # Write out a CTest configuration file
660 #
661 FILE(WRITE ${PROJECT_BINARY_DIR}/CTestCustom.ctest
662 "# This is a generated file.
663 MESSAGE(\"When testing is complete, review test output in the
664 ${PROJECT_BINARY_DIR}/Testing/Temporary folder.\")
665 MESSAGE(\"\")
666 ")
667
668 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_test.sh
669 "#! /bin/sh
670 # This is a generated file.
671 srcdir=${PROJECT_SOURCE_DIR}
672 pcretest=${PCRETEST_EXE}
673 source ${PROJECT_SOURCE_DIR}/RunTest
674 if test \"$?\" != \"0\"; then exit 1; fi
675 # End
676 ")
677
678 IF(UNIX)
679 ADD_TEST(pcre_test sh ${PROJECT_BINARY_DIR}/pcre_test.sh)
680 ENDIF(UNIX)
681
682 IF(PCRE_BUILD_PCREGREP)
683 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_grep_test.sh
684 "#! /bin/sh
685 # This is a generated file.
686 srcdir=${PROJECT_SOURCE_DIR}
687 pcregrep=${PCREGREP_EXE}
688 pcretest=${PCRETEST_EXE}
689 source ${PROJECT_SOURCE_DIR}/RunGrepTest
690 if test \"$?\" != \"0\"; then exit 1; fi
691 # End
692 ")
693
694 IF(UNIX)
695 ADD_TEST(pcre_grep_test sh ${PROJECT_BINARY_DIR}/pcre_grep_test.sh)
696 ENDIF(UNIX)
697 ENDIF(PCRE_BUILD_PCREGREP)
698
699 IF(WIN32)
700 # Provide environment for executing the bat file version of RunTest
701 string(REPLACE "/" "\\" winsrc "${PROJECT_SOURCE_DIR}")
702
703 FILE(WRITE ${PROJECT_BINARY_DIR}/pcre_test.txt
704 "\@REM This is a generated file.
705 \@Echo off
706 setlocal
707 SET\ srcdir=\${srcdir}
708 SET\ pcretest=\${pcretest}
709 call \"\${srcdir}\\RunTest.Bat\"
710 if errorlevel 1 exit /b 1
711 echo RunTest.bat tests successfully completed
712 ")
713
714 FILE(WRITE ${PROJECT_BINARY_DIR}/BatDriver.cmake
715 "# This is a generated file.
716 # this script is run with arguments via the cmake command in add_test(NAME pcre_test_bat)
717 # BatDriver feeds the actual location of pcretest.exe
718 FILE(TO_NATIVE_PATH \${pcretestx} pcretest)
719 FILE(TO_NATIVE_PATH \${srcdirx} srcdir)
720 configure_file(\"\${bindirx}/pcre_test.txt\" \"\${bindirx}/pcre_test.bat\")
721 # MESSAGE(\"cmake\ variable\ pcretest\ is\ \${pcretest}\")
722 # STRING(REPLACE \" \" \"\\ \" bindir \${bindirx})
723 MESSAGE(\"COMMAND pcre_test.bat \")
724 EXECUTE_PROCESS(COMMAND pcre_test.bat
725 WORKING_DIRECTORY .
726 OUTPUT_VARIABLE batoutput)
727 MESSAGE(\"OUTPUT: \${batoutput}\")
728 ")
729
730 ADD_TEST(NAME pcre_test_bat
731 COMMAND ${CMAKE_COMMAND} -D bindirx=${PROJECT_BINARY_DIR} -D srcdirx=${PROJECT_SOURCE_DIR} -D pcretestx=$<TARGET_FILE:pcretest> -P "${PROJECT_BINARY_DIR}/BatDriver.cmake")
732 SET_TESTS_PROPERTIES(pcre_test_bat PROPERTIES
733 PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed")
734
735 IF("$ENV{OSTYPE}" STREQUAL "msys")
736 # Both the sh and bat file versions of RunTest are run if make test is used
737 # in msys
738 ADD_TEST(pcre_test_sh sh.exe ${PROJECT_BINARY_DIR}/pcre_test.sh)
739 IF(PCRE_BUILD_PCREGREP)
740 ADD_TEST(pcre_grep_test sh.exe ${PROJECT_BINARY_DIR}/pcre_grep_test.sh)
741 ENDIF(PCRE_BUILD_PCREGREP)
742 ENDIF("$ENV{OSTYPE}" STREQUAL "msys")
743
744 ENDIF(WIN32)
745
746 # Changed to accommodate testing whichever location was just built
747
748 IF(PCRE_SUPPORT_JIT)
749 ADD_TEST(pcre_jit_test pcre_jit_test)
750 ENDIF(PCRE_SUPPORT_JIT)
751
752 IF(PCRE_BUILD_PCRECPP)
753 ADD_TEST(pcrecpp_test pcrecpp_unittest)
754 ADD_TEST(pcre_scanner_test pcre_scanner_unittest)
755 ADD_TEST(pcre_stringpiece_test pcre_stringpiece_unittest)
756 ENDIF(PCRE_BUILD_PCRECPP)
757
758 ENDIF(PCRE_BUILD_TESTS)
759
760 # Installation
761 SET(CMAKE_INSTALL_ALWAYS 1)
762
763 INSTALL(TARGETS ${targets}
764 RUNTIME DESTINATION bin
765 LIBRARY DESTINATION lib
766 ARCHIVE DESTINATION lib)
767
768 INSTALL(FILES ${PCRE_HEADERS} ${PCREPOSIX_HEADERS} DESTINATION include)
769
770 FILE(GLOB html ${PROJECT_SOURCE_DIR}/doc/html/*.html)
771 FILE(GLOB man1 ${PROJECT_SOURCE_DIR}/doc/*.1)
772 FILE(GLOB man3 ${PROJECT_SOURCE_DIR}/doc/*.3)
773
774 IF(PCRE_BUILD_PCRECPP)
775 INSTALL(FILES ${PCRECPP_HEADERS} DESTINATION include)
776 ELSE(PCRE_BUILD_PCRECPP)
777 # Remove pcrecpp.3
778 FOREACH(man ${man3})
779 GET_FILENAME_COMPONENT(man_tmp ${man} NAME)
780 IF(NOT man_tmp STREQUAL "pcrecpp.3")
781 SET(man3_new ${man3} ${man})
782 ENDIF(NOT man_tmp STREQUAL "pcrecpp.3")
783 ENDFOREACH(man ${man3})
784 SET(man3 ${man3_new})
785 ENDIF(PCRE_BUILD_PCRECPP)
786
787 INSTALL(FILES ${man1} DESTINATION man/man1)
788 INSTALL(FILES ${man3} DESTINATION man/man3)
789 INSTALL(FILES ${html} DESTINATION share/doc/pcre/html)
790
791 # help, only for nice output
792 IF(BUILD_SHARED_LIBS)
793 SET(BUILD_STATIC_LIBS OFF)
794 ELSE(BUILD_SHARED_LIBS)
795 SET(BUILD_STATIC_LIBS ON)
796 ENDIF(BUILD_SHARED_LIBS)
797
798 IF(PCRE_SHOW_REPORT)
799 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
800 IF (CMAKE_C_FLAGS)
801 SET(cfsp " ")
802 ENDIF(CMAKE_C_FLAGS)
803 IF (CMAKE_CXX_FLAGS)
804 SET(cxxfsp " ")
805 ENDIF(CMAKE_CXX_FLAGS)
806 MESSAGE(STATUS "")
807 MESSAGE(STATUS "")
808 MESSAGE(STATUS "PCRE configuration summary:")
809 MESSAGE(STATUS "")
810 MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
811 MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}")
812 MESSAGE(STATUS " C++ compiler .................... : ${CMAKE_CXX_COMPILER}")
813 MESSAGE(STATUS " C compiler flags ................ : ${CMAKE_C_FLAGS}${cfsp}${CMAKE_C_FLAGS_${buildtype}}")
814 MESSAGE(STATUS " C++ compiler flags .............. : ${CMAKE_CXX_FLAGS}${cxxfsp}${CMAKE_CXX_FLAGS_${buildtype}}")
815 MESSAGE(STATUS "")
816 MESSAGE(STATUS " Build 8 bit PCRE library ........ : ${PCRE_BUILD_PCRE8}")
817 MESSAGE(STATUS " Build 16 bit PCRE library ....... : ${PCRE_BUILD_PCRE16}")
818 MESSAGE(STATUS " Build C++ library ............... : ${PCRE_BUILD_PCRECPP}")
819 MESSAGE(STATUS " Enable JIT compiling support .... : ${PCRE_SUPPORT_JIT}")
820 MESSAGE(STATUS " Enable UTF support .............. : ${PCRE_SUPPORT_UTF}")
821 MESSAGE(STATUS " Unicode properties .............. : ${PCRE_SUPPORT_UNICODE_PROPERTIES}")
822 MESSAGE(STATUS " Newline char/sequence ........... : ${PCRE_NEWLINE}")
823 MESSAGE(STATUS " \\R matches only ANYCRLF ......... : ${PCRE_SUPPORT_BSR_ANYCRLF}")
824 MESSAGE(STATUS " EBCDIC coding ................... : ${PCRE_EBCDIC}")
825 MESSAGE(STATUS " Rebuild char tables ............. : ${PCRE_REBUILD_CHARTABLES}")
826 MESSAGE(STATUS " No stack recursion .............. : ${PCRE_NO_RECURSE}")
827 MESSAGE(STATUS " POSIX mem threshold ............. : ${PCRE_POSIX_MALLOC_THRESHOLD}")
828 MESSAGE(STATUS " Internal link size .............. : ${PCRE_LINK_SIZE}")
829 MESSAGE(STATUS " Match limit ..................... : ${PCRE_MATCH_LIMIT}")
830 MESSAGE(STATUS " Match limit recursion ........... : ${PCRE_MATCH_LIMIT_RECURSION}")
831 MESSAGE(STATUS " Build shared libs ............... : ${BUILD_SHARED_LIBS}")
832 MESSAGE(STATUS " Build static libs ............... : ${BUILD_STATIC_LIBS}")
833 MESSAGE(STATUS " Build pcregrep .................. : ${PCRE_BUILD_PCREGREP}")
834 MESSAGE(STATUS " Enable JIT in pcregrep .......... : ${PCRE_SUPPORT_PCREGREP_JIT}")
835 MESSAGE(STATUS " Buffer size for pcregrep ........ : ${PCREGREP_BUFSIZE}")
836 MESSAGE(STATUS " Build tests (implies pcretest .. : ${PCRE_BUILD_TESTS}")
837 MESSAGE(STATUS " and pcregrep)")
838 IF(ZLIB_FOUND)
839 MESSAGE(STATUS " Link pcregrep with libz ......... : ${PCRE_SUPPORT_LIBZ}")
840 ELSE(ZLIB_FOUND)
841 MESSAGE(STATUS " Link pcregrep with libz ......... : Library not found" )
842 ENDIF(ZLIB_FOUND)
843 IF(BZIP2_FOUND)
844 MESSAGE(STATUS " Link pcregrep with libbz2 ....... : ${PCRE_SUPPORT_LIBBZ2}")
845 ELSE(BZIP2_FOUND)
846 MESSAGE(STATUS " Link pcregrep with libbz2 ....... : Library not found" )
847 ENDIF(BZIP2_FOUND)
848 IF(EDITLINE_FOUND)
849 MESSAGE(STATUS " Link pcretest with libeditline .. : ${PCRE_SUPPORT_LIBEDIT}")
850 ELSE(EDITLINE_FOUND)
851 MESSAGE(STATUS " Link pcretest with libeditline .. : Library not found" )
852 ENDIF(EDITLINE_FOUND)
853 IF(READLINE_FOUND)
854 MESSAGE(STATUS " Link pcretest with libreadline .. : ${PCRE_SUPPORT_LIBREADLINE}")
855 ELSE(READLINE_FOUND)
856 MESSAGE(STATUS " Link pcretest with libreadline .. : Library not found" )
857 ENDIF(READLINE_FOUND)
858
859 IF(MINGW AND NOT PCRE_STATIC)
860 MESSAGE(STATUS " Non-standard dll names (prefix) . : ${NON_STANDARD_LIB_PREFIX}")
861 MESSAGE(STATUS " Non-standard dll names (suffix) . : ${NON_STANDARD_LIB_SUFFIX}")
862 ENDIF(MINGW AND NOT PCRE_STATIC)
863 MESSAGE(STATUS "")
864 ENDIF(PCRE_SHOW_REPORT)
865
866 # end CMakeLists.txt

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12