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
94 include/apr_file_info.h
99 include/apr_global_mutex.h
101 include/apr_inherit.h
104 include/apr_network_io.h
107 include/apr_portable.h
108 include/apr_proc_mutex.h
113 include/apr_skiplist.h
114 include/apr_strings.h
115 include/apr_support.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
123 include/apr_version.h
126 SET(APR_PUBLIC_HEADERS_GENERATED
127 ${PROJECT_BINARY_DIR}/apr.h
131 atomic/win32/apr_atomic.c
133 encoding/apr_escape.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
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
149 file_io/win32/readwrite.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
158 misc/unix/otherchild.c
162 misc/win32/internal.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
182 random/unix/apr_random.c
184 random/unix/sha2_glue.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
193 tables/apr_skiplist.c
195 threadproc/win32/proc.c
196 threadproc/win32/signals.c
197 threadproc/win32/thread.c
198 threadproc/win32/threadpriv.c
201 user/win32/groupinfo.c
202 user/win32/userinfo.c
221 test/testglobalmutex.c
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)
265 ADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
266 SET(install_targets ${install_targets} apr-1)
267 TARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS})
268 SET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT")
269 ADD_DEPENDENCIES(apr-1 test_char_header)
271 # libaprapp-1 and aprapp-1 are static
272 ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
273 SET(install_targets ${install_targets} libaprapp-1)
274 SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT")
276 ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
277 SET(install_targets ${install_targets} aprapp-1)
278 SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT")
280 IF(APR_BUILD_TESTAPR)
282 # Create a "check" target that displays test program output to the console.
283 ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
285 # copy data files to build directory so that we can run programs from there
286 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory
287 ${PROJECT_BINARY_DIR}/data)
288 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different
289 ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt
290 ${PROJECT_BINARY_DIR}/data/file_datafile.txt)
291 EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different
292 ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt
293 ${PROJECT_BINARY_DIR}/data/mmap_datafile.txt)
297 SET(whichaprapp aprapp-1)
298 SET(apiflag -DAPR_DECLARE_STATIC)
300 SET(whichapr libapr-1)
301 SET(whichaprapp libaprapp-1)
305 ADD_EXECUTABLE(testapp test/testapp.c)
306 TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp} ${APR_SYSTEM_LIBS})
307 SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup)
309 SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag})
311 ADD_TEST(NAME testapp COMMAND testapp)
313 ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
314 TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS})
316 SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag})
318 ADD_TEST(NAME testall COMMAND testall)
320 ADD_LIBRARY(mod_test MODULE test/mod_test.c)
321 TARGET_LINK_LIBRARIES(mod_test ${whichapr} ${APR_SYSTEM_LIBS})
322 SET_PROPERTY(TARGET mod_test APPEND PROPERTY LINK_FLAGS /export:print_hello)
323 # nasty work-around for difficulties adding more than one additional flag
324 # (they get joined in a bad way behind the scenes)
325 GET_PROPERTY(link_flags TARGET mod_test PROPERTY LINK_FLAGS)
326 SET(link_flags "${link_flags} /export:count_reps")
327 SET_TARGET_PROPERTIES(mod_test PROPERTIES LINK_FLAGS ${link_flags})
329 SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag})
332 # Build all the single-source executable files with no special build
334 SET(single_source_programs
339 test/testmutexscope.c
340 test/globalmutexchild.c
345 test/testshmproducer.c
346 test/testshmconsumer.c
348 test/internal/testucs.c
351 FOREACH(sourcefile ${single_source_programs})
352 STRING(REGEX REPLACE ".*/([^\\]+)\\.c" "\\1" proggie ${sourcefile})
353 ADD_EXECUTABLE(${proggie} ${sourcefile})
354 TARGET_LINK_LIBRARIES(${proggie} ${whichapr} ${APR_SYSTEM_LIBS})
356 SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag})
360 # Add tests for programs that run by themselves with no arguments.
366 FOREACH(simple ${simple_tests})
367 ADD_TEST(NAME ${simple} COMMAND ${simple})
370 # testlockperf takes forever on Windows with default counter limit
371 ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000)
373 # sendfile runs multiple times with different parameters.
374 FOREACH(sendfile_mode blocking nonblocking timeout)
375 ADD_TEST(NAME sendfile-${sendfile_mode} COMMAND sendfile client ${sendfile_mode} startserver)
378 # No test is added for echod+sockperf. Those will have to be run manually.
380 ENDIF (APR_BUILD_TESTAPR)
384 INSTALL(TARGETS ${install_targets}
385 RUNTIME DESTINATION bin
386 LIBRARY DESTINATION lib
387 ARCHIVE DESTINATION lib
391 INSTALL(FILES ${install_bin_pdb}
393 CONFIGURATIONS RelWithDebInfo Debug)
396 INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include)
397 IF(APR_INSTALL_PRIVATE_H)
398 # Kludges for unexpected dependencies of httpd 2.x, not installed by default
399 SET(APR_PRIVATE_H_FOR_HTTPD
400 include/arch/win32/apr_arch_file_io.h
401 include/arch/win32/apr_arch_misc.h
402 include/arch/win32/apr_arch_utf8.h
403 include/arch/win32/apr_private.h
405 INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32)
406 INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch)
409 STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
412 MESSAGE(STATUS "APR configuration summary:")
415 MESSAGE(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}")
416 MESSAGE(STATUS " Install .pdb (if available)...... : ${INSTALL_PDB}")
417 MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
418 MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}")
419 MESSAGE(STATUS " IPv6 ............................ : ${APR_HAVE_IPV6}")
420 MESSAGE(STATUS " Minimum Windows version ......... : ${MIN_WINDOWS_VER}")
421 MESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}")
423 MESSAGE(STATUS " (testing static libraries)")
425 MESSAGE(STATUS " (testing dynamic libraries)")
427 MESSAGE(STATUS " Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}")