cmake: move winhttp build instructions into subdirectory Extract code required to build the winhttp library into its own CMakeLists.txt, which is included as required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d56069a..ab6077e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -398,38 +398,17 @@ IF (WIN32 AND WINHTTP)
# Since MinGW does not come with headers or an import library for winhttp,
# we have to include a private header and generate our own import library
IF (MINGW)
- FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
- IF (NOT DLLTOOL)
- MESSAGE(FATAL_ERROR "Could not find dlltool command")
- ENDIF ()
-
- SET(LIBWINHTTP_PATH "${CMAKE_BINARY_DIR}/deps/winhttp")
- FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH})
-
- IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(WINHTTP_DEF "${CMAKE_SOURCE_DIR}/deps/winhttp/winhttp64.def")
- ELSE()
- set(WINHTTP_DEF "${CMAKE_SOURCE_DIR}/deps/winhttp/winhttp.def")
- ENDIF()
-
- ADD_CUSTOM_COMMAND(
- OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
- COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a
- DEPENDS ${WINHTTP_DEF}
- WORKING_DIRECTORY ${LIBWINHTTP_PATH}
- )
-
- SET_SOURCE_FILES_PROPERTIES(
- ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
- PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
- )
-
+ ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/deps/winhttp" "${CMAKE_BINARY_DIR}/deps/winhttp")
+ LIST(APPEND LIBGIT2_LIBS winhttp)
LIST(APPEND LIBGIT2_INCLUDES "${CMAKE_SOURCE_DIR}/deps/winhttp")
LIST(APPEND LIBGIT2_LIBDIRS ${LIBWINHTTP_PATH})
+ ELSE()
+ LIST(APPEND LIBGIT2_LIBS "winhttp")
+ LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
ENDIF ()
- LIST(APPEND LIBGIT2_LIBS "winhttp" "rpcrt4" "crypt32" "ole32")
- LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32")
+ LIST(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32")
+ LIST(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
ELSE ()
IF (CURL)
PKG_CHECK_MODULES(CURL libcurl)
diff --git a/deps/winhttp/CMakeLists.txt b/deps/winhttp/CMakeLists.txt
new file mode 100644
index 0000000..baa9fe2
--- /dev/null
+++ b/deps/winhttp/CMakeLists.txt
@@ -0,0 +1,26 @@
+FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
+IF (NOT DLLTOOL)
+ MESSAGE(FATAL_ERROR "Could not find dlltool command")
+ENDIF ()
+
+SET(LIBWINHTTP_PATH "${CMAKE_BINARY_DIR}/deps/winhttp")
+SET(LIBWINHTTP_PATH ${LIBWINHTTP_PATH} PARENT_SCOPE)
+FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH})
+
+IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(WINHTTP_DEF "winhttp64.def")
+ELSE()
+ set(WINHTTP_DEF "winhttp.def")
+ENDIF()
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
+ COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a
+ DEPENDS ${WINHTTP_DEF}
+ WORKING_DIRECTORY ${LIBWINHTTP_PATH}
+)
+
+SET_SOURCE_FILES_PROPERTIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
+ PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a
+)