@@ -20,6 +20,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mo
2020
2121INCLUDE (CheckLibraryExists )
2222INCLUDE (CheckFunctionExists )
23+ INCLUDE (CheckStructHasMember )
2324INCLUDE (AddCFlagIfSupported )
2425INCLUDE (FindPkgConfig )
2526
@@ -40,6 +41,11 @@ OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
4041OPTION ( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
4142OPTION ( VALGRIND "Configure build for valgrind" OFF )
4243OPTION ( CURL "User curl for HTTP if available" ON )
44+ OPTION ( DEBUG_POOL "Enable debug pool allocator" OFF )
45+
46+ IF (DEBUG_POOL)
47+ ADD_DEFINITIONS (-DGIT_DEBUG_POOL )
48+ ENDIF ()
4349
4450IF (${CMAKE_SYSTEM_NAME } MATCHES "Darwin" )
4551 SET ( USE_ICONV ON )
@@ -60,6 +66,10 @@ IF(MSVC)
6066 # are linking statically
6167 OPTION ( STATIC_CRT "Link the static CRT libraries" ON )
6268
69+ # If you want to embed a copy of libssh2 into libgit2, pass a
70+ # path to libssh2
71+ OPTION ( EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF )
72+
6373 ADD_DEFINITIONS (-D_SCL_SECURE_NO_WARNINGS )
6474 ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE )
6575 ADD_DEFINITIONS (-D_CRT_NONSTDC_NO_DEPRECATE )
@@ -81,6 +91,27 @@ IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8191 OPTION ( USE_OPENSSL "Link with and use openssl library" ON )
8292ENDIF ()
8393
94+ CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
95+ HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C )
96+ CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
97+ HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C )
98+ CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtime_nsec sys/stat.h
99+ HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C )
100+
101+ IF (HAVE_STRUCT_STAT_ST_MTIM)
102+ CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim.tv_nsec sys/stat.h
103+ HAVE_STRUCT_STAT_NSEC LANGUAGE C )
104+ ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
105+ CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec.tv_nsec sys/stat.h
106+ HAVE_STRUCT_STAT_NSEC LANGUAGE C )
107+ ELSE ()
108+ SET ( HAVE_STRUCT_STAT_NSEC ON )
109+ ENDIF ()
110+
111+ IF (HAVE_STRUCT_STAT_NSEC OR WIN32 )
112+ OPTION ( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
113+ ENDIF ()
114+
84115# This variable will contain the libraries we need to put into
85116# libgit2.pc's Requires.private. That is, what we're linking to or
86117# what someone who's statically linking us needs to link to.
@@ -133,13 +164,13 @@ FUNCTION(TARGET_OS_LIBRARIES target)
133164 ENDIF ()
134165ENDFUNCTION ()
135166
136- # For the MSVC IDE, this function splits up the source files like windows
137- # explorer does. This is esp. useful with the libgit2_clar project, were
138- # usually 2 or more files share the same name. Sadly, this file grouping
139- # is a per-directory option in cmake and not per-target, resulting in
140- # empty virtual folders " tests" for the git2.dll
141- FUNCTION (MSVC_SPLIT_SOURCES target )
142- IF (MSVC_IDE )
167+ # This function splits the sources files up into their appropriate
168+ # subdirectories. This is especially useful for IDEs like Xcode and
169+ # Visual Studio, so that you can navigate into the libgit2_clar project,
170+ # and see the folders within the tests folder (instead of just seeing all
171+ # source and tests in a single folder.)
172+ FUNCTION (IDE_SPLIT_SOURCES target )
173+ IF (MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode )
143174 GET_TARGET_PROPERTY (sources ${target} SOURCES )
144175 FOREACH (source ${sources} )
145176 IF (source MATCHES ".*/" )
@@ -190,6 +221,13 @@ IF (COREFOUNDATION_FOUND)
190221ENDIF ()
191222
192223
224+ IF (WIN32 AND EMBED_SSH_PATH)
225+ FILE (GLOB SRC_SSH "${EMBED_SSH_PATH} /src/*.c" )
226+ INCLUDE_DIRECTORIES ("${EMBED_SSH_PATH} /include" )
227+ FILE (WRITE "${EMBED_SSH_PATH} /src/libssh2_config.h" "#define HAVE_WINCNG\n #define LIBSSH2_WINCNG\n #include \" ../win32/libssh2_config.h\" " )
228+ ADD_DEFINITIONS (-DGIT_SSH )
229+ ENDIF ()
230+
193231IF (WIN32 AND WINHTTP)
194232 ADD_DEFINITIONS (-DGIT_WINHTTP )
195233 INCLUDE_DIRECTORIES (deps/http-parser )
@@ -206,7 +244,7 @@ IF (WIN32 AND WINHTTP)
206244 SET (LIBWINHTTP_PATH "${CMAKE_CURRENT_BINARY_DIR } /deps/winhttp" )
207245 FILE (MAKE_DIRECTORY ${LIBWINHTTP_PATH} )
208246
209- IF (" ${ CMAKE_SIZEOF_VOID_P } " EQUAL "8" )
247+ IF (CMAKE_SIZEOF_VOID_P EQUAL 8 )
210248 set (WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR } /deps/winhttp/winhttp64.def" )
211249 ELSE ()
212250 set (WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR } /deps/winhttp/winhttp.def" )
@@ -228,7 +266,8 @@ IF (WIN32 AND WINHTTP)
228266 LINK_DIRECTORIES (${LIBWINHTTP_PATH} )
229267 ENDIF ()
230268
231- LINK_LIBRARIES (winhttp rpcrt4 crypt32 )
269+ LINK_LIBRARIES (winhttp rpcrt4 crypt32 ole32 )
270+ LIST (APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32" )
232271ELSE ()
233272 IF (CURL)
234273 PKG_CHECK_MODULES (CURL libcurl )
@@ -364,6 +403,7 @@ IF (MSVC)
364403
365404 IF (MSVC_CRTDBG)
366405 SET (CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} /DGIT_MSVC_CRTDBG" )
406+ SET (CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} " "Dbghelp.lib" )
367407 ENDIF ()
368408
369409 # /Zi - Create debugging information
@@ -372,7 +412,7 @@ IF (MSVC)
372412 # /MTd - Statically link the multithreaded debug version of the CRT
373413 # /MDd - Dynamically link the multithreaded debug version of the CRT
374414 # /RTC1 - Run time checks
375- SET (CMAKE_C_FLAGS_DEBUG "/Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG} " )
415+ SET (CMAKE_C_FLAGS_DEBUG "${ CMAKE_C_FLAGS_DEBUG } /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG} " )
376416
377417 # /DNDEBUG - Disables asserts
378418 # /MT - Statically link the multithreaded release version of the CRT
@@ -424,7 +464,7 @@ ELSE ()
424464 ENDIF ()
425465
426466 IF (WIN32 AND NOT CYGWIN )
427- SET (CMAKE_C_FLAGS_DEBUG "-D_DEBUG" )
467+ SET (CMAKE_C_FLAGS_DEBUG "${ CMAKE_C_FLAGS_DEBUG } -D_DEBUG" )
428468 ENDIF ()
429469
430470 IF (MINGW) # MinGW always does PIC and complains if we tell it to
@@ -504,6 +544,18 @@ IF (THREADSAFE)
504544 ADD_DEFINITIONS (-DGIT_THREADS )
505545ENDIF ()
506546
547+ IF (USE_NSEC)
548+ ADD_DEFINITIONS (-DGIT_USE_NSEC )
549+ ENDIF ()
550+
551+ IF (HAVE_STRUCT_STAT_ST_MTIM)
552+ ADD_DEFINITIONS (-DGIT_USE_STAT_MTIM )
553+ ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
554+ ADD_DEFINITIONS (-DGIT_USE_STAT_MTIMESPEC )
555+ ELSEIF (HAVE_STRUCT_STAT_ST_MTIME_NSEC)
556+ ADD_DEFINITIONS (-DGIT_USE_STAT_MTIME_NSEC )
557+ ENDIF ()
558+
507559ADD_DEFINITIONS (-D_FILE_OFFSET_BITS=64 )
508560
509561# Collect sourcefiles
@@ -533,7 +585,7 @@ ELSE()
533585ENDIF ()
534586
535587# Compile and link libgit2
536- ADD_LIBRARY (git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} ${WIN_RC} )
588+ ADD_LIBRARY (git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${ SRC_SHA1} ${WIN_RC} )
537589TARGET_LINK_LIBRARIES (git2 ${SECURITY_DIRS} )
538590TARGET_LINK_LIBRARIES (git2 ${COREFOUNDATION_DIRS} )
539591TARGET_LINK_LIBRARIES (git2 ${SSL_LIBRARIES} )
@@ -548,14 +600,16 @@ IF(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
548600 SET_TARGET_PROPERTIES (git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64" )
549601ENDIF ()
550602
551- MSVC_SPLIT_SOURCES (git2 )
603+ IDE_SPLIT_SOURCES (git2 )
552604
553605IF (SONAME)
554606 SET_TARGET_PROPERTIES (git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING} )
555607 SET_TARGET_PROPERTIES (git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION} )
556608 IF (LIBGIT2_FILENAME)
557609 ADD_DEFINITIONS (-DLIBGIT2_FILENAME= \"${LIBGIT2_FILENAME} \" )
558610 SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME} )
611+ ELSEIF (DEFINED LIBGIT2_PREFIX)
612+ SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX " ${LIBGIT2_PREFIX} ")
559613 ENDIF()
560614ENDIF()
561615STRING(REPLACE " ; " " " LIBGIT2_PC_LIBS " ${LIBGIT2_PC_LIBS} ")
@@ -608,7 +662,7 @@ IF (BUILD_CLAR)
608662 ${CLAR_PATH} /clar.c
609663 PROPERTIES OBJECT_DEPENDS ${CLAR_PATH} /clar.suite)
610664
611- ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} )
665+ ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${ SRC_SHA1} )
612666
613667 TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS} )
614668 TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS} )
@@ -617,7 +671,7 @@ IF (BUILD_CLAR)
617671 TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES} )
618672 TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES} )
619673 TARGET_OS_LIBRARIES(libgit2_clar)
620- MSVC_SPLIT_SOURCES (libgit2_clar)
674+ IDE_SPLIT_SOURCES (libgit2_clar)
621675
622676 IF (MSVC_IDE)
623677 # Precompiled headers
@@ -630,6 +684,10 @@ IF (BUILD_CLAR)
630684 ELSE ()
631685 ADD_TEST(libgit2_clar libgit2_clar -v)
632686 ENDIF ()
687+
688+ # Add a test target which runs the cred callback tests, to be
689+ # called after setting the url and user
690+ ADD_TEST(libgit2_clar-cred_callback libgit2_clar -v -sonline::clone::cred_callback)
633691ENDIF ()
634692
635693IF (TAGS)
0 commit comments