环境:
win7_x64旗舰版、VS2015企业版、CMake3.8
一、下载apr相关库
1.1)expat下载地址:https://github.com/libexpat/libexpat/releases/download/R_2_1_0/expat-2.1.0.tar.gz
1.2)apr库下载地址:http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3-win32-src.zip (注意不能在github上下载trunk版本,win32条件变量使用有问题,亲测!!!)
1.3)apr-util库下载地址:http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1-win32-src.zip
解压到指定目录下,最后的目录结构如下
二、编译expat
2.1)编写构建脚本build_expat_for_vs_2015_x86_debug.bat
@echo off ::VS2015 x86编译环境 call "%VS140COMNTOOLS%....VCvcvarsall.bat" x86 ::创建构建目录 if not exist cmake ( mkdir cmake ) cd cmake ::创建nmake工程 ::MSVC=ON 禁止4996警告 ::BUILD_tools=OFF 禁止生成BUILD_tools ::BUILD_examples=OFF 禁止生成BUILD_examples ::BUILD_tests=OFF 禁止生成BUILD_tests ::DBUILD_shared=OFF 生成静态库 ::CMAKE_BUILD_TYPE=Debug 生成调试信息 cmake -G "NMake Makefiles" -DMSVC=ON -DBUILD_tools=OFF -DBUILD_examples=OFF -DBUILD_tests=OFF -DBUILD_shared=OFF -DCMAKE_BUILD_TYPE=Debug .. nmake pause
2.2)生成expat库
将build_expat_for_vs_2015_x86_debug.bat文件放到expat-2.1.0目录下,执行脚本生成静态库expat.lib文件。
三、编译apr
3.1)编写构建脚本build_apr_for_vs_2015_x86_debug.bat
@echo off ::VS2015 x86编译环境 call "%VS140COMNTOOLS%....VCvcvarsall.bat" x86 ::创建构建目录 if not exist cmake ( mkdir cmake ) cd cmake ::创建nmake工程 ::APR_INSTALL_PRIVATE_H=OFF 禁止APR_INSTALL_PRIVATE_H ::APR_HAVE_IPV6=OFF 禁止APR_HAVE_IPV6 ::INSTALL_PDB=OFF 禁止INSTALL_PDB ::APR_BUILD_TESTAPR=OFF 禁止APR_BUILD_TESTAPR ::TEST_STATIC_LIBS=OFF 禁止TEST_STATIC_LIBS ::CMAKE_BUILD_TYPE=Debug 生成调试版本 cmake -G "NMake Makefiles" -DAPR_INSTALL_PRIVATE_H=OFF -DAPR_HAVE_IPV6=OFF -DINSTALL_PDB=OFF -DAPR_BUILD_TESTAPR=OFF -DTEST_STATIC_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug .. nmake ::拷贝头文件 copy /y apr.h ../include/ pause
3.2)生成apr库
将build_apr_for_vs_2015_x86_debug.bat 文件放到apr-1.6.3目录下,执行脚本生成静态库expat.lib文件。
四、编译apr-util
4.1)修改CMakeLists.txt文件,添加红色的内容
PROJECT(APR-Util C) CMAKE_MINIMUM_REQUIRED(VERSION 2.8) #FIND_PACKAGE(OpenSSL) #FIND_PACKAGE(expat) ... SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libaprutil-1.pdb) TARGET_LINK_LIBRARIES(libaprutil-1 ${APR_LIBRARIES} ${XMLLIB_LIBRARIES} ${SYSTEM_LIBRARIES}) SET_TARGET_PROPERTIES(libaprutil-1 PROPERTIES COMPILE_DEFINITIONS "APU_DECLARE_EXPORT;APR_DECLARE_EXPORT;XML_STATIC;WINNT") ... SET(install_targets ${install_targets} aprutil-1) TARGET_LINK_LIBRARIES(aprutil-1 ${APR_LIBRARIES} ${XMLLIB_LIBRARIES} ${SYSTEM_LIBRARIES}) SET_TARGET_PROPERTIES(aprutil-1 PROPERTIES COMPILE_DEFINITIONS "APU_DECLARE_STATIC;APR_DECLARE_STATIC;APU_DSO_MODULE_BUILD;XML_STATIC")
4.2)编写构建脚本build_aprutil_for_vs_2015_x86_debug.bat
@echo off ::VS2015 x86编译环境 call "%VS140COMNTOOLS%....VCvcvarsall.bat" x86 set CURRENT_DIR=%~dp0 ::设置APR头文件目录 set APR_INCLUDE_DIR=%CURRENT_DIR%../apr-1.6.3/include ::设置APR库文件 set APR_LIBRARIES=%CURRENT_DIR%../apr-1.6.3/cmake/apr-1.lib ::设置EXPAT头文件目录 set EXPAT_INCLUDE_DIRS=%CURRENT_DIR%../expat-2.1.0/lib ::设置EXPAT库文件 set EXPAT_LIBRARIES=%CURRENT_DIR%../expat-2.1.0/cmake/expat.lib ::设置window系统库文件 set SYSTEM_LIBRARIES="ws2_32.lib mswsock.lib rpcrt4.lib" ::创建构建目录 if not exist cmake ( mkdir cmake ) cd cmake ::创建nmake工程 ::MSVC=ON 禁止4996警告 ::APU_HAVE_CRYPTO=OFF 禁止APU_HAVE_CRYPTO ::APU_HAVE_ODBC=OFF 禁止APU_HAVE_ODBC ::APU_HAVE_ODBC=OFF 禁止APU_HAVE_ODBC ::APR_HAS_LDAP=OFF 禁止APR_HAS_LDAP ::INSTALL_PDB=OFF 禁止INSTALL_PDB ::APR_BUILD_TESTAPR=OFF 禁止APR_BUILD_TESTAPR ::TEST_STATIC_LIBS=OFF 禁止TEST_STATIC_LIBS ::APR_INCLUDE_DIR=ON 启用EXPAT_FOUND ::APR_INCLUDE_DIR=%APR_INCLUDE_DIR% 设置APR头文件目录 ::APR_LIBRARIES=%APR_LIBRARIES% 设置APR库文件 ::EXPAT_INCLUDE_DIRS=%EXPAT_INCLUDE_DIRS% 设置EXPAT头文件目录 ::EXPAT_LIBRARIES=%EXPAT_LIBRARIES% 设置EXPAT库文件 ::SYSTEM_LIBRARIES=%SYSTEM_LIBRARIES% 设置window系统库文件 ::CMAKE_BUILD_TYPE=Debug 生成调试版本 cmake -G "NMake Makefiles" -DAPU_HAVE_CRYPTO=OFF -DAPU_HAVE_ODBC=OFF -DAPR_HAS_LDAP=OFF -DINSTALL_PDB=OFF -DAPR_BUILD_TESTAPR=OFF -DTEST_STATIC_LIBS=OFF -DEXPAT_FOUND=ON -DAPR_INCLUDE_DIR=%APR_INCLUDE_DIR% -DAPR_LIBRARIES=%APR_LIBRARIES% -DEXPAT_INCLUDE_DIRS=%EXPAT_INCLUDE_DIRS% -DEXPAT_LIBRARIES=%EXPAT_LIBRARIES% -DSYSTEM_LIBRARIES=%SYSTEM_LIBRARIES% -DCMAKE_BUILD_TYPE=Debug .. nmake pause
4.3)生成aprutil库
将build_aprutil_for_vs_2015_x86_debug.bat 文件放到apr-util-1.6.1目录下,执行脚本生成静态库aprutil-1.lib和动态库libaprutil-1.lib、libaprutil-1.dll文件。