1266733Speter# Licensed to the Apache Software Foundation (ASF) under one or more 2266733Speter# contributor license agreements. See the NOTICE file distributed with 3266733Speter# this work for additional information regarding copyright ownership. 4266733Speter# The ASF licenses this file to You under the Apache License, Version 2.0 5266733Speter# (the "License"); you may not use this file except in compliance with 6266733Speter# the License. You may obtain a copy of the License at 7266733Speter# 8266733Speter# http://www.apache.org/licenses/LICENSE-2.0 9266733Speter# 10266733Speter# Unless required by applicable law or agreed to in writing, software 11266733Speter# distributed under the License is distributed on an "AS IS" BASIS, 12266733Speter# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13266733Speter# See the License for the specific language governing permissions and 14266733Speter# limitations under the License. 15266733Speter# 16266733Speter# Read README.cmake before using this. 17266733Speter 18266733SpeterPROJECT(APR C) 19266733Speter 20266733SpeterCMAKE_MINIMUM_REQUIRED(VERSION 2.8) 21266733Speter 22266733SpeterOPTION(APR_INSTALL_PRIVATE_H "Install selected private .h files (for httpd)" OFF) 23266733SpeterOPTION(APR_HAVE_IPV6 "IPv6 support" ON) 24266733SpeterOPTION(INSTALL_PDB "Install .pdb files (if generated)" ON) 25266733SpeterOPTION(APR_BUILD_TESTAPR "Build the test suite" OFF) 26266733SpeterOPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF) 27266733SpeterSET(MIN_WINDOWS_VER "Vista" 28266733Speter CACHE STRING "Minimum Windows version") 29266733Speter 30266733Speter# create 1-or-0 representation of feature tests for apr.h 31266733Speter 32266733SpeterSET(apr_have_ipv6_10 0) 33266733Speter 34266733SpeterIF(APR_HAVE_IPV6) 35266733Speter SET(apr_have_ipv6_10 1) 36266733SpeterENDIF() 37266733Speter 38266733SpeterIF("${MIN_WINDOWS_VER}" STREQUAL "") 39266733Speter SET(win32_winnt_str "0x0600") 40266733SpeterELSEIF(${MIN_WINDOWS_VER} STREQUAL "Vista") 41266733Speter SET(win32_winnt_str "0x0600") 42266733SpeterELSEIF(${MIN_WINDOWS_VER} STREQUAL "Windows7") 43266733Speter SET(win32_winnt_str "0x0601") 44266733SpeterELSE() 45266733Speter SET(win32_winnt_str ${MIN_WINDOWS_VER}) 46266733SpeterENDIF() 47266733Speter 48266733SpeterCONFIGURE_FILE(include/apr.hwc 49266733Speter ${PROJECT_BINARY_DIR}/apr.h) 50266733Speter 51266733SpeterADD_EXECUTABLE(gen_test_char tools/gen_test_char.c) 52266733SpeterGET_TARGET_PROPERTY(GEN_TEST_CHAR_EXE gen_test_char LOCATION) 53266733SpeterADD_CUSTOM_COMMAND( 54266733Speter COMMENT "Generating character tables, apr_escape_test_char.h, for current locale" 55266733Speter DEPENDS gen_test_char 56266733Speter COMMAND ${GEN_TEST_CHAR_EXE} > ${PROJECT_BINARY_DIR}/apr_escape_test_char.h 57266733Speter OUTPUT ${PROJECT_BINARY_DIR}/apr_escape_test_char.h 58266733Speter) 59266733SpeterADD_CUSTOM_TARGET( 60266733Speter test_char_header ALL 61266733Speter DEPENDS ${PROJECT_BINARY_DIR}/apr_escape_test_char.h 62266733Speter) 63266733Speter 64266733Speter# Generated .h files are stored in PROJECT_BINARY_DIR, not the 65266733Speter# source tree. 66266733Speter# 67266733Speter# BROKEN: not searching PROJECT_BINARY_DIR first, so you have to 68266733Speter# manually delete apr.h in PROJECT_SOURCE_DIR/include if 69266733Speter# you've generated apr.h before using a different build 70266733Speter 71266733SpeterSET(APR_INCLUDE_DIRECTORIES 72266733Speter ${PROJECT_BINARY_DIR} 73266733Speter ${CMAKE_CURRENT_SOURCE_DIR}/include 74266733Speter ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/win32 75266733Speter ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/unix 76266733Speter ${CMAKE_CURRENT_SOURCE_DIR}/include/private 77266733Speter) 78266733Speter 79266733SpeterSET(APR_SYSTEM_LIBS 80266733Speter ws2_32 81266733Speter mswsock 82266733Speter rpcrt4 83266733Speter) 84266733Speter 85266733SpeterINCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES}) 86266733Speter 87266733SpeterSET(APR_PUBLIC_HEADERS_STATIC 88266733Speter include/apr_allocator.h 89266733Speter include/apr_atomic.h 90266733Speter include/apr_dso.h 91266733Speter include/apr_env.h 92266733Speter include/apr_errno.h 93266733Speter include/apr_escape.h 94266733Speter include/apr_file_info.h 95266733Speter include/apr_file_io.h 96266733Speter include/apr_fnmatch.h 97266733Speter include/apr_general.h 98266733Speter include/apr_getopt.h 99266733Speter include/apr_global_mutex.h 100266733Speter include/apr_hash.h 101266733Speter include/apr_inherit.h 102266733Speter include/apr_lib.h 103266733Speter include/apr_mmap.h 104266733Speter include/apr_network_io.h 105266733Speter include/apr_poll.h 106266733Speter include/apr_pools.h 107266733Speter include/apr_portable.h 108266733Speter include/apr_proc_mutex.h 109266733Speter include/apr_random.h 110266733Speter include/apr_ring.h 111266733Speter include/apr_shm.h 112266733Speter include/apr_signal.h 113266733Speter include/apr_skiplist.h 114266733Speter include/apr_strings.h 115266733Speter include/apr_support.h 116266733Speter include/apr_tables.h 117266733Speter include/apr_thread_cond.h 118266733Speter include/apr_thread_mutex.h 119266733Speter include/apr_thread_proc.h 120266733Speter include/apr_thread_rwlock.h 121266733Speter include/apr_time.h 122266733Speter include/apr_user.h 123266733Speter include/apr_version.h 124266733Speter include/apr_want.h 125266733Speter) 126266733SpeterSET(APR_PUBLIC_HEADERS_GENERATED 127266733Speter ${PROJECT_BINARY_DIR}/apr.h 128266733Speter) 129266733Speter 130266733SpeterSET(APR_SOURCES 131266733Speter atomic/win32/apr_atomic.c 132266733Speter dso/win32/dso.c 133266733Speter encoding/apr_escape.c 134266733Speter file_io/unix/copy.c 135266733Speter file_io/unix/fileacc.c 136266733Speter file_io/unix/filepath_util.c 137266733Speter file_io/unix/fullrw.c 138266733Speter file_io/unix/mktemp.c 139266733Speter file_io/unix/tempdir.c 140266733Speter file_io/win32/buffer.c 141266733Speter file_io/win32/dir.c 142266733Speter file_io/win32/filedup.c 143266733Speter file_io/win32/filepath.c 144266733Speter file_io/win32/filestat.c 145266733Speter file_io/win32/filesys.c 146266733Speter file_io/win32/flock.c 147266733Speter file_io/win32/open.c 148266733Speter file_io/win32/pipe.c 149266733Speter file_io/win32/readwrite.c 150266733Speter file_io/win32/seek.c 151266733Speter locks/win32/proc_mutex.c 152266733Speter locks/win32/thread_cond.c 153266733Speter locks/win32/thread_mutex.c 154266733Speter locks/win32/thread_rwlock.c 155266733Speter memory/unix/apr_pools.c 156266733Speter misc/unix/errorcodes.c 157266733Speter misc/unix/getopt.c 158266733Speter misc/unix/otherchild.c 159266733Speter misc/unix/version.c 160266733Speter misc/win32/charset.c 161266733Speter misc/win32/env.c 162266733Speter misc/win32/internal.c 163266733Speter misc/win32/misc.c 164266733Speter misc/win32/rand.c 165266733Speter misc/win32/start.c 166266733Speter misc/win32/utf8.c 167266733Speter mmap/unix/common.c 168266733Speter mmap/win32/mmap.c 169266733Speter network_io/unix/inet_ntop.c 170266733Speter network_io/unix/inet_pton.c 171266733Speter network_io/unix/multicast.c 172266733Speter network_io/unix/sockaddr.c 173266733Speter network_io/unix/socket_util.c 174266733Speter network_io/win32/sendrecv.c 175266733Speter network_io/win32/sockets.c 176266733Speter network_io/win32/sockopt.c 177266733Speter passwd/apr_getpass.c 178266733Speter poll/unix/poll.c 179266733Speter poll/unix/pollcb.c 180266733Speter poll/unix/pollset.c 181266733Speter poll/unix/select.c 182266733Speter random/unix/apr_random.c 183266733Speter random/unix/sha2.c 184266733Speter random/unix/sha2_glue.c 185266733Speter shmem/win32/shm.c 186266733Speter strings/apr_cpystrn.c 187266733Speter strings/apr_fnmatch.c 188266733Speter strings/apr_snprintf.c 189266733Speter strings/apr_strings.c 190266733Speter strings/apr_strnatcmp.c 191266733Speter strings/apr_strtok.c 192266733Speter tables/apr_hash.c 193266733Speter tables/apr_skiplist.c 194266733Speter tables/apr_tables.c 195266733Speter threadproc/win32/proc.c 196266733Speter threadproc/win32/signals.c 197266733Speter threadproc/win32/thread.c 198266733Speter threadproc/win32/threadpriv.c 199266733Speter time/win32/time.c 200266733Speter time/win32/timestr.c 201266733Speter user/win32/groupinfo.c 202266733Speter user/win32/userinfo.c 203266733Speter) 204266733Speter 205266733SpeterSET(APR_TEST_SOURCES 206266733Speter test/abts.c 207266733Speter test/testargs.c 208266733Speter test/testatomic.c 209266733Speter test/testcond.c 210266733Speter test/testdir.c 211266733Speter test/testdso.c 212266733Speter test/testdup.c 213266733Speter test/testenv.c 214266733Speter test/testescape.c 215266733Speter test/testfile.c 216266733Speter test/testfilecopy.c 217266733Speter test/testfileinfo.c 218266733Speter test/testflock.c 219266733Speter test/testfmt.c 220266733Speter test/testfnmatch.c 221266733Speter test/testglobalmutex.c 222266733Speter test/testhash.c 223266733Speter test/testipsub.c 224266733Speter test/testlfs.c 225266733Speter test/testlock.c 226266733Speter test/testmmap.c 227266733Speter test/testnames.c 228266733Speter test/testoc.c 229266733Speter test/testpath.c 230266733Speter test/testpipe.c 231266733Speter test/testpoll.c 232266733Speter test/testpools.c 233266733Speter test/testproc.c 234266733Speter test/testprocmutex.c 235266733Speter test/testrand.c 236266733Speter test/testshm.c 237289166Speter test/testskiplist.c 238266733Speter test/testsleep.c 239266733Speter test/testsock.c 240266733Speter test/testsockets.c 241266733Speter test/testsockopt.c 242266733Speter test/teststr.c 243266733Speter test/teststrnatcmp.c 244266733Speter test/testtable.c 245266733Speter test/testtemp.c 246266733Speter test/testthread.c 247266733Speter test/testtime.c 248266733Speter test/testud.c 249266733Speter test/testuser.c 250266733Speter test/testutil.c 251266733Speter test/testvsn.c 252266733Speter) 253266733Speter 254266733SpeterSET(install_targets) 255266733SpeterSET(install_bin_pdb) 256266733Speter 257266733Speter# libapr-1 is shared, apr-1 is static 258266733SpeterADD_LIBRARY(libapr-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc) 259266733SpeterSET(install_targets ${install_targets} libapr-1) 260266733SpeterSET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libapr-1.pdb) 261266733SpeterTARGET_LINK_LIBRARIES(libapr-1 ${APR_SYSTEM_LIBS}) 262266733SpeterSET_TARGET_PROPERTIES(libapr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_EXPORT;WINNT") 263266733SpeterADD_DEPENDENCIES(libapr-1 test_char_header) 264266733Speter 265266733SpeterADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED}) 266266733SpeterSET(install_targets ${install_targets} apr-1) 267266733SpeterTARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS}) 268266733SpeterSET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT") 269266733SpeterADD_DEPENDENCIES(apr-1 test_char_header) 270266733Speter 271266733Speter# libaprapp-1 and aprapp-1 are static 272266733SpeterADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED}) 273266733SpeterSET(install_targets ${install_targets} libaprapp-1) 274266733SpeterSET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT") 275266733Speter 276266733SpeterADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED}) 277266733SpeterSET(install_targets ${install_targets} aprapp-1) 278266733SpeterSET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT") 279266733Speter 280266733SpeterIF(APR_BUILD_TESTAPR) 281266733Speter ENABLE_TESTING() 282266733Speter # Create a "check" target that displays test program output to the console. 283266733Speter ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose) 284266733Speter 285266733Speter # copy data files to build directory so that we can run programs from there 286266733Speter EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory 287266733Speter ${PROJECT_BINARY_DIR}/data) 288266733Speter EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different 289266733Speter ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt 290266733Speter ${PROJECT_BINARY_DIR}/data/file_datafile.txt) 291266733Speter EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different 292266733Speter ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt 293266733Speter ${PROJECT_BINARY_DIR}/data/mmap_datafile.txt) 294266733Speter 295266733Speter IF(TEST_STATIC_LIBS) 296266733Speter SET(whichapr apr-1) 297266733Speter SET(whichaprapp aprapp-1) 298266733Speter SET(apiflag -DAPR_DECLARE_STATIC) 299266733Speter ELSE() 300266733Speter SET(whichapr libapr-1) 301266733Speter SET(whichaprapp libaprapp-1) 302266733Speter SET(apiflag) 303266733Speter ENDIF() 304266733Speter 305266733Speter ADD_EXECUTABLE(testapp test/testapp.c) 306266733Speter TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp} ${APR_SYSTEM_LIBS}) 307266733Speter SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup) 308266733Speter IF(apiflag) 309266733Speter SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag}) 310266733Speter ENDIF() 311266733Speter ADD_TEST(NAME testapp COMMAND testapp) 312266733Speter 313266733Speter ADD_EXECUTABLE(testall ${APR_TEST_SOURCES}) 314266733Speter TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS}) 315266733Speter IF(apiflag) 316266733Speter SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag}) 317266733Speter ENDIF() 318266733Speter ADD_TEST(NAME testall COMMAND testall) 319266733Speter 320266733Speter ADD_LIBRARY(mod_test MODULE test/mod_test.c) 321266733Speter TARGET_LINK_LIBRARIES(mod_test ${whichapr} ${APR_SYSTEM_LIBS}) 322266733Speter SET_PROPERTY(TARGET mod_test APPEND PROPERTY LINK_FLAGS /export:print_hello) 323266733Speter # nasty work-around for difficulties adding more than one additional flag 324266733Speter # (they get joined in a bad way behind the scenes) 325266733Speter GET_PROPERTY(link_flags TARGET mod_test PROPERTY LINK_FLAGS) 326266733Speter SET(link_flags "${link_flags} /export:count_reps") 327266733Speter SET_TARGET_PROPERTIES(mod_test PROPERTIES LINK_FLAGS ${link_flags}) 328266733Speter IF(apiflag) 329266733Speter SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag}) 330266733Speter ENDIF() 331266733Speter 332266733Speter # Build all the single-source executable files with no special build 333266733Speter # requirements. 334266733Speter SET(single_source_programs 335266733Speter test/echod.c 336266733Speter test/sendfile.c 337266733Speter test/sockperf.c 338266733Speter test/testlockperf.c 339266733Speter test/testmutexscope.c 340266733Speter test/globalmutexchild.c 341266733Speter test/occhild.c 342266733Speter test/proc_child.c 343266733Speter test/readchild.c 344266733Speter test/sockchild.c 345266733Speter test/testshmproducer.c 346266733Speter test/testshmconsumer.c 347266733Speter test/tryread.c 348266733Speter test/internal/testucs.c 349266733Speter ) 350266733Speter 351266733Speter FOREACH(sourcefile ${single_source_programs}) 352266733Speter STRING(REGEX REPLACE ".*/([^\\]+)\\.c" "\\1" proggie ${sourcefile}) 353266733Speter ADD_EXECUTABLE(${proggie} ${sourcefile}) 354266733Speter TARGET_LINK_LIBRARIES(${proggie} ${whichapr} ${APR_SYSTEM_LIBS}) 355266733Speter IF(apiflag) 356266733Speter SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag}) 357266733Speter ENDIF() 358266733Speter ENDFOREACH() 359266733Speter 360266733Speter # Add tests for programs that run by themselves with no arguments. 361266733Speter SET(simple_tests 362266733Speter testmutexscope 363266733Speter testucs 364266733Speter ) 365266733Speter 366266733Speter FOREACH(simple ${simple_tests}) 367266733Speter ADD_TEST(NAME ${simple} COMMAND ${simple}) 368266733Speter ENDFOREACH() 369266733Speter 370266733Speter # testlockperf takes forever on Windows with default counter limit 371266733Speter ADD_TEST(NAME testlockperf COMMAND testlockperf -c 50000) 372266733Speter 373266733Speter # sendfile runs multiple times with different parameters. 374266733Speter FOREACH(sendfile_mode blocking nonblocking timeout) 375266733Speter ADD_TEST(NAME sendfile-${sendfile_mode} COMMAND sendfile client ${sendfile_mode} startserver) 376266733Speter ENDFOREACH() 377266733Speter 378266733Speter # No test is added for echod+sockperf. Those will have to be run manually. 379266733Speter 380266733SpeterENDIF (APR_BUILD_TESTAPR) 381266733Speter 382266733Speter# Installation 383266733Speter 384266733SpeterINSTALL(TARGETS ${install_targets} 385266733Speter RUNTIME DESTINATION bin 386266733Speter LIBRARY DESTINATION lib 387266733Speter ARCHIVE DESTINATION lib 388266733Speter ) 389266733Speter 390266733SpeterIF(INSTALL_PDB) 391266733Speter INSTALL(FILES ${install_bin_pdb} 392266733Speter DESTINATION bin 393266733Speter CONFIGURATIONS RelWithDebInfo Debug) 394266733SpeterENDIF() 395266733Speter 396266733SpeterINSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include) 397266733SpeterIF(APR_INSTALL_PRIVATE_H) 398266733Speter # Kludges for unexpected dependencies of httpd 2.x, not installed by default 399266733Speter SET(APR_PRIVATE_H_FOR_HTTPD 400266733Speter include/arch/win32/apr_arch_file_io.h 401266733Speter include/arch/win32/apr_arch_misc.h 402266733Speter include/arch/win32/apr_arch_utf8.h 403266733Speter include/arch/win32/apr_private.h 404266733Speter ) 405266733Speter INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32) 406266733Speter INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch) 407266733SpeterENDIF() 408266733Speter 409266733SpeterSTRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) 410266733SpeterMESSAGE(STATUS "") 411266733SpeterMESSAGE(STATUS "") 412266733SpeterMESSAGE(STATUS "APR configuration summary:") 413266733SpeterMESSAGE(STATUS "") 414266733Speter 415266733SpeterMESSAGE(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}") 416266733SpeterMESSAGE(STATUS " Install .pdb (if available)...... : ${INSTALL_PDB}") 417266733SpeterMESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}") 418266733SpeterMESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}") 419266733SpeterMESSAGE(STATUS " IPv6 ............................ : ${APR_HAVE_IPV6}") 420266733SpeterMESSAGE(STATUS " Minimum Windows version ......... : ${MIN_WINDOWS_VER}") 421266733SpeterMESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}") 422266733SpeterIF(TEST_STATIC_LIBS) 423266733SpeterMESSAGE(STATUS " (testing static libraries)") 424266733SpeterELSE() 425266733SpeterMESSAGE(STATUS " (testing dynamic libraries)") 426266733SpeterENDIF() 427266733SpeterMESSAGE(STATUS " Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}") 428