XiZi's Blog
Build Apache On Windows
0、为目标平台准备 perl,zlib,pcre,openssl。
perl需要安装并加入到PATH环境变量里。pcre和httpd的编译都要用到。
zlib和pcre均使用cmake编译,这里就不说了。
openssl 的编译,按照源文件下的INSTALL进行编译,注意有win32,win64a,win64i之分。并enable-zlib。
1、使用window版本的源代码:
apr-1.5.0-win32-src.zip,apr-iconv-1.2.1-win32-src-r2.zip,apr-util-1.5.3-win32-src.zip
2、全部解压到当前目录
创建并重命名或者创建符号链接,去掉版本号即目录下:apr,apr-iconv,apr-util.
3、这里我们使用visual studio 编译:
1)IED编译。打开apr-util下的aprutil.dsw,会提示转换。选择是进行转换。然后尝试编译。
2)命令行编译。打开vs command promote 命令行,进入apr-util目录
NMAKE /f "libaprutil.mak" CFG="libaprutil - Win32 Release" REM "libaprutil - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") REM "libaprutil - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") REM "libaprutil - x64 Release" (based on "Win32 (x86) Dynamic-Link Library") REM "libaprutil - x64 Debug" (based on "Win32 (x86) Dynamic-Link Library")
这里要修改原来的文件的一处错误:
--- apr-iconv-1.2.1.orig\build\modules.mk.win Fri Oct 19 04:49:36 2007 +++ apr-iconv-1.2.1\build\modules.mk.win Mon Apr 21 14:56:22 2014 @@ -218,7 +218,7 @@ .c{$(OUTPUT_DIR)}.so: $(SILENT)cl $(ALL_CFLAGS) /Fo$*.obj /Yuiconv.h /c $< - $(SILENT)link $(ALL_LDFLAGS) $*.obj $(API_LIBS) /out:$@ \ + $(SILENT)link $(ALL_LDFLAGS) $*.obj $(MODRES).obj $(API_LIBS) /out:$@ \ /base:@"..\build\BaseAddr.ref",$(@F) $(SILENT)if exist $@.manifest \ $(SILENT)mt -nologo -manifest $@.manifest -outputresource:$@;2 \
4、编译httpd之前的准备
1)这里我们要把所有的include文件合并到一起,要门cmake进行configure的时候会出错。 拷贝apr,apr-iconv和apr-util下的include文件夹合并到上一层的include文件夹。
2)修正CMakeLists.txt的错误。
--- httpd-2.4.9.orig\CMakeLists.txt Tue Nov 19 05:18:12 2013 +++ httpd-2.4.9\CMakeLists.txt Mon Apr 21 18:42:32 2014 @@ -678,8 +678,8 @@ IF("${${mod_name}_install_lib}") SET(installed_mod_libs_exps ${installed_mod_libs_exps} - "${PROJECT_BINARY_DIR}/${mod_name}.lib" - "${PROJECT_BINARY_DIR}/${mod_name}.exp" + "${PROJECT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${mod_name}.lib" + "${PROJECT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${mod_name}.exp" ) ENDIF() SET(mod_extra_libs "${mod_name}_extra_libs") @@ -825,7 +825,7 @@ ) INSTALL(FILES ${other_installed_h} DESTINATION include) INSTALL(FILES ${installed_mod_libs_exps} DESTINATION lib) -INSTALL(FILES "${CMAKE_BINARY_DIR}/libhttpd.exp" DESTINATION LIB) +INSTALL(FILES "${CMAKE_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/libhttpd.exp" DESTINATION LIB) IF(INSTALL_MANUAL) # Silly? This takes a while, and a dev doesn't need it. INSTALL(DIRECTORY docs/manual/ DESTINATION manual) @@ -849,7 +849,7 @@ # Windows anyway. STRING(REPLACE "/" "\\\\" native_src ${CMAKE_BINARY_DIR}/conf/original) STRING(REPLACE "/" "\\\\" native_dest ${CMAKE_INSTALL_PREFIX}/conf/original) -INSTALL(CODE "EXECUTE_PROCESS(COMMAND xcopy ${native_src} ${native_dest} /Q /S /Y)") +INSTALL(CODE "EXECUTE_PROCESS(COMMAND robocopy ${native_src} ${native_dest} /E)") STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) MESSAGE(STATUS "")
5、使用cmake生成httpd工程(这里使用的是httpd-2.4.9的版本)
这里我们要给定openssl,zlib,pcre,apr,当然如果用得到libxml2也一样给定。
configure,generate,build.