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 18PROJECT(APR C) 19 20CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 21 22OPTION(APR_INSTALL_PRIVATE_H "Install selected private .h files (for httpd)" OFF) 23OPTION(APR_HAVE_IPV6 "IPv6 support" ON) 24OPTION(INSTALL_PDB "Install .pdb files (if generated)" ON) 25OPTION(APR_BUILD_TESTAPR "Build the test suite" OFF) 26OPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF) 27SET(MIN_WINDOWS_VER "Vista" 28 CACHE STRING "Minimum Windows version") 29 30# create 1-or-0 representation of feature tests for apr.h 31 32SET(apr_have_ipv6_10 0) 33 34IF(APR_HAVE_IPV6) 35 SET(apr_have_ipv6_10 1) 36ENDIF() 37 38IF("${MIN_WINDOWS_VER}" STREQUAL "") 39 SET(win32_winnt_str "0x0600") 40ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Vista") 41 SET(win32_winnt_str "0x0600") 42ELSEIF(${MIN_WINDOWS_VER} STREQUAL "Windows7") 43 SET(win32_winnt_str "0x0601") 44ELSE() 45 SET(win32_winnt_str ${MIN_WINDOWS_VER}) 46ENDIF() 47 48CONFIGURE_FILE(include/apr.hwc 49 ${PROJECT_BINARY_DIR}/apr.h) 50 51ADD_EXECUTABLE(gen_test_char tools/gen_test_char.c) 52GET_TARGET_PROPERTY(GEN_TEST_CHAR_EXE gen_test_char LOCATION) 53ADD_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) 59ADD_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 71SET(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 79SET(APR_SYSTEM_LIBS 80 ws2_32 81 mswsock 82 rpcrt4 83) 84 85INCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES}) 86 87SET(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) 126SET(APR_PUBLIC_HEADERS_GENERATED 127 ${PROJECT_BINARY_DIR}/apr.h 128) 129 130SET(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 205SET(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/testskiplist.c 238 test/testsleep.c 239 test/testsock.c 240 test/testsockets.c 241 test/testsockopt.c 242 test/teststr.c 243 test/teststrnatcmp.c 244 test/testtable.c 245 test/testtemp.c 246 test/testthread.c 247 test/testtime.c 248 test/testud.c 249 test/testuser.c 250 test/testutil.c 251 test/testvsn.c 252) 253 254SET(install_targets) 255SET(install_bin_pdb) 256 257# libapr-1 is shared, apr-1 is static 258ADD_LIBRARY(libapr-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc) 259SET(install_targets ${install_targets} libapr-1) 260SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libapr-1.pdb) 261TARGET_LINK_LIBRARIES(libapr-1 ${APR_SYSTEM_LIBS}) 262SET_TARGET_PROPERTIES(libapr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_EXPORT;WINNT") 263ADD_DEPENDENCIES(libapr-1 test_char_header) 264 265ADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED}) 266SET(install_targets ${install_targets} apr-1) 267TARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS}) 268SET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT") 269ADD_DEPENDENCIES(apr-1 test_char_header) 270 271# libaprapp-1 and aprapp-1 are static 272ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED}) 273SET(install_targets ${install_targets} libaprapp-1) 274SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT") 275 276ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED}) 277SET(install_targets ${install_targets} aprapp-1) 278SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT") 279 280IF(APR_BUILD_TESTAPR) 281 ENABLE_TESTING() 282 # Create a "check" target that displays test program output to the console. 283 ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose) 284 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) 294 295 IF(TEST_STATIC_LIBS) 296 SET(whichapr apr-1) 297 SET(whichaprapp aprapp-1) 298 SET(apiflag -DAPR_DECLARE_STATIC) 299 ELSE() 300 SET(whichapr libapr-1) 301 SET(whichaprapp libaprapp-1) 302 SET(apiflag) 303 ENDIF() 304 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) 308 IF(apiflag) 309 SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag}) 310 ENDIF() 311 ADD_TEST(NAME testapp COMMAND testapp) 312 313 ADD_EXECUTABLE(testall ${APR_TEST_SOURCES}) 314 TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS}) 315 IF(apiflag) 316 SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag}) 317 ENDIF() 318 ADD_TEST(NAME testall COMMAND testall) 319 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}) 328 IF(apiflag) 329 SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag}) 330 ENDIF() 331 332 # Build all the single-source executable files with no special build 333 # requirements. 334 SET(single_source_programs 335 test/echod.c 336 test/sendfile.c 337 test/sockperf.c 338 test/testlockperf.c 339 test/testmutexscope.c 340 test/globalmutexchild.c 341 test/occhild.c 342 test/proc_child.c 343 test/readchild.c 344 test/sockchild.c 345 test/testshmproducer.c 346 test/testshmconsumer.c 347 test/tryread.c 348 test/internal/testucs.c 349 ) 350 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}) 355 IF(apiflag) 356 SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag}) 357 ENDIF() 358 ENDFOREACH() 359 360 # Add tests for programs that run by themselves with no arguments. 361 SET(simple_tests 362 testmutexscope 363 testucs 364 ) 365 366 FOREACH(simple ${simple_tests}) 367 ADD_TEST(NAME ${simple} COMMAND ${simple}) 368 ENDFOREACH() 369 370 # testlockperf takes forever on Windows with default counter limit 371 ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000) 372 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) 376 ENDFOREACH() 377 378 # No test is added for echod+sockperf. Those will have to be run manually. 379 380ENDIF (APR_BUILD_TESTAPR) 381 382# Installation 383 384INSTALL(TARGETS ${install_targets} 385 RUNTIME DESTINATION bin 386 LIBRARY DESTINATION lib 387 ARCHIVE DESTINATION lib 388 ) 389 390IF(INSTALL_PDB) 391 INSTALL(FILES ${install_bin_pdb} 392 DESTINATION bin 393 CONFIGURATIONS RelWithDebInfo Debug) 394ENDIF() 395 396INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include) 397IF(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 404 ) 405 INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32) 406 INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch) 407ENDIF() 408 409STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) 410MESSAGE(STATUS "") 411MESSAGE(STATUS "") 412MESSAGE(STATUS "APR configuration summary:") 413MESSAGE(STATUS "") 414 415MESSAGE(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}") 416MESSAGE(STATUS " Install .pdb (if available)...... : ${INSTALL_PDB}") 417MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}") 418MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}") 419MESSAGE(STATUS " IPv6 ............................ : ${APR_HAVE_IPV6}") 420MESSAGE(STATUS " Minimum Windows version ......... : ${MIN_WINDOWS_VER}") 421MESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}") 422IF(TEST_STATIC_LIBS) 423MESSAGE(STATUS " (testing static libraries)") 424ELSE() 425MESSAGE(STATUS " (testing dynamic libraries)") 426ENDIF() 427MESSAGE(STATUS " Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}") 428