]> git.proxmox.com Git - libgit2.git/blame - src/CMakeLists.txt
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / CMakeLists.txt
CommitLineData
22a2d3d5
UG
1add_library(git2internal OBJECT)
2set_target_properties(git2internal PROPERTIES C_STANDARD 90)
e579e0f7 3set_target_properties(git2internal PROPERTIES C_EXTENSIONS OFF)
22a2d3d5 4
eae0bfdc 5
e579e0f7
MB
6if(DEPRECATE_HARD)
7 add_definitions(-DGIT_DEPRECATE_HARD)
8endif()
9
10if(DEBUG_POOL)
11 set(GIT_DEBUG_POOL 1)
12endif()
13add_feature_info(debugpool GIT_DEBUG_POOL "debug pool allocator")
14
15if(DEBUG_STRICT_ALLOC)
16 set(GIT_DEBUG_STRICT_ALLOC 1)
17endif()
18add_feature_info(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators")
19
20if(DEBUG_STRICT_OPEN)
21 set(GIT_DEBUG_STRICT_OPEN 1)
22endif()
23add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
c25aa7cd 24
c25aa7cd 25
e579e0f7
MB
26include(PkgBuildConfig)
27include(SanitizeBool)
22a2d3d5 28
eae0bfdc
PP
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.
e579e0f7 32set(LIBGIT2_PC_REQUIRES "")
eae0bfdc
PP
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
35# pc file.
e579e0f7 36set(LIBGIT2_PC_LIBS "")
eae0bfdc 37
e579e0f7 38set(LIBGIT2_INCLUDES
eae0bfdc 39 "${CMAKE_CURRENT_BINARY_DIR}"
e579e0f7
MB
40 "${PROJECT_SOURCE_DIR}/src"
41 "${PROJECT_SOURCE_DIR}/include")
eae0bfdc 42
e579e0f7
MB
43if(HAVE_FUTIMENS)
44 set(GIT_USE_FUTIMENS 1)
45endif ()
46add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
eae0bfdc 47
e579e0f7 48check_prototype_definition(qsort_r
6c7cee42 49 "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
e579e0f7 50 "" "stdlib.h" GIT_QSORT_R_BSD)
6c7cee42 51
e579e0f7 52check_prototype_definition(qsort_r
6c7cee42 53 "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
e579e0f7 54 "" "stdlib.h" GIT_QSORT_R_GNU)
eae0bfdc 55
e579e0f7
MB
56check_function_exists(qsort_s GIT_QSORT_S)
57
58check_function_exists(getentropy GIT_RAND_GETENTROPY)
eae0bfdc
PP
59
60# Find required dependencies
61
e579e0f7
MB
62if(WIN32)
63 list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
64elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
65 list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
66 list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
67elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
68 list(APPEND LIBGIT2_SYSTEM_LIBS network)
69 list(APPEND LIBGIT2_PC_LIBS "-lnetwork")
70endif()
71
72check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
73if(NEED_LIBRT)
74 list(APPEND LIBGIT2_SYSTEM_LIBS rt)
75 list(APPEND LIBGIT2_PC_LIBS "-lrt")
76endif()
77
78if(USE_THREADS)
79 list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
80 list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
81endif()
82add_feature_info(threadsafe USE_THREADS "threadsafe support")
eae0bfdc
PP
83
84
22a2d3d5
UG
85if(WIN32 AND EMBED_SSH_PATH)
86 file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
87 list(SORT SRC_SSH)
88 target_sources(git2internal PRIVATE ${SRC_SSH})
89
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\"")
92 set(GIT_SSH 1)
93endif()
eae0bfdc 94
22a2d3d5
UG
95include(SelectHTTPSBackend)
96include(SelectHashes)
e579e0f7
MB
97include(SelectHTTPParser)
98include(SelectRegex)
99include(SelectSSH)
100include(SelectWinHTTP)
101include(SelectZlib)
102
103
104if(USE_SHA1 STREQUAL "CollisionDetection")
105 file(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
106elseif(USE_SHA1 STREQUAL "OpenSSL")
107 file(GLOB SRC_SHA1 hash/sha1/openssl.*)
108elseif(USE_SHA1 STREQUAL "CommonCrypto")
109 file(GLOB SRC_SHA1 hash/sha1/common_crypto.*)
110elseif(USE_SHA1 STREQUAL "mbedTLS")
111 file(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
112elseif(USE_SHA1 STREQUAL "Win32")
113 file(GLOB SRC_SHA1 hash/sha1/win32.*)
114elseif(USE_SHA1 STREQUAL "Generic")
115 file(GLOB SRC_SHA1 hash/sha1/generic.*)
116endif()
117list(APPEND SRC_SHA1 "hash/sha1.h")
22a2d3d5 118target_sources(git2internal PRIVATE ${SRC_SHA1})
eae0bfdc 119
22a2d3d5 120# Optional external dependency: ntlmclient
e579e0f7
MB
121if(USE_NTLMCLIENT)
122 set(GIT_NTLM 1)
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>")
126endif()
127add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
22a2d3d5
UG
128
129# Optional external dependency: GSSAPI
130
e579e0f7 131include(SelectGSSAPI)
eae0bfdc
PP
132
133# Optional external dependency: iconv
e579e0f7
MB
134if(USE_ICONV)
135 find_package(Iconv)
136endif()
137if(ICONV_FOUND)
138 set(GIT_USE_ICONV 1)
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})
142endif()
143add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
144
145
146if(USE_THREADS)
147 if(NOT WIN32)
148 find_package(Threads REQUIRED)
149 endif()
150
151 set(GIT_THREADS 1)
152endif()
153
154if(USE_NSEC)
155 set(GIT_USE_NSEC 1)
156endif()
157
158if(HAVE_STRUCT_STAT_ST_MTIM)
159 set(GIT_USE_STAT_MTIM 1)
160elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
161 set(GIT_USE_STAT_MTIMESPEC 1)
162elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC)
163 set(GIT_USE_STAT_MTIME_NSEC 1)
164endif()
eae0bfdc 165
22a2d3d5 166target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64)
eae0bfdc
PP
167
168# Collect sourcefiles
22a2d3d5 169file(GLOB SRC_H
e579e0f7
MB
170 "${PROJECT_SOURCE_DIR}/include/git2.h"
171 "${PROJECT_SOURCE_DIR}/include/git2/*.h"
172 "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h")
22a2d3d5
UG
173list(SORT SRC_H)
174target_sources(git2internal PRIVATE ${SRC_H})
eae0bfdc
PP
175
176# On Windows use specific platform sources
22a2d3d5 177if(WIN32 AND NOT CYGWIN)
e579e0f7 178 set(WIN_RC "win32/git2.rc")
22a2d3d5
UG
179
180 file(GLOB SRC_OS win32/*.c win32/*.h)
181 list(SORT SRC_OS)
182 target_sources(git2internal PRIVATE ${SRC_OS})
183elseif(AMIGA)
184 target_compile_definitions(git2internal PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
185else()
186 file(GLOB SRC_OS unix/*.c unix/*.h)
187 list(SORT SRC_OS)
188 target_sources(git2internal PRIVATE ${SRC_OS})
189endif()
190
e579e0f7 191if(USE_LEAK_CHECKER STREQUAL "valgrind")
22a2d3d5 192 target_compile_definitions(git2internal PRIVATE VALGRIND)
e579e0f7 193endif()
22a2d3d5
UG
194
195file(GLOB SRC_GIT2 *.c *.h
196 allocators/*.c allocators/*.h
eae0bfdc
PP
197 streams/*.c streams/*.h
198 transports/*.c transports/*.h
199 xdiff/*.c xdiff/*.h)
22a2d3d5
UG
200list(SORT SRC_GIT2)
201target_sources(git2internal PRIVATE ${SRC_GIT2})
202
e579e0f7 203if(APPLE)
22a2d3d5 204 # The old Secure Transport API has been deprecated in macOS 10.15.
e579e0f7
MB
205 set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated)
206endif()
22a2d3d5
UG
207
208# the xdiff dependency is not (yet) warning-free, disable warnings as
209# errors for the xdiff sources until we've sorted them out
e579e0f7
MB
210if(MSVC)
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-)
217else()
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")
223endif()
eae0bfdc
PP
224
225# Determine architecture of the machine
e579e0f7
MB
226if(CMAKE_SIZEOF_VOID_P EQUAL 8)
227 set(GIT_ARCH_64 1)
228elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
229 set(GIT_ARCH_32 1)
230elseif(CMAKE_SIZEOF_VOID_P)
231 message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)")
232else()
233 message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
234endif()
235
236configure_file(features.h.in git2/sys/features.h)
237
238ide_split_sources(git2internal)
239list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal> ${LIBGIT2_DEPENDENCY_OBJECTS})
240
241target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include)
242target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
243
244set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
245set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
246set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE)
247set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
248set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
249set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
250
251if(XCODE_VERSION)
eae0bfdc
PP
252 # This is required for Xcode to actually link the libgit2 library
253 # when using only object libraries.
e579e0f7
MB
254 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "")
255 list(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
256endif()
eae0bfdc
PP
257
258# Compile and link libgit2
e579e0f7
MB
259add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
260target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS})
eae0bfdc 261
e579e0f7
MB
262set_target_properties(git2 PROPERTIES C_STANDARD 90)
263set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
264set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
265set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
eae0bfdc
PP
266
267# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
268# Win64+MSVC+static libs = linker error
e579e0f7
MB
269if(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
270 set_target_properties(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64")
271endif()
eae0bfdc 272
e579e0f7 273ide_split_sources(git2)
eae0bfdc 274
22a2d3d5
UG
275if(SONAME)
276 set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION})
277 set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
278 if(LIBGIT2_FILENAME)
c25aa7cd 279 target_compile_definitions(git2 PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
22a2d3d5
UG
280 set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
281 elseif(DEFINED LIBGIT2_PREFIX)
282 set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
283 endif()
284endif()
285
e579e0f7 286pkg_build_config(NAME libgit2
22a2d3d5
UG
287 VERSION ${libgit2_VERSION}
288 DESCRIPTION "The git library, take 2"
289 LIBS_SELF git2
290 PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
291 REQUIRES ${LIBGIT2_PC_REQUIRES}
292)
eae0bfdc 293
e579e0f7
MB
294if(MSVC_IDE)
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")
298endif()
eae0bfdc
PP
299
300# Install
e579e0f7 301install(TARGETS git2
22a2d3d5
UG
302 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
303 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
304 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
eae0bfdc 305)
e579e0f7
MB
306install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
307install(FILES ${PROJECT_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})