1 add_library(git2internal OBJECT)
2 set_target_properties(git2internal PROPERTIES C_STANDARD 90)
3 set_target_properties(git2internal PROPERTIES C_EXTENSIONS OFF)
7 add_definitions(-DGIT_DEPRECATE_HARD)
13 add_feature_info(debugpool GIT_DEBUG_POOL "debug pool allocator")
15 if(DEBUG_STRICT_ALLOC)
16 set(GIT_DEBUG_STRICT_ALLOC 1)
18 add_feature_info(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators")
21 set(GIT_DEBUG_STRICT_OPEN 1)
23 add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
26 include(PkgBuildConfig)
29 # This variable will contain the libraries we need to put into
30 # libgit2.pc's Requires.private. That is, what we're linking to or
31 # what someone who's statically linking us needs to link to.
32 set(LIBGIT2_PC_REQUIRES "")
33 # This will be set later if we use the system's http-parser library or
34 # use iconv (OSX) and will be written to the Libs.private field in the
36 set(LIBGIT2_PC_LIBS "")
39 "${CMAKE_CURRENT_BINARY_DIR}"
40 "${PROJECT_SOURCE_DIR}/src"
41 "${PROJECT_SOURCE_DIR}/include")
44 set(GIT_USE_FUTIMENS 1)
46 add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
48 check_prototype_definition(qsort_r
49 "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
50 "" "stdlib.h" GIT_QSORT_R_BSD)
52 check_prototype_definition(qsort_r
53 "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
54 "" "stdlib.h" GIT_QSORT_R_GNU)
56 check_function_exists(qsort_s GIT_QSORT_S)
58 check_function_exists(getentropy GIT_RAND_GETENTROPY)
60 # Find required dependencies
63 list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
64 elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
65 list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
66 list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
67 elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
68 list(APPEND LIBGIT2_SYSTEM_LIBS network)
69 list(APPEND LIBGIT2_PC_LIBS "-lnetwork")
72 check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
74 list(APPEND LIBGIT2_SYSTEM_LIBS rt)
75 list(APPEND LIBGIT2_PC_LIBS "-lrt")
79 list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
80 list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
82 add_feature_info(threadsafe USE_THREADS "threadsafe support")
85 if(WIN32 AND EMBED_SSH_PATH)
86 file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
88 target_sources(git2internal PRIVATE ${SRC_SSH})
90 list(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include")
91 file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
95 include(SelectHTTPSBackend)
97 include(SelectHTTPParser)
100 include(SelectWinHTTP)
104 if(USE_SHA1 STREQUAL "CollisionDetection")
105 file(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
106 elseif(USE_SHA1 STREQUAL "OpenSSL")
107 file(GLOB SRC_SHA1 hash/sha1/openssl.*)
108 elseif(USE_SHA1 STREQUAL "CommonCrypto")
109 file(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
110 elseif(USE_SHA1 STREQUAL "mbedTLS")
111 file(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
112 elseif(USE_SHA1 STREQUAL "Win32")
113 file(GLOB SRC_SHA1 hash/sha1/win32.*)
114 elseif(USE_SHA1 STREQUAL "Generic")
115 file(GLOB SRC_SHA1 hash/sha1/generic.*)
117 list(APPEND SRC_SHA1 "hash/sha1.h")
118 target_sources(git2internal PRIVATE ${SRC_SHA1})
120 # Optional external dependency: ntlmclient
123 add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient")
124 list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/ntlmclient")
125 list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
127 add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
129 # Optional external dependency: GSSAPI
131 include(SelectGSSAPI)
133 # Optional external dependency: iconv
139 list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
140 list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
141 list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
143 add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
148 find_package(Threads REQUIRED)
158 if(HAVE_STRUCT_STAT_ST_MTIM)
159 set(GIT_USE_STAT_MTIM 1)
160 elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
161 set(GIT_USE_STAT_MTIMESPEC 1)
162 elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC)
163 set(GIT_USE_STAT_MTIME_NSEC 1)
166 target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64)
168 # Collect sourcefiles
170 "${PROJECT_SOURCE_DIR}/include/git2.h"
171 "${PROJECT_SOURCE_DIR}/include/git2/*.h"
172 "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h")
174 target_sources(git2internal PRIVATE ${SRC_H})
176 # On Windows use specific platform sources
177 if(WIN32 AND NOT CYGWIN)
178 set(WIN_RC "win32/git2.rc")
180 file(GLOB SRC_OS win32/*.c win32/*.h)
182 target_sources(git2internal PRIVATE ${SRC_OS})
184 target_compile_definitions(git2internal PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
186 file(GLOB SRC_OS unix/*.c unix/*.h)
188 target_sources(git2internal PRIVATE ${SRC_OS})
191 if(USE_LEAK_CHECKER STREQUAL "valgrind")
192 target_compile_definitions(git2internal PRIVATE VALGRIND)
195 file(GLOB SRC_GIT2 *.c *.h
196 allocators/*.c allocators/*.h
197 streams/*.c streams/*.h
198 transports/*.c transports/*.h
201 target_sources(git2internal PRIVATE ${SRC_GIT2})
204 # The old Secure Transport API has been deprecated in macOS 10.15.
205 set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated)
208 # the xdiff dependency is not (yet) warning-free, disable warnings as
209 # errors for the xdiff sources until we've sorted them out
211 set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
212 set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS -WX-)
213 set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS -WX-)
214 set_source_files_properties(xdiff/xmerge.c PROPERTIES COMPILE_FLAGS -WX-)
215 set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
216 set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS -WX-)
218 set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter")
219 set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter")
220 set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
221 set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
222 set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")
225 # Determine architecture of the machine
226 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
228 elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
230 elseif(CMAKE_SIZEOF_VOID_P)
231 message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)")
233 message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
236 configure_file(features.h.in git2/sys/features.h)
238 ide_split_sources(git2internal)
239 list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal> ${LIBGIT2_DEPENDENCY_OBJECTS})
241 target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include)
242 target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
244 set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
245 set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
246 set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE)
247 set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
248 set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
249 set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
252 # This is required for Xcode to actually link the libgit2 library
253 # when using only object libraries.
254 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "")
255 list(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
258 # Compile and link libgit2
259 add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
260 target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS})
262 set_target_properties(git2 PROPERTIES C_STANDARD 90)
263 set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
264 set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
265 set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
267 # Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
268 # Win64+MSVC+static libs = linker error
269 if(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
270 set_target_properties(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64")
273 ide_split_sources(git2)
276 set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION})
277 set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
279 target_compile_definitions(git2 PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
280 set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
281 elseif(DEFINED LIBGIT2_PREFIX)
282 set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
286 pkg_build_config(NAME libgit2
287 VERSION ${libgit2_VERSION}
288 DESCRIPTION "The git library, take 2"
290 PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
291 REQUIRES ${LIBGIT2_PC_REQUIRES}
295 # Precompiled headers
296 set_target_properties(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
297 set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h")
302 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
303 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
304 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
306 install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
307 install(FILES ${PROJECT_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})