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-Util C) 19 20CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 21 22FIND_PACKAGE(OpenSSL) 23 24FIND_PACKAGE(expat) 25 26OPTION(APU_HAVE_CRYPTO "Crypto support" OFF) 27OPTION(APU_HAVE_ODBC "Build ODBC DBD driver" ON) 28OPTION(APR_HAS_LDAP "LDAP support" ON) 29OPTION(INSTALL_PDB "Install .pdb files (if generated)" ON) 30OPTION(APR_BUILD_TESTAPR "Build the test suite" OFF) 31OPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF) 32SET(APR_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE STRING "Directory with APR include files") 33SET(APR_LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/libapr-1.lib" CACHE STRING "APR library to link with") 34 35IF(NOT EXISTS "${APR_INCLUDE_DIR}/apr.h") 36 MESSAGE(FATAL_ERROR "APR include directory ${APR_INCLUDE_DIR} is not correct.") 37ENDIF() 38FOREACH(onelib ${APR_LIBRARIES}) 39 IF(NOT EXISTS ${onelib}) 40 MESSAGE(FATAL_ERROR "APR library ${onelib} was not found.") 41 ENDIF() 42ENDFOREACH() 43 44IF(APU_HAVE_CRYPTO) 45IF(NOT OPENSSL_FOUND) 46 MESSAGE(FATAL_ERROR "OpenSSL is the only supported crypto implementation, and it wasn't found!") 47ENDIF() 48ENDIF() 49 50# create 1-or-0 representation of feature tests for apu.h 51 52SET(apu_have_crypto_10 0) 53SET(apu_have_apr_iconv_10 0) # not yet implemented 54SET(apr_has_ldap_10 0) 55 56IF(APU_HAVE_CRYPTO) 57 SET(apu_have_crypto_10 1) 58ENDIF() 59 60IF(APR_HAS_LDAP) 61 SET(apr_has_ldap_10 1) 62ENDIF() 63 64IF(NOT EXPAT_FOUND) 65 MESSAGE(FATAL_ERROR "Expat is required, and it wasn't found!") 66ENDIF() 67 68SET(XMLLIB_INCLUDE_DIR ${EXPAT_INCLUDE_DIRS}) 69SET(XMLLIB_LIBRARIES ${EXPAT_LIBRARIES}) 70 71SET(LDAP_LIBRARIES) 72IF(APR_HAS_LDAP) 73 SET(LDAP_LIBRARIES wldap32) 74ENDIF() 75 76CONFIGURE_FILE(include/apu.hwc 77 ${PROJECT_BINARY_DIR}/apu.h) 78CONFIGURE_FILE(include/apr_ldap.hwc 79 ${PROJECT_BINARY_DIR}/apr_ldap.h) 80# "COPYONLY" just because anything else isn't implemented ;) 81CONFIGURE_FILE(include/private/apu_config.hw 82 ${PROJECT_BINARY_DIR}/apu_config.h 83 COPYONLY) 84CONFIGURE_FILE(include/private/apu_select_dbm.hw 85 ${PROJECT_BINARY_DIR}/apu_select_dbm.h 86 COPYONLY) 87CONFIGURE_FILE(include/apu_want.hw 88 ${PROJECT_BINARY_DIR}/apu_want.h 89 COPYONLY) 90 91# Generated .h files are stored in PROJECT_BINARY_DIR, not the 92# source tree. 93# 94# BROKEN: not searching PROJECT_BINARY_DIR first, so you have to 95# manually delete apu.h in PROJECT_SOURCE_DIR/include if 96# you've generated apu.h before using a different build 97 98SET(APR_INCLUDE_DIRECTORIES 99 ${PROJECT_BINARY_DIR} 100 ${CMAKE_CURRENT_SOURCE_DIR}/include 101 ${CMAKE_CURRENT_SOURCE_DIR}/include/private 102 ${APR_INCLUDE_DIR} 103) 104 105INCLUDE_DIRECTORIES(${APR_INCLUDE_DIRECTORIES} ${XMLLIB_INCLUDE_DIR}) 106 107SET(APR_PUBLIC_HEADERS_STATIC 108 include/apr_anylock.h 109 include/apr_base64.h 110 include/apr_buckets.h 111 include/apr_crypto.h 112 include/apr_date.h 113 include/apr_dbd.h 114 include/apr_dbm.h 115 include/apr_hooks.h 116 include/apr_ldap_init.h 117 include/apr_ldap_option.h 118 include/apr_ldap_rebind.h 119 include/apr_ldap_url.h 120 include/apr_md4.h 121 include/apr_md5.h 122 include/apr_memcache.h 123 include/apr_optional.h 124 include/apr_optional_hooks.h 125 include/apr_queue.h 126 include/apr_redis.h 127 include/apr_reslist.h 128 include/apr_rmm.h 129 include/apr_sdbm.h 130 include/apr_sha1.h 131 include/apr_siphash.h 132 include/apr_strmatch.h 133 include/apr_thread_pool.h 134 include/apr_uri.h 135 include/apr_uuid.h 136 include/apr_xlate.h 137 include/apr_xml.h 138 include/apu_errno.h 139 include/apu_version.h 140) 141 142# apu_config.h and apu_select_dbm.h are private 143SET(APR_PUBLIC_HEADERS_GENERATED 144 ${PROJECT_BINARY_DIR}/apu.h 145 ${PROJECT_BINARY_DIR}/apr_ldap.h 146 ${PROJECT_BINARY_DIR}/apu_want.h 147) 148 149SET(APR_SOURCES 150 buckets/apr_brigade.c 151 buckets/apr_buckets.c 152 buckets/apr_buckets_alloc.c 153 buckets/apr_buckets_eos.c 154 buckets/apr_buckets_file.c 155 buckets/apr_buckets_flush.c 156 buckets/apr_buckets_heap.c 157 buckets/apr_buckets_mmap.c 158 buckets/apr_buckets_pipe.c 159 buckets/apr_buckets_pool.c 160 buckets/apr_buckets_refcount.c 161 buckets/apr_buckets_simple.c 162 buckets/apr_buckets_socket.c 163 crypto/apr_crypto.c 164 crypto/apr_md4.c 165 crypto/apr_md5.c 166 crypto/apr_passwd.c 167 crypto/apr_sha1.c 168 crypto/apr_siphash.c 169 crypto/crypt_blowfish.c 170 crypto/getuuid.c 171 crypto/uuid.c 172 dbd/apr_dbd.c 173 dbm/apr_dbm.c 174 dbm/apr_dbm_sdbm.c 175 dbm/sdbm/sdbm.c 176 dbm/sdbm/sdbm_hash.c 177 dbm/sdbm/sdbm_lock.c 178 dbm/sdbm/sdbm_pair.c 179 encoding/apr_base64.c 180 hooks/apr_hooks.c 181 memcache/apr_memcache.c 182 misc/apr_date.c 183 misc/apr_queue.c 184 misc/apr_reslist.c 185 misc/apr_rmm.c 186 misc/apr_thread_pool.c 187 misc/apu_dso.c 188 misc/apu_version.c 189 redis/apr_redis.c 190 strmatch/apr_strmatch.c 191 uri/apr_uri.c 192 xlate/xlate.c 193 xml/apr_xml.c 194) 195 196IF(APR_HAS_LDAP) 197 SET(APR_SOURCES ${APR_SOURCES} ldap/apr_ldap_stub.c ldap/apr_ldap_url.c) 198ENDIF() 199 200SET(APR_TEST_SOURCES 201 test/abts.c 202 test/testbuckets.c 203 test/testcrypto.c 204 test/testdate.c 205 test/testdbd.c 206 test/testdbm.c 207 test/testldap.c 208 test/testmd4.c 209 test/testmd5.c 210 test/testmemcache.c 211 test/testpass.c 212 test/testqueue.c 213 test/testredis.c 214 test/testreslist.c 215 test/testrmm.c 216 test/testsiphash.c 217 test/teststrmatch.c 218 test/testuri.c 219 test/testutil.c 220 test/testuuid.c 221 test/testxlate.c 222 test/testxml.c 223) 224 225SET(install_targets) 226SET(install_bin_pdb) 227SET(dbd_drivers) 228 229# Note: The WINNT definition on some targets is used only by libaprutil.rc. 230 231# libaprutil-1 is shared, aprutil-1 is static 232ADD_LIBRARY(libaprutil-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libaprutil.rc) 233SET(install_targets ${install_targets} libaprutil-1) 234SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libaprutil-1.pdb) 235TARGET_LINK_LIBRARIES(libaprutil-1 ${APR_LIBRARIES} ${XMLLIB_LIBRARIES}) 236SET_TARGET_PROPERTIES(libaprutil-1 PROPERTIES COMPILE_DEFINITIONS "APU_DECLARE_EXPORT;APR_DECLARE_EXPORT;XML_STATIC;WINNT") 237 238ADD_LIBRARY(aprutil-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED}) 239SET(install_targets ${install_targets} aprutil-1) 240TARGET_LINK_LIBRARIES(aprutil-1 ${APR_LIBRARIES} ${XMLLIB_LIBRARIES}) 241SET_TARGET_PROPERTIES(aprutil-1 PROPERTIES COMPILE_DEFINITIONS "APU_DECLARE_STATIC;APR_DECLARE_STATIC;APU_DSO_MODULE_BUILD;XML_STATIC") 242 243IF(APU_HAVE_CRYPTO) 244 IF(NOT OPENSSL_FOUND) 245 MESSAGE(FATAL_ERROR "Only OpenSSL-based crypto is currently implemented in the cmake build") 246 ENDIF() 247 ADD_LIBRARY(apr_crypto_openssl-1 SHARED crypto/apr_crypto_openssl.c libaprutil.rc) 248 SET(install_targets ${install_targets} apr_crypto_openssl-1) 249 SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/apr_crypto_openssl-1.pdb) 250 SET_TARGET_PROPERTIES(apr_crypto_openssl-1 PROPERTIES INCLUDE_DIRECTORIES "${APR_INCLUDE_DIRECTORIES};${OPENSSL_INCLUDE_DIR}") 251 SET_TARGET_PROPERTIES(apr_crypto_openssl-1 PROPERTIES COMPILE_DEFINITIONS "WINNT") 252 SET_TARGET_PROPERTIES(apr_crypto_openssl-1 PROPERTIES COMPILE_FLAGS "-DAPR_DECLARE_EXPORT=1 -DAPU_DECLARE_EXPORT=1 -DDLL_NAME=apr_crypto_openssl") 253 TARGET_LINK_LIBRARIES(apr_crypto_openssl-1 libaprutil-1 ${APR_LIBRARIES} ${OPENSSL_LIBRARIES}) 254ENDIF() 255 256IF(APU_HAVE_ODBC) 257 ADD_LIBRARY(apr_dbd_odbc-1 SHARED dbd/apr_dbd_odbc.c libaprutil.rc) 258 SET(install_targets ${install_targets} apr_dbd_odbc-1) 259 SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/apr_dbd_odbc-1.pdb) 260 SET(dbd_drivers ${dbd_drivers} odbc) 261 TARGET_LINK_LIBRARIES(apr_dbd_odbc-1 libaprutil-1 ${APR_LIBRARIES} odbc32 odbccp32) 262 SET_PROPERTY(TARGET apr_dbd_odbc-1 APPEND PROPERTY LINK_FLAGS /export:apr_dbd_odbc_driver) 263 SET_TARGET_PROPERTIES(apr_dbd_odbc-1 PROPERTIES COMPILE_DEFINITIONS "APU_HAVE_ODBC;HAVE_SQL_H;APU_DECLARE_EXPORT;APR_DECLARE_EXPORT;APU_DSO_MODULE_BUILD;WINNT") 264 SET_TARGET_PROPERTIES(apr_dbd_odbc-1 PROPERTIES COMPILE_FLAGS "-DAPR_DECLARE_EXPORT=1 -DAPU_DECLARE_EXPORT=1 -DDLL_NAME=apr_dbd_odbc") 265ENDIF() 266 267IF(APR_HAS_LDAP) 268 ADD_LIBRARY(apr_ldap-1 SHARED ldap/apr_ldap_init.c ldap/apr_ldap_option.c 269 ldap/apr_ldap_rebind.c libaprutil.rc) 270 SET(install_targets ${install_targets} apr_ldap-1) 271 SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/apr_ldap-1.pdb) 272 TARGET_LINK_LIBRARIES(apr_ldap-1 libaprutil-1 ${APR_LIBRARIES} ${LDAP_LIBRARIES}) 273 SET_TARGET_PROPERTIES(apr_ldap-1 PROPERTIES COMPILE_DEFINITIONS "WINNT") 274 SET_TARGET_PROPERTIES(apr_ldap-1 PROPERTIES COMPILE_FLAGS "-DAPR_DECLARE_EXPORT=1 -DAPU_DECLARE_EXPORT=1 -DDLL_NAME=apr_ldap") 275 SET(apr_ldap_libraries apr_ldap-1) 276ELSE() 277 SET(apr_ldap_libraries) 278ENDIF() 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/billion-laughs.xml 290 ${PROJECT_BINARY_DIR}/data/billion-laughs.xml) 291 292 IF(TEST_STATIC_LIBS) 293 SET(whichapr aprutil-1) 294 SET(apiflag "-DAPR_DECLARE_STATIC -DAPU_DECLARE_STATIC") 295 ELSE() 296 SET(whichapr libaprutil-1) 297 SET(apiflag) 298 ENDIF() 299 300 ADD_EXECUTABLE(testall ${APR_TEST_SOURCES}) 301 TARGET_LINK_LIBRARIES(testall ${whichapr} ${apr_ldap_libraries} ${XMLLIB_LIBRARIES} ${LDAP_LIBRARIES}) 302 IF(apiflag) 303 SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag}) 304 ENDIF() 305 ADD_TEST(NAME testall COMMAND testall) 306 307 ADD_EXECUTABLE(dbd test/dbd.c) 308 TARGET_LINK_LIBRARIES(dbd ${whichapr}) 309 IF(apiflag) 310 SET_TARGET_PROPERTIES(dbd PROPERTIES COMPILE_FLAGS ${apiflag}) 311 ENDIF() 312 313 # dbd is run multiple times with different parameters. 314 FOREACH(somedbd ${dbd_drivers}) 315 ADD_TEST(NAME dbd-${somedbd} COMMAND dbd ${somedbd}) 316 ENDFOREACH() 317 318ENDIF (APR_BUILD_TESTAPR) 319 320# Installation 321 322INSTALL(TARGETS ${install_targets} 323 RUNTIME DESTINATION bin 324 LIBRARY DESTINATION lib 325 ARCHIVE DESTINATION lib 326 ) 327 328IF(INSTALL_PDB) 329 INSTALL(FILES ${install_bin_pdb} 330 DESTINATION bin 331 CONFIGURATIONS RelWithDebInfo Debug) 332ENDIF() 333 334INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include) 335 336STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) 337MESSAGE(STATUS "") 338MESSAGE(STATUS "") 339MESSAGE(STATUS "APR-Util configuration summary:") 340MESSAGE(STATUS "") 341MESSAGE(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}") 342MESSAGE(STATUS " Install .pdb (if available)...... : ${INSTALL_PDB}") 343MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}") 344MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}") 345MESSAGE(STATUS " APR include directory ........... : ${APR_INCLUDE_DIR}") 346MESSAGE(STATUS " APR libraries ................... : ${APR_LIBRARIES}") 347MESSAGE(STATUS " DBD ODBC driver ................. : ${APU_HAVE_ODBC}") 348MESSAGE(STATUS " APU_HAVE_CRYPTO ................. : ${APU_HAVE_CRYPTO}") 349MESSAGE(STATUS " APR_HAS_LDAP .................... : ${APR_HAS_LDAP}") 350MESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}") 351IF(TEST_STATIC_LIBS) 352MESSAGE(STATUS " (testing static libraries)") 353ELSE() 354MESSAGE(STATUS " (testing dynamic libraries)") 355ENDIF() 356