]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/apr/CMakeLists.txt
ident(1): Normalizing date format
[FreeBSD/FreeBSD.git] / contrib / apr / CMakeLists.txt
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Read README.cmake before using this.
17
18 PROJECT(APR C)
19
20 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
21
22 OPTION(APR_INSTALL_PRIVATE_H  "Install selected private .h files (for httpd)"  OFF)
23 OPTION(APR_HAVE_IPV6        "IPv6 support"                 ON)
24 OPTION(INSTALL_PDB          "Install .pdb files (if generated)"  ON)
25 OPTION(APR_BUILD_TESTAPR    "Build the test suite"         OFF)
26 OPTION(TEST_STATIC_LIBS     "Test programs use APR static libraries instead of shared libraries?" OFF)
27 SET(MIN_WINDOWS_VER             "Vista" 
28     CACHE STRING "Minimum Windows version")
29
30 # create 1-or-0 representation of feature tests for apr.h
31
32 SET(apr_have_ipv6_10 0)
33
34 IF(APR_HAVE_IPV6)
35   SET(apr_have_ipv6_10 1)
36 ENDIF()
37
38 IF("${MIN_WINDOWS_VER}" STREQUAL "")
39   SET(win32_winnt_str "0x0600")
40 ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Vista")
41   SET(win32_winnt_str "0x0600")
42 ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Windows7")
43   SET(win32_winnt_str "0x0601")
44 ELSE()
45   SET(win32_winnt_str ${MIN_WINDOWS_VER})
46 ENDIF()
47
48 CONFIGURE_FILE(include/apr.hwc
49                ${PROJECT_BINARY_DIR}/apr.h)
50
51 ADD_EXECUTABLE(gen_test_char tools/gen_test_char.c)
52 GET_TARGET_PROPERTY(GEN_TEST_CHAR_EXE gen_test_char LOCATION)
53 ADD_CUSTOM_COMMAND(
54   COMMENT "Generating character tables, apr_escape_test_char.h, for current locale"
55   DEPENDS gen_test_char
56   COMMAND ${GEN_TEST_CHAR_EXE} > ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
57   OUTPUT ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
58 )
59 ADD_CUSTOM_TARGET(
60   test_char_header ALL
61   DEPENDS ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
62 )
63
64 # Generated .h files are stored in PROJECT_BINARY_DIR, not the
65 # source tree.
66 #
67 # BROKEN: not searching PROJECT_BINARY_DIR first, so you have to
68 #         manually delete apr.h in PROJECT_SOURCE_DIR/include if
69 #         you've generated apr.h before using a different build
70
71 SET(APR_INCLUDE_DIRECTORIES
72   ${PROJECT_BINARY_DIR}
73   ${CMAKE_CURRENT_SOURCE_DIR}/include
74   ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/win32
75   ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/unix
76   ${CMAKE_CURRENT_SOURCE_DIR}/include/private
77 )
78
79 SET(APR_SYSTEM_LIBS
80   ws2_32
81   mswsock
82   rpcrt4
83 )
84
85 INCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES})
86
87 SET(APR_PUBLIC_HEADERS_STATIC
88   include/apr_allocator.h
89   include/apr_atomic.h
90   include/apr_cstr.h
91   include/apr_dso.h
92   include/apr_env.h
93   include/apr_errno.h
94   include/apr_escape.h
95   include/apr_file_info.h
96   include/apr_file_io.h
97   include/apr_fnmatch.h
98   include/apr_general.h
99   include/apr_getopt.h
100   include/apr_global_mutex.h
101   include/apr_hash.h
102   include/apr_inherit.h
103   include/apr_lib.h
104   include/apr_mmap.h
105   include/apr_network_io.h
106   include/apr_perms_set.h
107   include/apr_poll.h
108   include/apr_pools.h
109   include/apr_portable.h
110   include/apr_proc_mutex.h
111   include/apr_random.h
112   include/apr_ring.h
113   include/apr_shm.h
114   include/apr_signal.h
115   include/apr_skiplist.h
116   include/apr_strings.h
117   include/apr_support.h
118   include/apr_tables.h
119   include/apr_thread_cond.h
120   include/apr_thread_mutex.h
121   include/apr_thread_proc.h
122   include/apr_thread_rwlock.h
123   include/apr_time.h
124   include/apr_user.h
125   include/apr_version.h
126   include/apr_want.h
127 )
128 SET(APR_PUBLIC_HEADERS_GENERATED
129   ${PROJECT_BINARY_DIR}/apr.h
130 )
131
132 SET(APR_SOURCES
133   atomic/win32/apr_atomic.c
134   dso/win32/dso.c
135   encoding/apr_escape.c
136   file_io/unix/copy.c
137   file_io/unix/fileacc.c
138   file_io/unix/filepath_util.c
139   file_io/unix/fullrw.c
140   file_io/unix/mktemp.c
141   file_io/unix/tempdir.c
142   file_io/win32/buffer.c
143   file_io/win32/dir.c
144   file_io/win32/filedup.c
145   file_io/win32/filepath.c
146   file_io/win32/filestat.c
147   file_io/win32/filesys.c
148   file_io/win32/flock.c
149   file_io/win32/open.c
150   file_io/win32/pipe.c
151   file_io/win32/readwrite.c
152   file_io/win32/seek.c
153   locks/win32/proc_mutex.c
154   locks/win32/thread_cond.c
155   locks/win32/thread_mutex.c
156   locks/win32/thread_rwlock.c
157   memory/unix/apr_pools.c
158   misc/unix/errorcodes.c
159   misc/unix/getopt.c
160   misc/unix/otherchild.c
161   misc/unix/version.c
162   misc/win32/charset.c
163   misc/win32/env.c
164   misc/win32/internal.c
165   misc/win32/misc.c
166   misc/win32/rand.c
167   misc/win32/start.c
168   misc/win32/utf8.c
169   mmap/unix/common.c
170   mmap/win32/mmap.c
171   network_io/unix/inet_ntop.c
172   network_io/unix/inet_pton.c
173   network_io/unix/multicast.c
174   network_io/unix/sockaddr.c
175   network_io/unix/socket_util.c
176   network_io/win32/sendrecv.c
177   network_io/win32/sockets.c
178   network_io/win32/sockopt.c
179   passwd/apr_getpass.c
180   poll/unix/poll.c
181   poll/unix/pollcb.c
182   poll/unix/pollset.c
183   poll/unix/select.c
184   poll/unix/wakeup.c
185   random/unix/apr_random.c
186   random/unix/sha2.c
187   random/unix/sha2_glue.c
188   shmem/win32/shm.c
189   strings/apr_cpystrn.c
190   strings/apr_cstr.c
191   strings/apr_fnmatch.c
192   strings/apr_snprintf.c
193   strings/apr_strings.c
194   strings/apr_strnatcmp.c
195   strings/apr_strtok.c
196   tables/apr_hash.c
197   tables/apr_skiplist.c
198   tables/apr_tables.c
199   threadproc/win32/proc.c
200   threadproc/win32/signals.c
201   threadproc/win32/thread.c
202   threadproc/win32/threadpriv.c
203   time/win32/time.c
204   time/win32/timestr.c
205   user/win32/groupinfo.c
206   user/win32/userinfo.c
207 )
208
209 SET(APR_TEST_SOURCES
210   test/abts.c
211   test/testargs.c
212   test/testatomic.c
213   test/testcond.c
214   test/testdir.c
215   test/testdso.c
216   test/testdup.c
217   test/testenv.c
218   test/testescape.c
219   test/testfile.c
220   test/testfilecopy.c
221   test/testfileinfo.c
222   test/testflock.c
223   test/testfmt.c
224   test/testfnmatch.c
225   test/testglobalmutex.c
226   test/testhash.c
227   test/testipsub.c
228   test/testlfs.c
229   test/testlock.c
230   test/testmmap.c
231   test/testnames.c
232   test/testoc.c
233   test/testpath.c
234   test/testpipe.c
235   test/testpoll.c
236   test/testpools.c
237   test/testproc.c
238   test/testprocmutex.c
239   test/testrand.c
240   test/testshm.c
241   test/testskiplist.c
242   test/testsleep.c
243   test/testsock.c
244   test/testsockets.c
245   test/testsockopt.c
246   test/teststr.c
247   test/teststrnatcmp.c
248   test/testtable.c
249   test/testtemp.c
250   test/testthread.c
251   test/testtime.c
252   test/testud.c
253   test/testuser.c
254   test/testutil.c
255   test/testvsn.c
256 )
257
258 SET(install_targets)
259 SET(install_bin_pdb)
260
261 # libapr-1 is shared, apr-1 is static
262 ADD_LIBRARY(libapr-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc)
263 SET(install_targets ${install_targets} libapr-1)
264 SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libapr-1.pdb)
265 TARGET_LINK_LIBRARIES(libapr-1 ${APR_SYSTEM_LIBS})
266 SET_TARGET_PROPERTIES(libapr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_EXPORT;WINNT")
267 ADD_DEPENDENCIES(libapr-1 test_char_header)
268
269 ADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
270 SET(install_targets ${install_targets} apr-1)
271 TARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS})
272 SET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT")
273 ADD_DEPENDENCIES(apr-1 test_char_header)
274
275 # libaprapp-1 and aprapp-1 are static
276 ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
277 SET(install_targets ${install_targets} libaprapp-1)
278 SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT")
279
280 ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
281 SET(install_targets ${install_targets} aprapp-1)
282 SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT")
283
284 IF(APR_BUILD_TESTAPR)
285   ENABLE_TESTING()
286   # Create a "check" target that displays test program output to the console.
287   ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
288
289   # copy data files to build directory so that we can run programs from there
290   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory 
291                   ${PROJECT_BINARY_DIR}/data)
292   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different 
293                   ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt
294                   ${PROJECT_BINARY_DIR}/data/file_datafile.txt)
295   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different
296                   ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt
297                   ${PROJECT_BINARY_DIR}/data/mmap_datafile.txt)
298
299   IF(TEST_STATIC_LIBS)
300     SET(whichapr    apr-1)
301     SET(whichaprapp aprapp-1)
302     SET(apiflag     -DAPR_DECLARE_STATIC)
303   ELSE()
304     SET(whichapr    libapr-1)
305     SET(whichaprapp libaprapp-1)
306     SET(apiflag)
307   ENDIF()
308
309   ADD_EXECUTABLE(testapp test/testapp.c)
310   TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp} ${APR_SYSTEM_LIBS})
311   SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup)
312   IF(apiflag)
313     SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag})
314   ENDIF()
315   ADD_TEST(NAME testapp COMMAND testapp)
316
317   ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
318   TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS})
319   IF(apiflag)
320     SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag})
321   ENDIF()
322   ADD_TEST(NAME testall COMMAND testall)
323
324   ADD_LIBRARY(mod_test MODULE test/mod_test.c)
325   TARGET_LINK_LIBRARIES(mod_test ${whichapr} ${APR_SYSTEM_LIBS})
326   SET_PROPERTY(TARGET mod_test APPEND PROPERTY LINK_FLAGS /export:print_hello)
327   # nasty work-around for difficulties adding more than one additional flag
328   # (they get joined in a bad way behind the scenes)
329   GET_PROPERTY(link_flags TARGET mod_test PROPERTY LINK_FLAGS)
330   SET(link_flags "${link_flags} /export:count_reps")
331   SET_TARGET_PROPERTIES(mod_test PROPERTIES LINK_FLAGS ${link_flags})
332   IF(apiflag)
333     SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag})
334   ENDIF()
335
336   # Build all the single-source executable files with no special build
337   # requirements.
338   SET(single_source_programs
339     test/echod.c
340     test/sendfile.c
341     test/sockperf.c
342     test/testlockperf.c
343     test/testmutexscope.c
344     test/globalmutexchild.c
345     test/occhild.c
346     test/proc_child.c
347     test/readchild.c
348     test/sockchild.c
349     test/testshmproducer.c
350     test/testshmconsumer.c
351     test/tryread.c
352     test/internal/testucs.c
353   )
354
355   FOREACH(sourcefile ${single_source_programs})
356     STRING(REGEX REPLACE ".*/([^\\]+)\\.c" "\\1" proggie ${sourcefile})
357     ADD_EXECUTABLE(${proggie} ${sourcefile})
358     TARGET_LINK_LIBRARIES(${proggie} ${whichapr} ${APR_SYSTEM_LIBS})
359     IF(apiflag)
360       SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag})
361     ENDIF()
362   ENDFOREACH()
363
364   # Add tests for programs that run by themselves with no arguments.
365   SET(simple_tests
366     testmutexscope
367     testucs
368   )
369
370   FOREACH(simple ${simple_tests})
371     ADD_TEST(NAME ${simple} COMMAND ${simple})
372   ENDFOREACH()
373
374   # testlockperf takes forever on Windows with default counter limit
375   ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000)
376
377   # sendfile runs multiple times with different parameters.
378   FOREACH(sendfile_mode blocking nonblocking timeout)
379     ADD_TEST(NAME sendfile-${sendfile_mode} COMMAND sendfile client ${sendfile_mode} startserver)
380   ENDFOREACH()
381
382   # No test is added for echod+sockperf.  Those will have to be run manually.
383
384 ENDIF (APR_BUILD_TESTAPR)
385
386 # Installation
387
388 INSTALL(TARGETS ${install_targets}
389         RUNTIME DESTINATION bin
390         LIBRARY DESTINATION lib
391         ARCHIVE DESTINATION lib
392        )
393
394 IF(INSTALL_PDB)
395   INSTALL(FILES ${install_bin_pdb}
396           DESTINATION bin
397           CONFIGURATIONS RelWithDebInfo Debug)
398 ENDIF()
399
400 INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include)
401 IF(APR_INSTALL_PRIVATE_H)
402   # Kludges for unexpected dependencies of httpd 2.x, not installed by default
403   SET(APR_PRIVATE_H_FOR_HTTPD
404     include/arch/win32/apr_arch_file_io.h
405     include/arch/win32/apr_arch_misc.h
406     include/arch/win32/apr_arch_utf8.h
407     include/arch/win32/apr_private.h
408     )
409   INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32)
410   INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch)
411 ENDIF()
412
413 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
414 MESSAGE(STATUS "")
415 MESSAGE(STATUS "")
416 MESSAGE(STATUS "APR configuration summary:")
417 MESSAGE(STATUS "")
418
419 MESSAGE(STATUS "  Build type ...................... : ${CMAKE_BUILD_TYPE}")
420 MESSAGE(STATUS "  Install .pdb (if available)...... : ${INSTALL_PDB}")
421 MESSAGE(STATUS "  Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
422 MESSAGE(STATUS "  C compiler ...................... : ${CMAKE_C_COMPILER}")
423 MESSAGE(STATUS "  IPv6 ............................ : ${APR_HAVE_IPV6}")
424 MESSAGE(STATUS "  Minimum Windows version ......... : ${MIN_WINDOWS_VER}")
425 MESSAGE(STATUS "  Build test suite ................ : ${APR_BUILD_TESTAPR}")
426 IF(TEST_STATIC_LIBS)
427 MESSAGE(STATUS "    (testing static libraries)")
428 ELSE()
429 MESSAGE(STATUS "    (testing dynamic libraries)")
430 ENDIF()
431 MESSAGE(STATUS "  Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}")