]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/apr/CMakeLists.txt
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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_dso.h
91   include/apr_env.h
92   include/apr_errno.h
93   include/apr_escape.h
94   include/apr_file_info.h
95   include/apr_file_io.h
96   include/apr_fnmatch.h
97   include/apr_general.h
98   include/apr_getopt.h
99   include/apr_global_mutex.h
100   include/apr_hash.h
101   include/apr_inherit.h
102   include/apr_lib.h
103   include/apr_mmap.h
104   include/apr_network_io.h
105   include/apr_poll.h
106   include/apr_pools.h
107   include/apr_portable.h
108   include/apr_proc_mutex.h
109   include/apr_random.h
110   include/apr_ring.h
111   include/apr_shm.h
112   include/apr_signal.h
113   include/apr_skiplist.h
114   include/apr_strings.h
115   include/apr_support.h
116   include/apr_tables.h
117   include/apr_thread_cond.h
118   include/apr_thread_mutex.h
119   include/apr_thread_proc.h
120   include/apr_thread_rwlock.h
121   include/apr_time.h
122   include/apr_user.h
123   include/apr_version.h
124   include/apr_want.h
125 )
126 SET(APR_PUBLIC_HEADERS_GENERATED
127   ${PROJECT_BINARY_DIR}/apr.h
128 )
129
130 SET(APR_SOURCES
131   atomic/win32/apr_atomic.c
132   dso/win32/dso.c
133   encoding/apr_escape.c
134   file_io/unix/copy.c
135   file_io/unix/fileacc.c
136   file_io/unix/filepath_util.c
137   file_io/unix/fullrw.c
138   file_io/unix/mktemp.c
139   file_io/unix/tempdir.c
140   file_io/win32/buffer.c
141   file_io/win32/dir.c
142   file_io/win32/filedup.c
143   file_io/win32/filepath.c
144   file_io/win32/filestat.c
145   file_io/win32/filesys.c
146   file_io/win32/flock.c
147   file_io/win32/open.c
148   file_io/win32/pipe.c
149   file_io/win32/readwrite.c
150   file_io/win32/seek.c
151   locks/win32/proc_mutex.c
152   locks/win32/thread_cond.c
153   locks/win32/thread_mutex.c
154   locks/win32/thread_rwlock.c
155   memory/unix/apr_pools.c
156   misc/unix/errorcodes.c
157   misc/unix/getopt.c
158   misc/unix/otherchild.c
159   misc/unix/version.c
160   misc/win32/charset.c
161   misc/win32/env.c
162   misc/win32/internal.c
163   misc/win32/misc.c
164   misc/win32/rand.c
165   misc/win32/start.c
166   misc/win32/utf8.c
167   mmap/unix/common.c
168   mmap/win32/mmap.c
169   network_io/unix/inet_ntop.c
170   network_io/unix/inet_pton.c
171   network_io/unix/multicast.c
172   network_io/unix/sockaddr.c
173   network_io/unix/socket_util.c
174   network_io/win32/sendrecv.c
175   network_io/win32/sockets.c
176   network_io/win32/sockopt.c
177   passwd/apr_getpass.c
178   poll/unix/poll.c
179   poll/unix/pollcb.c
180   poll/unix/pollset.c
181   poll/unix/select.c
182   random/unix/apr_random.c
183   random/unix/sha2.c
184   random/unix/sha2_glue.c
185   shmem/win32/shm.c
186   strings/apr_cpystrn.c
187   strings/apr_fnmatch.c
188   strings/apr_snprintf.c
189   strings/apr_strings.c
190   strings/apr_strnatcmp.c
191   strings/apr_strtok.c
192   tables/apr_hash.c
193   tables/apr_skiplist.c
194   tables/apr_tables.c
195   threadproc/win32/proc.c
196   threadproc/win32/signals.c
197   threadproc/win32/thread.c
198   threadproc/win32/threadpriv.c
199   time/win32/time.c
200   time/win32/timestr.c
201   user/win32/groupinfo.c
202   user/win32/userinfo.c
203 )
204
205 SET(APR_TEST_SOURCES
206   test/abts.c
207   test/testargs.c
208   test/testatomic.c
209   test/testcond.c
210   test/testdir.c
211   test/testdso.c
212   test/testdup.c
213   test/testenv.c
214   test/testescape.c
215   test/testfile.c
216   test/testfilecopy.c
217   test/testfileinfo.c
218   test/testflock.c
219   test/testfmt.c
220   test/testfnmatch.c
221   test/testglobalmutex.c
222   test/testhash.c
223   test/testipsub.c
224   test/testlfs.c
225   test/testlock.c
226   test/testmmap.c
227   test/testnames.c
228   test/testoc.c
229   test/testpath.c
230   test/testpipe.c
231   test/testpoll.c
232   test/testpools.c
233   test/testproc.c
234   test/testprocmutex.c
235   test/testrand.c
236   test/testshm.c
237   test/testsleep.c
238   test/testsock.c
239   test/testsockets.c
240   test/testsockopt.c
241   test/teststr.c
242   test/teststrnatcmp.c
243   test/testtable.c
244   test/testtemp.c
245   test/testthread.c
246   test/testtime.c
247   test/testud.c
248   test/testuser.c
249   test/testutil.c
250   test/testvsn.c
251 )
252
253 SET(install_targets)
254 SET(install_bin_pdb)
255 SET(install_lib_pdb)
256
257 # libapr-1 is shared, apr-1 is static
258 ADD_LIBRARY(libapr-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc)
259 SET(install_targets ${install_targets} libapr-1)
260 SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libapr-1.pdb)
261 TARGET_LINK_LIBRARIES(libapr-1 ${APR_SYSTEM_LIBS})
262 SET_TARGET_PROPERTIES(libapr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_EXPORT;WINNT")
263 ADD_DEPENDENCIES(libapr-1 test_char_header)
264
265 ADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
266 SET(install_targets ${install_targets} apr-1)
267 SET(install_lib_pdb ${install_lib_pdb} ${PROJECT_BINARY_DIR}/apr-1.pdb)
268 TARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS})
269 SET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT")
270 ADD_DEPENDENCIES(apr-1 test_char_header)
271
272 # libaprapp-1 and aprapp-1 are static
273 ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
274 SET(install_targets ${install_targets} libaprapp-1)
275 SET(install_lib_pdb ${install_lib_pdb} ${PROJECT_BINARY_DIR}/libaprapp-1.pdb)
276 SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT")
277
278 ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
279 SET(install_targets ${install_targets} aprapp-1)
280 SET(install_lib_pdb ${install_lib_pdb} ${PROJECT_BINARY_DIR}/aprapp-1.pdb)
281 SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT")
282
283 IF(APR_BUILD_TESTAPR)
284   ENABLE_TESTING()
285   # Create a "check" target that displays test program output to the console.
286   ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
287
288   # copy data files to build directory so that we can run programs from there
289   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory 
290                   ${PROJECT_BINARY_DIR}/data)
291   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different 
292                   ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt
293                   ${PROJECT_BINARY_DIR}/data/file_datafile.txt)
294   EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different
295                   ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt
296                   ${PROJECT_BINARY_DIR}/data/mmap_datafile.txt)
297
298   IF(TEST_STATIC_LIBS)
299     SET(whichapr    apr-1)
300     SET(whichaprapp aprapp-1)
301     SET(apiflag     -DAPR_DECLARE_STATIC)
302   ELSE()
303     SET(whichapr    libapr-1)
304     SET(whichaprapp libaprapp-1)
305     SET(apiflag)
306   ENDIF()
307
308   ADD_EXECUTABLE(testapp test/testapp.c)
309   TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp} ${APR_SYSTEM_LIBS})
310   SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup)
311   IF(apiflag)
312     SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag})
313   ENDIF()
314   ADD_TEST(NAME testapp COMMAND testapp)
315
316   ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
317   TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS})
318   IF(apiflag)
319     SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag})
320   ENDIF()
321   ADD_TEST(NAME testall COMMAND testall)
322
323   ADD_LIBRARY(mod_test MODULE test/mod_test.c)
324   TARGET_LINK_LIBRARIES(mod_test ${whichapr} ${APR_SYSTEM_LIBS})
325   SET_PROPERTY(TARGET mod_test APPEND PROPERTY LINK_FLAGS /export:print_hello)
326   # nasty work-around for difficulties adding more than one additional flag
327   # (they get joined in a bad way behind the scenes)
328   GET_PROPERTY(link_flags TARGET mod_test PROPERTY LINK_FLAGS)
329   SET(link_flags "${link_flags} /export:count_reps")
330   SET_TARGET_PROPERTIES(mod_test PROPERTIES LINK_FLAGS ${link_flags})
331   IF(apiflag)
332     SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag})
333   ENDIF()
334
335   # Build all the single-source executable files with no special build
336   # requirements.
337   SET(single_source_programs
338     test/echod.c
339     test/sendfile.c
340     test/sockperf.c
341     test/testlockperf.c
342     test/testmutexscope.c
343     test/globalmutexchild.c
344     test/occhild.c
345     test/proc_child.c
346     test/readchild.c
347     test/sockchild.c
348     test/testshmproducer.c
349     test/testshmconsumer.c
350     test/tryread.c
351     test/internal/testucs.c
352   )
353
354   FOREACH(sourcefile ${single_source_programs})
355     STRING(REGEX REPLACE ".*/([^\\]+)\\.c" "\\1" proggie ${sourcefile})
356     ADD_EXECUTABLE(${proggie} ${sourcefile})
357     TARGET_LINK_LIBRARIES(${proggie} ${whichapr} ${APR_SYSTEM_LIBS})
358     IF(apiflag)
359       SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag})
360     ENDIF()
361   ENDFOREACH()
362
363   # Add tests for programs that run by themselves with no arguments.
364   SET(simple_tests
365     testmutexscope
366     testucs
367   )
368
369   FOREACH(simple ${simple_tests})
370     ADD_TEST(NAME ${simple} COMMAND ${simple})
371   ENDFOREACH()
372
373   # testlockperf takes forever on Windows with default counter limit
374   ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000)
375
376   # sendfile runs multiple times with different parameters.
377   FOREACH(sendfile_mode blocking nonblocking timeout)
378     ADD_TEST(NAME sendfile-${sendfile_mode} COMMAND sendfile client ${sendfile_mode} startserver)
379   ENDFOREACH()
380
381   # No test is added for echod+sockperf.  Those will have to be run manually.
382
383 ENDIF (APR_BUILD_TESTAPR)
384
385 # Installation
386
387 INSTALL(TARGETS ${install_targets}
388         RUNTIME DESTINATION bin
389         LIBRARY DESTINATION lib
390         ARCHIVE DESTINATION lib
391        )
392
393 IF(INSTALL_PDB)
394   INSTALL(FILES ${install_bin_pdb}
395           DESTINATION bin
396           CONFIGURATIONS RelWithDebInfo Debug)
397
398   INSTALL(FILES ${install_lib_pdb}
399           DESTINATION lib
400           CONFIGURATIONS RelWithDebInfo Debug)
401 ENDIF()
402
403 INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include)
404 IF(APR_INSTALL_PRIVATE_H)
405   # Kludges for unexpected dependencies of httpd 2.x, not installed by default
406   SET(APR_PRIVATE_H_FOR_HTTPD
407     include/arch/win32/apr_arch_file_io.h
408     include/arch/win32/apr_arch_misc.h
409     include/arch/win32/apr_arch_utf8.h
410     include/arch/win32/apr_private.h
411     )
412   INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32)
413   INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch)
414 ENDIF()
415
416 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
417 MESSAGE(STATUS "")
418 MESSAGE(STATUS "")
419 MESSAGE(STATUS "APR configuration summary:")
420 MESSAGE(STATUS "")
421
422 MESSAGE(STATUS "  Build type ...................... : ${CMAKE_BUILD_TYPE}")
423 MESSAGE(STATUS "  Install .pdb (if available)...... : ${INSTALL_PDB}")
424 MESSAGE(STATUS "  Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
425 MESSAGE(STATUS "  C compiler ...................... : ${CMAKE_C_COMPILER}")
426 MESSAGE(STATUS "  IPv6 ............................ : ${APR_HAVE_IPV6}")
427 MESSAGE(STATUS "  Minimum Windows version ......... : ${MIN_WINDOWS_VER}")
428 MESSAGE(STATUS "  Build test suite ................ : ${APR_BUILD_TESTAPR}")
429 IF(TEST_STATIC_LIBS)
430 MESSAGE(STATUS "    (testing static libraries)")
431 ELSE()
432 MESSAGE(STATUS "    (testing dynamic libraries)")
433 ENDIF()
434 MESSAGE(STATUS "  Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}")