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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Read README.cmake before using this.
20 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
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")
30 # create 1-or-0 representation of feature tests for apr.h
32 SET(apr_have_ipv6_10 0)
35 SET(apr_have_ipv6_10 1)
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")
45 SET(win32_winnt_str ${MIN_WINDOWS_VER})
48 CONFIGURE_FILE(include/apr.hwc
49 ${PROJECT_BINARY_DIR}/apr.h)
51 ADD_EXECUTABLE(gen_test_char tools/gen_test_char.c)
52 GET_TARGET_PROPERTY(GEN_TEST_CHAR_EXE gen_test_char LOCATION)
54 COMMENT "Generating character tables, apr_escape_test_char.h, for current locale"
56 COMMAND ${GEN_TEST_CHAR_EXE} > ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
57 OUTPUT ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
61 DEPENDS ${PROJECT_BINARY_DIR}/apr_escape_test_char.h
64 # Generated .h files are stored in PROJECT_BINARY_DIR, not the
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
71 SET(APR_INCLUDE_DIRECTORIES
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
85 INCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES})
87 SET(APR_PUBLIC_HEADERS_STATIC
88 include/apr_allocator.h
95 include/apr_file_info.h
100 include/apr_global_mutex.h
102 include/apr_inherit.h
105 include/apr_network_io.h
106 include/apr_perms_set.h
109 include/apr_portable.h
110 include/apr_proc_mutex.h
115 include/apr_skiplist.h
116 include/apr_strings.h
117 include/apr_support.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
125 include/apr_version.h
128 SET(APR_PUBLIC_HEADERS_GENERATED
129 ${PROJECT_BINARY_DIR}/apr.h
133 atomic/win32/apr_atomic.c
135 encoding/apr_escape.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
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
151 file_io/win32/readwrite.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
160 misc/unix/otherchild.c
164 misc/win32/internal.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
185 random/unix/apr_random.c
187 random/unix/sha2_glue.c
189 strings/apr_cpystrn.c
191 strings/apr_fnmatch.c
192 strings/apr_snprintf.c
193 strings/apr_strings.c
194 strings/apr_strnatcmp.c
197 tables/apr_skiplist.c
199 threadproc/win32/proc.c
200 threadproc/win32/signals.c
201 threadproc/win32/thread.c
202 threadproc/win32/threadpriv.c
205 user/win32/groupinfo.c
206 user/win32/userinfo.c
225 test/testglobalmutex.c
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)
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)
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")
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")
284 IF(APR_BUILD_TESTAPR)
286 # Create a "check" target that displays test program output to the console.
287 ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
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)
301 SET(whichaprapp aprapp-1)
302 SET(apiflag -DAPR_DECLARE_STATIC)
304 SET(whichapr libapr-1)
305 SET(whichaprapp libaprapp-1)
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)
313 SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag})
315 ADD_TEST(NAME testapp COMMAND testapp)
317 ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
318 TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS})
320 SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag})
322 ADD_TEST(NAME testall COMMAND testall)
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})
333 SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag})
336 # Build all the single-source executable files with no special build
338 SET(single_source_programs
343 test/testmutexscope.c
344 test/globalmutexchild.c
349 test/testshmproducer.c
350 test/testshmconsumer.c
352 test/internal/testucs.c
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})
360 SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag})
364 # Add tests for programs that run by themselves with no arguments.
370 FOREACH(simple ${simple_tests})
371 ADD_TEST(NAME ${simple} COMMAND ${simple})
374 # testlockperf takes forever on Windows with default counter limit
375 ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000)
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)
382 # No test is added for echod+sockperf. Those will have to be run manually.
384 ENDIF (APR_BUILD_TESTAPR)
388 INSTALL(TARGETS ${install_targets}
389 RUNTIME DESTINATION bin
390 LIBRARY DESTINATION lib
391 ARCHIVE DESTINATION lib
395 INSTALL(FILES ${install_bin_pdb}
397 CONFIGURATIONS RelWithDebInfo Debug)
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
409 INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32)
410 INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch)
413 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
416 MESSAGE(STATUS "APR configuration summary:")
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}")
427 MESSAGE(STATUS " (testing static libraries)")
429 MESSAGE(STATUS " (testing dynamic libraries)")
431 MESSAGE(STATUS " Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}")