@@ -193,37 +193,46 @@ set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp CACHE PATH
193193aux_source_directory (${CTIMESTAMP_PATH_SRC} / DRV_SRC)
194194
195195#
196- # add libcurl to the project
196+ # add libcurl (and zlib) to the project
197197#
198198set (LIBCURL_PATH_SRC ${CMAKE_SOURCE_DIR} /libs/curl CACHE PATH
199199 "Lib curl source path" )
200- set (LIBCURL_LINK_MODE static CACHE STRING
201- "Lib curl linking mode: static (default) or dll" )
202200set (LIBCURL_BUILD_TYPE debug CACHE STRING
203201 "Lib curl build type: debug (default) or release" )
204202
203+ # zlib paths
204+ set (ZLIB_PATH_SRC ${CMAKE_SOURCE_DIR} /libs/zlib CACHE PATH
205+ "Lib zlib source path" )
206+ set (ZLIB_PATH_INST ${CMAKE_BINARY_DIR} /zlib CACHE PATH
207+ "Lib zlib install path" )
208+
205209if (${LIBCURL_BUILD_TYPE} MATCHES [Dd][Ee][Bb][Uu][Gg])
206210 set (LIBCURL_DEBUG_ENABLED yes )
207211 set (LIBCURL_BUILD_TYPE debug)
208212 set (LIBCURL_BUILD_SUFFIX _debug)
213+ # zlib's nmake-based "win32" build system contains a default,
214+ # non-modifiable "-MD". Setting ZLIB_LOC will override it, which will
215+ # issue a compiler warning (that can be ignored, can't be supressed).
216+ set (ZLIB_LOC -MDd)
209217else (${LIBCURL_BUILD_TYPE} MATCHES [Dd][Ee][Bb][Uu][Gg])
210218 set (LIBCURL_DEBUG_ENABLED no )
211219 set (LIBCURL_BUILD_TYPE release)
212220 # empty LIBCURL_BUILD_SUFFIX
221+ # empty ZLIB_LOC
213222endif (${LIBCURL_BUILD_TYPE} MATCHES [Dd][Ee][Bb][Uu][Gg])
214223
215224set (LIBCURL_LD_PATH
216225 # Curl "installs" the .dll and .lib in different directories -> use the
217226 # build dir to find both files in same directory instead of installing.
218227 # Curl's win build root directory is not configurable.
219- # The path built below is only constant for the subtree tag (current:
220- # 7.61.0) and default/below nmake options (only with: IPv6, SSPI, WinSSL) .
221- ${LIBCURL_PATH_SRC} /builds/libcurl-vc-${TARCH} -${LIBCURL_BUILD_TYPE} -${LIBCURL_LINK_MODE} -ipv6-sspi-winssl-obj-lib/
228+ # The path built below is only constant for the subtree tag and the nmake
229+ # options below: ZLIB, IPv6, SSPI, WinSSL, plus IDN, not echoed in name .
230+ ${LIBCURL_PATH_SRC} /builds/libcurl-vc-${TARCH} -${LIBCURL_BUILD_TYPE} -static -zlib- static -ipv6-sspi-winssl-obj-lib/
222231 CACHE PATH "Lib curl load library path" )
223232set (LIBCURL_INC_PATH ${LIBCURL_PATH_SRC} /include CACHE PATH
224233 "Lib curl include path" )
225234
226- # Build libcurl.
235+ # Build zlib, then libcurl.
227236# Note: this happens at config time as a pre-requisite, for now. This might
228237# be changed to a build target later (possibly as a CMake subproject: re-link
229238# only if out-of-date, skip building the .exe, allow disabling non-HTTP
@@ -232,14 +241,38 @@ set(LIBCURL_INC_PATH ${LIBCURL_PATH_SRC}/include CACHE PATH
232241# entire build "single-config", since the build type (rel/dbg) is decided at
233242# CMake-generation, not along the MSBuild invocation.
234243if (NOT IS_DIRECTORY ${LIBCURL_LD_PATH} )
244+ # build zlib first.
245+ message ("Building zlib library in ${ZLIB_PATH_SRC} " )
246+ execute_process (COMMAND
247+ # zlib's "win32" makefile builds in situ => always clean before
248+ # building, potentially removing builds of different architecture than
249+ # current's build.
250+ nmake /f win32 /Makefile.msc clean zlib.lib LOC=${ZLIB_LOC}
251+ RESULT_VARIABLE CMD_RETURN
252+ WORKING_DIRECTORY "${ZLIB_PATH_SRC} "
253+ )
254+ if (${CMD_RETURN} )
255+ message (FATAL_ERROR "Building zlib failed." )
256+ endif (${CMD_RETURN} )
257+ # libcurl expects a /lib and a /include folder under the location provided
258+ # as the path to zlib. zlib/win32's makefile has no install target, so
259+ # we'll just cmake-install them under the building dir.
260+ file (INSTALL ${ZLIB_PATH_SRC} /zlib.lib DESTINATION ${ZLIB_PATH_INST} /lib)
261+ file (GLOB ZLIB_H_FILES LIST_DIRECTORIES false ${ZLIB_PATH_SRC}
262+ ${ZLIB_PATH_SRC} /*.h)
263+ file (INSTALL ${ZLIB_H_FILES} DESTINATION ${ZLIB_PATH_INST} /include )
264+
265+ # build libcurl second: config first, build afterwards..
266+ message ("Building curl library in ${LIBCURL_PATH_SRC} " )
235267 execute_process (COMMAND buildconf.bat
236268 RESULT_VARIABLE CMD_RETURN
237269 WORKING_DIRECTORY "${LIBCURL_PATH_SRC} "
238270 )
239271 if (NOT ${CMD_RETURN} )
240272 execute_process (COMMAND
241- nmake /f Makefile.vc mode=${LIBCURL_LINK_MODE} MACHINE=${TARCH}
273+ nmake /f Makefile.vc mode=static MACHINE=${TARCH}
242274 ENABLE_WINSSL=yes ENABLE_IDN=yes ENABLE_IPV6=yes ENABLE_SSPI=yes
275+ WITH_ZLIB=static ZLIB_PATH=${ZLIB_PATH_INST}
243276 # build type needs to be synchronized (to link in the same CRT)
244277 DEBUG=${LIBCURL_DEBUG_ENABLED}
245278 # This "sneaks in" a define to disable all other protocols than
@@ -260,32 +293,31 @@ endif(NOT IS_DIRECTORY ${LIBCURL_LD_PATH})
260293
261294# add libcurl as dependency
262295if (${WIN32} )
263- if (${LIBCURL_LINK_MODE} MATCHES [Dd][Ll][Ll])
264- add_library (libcurl SHARED IMPORTED )
265- set_property (TARGET libcurl PROPERTY IMPORTED_LOCATION
266- ${LIBCURL_LD_PATH} /libcurl${LIBCURL_BUILD_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX} )
267- set_property (TARGET libcurl PROPERTY IMPORTED_IMPLIB
268- ${LIBCURL_LD_PATH} /libcurl${LIBCURL_BUILD_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX} )
269- # empty LIBCURL_WIN_LIBS
270- else (${LIBCURL_LINK_MODE} MATCHES [Dd][Ll][Ll])
271- add_library (libcurl STATIC IMPORTED )
272- set_property (TARGET libcurl PROPERTY IMPORTED_LOCATION
273- ${LIBCURL_LD_PATH} /libcurl_a${LIBCURL_BUILD_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} )
274- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DCURL_STATICLIB" )
275- # Libraries that libcurl/WinSSL links against.
276- # Removed: wldap32 advapi32 gdi32 user32 (unused with current config)
277- set (LIBCURL_WIN_LIBS ws2_32 crypt32 normaliz)
278- endif (${LIBCURL_LINK_MODE} MATCHES [Dd][Ll][Ll])
296+ add_library (zlib STATIC IMPORTED )
297+ set_property (TARGET zlib PROPERTY IMPORTED_LOCATION
298+ ${ZLIB_PATH_INST} /lib/zlib.lib)
299+
300+ add_library (libcurl STATIC IMPORTED )
301+ set_property (TARGET libcurl PROPERTY IMPORTED_LOCATION
302+ ${LIBCURL_LD_PATH} /libcurl_a${LIBCURL_BUILD_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} )
303+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DCURL_STATICLIB" )
304+ # Libraries that libcurl/WinSSL links against.
305+ # Removed: wldap32 advapi32 gdi32 user32 (unused with current config)
306+ set (LIBCURL_WIN_LIBS ws2_32 crypt32 normaliz)
279307else (${WIN32} )
280308 set_property (TARGET libcurl PROPERTY IMPORTED_LOCATION
281309 ${LIBCURL_LD_PATH} /libcurl${CMAKE_SHARED_LIBRARY_SUFFIX} )
282310endif (${WIN32} )
283311
284312add_custom_target (curlclean
285- COMMAND nmake /f Makefile.vc mode=${LIBCURL_LINK_MODE} clean
313+ COMMAND nmake /f Makefile.vc mode=static clean
286314 COMMAND ../buildconf.bat -clean
287315 WORKING_DIRECTORY "${LIBCURL_PATH_SRC} /winbuild"
288316 )
317+ add_custom_target (zlibclean
318+ COMMAND nmake /f win32 /Makefile.msc clean
319+ WORKING_DIRECTORY "${ZLIB_PATH_SRC} "
320+ )
289321
290322#
291323# add tinycbor to the project
@@ -376,7 +408,7 @@ include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC_PATH}
376408 ${DSNEDITOR_INC_PATH} )
377409target_link_libraries (${DRV_NAME} odbccp32 legacy_stdio_definitions
378410 ${DSNBND_LIB_BIN_DIR_BASE} -$<CONFIG>/esdsnbnd${BARCH}${CMAKE_IMPORT_LIBRARY_SUFFIX}
379- libcurl ${LIBCURL_WIN_LIBS} )
411+ zlib libcurl ${LIBCURL_WIN_LIBS} )
380412
381413
382414#
@@ -405,12 +437,6 @@ install(FILES
405437 LICENSE.rtf LICENSE.txt ${CMAKE_BINARY_DIR} /NOTICE.txt
406438 DESTINATION ${INSTALL_DIR} )
407439# add libcurl if build dynamically
408- if (${LIBCURL_LINK_MODE} MATCHES [Dd][Ll][Ll])
409- install (FILES
410- # need to use FILE : https://public.kitware.com/Bug/view.php?id=14311
411- ${LIBCURL_LD_PATH} /libcurl${LIBCURL_BUILD_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}
412- DESTINATION ${INSTALL_DIR} )
413- endif (${LIBCURL_LINK_MODE} MATCHES [Dd][Ll][Ll])
414440# add editor DLLs
415441install (FILES
416442 ${DSNBND_LIB_BIN_DIR_BASE} -$<CONFIG>/esdsnedt${CMAKE_SHARED_LIBRARY_SUFFIX}
0 commit comments