summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 647665ed55e5d2ee26c355da197d27c3db2672f9 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# CMakeLists.txt
#
#
# This file allows building PCRE with the CMake configuration and build
# tool. Download CMake in source or binary form from http://www.cmake.org/
#
# Original listfile by Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
# Refined and expanded by Daniel Richard G. <skunk@iSKUNK.ORG>
# 2007-09-14 mod by Sheri so 7.4 supported configuration options can be entered
# 2007-09-19 Adjusted by PH to retain previous default settings
# 2007-12-26 (a) On UNIX, use names libpcre instead of just pcre
#            (b) Ensure pcretest and pcregrep link with the local library,
#                not a previously-installed one.
#            (c) Add PCRE_SUPPORT_LIBREADLINE, PCRE_SUPPORT_LIBZ, and
#                PCRE_SUPPORT_LIBBZ2.
#

PROJECT(PCRE C CXX)

CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6)

# Configuration checks

INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckTypeSize)

CHECK_INCLUDE_FILE(dirent.h	HAVE_DIRENT_H)
CHECK_INCLUDE_FILE(unistd.h	HAVE_UNISTD_H)
CHECK_INCLUDE_FILE(sys/stat.h	HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE(sys/types.h	HAVE_SYS_TYPES_H)

CHECK_INCLUDE_FILE(bzlib.h      HAVE_BZLIB_H)
CHECK_INCLUDE_FILE(zlib.h       HAVE_ZLIB_H)
CHECK_INCLUDE_FILE(readline/history.h  HAVE_READLINE_HISTORY_H)
CHECK_INCLUDE_FILE(readline/readline.h HAVE_READLINE_READLINE_H)

CHECK_INCLUDE_FILE_CXX(type_traits.h		HAVE_TYPE_TRAITS_H)
CHECK_INCLUDE_FILE_CXX(bits/type_traits.h	HAVE_BITS_TYPE_TRAITS_H)

CHECK_FUNCTION_EXISTS(bcopy	HAVE_BCOPY)
CHECK_FUNCTION_EXISTS(memmove	HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS(strerror	HAVE_STRERROR)

CHECK_TYPE_SIZE("long long"		LONG_LONG)
CHECK_TYPE_SIZE("unsigned long long"	UNSIGNED_LONG_LONG)

# User-configurable options
#
# (Note: CMakeSetup displays these in alphabetical order, regardless of
# the order we use here)

SET(BUILD_SHARED_LIBS OFF CACHE BOOL
    "Build shared libraries instead of static ones.")

OPTION(PCRE_BUILD_PCRECPP "Build the PCRE C++ library (pcrecpp)." ON)

SET(PCRE_EBCDIC OFF CACHE BOOL
    "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems)")

SET(PCRE_LINK_SIZE "2" CACHE STRING
    "Internal link size (2, 3 or 4 allowed). See LINK_SIZE in config.h.in for details.")

SET(PCRE_MATCH_LIMIT "10000000" CACHE STRING
    "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.")

SET(PCRE_MATCH_LIMIT_RECURSION "MATCH_LIMIT" CACHE STRING
    "Default limit on internal recursion. See MATCH_LIMIT_RECURSION in config.h.in for details.")

SET(PCRE_NEWLINE "LF" CACHE STRING
    "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF).")

SET(PCRE_NO_RECURSE OFF CACHE BOOL
    "If ON, then don't use stack recursion when matching. See NO_RECURSE in config.h.in for details.")

SET(PCRE_POSIX_MALLOC_THRESHOLD "10" CACHE STRING
    "Threshold for malloc() usage. See POSIX_MALLOC_THRESHOLD in config.h.in for details.")

SET(PCRE_SUPPORT_UNICODE_PROPERTIES OFF CACHE BOOL
    "Enable support for Unicode properties. (If set, UTF-8 support will be enabled as well)")

SET(PCRE_SUPPORT_UTF8 OFF CACHE BOOL
    "Enable support for the Unicode UTF-8 encoding.")

SET(PCRE_SUPPORT_BSR_ANYCRLF OFF CACHE BOOL
    "ON=Backslash-R matches only LF CR and CRLF, OFF=Backslash-R matches all Unicode Linebreaks")

SET(PCRE_SUPPORT_LIBBZ2 OFF CACHE BOOL
    "Enable support for linking pcregrep with libbz2.")

SET (PCRE_SUPPORT_LIBZ OFF CACHE BOOL
    "Enable support for linking pcregrep with libz.")

SET (PCRE_SUPPORT_LIBREADLINE OFF CACHE BOOL
    "Enable support for linking pcretest with libreadline.")

# Prepare build configuration

SET(pcre_have_type_traits 0)
SET(pcre_have_bits_type_traits 0)

IF(HAVE_TYPE_TRAITS_H)
	SET(pcre_have_type_traits 1)
ENDIF(HAVE_TYPE_TRAITS_H)

IF(HAVE_BITS_TYPE_TRAITS_H)
	SET(pcre_have_bits_type_traits 1)
ENDIF(HAVE_BITS_TYPE_TRAITS_H)

SET(pcre_have_long_long 0)
SET(pcre_have_ulong_long 0)

IF(HAVE_LONG_LONG)
	SET(pcre_have_long_long 1)
ENDIF(HAVE_LONG_LONG)

IF(HAVE_UNSIGNED_LONG_LONG)
	SET(pcre_have_ulong_long 1)
ENDIF(HAVE_UNSIGNED_LONG_LONG)

IF(NOT BUILD_SHARED_LIBS)
	SET(PCRE_STATIC 1)
ENDIF(NOT BUILD_SHARED_LIBS)

IF(PCRE_SUPPORT_BSR_ANYCRLF)
	SET(BSR_ANYCRLF 1)
ENDIF(PCRE_SUPPORT_BSR_ANYCRLF)

IF(PCRE_SUPPORT_UTF8 OR PCRE_SUPPORT_UNICODE_PROPERTIES)
	SET(SUPPORT_UTF8 1)
ENDIF(PCRE_SUPPORT_UTF8 OR PCRE_SUPPORT_UNICODE_PROPERTIES)

IF(PCRE_SUPPORT_UNICODE_PROPERTIES)
	SET(SUPPORT_UCP 1)
ENDIF(PCRE_SUPPORT_UNICODE_PROPERTIES)

IF(PCRE_SUPPORT_LIBREADLINE)
        SET(SUPPORT_LIBREADLINE 1)
        SET(PCRETEST_LIBS readline)
ENDIF(PCRE_SUPPORT_LIBREADLINE)

IF(PCRE_SUPPORT_LIBZ)
        SET(SUPPORT_LIBZ 1)
        SET(PCREGREP_LIBS z)
ENDIF(PCRE_SUPPORT_LIBZ)

IF(PCRE_SUPPORT_LIBBZ2)
        SET(SUPPORT_LIBBZ2 1)
        SET(PCREGREP_LIBS ${PCREGREP_LIBS} bz2)
ENDIF(PCRE_SUPPORT_LIBBZ2)

SET(NEWLINE "")

IF(PCRE_NEWLINE STREQUAL "LF")
	SET(NEWLINE "10")
ENDIF(PCRE_NEWLINE STREQUAL "LF")
IF(PCRE_NEWLINE STREQUAL "CR")
	SET(NEWLINE "13")
ENDIF(PCRE_NEWLINE STREQUAL "CR")
IF(PCRE_NEWLINE STREQUAL "CRLF")
	SET(NEWLINE "3338")
ENDIF(PCRE_NEWLINE STREQUAL "CRLF")
IF(PCRE_NEWLINE STREQUAL "ANY")
	SET(NEWLINE "-1")
ENDIF(PCRE_NEWLINE STREQUAL "ANY")
IF(PCRE_NEWLINE STREQUAL "ANYCRLF")
	SET(NEWLINE "-2")
ENDIF(PCRE_NEWLINE STREQUAL "ANYCRLF")

IF(NEWLINE STREQUAL "")
	MESSAGE(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".")
ENDIF(NEWLINE STREQUAL "")

IF(PCRE_EBCDIC)
	SET(EBCDIC 1)
ENDIF(PCRE_EBCDIC)

IF(PCRE_NO_RECURSE)
	SET(NO_RECURSE 1)
ENDIF(PCRE_NO_RECURSE)

# Output files

CONFIGURE_FILE(config-cmake.h.in
               ${CMAKE_BINARY_DIR}/config.h
               @ONLY)

CONFIGURE_FILE(pcre.h.generic
               ${CMAKE_BINARY_DIR}/pcre.h
               COPYONLY)

# What about pcre-config and libpcre.pc?

IF(PCRE_BUILD_PCRECPP)
	CONFIGURE_FILE(pcre_stringpiece.h.in
		       ${CMAKE_BINARY_DIR}/pcre_stringpiece.h
		       @ONLY)

	CONFIGURE_FILE(pcrecpparg.h.in
		       ${CMAKE_BINARY_DIR}/pcrecpparg.h
		       @ONLY)
ENDIF(PCRE_BUILD_PCRECPP)

# Character table generation

ADD_EXECUTABLE(dftables dftables.c)

GET_TARGET_PROPERTY(DFTABLES_EXE dftables LOCATION)

ADD_CUSTOM_COMMAND(
	COMMENT "Generating character tables (pcre_chartables.c) for current locale"
	DEPENDS dftables
	COMMAND ${DFTABLES_EXE}
	ARGS	${CMAKE_BINARY_DIR}/pcre_chartables.c
	OUTPUT	${CMAKE_BINARY_DIR}/pcre_chartables.c
)

# Source code

SET(PCRE_HEADERS ${CMAKE_BINARY_DIR}/pcre.h)

SET(PCRE_SOURCES
	${CMAKE_BINARY_DIR}/pcre_chartables.c
	pcre_compile.c
	pcre_config.c
	pcre_dfa_exec.c
	pcre_exec.c
	pcre_fullinfo.c
	pcre_get.c
	pcre_globals.c
	pcre_info.c
	pcre_newline.c
	pcre_maketables.c
	pcre_ord2utf8.c
	pcre_refcount.c
	pcre_study.c
	pcre_tables.c
	pcre_try_flipped.c
	pcre_ucp_searchfuncs.c
	pcre_valid_utf8.c
	pcre_version.c
	pcre_xclass.c
)

SET(PCREPOSIX_HEADERS pcreposix.h)

SET(PCREPOSIX_SOURCES pcreposix.c)

SET(PCRECPP_HEADERS
	pcrecpp.h
	pcre_scanner.h
	${CMAKE_BINARY_DIR}/pcrecpparg.h
	${CMAKE_BINARY_DIR}/pcre_stringpiece.h
)

SET(PCRECPP_SOURCES
	pcrecpp.cc
	pcre_scanner.cc
	pcre_stringpiece.cc
)

# Build setup

ADD_DEFINITIONS(-DHAVE_CONFIG_H)

IF(WIN32)
	ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
ENDIF(WIN32)

SET(CMAKE_INCLUDE_CURRENT_DIR 1)

#SET(CMAKE_DEBUG_POSTFIX "d")

# Libraries

ADD_LIBRARY(pcre ${PCRE_HEADERS} ${PCRE_SOURCES})

ADD_LIBRARY(pcreposix ${PCREPOSIX_HEADERS} ${PCREPOSIX_SOURCES})
TARGET_LINK_LIBRARIES(pcreposix pcre)

IF(NOT UNIX)
SET_TARGET_PROPERTIES(pcre pcreposix
                        PROPERTIES PREFIX ""
)
ENDIF(NOT UNIX)

IF(PCRE_BUILD_PCRECPP)
	ADD_LIBRARY(pcrecpp ${PCRECPP_HEADERS} ${PCRECPP_SOURCES})
	TARGET_LINK_LIBRARIES(pcrecpp pcre)
	IF(MINGW)
		SET_TARGET_PROPERTIES(pcrecpp PROPERTIES PREFIX "mingw-")
	ENDIF(MINGW)
ENDIF(PCRE_BUILD_PCRECPP)

# Executables

ADD_EXECUTABLE(pcretest pcretest.c)
TARGET_LINK_LIBRARIES(pcretest pcreposix ${PCRETEST_LIBS})

ADD_EXECUTABLE(pcregrep pcregrep.c)
TARGET_LINK_LIBRARIES(pcregrep pcreposix ${PCREGREP_LIBS})

IF(PCRE_BUILD_PCRECPP)
	ADD_EXECUTABLE(pcrecpp_unittest pcrecpp_unittest.cc)
	TARGET_LINK_LIBRARIES(pcrecpp_unittest pcrecpp)

	ADD_EXECUTABLE(pcre_scanner_unittest pcre_scanner_unittest.cc)
	TARGET_LINK_LIBRARIES(pcre_scanner_unittest pcrecpp)

	ADD_EXECUTABLE(pcre_stringpiece_unittest pcre_stringpiece_unittest.cc)
	TARGET_LINK_LIBRARIES(pcre_stringpiece_unittest pcrecpp)
ENDIF(PCRE_BUILD_PCRECPP)

# Testing

ENABLE_TESTING()

GET_TARGET_PROPERTY(PCREGREP_EXE pcregrep DEBUG_LOCATION)
GET_TARGET_PROPERTY(PCRETEST_EXE pcretest DEBUG_LOCATION)

# Write out a CTest configuration file that sets some needed environment
# variables for the test scripts.
#
FILE(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.ctest
"# This is a generated file.
SET(ENV{srcdir} ${CMAKE_SOURCE_DIR})
SET(ENV{pcregrep} ${PCREGREP_EXE})
SET(ENV{pcretest} ${PCRETEST_EXE})
")

IF(UNIX)
	ADD_TEST(pcre_test	${CMAKE_SOURCE_DIR}/RunTest)
	ADD_TEST(pcre_grep_test ${CMAKE_SOURCE_DIR}/RunGrepTest)
ENDIF(UNIX)
IF(WIN32)
	ADD_TEST(pcre_test cmd /C ${CMAKE_SOURCE_DIR}/RunTest.bat)
ENDIF(WIN32)

GET_TARGET_PROPERTY(PCRECPP_UNITTEST_EXE
                    pcrecpp_unittest
                    DEBUG_LOCATION)

GET_TARGET_PROPERTY(PCRE_SCANNER_UNITTEST_EXE
                    pcre_scanner_unittest
                    DEBUG_LOCATION)

GET_TARGET_PROPERTY(PCRE_STRINGPIECE_UNITTEST_EXE
                    pcre_stringpiece_unittest
                    DEBUG_LOCATION)

ADD_TEST(pcrecpp_test          ${PCRECPP_UNITTEST_EXE})
ADD_TEST(pcre_scanner_test     ${PCRE_SCANNER_UNITTEST_EXE})
ADD_TEST(pcre_stringpiece_test ${PCRE_STRINGPIECE_UNITTEST_EXE})

# Installation

SET(CMAKE_INSTALL_ALWAYS 1)

INSTALL(TARGETS pcre pcreposix pcregrep pcretest
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

INSTALL(FILES ${PCRE_HEADERS} ${PCREPOSIX_HEADERS} DESTINATION include)

FILE(GLOB html ${CMAKE_SOURCE_DIR}/doc/html/*.html)
FILE(GLOB man1 ${CMAKE_SOURCE_DIR}/doc/*.1)
FILE(GLOB man3 ${CMAKE_SOURCE_DIR}/doc/*.3)

IF(PCRE_BUILD_PCRECPP)
	INSTALL(TARGETS pcrecpp
		RUNTIME DESTINATION bin
		LIBRARY DESTINATION lib
		ARCHIVE DESTINATION lib)
	INSTALL(FILES ${PCRECPP_HEADERS} DESTINATION include)
ELSE(PCRE_BUILD_PCRECPP)
	# Remove pcrecpp.3
	FOREACH(man ${man3})
		GET_FILENAME_COMPONENT(man_tmp ${man} NAME)
		IF(NOT man_tmp STREQUAL "pcrecpp.3")
			SET(man3_new ${man3} ${man})
		ENDIF(NOT man_tmp STREQUAL "pcrecpp.3")
	ENDFOREACH(man ${man3})
	SET(man3 ${man3_new})
ENDIF(PCRE_BUILD_PCRECPP)

INSTALL(FILES ${man1} DESTINATION man/man1)
INSTALL(FILES ${man3} DESTINATION man/man3)
INSTALL(FILES ${html} DESTINATION share/doc/pcre/html)

# end CMakeLists.txt