]>
Commit | Line | Data |
---|---|---|
583cf169 | 1 | # CMake build script for the libgit2 project |
73c46d53 | 2 | # |
bfe0658e | 3 | # Building (out of source build): |
73c46d53 | 4 | # > mkdir build && cd build |
bfe0658e PD |
5 | # > cmake .. [-DSETTINGS=VALUE] |
6 | # > cmake --build . | |
932d1baf | 7 | # |
73c46d53 PD |
8 | # Testing: |
9 | # > ctest -V | |
10 | # | |
11 | # Install: | |
bfe0658e | 12 | # > cmake --build . --target install |
73c46d53 | 13 | |
583cf169 | 14 | PROJECT(libgit2 C) |
37c84dc5 | 15 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) |
8f426d7d | 16 | CMAKE_POLICY(SET CMP0015 NEW) |
583cf169 | 17 | |
7a6e0281 | 18 | # Add find modules to the path |
7f0de93a | 19 | SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") |
7369b3c3 | 20 | |
5bda607c | 21 | INCLUDE(CheckLibraryExists) |
8649dfd8 | 22 | INCLUDE(CheckFunctionExists) |
ab96ca55 | 23 | INCLUDE(CheckSymbolExists) |
e9e6df2c | 24 | INCLUDE(CheckStructHasMember) |
5c8d5eac | 25 | INCLUDE(AddCFlagIfSupported) |
6e1205ef | 26 | INCLUDE(FindPkgConfig) |
5bda607c | 27 | |
19a766a2 SC |
28 | # Build options |
29 | # | |
058956ce | 30 | OPTION( SONAME "Set the (SO)VERSION of the target" ON ) |
19a766a2 | 31 | OPTION( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON ) |
79b0ae4e | 32 | OPTION( THREADSAFE "Build libgit2 as threadsafe" ON ) |
19a766a2 SC |
33 | OPTION( BUILD_CLAR "Build Tests using the Clar suite" ON ) |
34 | OPTION( BUILD_EXAMPLES "Build library usage example apps" OFF ) | |
35 | OPTION( TAGS "Generate tags" OFF ) | |
36 | OPTION( PROFILE "Generate profiling information" OFF ) | |
b5ec5430 | 37 | OPTION( ENABLE_TRACE "Enables tracing support" OFF ) |
92dac975 | 38 | OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF ) |
c1cf1af4 | 39 | |
2dfd1294 | 40 | OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF ) |
92dac975 | 41 | OPTION( USE_ICONV "Link with and use iconv library" OFF ) |
73291aff | 42 | OPTION( USE_SSH "Link with libssh to enable SSH support" ON ) |
23135afa | 43 | OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF ) |
7697e541 | 44 | OPTION( VALGRIND "Configure build for valgrind" OFF ) |
13b0b7d5 | 45 | OPTION( CURL "Use curl for HTTP if available" ON) |
ed0571f8 RD |
46 | OPTION( DEBUG_POOL "Enable debug pool allocator" OFF ) |
47 | ||
48 | IF(DEBUG_POOL) | |
49 | ADD_DEFINITIONS(-DGIT_DEBUG_POOL) | |
50 | ENDIF() | |
73291aff | 51 | |
726b75d1 | 52 | IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
92dac975 | 53 | SET( USE_ICONV ON ) |
6bb54cbf CMN |
54 | FIND_PACKAGE(Security) |
55 | FIND_PACKAGE(CoreFoundation REQUIRED) | |
92dac975 | 56 | ENDIF() |
82b2fc2c | 57 | |
19a766a2 | 58 | IF(MSVC) |
275d8d55 | 59 | # This option is only available when building with MSVC. By default, libgit2 |
e49dc687 BS |
60 | # is build using the cdecl calling convention, which is useful if you're |
61 | # writing C. However, the CLR and Win32 API both expect stdcall. | |
19a766a2 | 62 | # |
e49dc687 BS |
63 | # If you are writing a CLR program and want to link to libgit2, you'll want |
64 | # to turn this on by invoking CMake with the "-DSTDCALL=ON" argument. | |
65 | OPTION( STDCALL "Build libgit2 with the __stdcall convention" OFF ) | |
08f32085 Q |
66 | |
67 | # This option must match the settings used in your program, in particular if you | |
68 | # are linking statically | |
69 | OPTION( STATIC_CRT "Link the static CRT libraries" ON ) | |
1bfe7133 | 70 | |
01fe8374 CMN |
71 | # If you want to embed a copy of libssh2 into libgit2, pass a |
72 | # path to libssh2 | |
73 | OPTION( EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF ) | |
74 | ||
6874cafd | 75 | ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS) |
300f4412 M |
76 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) |
77 | ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE) | |
19a766a2 SC |
78 | ENDIF() |
79 | ||
6bb54cbf | 80 | |
8f426d7d PK |
81 | IF(WIN32) |
82 | # By default, libgit2 is built with WinHTTP. To use the built-in | |
83 | # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. | |
84 | OPTION( WINHTTP "Use Win32 WinHTTP routines" ON ) | |
85 | ENDIF() | |
86 | ||
d06c589f JH |
87 | IF(MSVC) |
88 | # Enable MSVC CRTDBG memory leak reporting when in debug mode. | |
89 | OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF) | |
90 | ENDIF() | |
91 | ||
6bb54cbf CMN |
92 | IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
93 | OPTION( USE_OPENSSL "Link with and use openssl library" ON ) | |
94 | ENDIF() | |
95 | ||
3d6a42d1 ET |
96 | CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h" |
97 | HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) | |
98 | CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h" | |
99 | HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) | |
100 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h | |
101 | HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) | |
102 | ||
103 | IF (HAVE_STRUCT_STAT_ST_MTIM) | |
eb11fac6 JG |
104 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h |
105 | HAVE_STRUCT_STAT_NSEC LANGUAGE C) | |
3d6a42d1 | 106 | ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) |
eb11fac6 JG |
107 | CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h |
108 | HAVE_STRUCT_STAT_NSEC LANGUAGE C) | |
3d6a42d1 ET |
109 | ELSE () |
110 | SET( HAVE_STRUCT_STAT_NSEC ON ) | |
eb11fac6 JG |
111 | ENDIF() |
112 | ||
113 | IF (HAVE_STRUCT_STAT_NSEC OR WIN32) | |
2d880712 | 114 | OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON ) |
c963fe1d | 115 | ENDIF() |
6bb54cbf | 116 | |
1ecda61e CMN |
117 | # This variable will contain the libraries we need to put into |
118 | # libgit2.pc's Requires.private. That is, what we're linking to or | |
119 | # what someone who's statically linking us needs to link to. | |
120 | SET(LIBGIT2_PC_REQUIRES "") | |
121 | # This will be set later if we use the system's http-parser library or | |
122 | # use iconv (OSX) and will be written to the Libs.private field in the | |
123 | # pc file. | |
124 | SET(LIBGIT2_PC_LIBS "") | |
125 | ||
19a766a2 SC |
126 | # Installation paths |
127 | # | |
128 | SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.") | |
129 | SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.") | |
130 | SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.") | |
131 | ||
5540d9db DL |
132 | # Set a couple variables to be substituted inside the .pc file. |
133 | # We can't just use LIB_INSTALL_DIR in the .pc file, as passing them as absolue | |
134 | # or relative paths is both valid and supported by cmake. | |
135 | SET (PKGCONFIG_PREFIX ${CMAKE_INSTALL_PREFIX}) | |
136 | ||
137 | IF(IS_ABSOLUTE ${LIB_INSTALL_DIR}) | |
138 | SET (PKGCONFIG_LIBDIR ${LIB_INSTALL_DIR}) | |
139 | ELSE(IS_ABSOLUTE ${LIB_INSTALL_DIR}) | |
140 | SET (PKGCONFIG_LIBDIR "\${prefix}/${LIB_INSTALL_DIR}") | |
141 | ENDIF (IS_ABSOLUTE ${LIB_INSTALL_DIR}) | |
142 | ||
143 | IF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) | |
144 | SET (PKGCONFIG_INCLUDEDIR ${INCLUDE_INSTALL_DIR}) | |
145 | ELSE(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) | |
146 | SET (PKGCONFIG_INCLUDEDIR "\${prefix}/${INCLUDE_INSTALL_DIR}") | |
147 | ENDIF(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) | |
148 | ||
94243295 SC |
149 | FUNCTION(TARGET_OS_LIBRARIES target) |
150 | IF(WIN32) | |
151 | TARGET_LINK_LIBRARIES(${target} ws2_32) | |
152 | ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") | |
153 | TARGET_LINK_LIBRARIES(${target} socket nsl) | |
fd2d11a1 CMN |
154 | LIST(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl") |
155 | SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE) | |
d94f5037 FR |
156 | ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Haiku") |
157 | TARGET_LINK_LIBRARIES(${target} network) | |
158 | LIST(APPEND LIBGIT2_PC_LIBS "-lnetwork") | |
159 | SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE) | |
5bda607c TM |
160 | ENDIF() |
161 | CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT) | |
162 | IF(NEED_LIBRT) | |
b176eded | 163 | TARGET_LINK_LIBRARIES(${target} rt) |
fd2d11a1 CMN |
164 | LIST(APPEND LIBGIT2_PC_LIBS "-lrt") |
165 | SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE) | |
92dac975 RB |
166 | ENDIF() |
167 | ||
94243295 SC |
168 | IF(THREADSAFE) |
169 | TARGET_LINK_LIBRARIES(${target} ${CMAKE_THREAD_LIBS_INIT}) | |
097b0761 ET |
170 | LIST(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) |
171 | SET(LIBGIT2_PC_LIBS ${LIBGIT2_PC_LIBS} PARENT_SCOPE) | |
94243295 SC |
172 | ENDIF() |
173 | ENDFUNCTION() | |
174 | ||
7208ff4d ET |
175 | # This function splits the sources files up into their appropriate |
176 | # subdirectories. This is especially useful for IDEs like Xcode and | |
177 | # Visual Studio, so that you can navigate into the libgit2_clar project, | |
178 | # and see the folders within the tests folder (instead of just seeing all | |
179 | # source and tests in a single folder.) | |
180 | FUNCTION(IDE_SPLIT_SOURCES target) | |
181 | IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) | |
523a3ae5 SC |
182 | GET_TARGET_PROPERTY(sources ${target} SOURCES) |
183 | FOREACH(source ${sources}) | |
184 | IF(source MATCHES ".*/") | |
185 | STRING(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/ "" rel ${source}) | |
186 | IF(rel) | |
187 | STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) | |
188 | IF(rel) | |
189 | STRING(REPLACE "/" "\\\\" rel ${rel}) | |
190 | SOURCE_GROUP(${rel} FILES ${source}) | |
191 | ENDIF() | |
192 | ENDIF() | |
193 | ENDIF() | |
194 | ENDFOREACH() | |
195 | ENDIF() | |
196 | ENDFUNCTION() | |
197 | ||
96fab093 | 198 | FILE(STRINGS "include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$") |
9d1dcca2 VM |
199 | |
200 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}") | |
201 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}") | |
202 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") | |
203 | SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") | |
204 | ||
99807672 CMN |
205 | FILE(STRINGS "include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$") |
206 | STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}") | |
207 | ||
7cbdaf7f | 208 | # Find required dependencies |
8d457891 | 209 | INCLUDE_DIRECTORIES(src include) |
20e83aa4 | 210 | |
6bb54cbf | 211 | IF (SECURITY_FOUND) |
b445940e CMN |
212 | # OS X 10.7 and older do not have some functions we use, fall back to OpenSSL there |
213 | CHECK_LIBRARY_EXISTS("${SECURITY_DIRS}" SSLCreateContext "Security/SecureTransport.h" HAVE_NEWER_SECURITY) | |
214 | IF (HAVE_NEWER_SECURITY) | |
215 | MESSAGE("-- Found Security ${SECURITY_DIRS}") | |
216 | LIST(APPEND LIBGIT2_PC_LIBS "-framework Security") | |
217 | ELSE() | |
218 | MESSAGE("-- Security framework is too old, falling back to OpenSSL") | |
219 | SET(SECURITY_FOUND "NO") | |
220 | SET(SECURITY_DIRS "") | |
221 | SET(SECURITY_DIR "") | |
222 | SET(USE_OPENSSL "ON") | |
223 | ENDIF() | |
6bb54cbf CMN |
224 | ENDIF() |
225 | ||
226 | IF (COREFOUNDATION_FOUND) | |
227 | MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}") | |
fd2d11a1 | 228 | LIST(APPEND LIBGIT2_PC_LIBS "-framework CoreFoundation") |
6bb54cbf CMN |
229 | ENDIF() |
230 | ||
231 | ||
01fe8374 CMN |
232 | IF (WIN32 AND EMBED_SSH_PATH) |
233 | FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c") | |
234 | INCLUDE_DIRECTORIES("${EMBED_SSH_PATH}/include") | |
235 | FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") | |
236 | ADD_DEFINITIONS(-DGIT_SSH) | |
237 | ENDIF() | |
238 | ||
236a690c ES |
239 | IF (WIN32 AND WINHTTP) |
240 | ADD_DEFINITIONS(-DGIT_WINHTTP) | |
a4de1ae3 | 241 | ADD_DEFINITIONS(-DGIT_HTTPS) |
8f426d7d PK |
242 | |
243 | # Since MinGW does not come with headers or an import library for winhttp, | |
244 | # we have to include a private header and generate our own import library | |
245 | IF (MINGW) | |
246 | FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH) | |
247 | IF (NOT DLLTOOL) | |
248 | MESSAGE(FATAL_ERROR "Could not find dlltool command") | |
249 | ENDIF () | |
250 | ||
d612e48e TK |
251 | SET(LIBWINHTTP_PATH "${CMAKE_CURRENT_BINARY_DIR}/deps/winhttp") |
252 | FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH}) | |
8f426d7d | 253 | |
0878ca9b | 254 | IF (CMAKE_SIZEOF_VOID_P EQUAL 8) |
547517d7 TK |
255 | set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp64.def") |
256 | ELSE() | |
257 | set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp.def") | |
258 | ENDIF() | |
259 | ||
8f426d7d PK |
260 | ADD_CUSTOM_COMMAND( |
261 | OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a | |
547517d7 TK |
262 | COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a |
263 | DEPENDS ${WINHTTP_DEF} | |
8f426d7d PK |
264 | WORKING_DIRECTORY ${LIBWINHTTP_PATH} |
265 | ) | |
266 | ||
267 | SET_SOURCE_FILES_PROPERTIES( | |
268 | ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c | |
269 | PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a | |
270 | ) | |
271 | ||
272 | INCLUDE_DIRECTORIES(deps/winhttp) | |
d612e48e | 273 | LINK_DIRECTORIES(${LIBWINHTTP_PATH}) |
8f426d7d PK |
274 | ENDIF () |
275 | ||
8a0133c0 AS |
276 | LINK_LIBRARIES(winhttp rpcrt4 crypt32 ole32) |
277 | LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp" "-lrpcrt4" "-lcrypt32" "-lole32") | |
3ce22c74 | 278 | ELSE () |
cf9d5f76 | 279 | IF (CURL) |
790cabf0 | 280 | PKG_CHECK_MODULES(CURL libcurl) |
cf9d5f76 CMN |
281 | ENDIF () |
282 | ||
7641327c | 283 | IF (NOT AMIGA AND USE_OPENSSL) |
c57c4af3 SB |
284 | FIND_PACKAGE(OpenSSL) |
285 | ENDIF () | |
7a6e0281 | 286 | |
cf9d5f76 CMN |
287 | IF (CURL_FOUND) |
288 | ADD_DEFINITIONS(-DGIT_CURL) | |
289 | INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) | |
528b2f7d | 290 | LINK_DIRECTORIES(${CURL_LIBRARY_DIRS}) |
cf9d5f76 | 291 | LINK_LIBRARIES(${CURL_LIBRARIES}) |
fd2d11a1 | 292 | LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS}) |
cf9d5f76 | 293 | ENDIF() |
3ce22c74 | 294 | ENDIF() |
20e83aa4 | 295 | |
c3f7a938 | 296 | # Specify sha1 implementation |
2dfd1294 ET |
297 | IF (USE_SHA1DC) |
298 | ADD_DEFINITIONS(-DGIT_SHA1_COLLISIONDETECT) | |
db1abffa PS |
299 | ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1) |
300 | ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") | |
301 | ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") | |
2dfd1294 | 302 | FILE(GLOB SRC_SHA1 src/hash/hash_collisiondetect.c src/hash/sha1dc/*) |
9f128d2a | 303 | ELSEIF (WIN32 AND NOT MINGW) |
a371a8ae | 304 | ADD_DEFINITIONS(-DGIT_SHA1_WIN32) |
ccf1a2ba | 305 | FILE(GLOB SRC_SHA1 src/hash/hash_win32.c) |
2d2aa1ff | 306 | ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
a371a8ae | 307 | ADD_DEFINITIONS(-DGIT_SHA1_COMMON_CRYPTO) |
9f128d2a | 308 | ELSEIF (OPENSSL_FOUND) |
a371a8ae | 309 | ADD_DEFINITIONS(-DGIT_SHA1_OPENSSL) |
096ac799 | 310 | IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") |
fd2d11a1 | 311 | LIST(APPEND LIBGIT2_PC_LIBS "-lssl") |
096ac799 TWL |
312 | ELSE() |
313 | SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl") | |
314 | ENDIF () | |
d6fb0924 ET |
315 | ELSE() |
316 | FILE(GLOB SRC_SHA1 src/hash/hash_generic.c) | |
c3f7a938 CY |
317 | ENDIF() |
318 | ||
b5ec5430 ET |
319 | # Enable tracing |
320 | IF (ENABLE_TRACE STREQUAL "ON") | |
321 | ADD_DEFINITIONS(-DGIT_TRACE) | |
322 | ENDIF() | |
323 | ||
3d007f4f | 324 | # Include POSIX regex when it is required |
57aa839c | 325 | IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") |
c17b1d00 CMN |
326 | INCLUDE_DIRECTORIES(deps/regex) |
327 | SET(SRC_REGEX deps/regex/regex.c) | |
1f4f4d17 | 328 | ENDIF() |
f443a879 | 329 | |
e56e4c76 ES |
330 | # Optional external dependency: http-parser |
331 | FIND_PACKAGE(HTTP_Parser) | |
332 | IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) | |
333 | INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS}) | |
334 | LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES}) | |
335 | LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") | |
336 | ELSE() | |
337 | MESSAGE(STATUS "http-parser version 2 was not found; using bundled 3rd-party sources.") | |
338 | INCLUDE_DIRECTORIES(deps/http-parser) | |
339 | FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h) | |
340 | ENDIF() | |
341 | ||
b53671ae | 342 | # Optional external dependency: zlib |
04739e9f | 343 | FIND_PACKAGE(ZLIB) |
1f4f4d17 TH |
344 | IF (ZLIB_FOUND) |
345 | INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) | |
346 | LINK_LIBRARIES(${ZLIB_LIBRARIES}) | |
096ac799 | 347 | IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") |
fd2d11a1 | 348 | LIST(APPEND LIBGIT2_PC_LIBS "-lz") |
474c8cf8 CMN |
349 | ELSE() |
350 | SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib") | |
351 | ENDIF() | |
c41281ad | 352 | ELSE() |
86f92b74 | 353 | MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." ) |
1f4f4d17 TH |
354 | INCLUDE_DIRECTORIES(deps/zlib) |
355 | ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) | |
cdacd3d9 | 356 | FILE(GLOB SRC_ZLIB deps/zlib/*.c deps/zlib/*.h) |
c9f79972 | 357 | ENDIF() |
f443a879 | 358 | |
726b75d1 | 359 | # Optional external dependency: libssh2 |
f5fc63bc | 360 | IF (USE_SSH) |
4f91bfa3 | 361 | PKG_CHECK_MODULES(LIBSSH2 libssh2) |
5be622fb | 362 | ENDIF() |
7369b3c3 BM |
363 | IF (LIBSSH2_FOUND) |
364 | ADD_DEFINITIONS(-DGIT_SSH) | |
461fd5a0 RKC |
365 | INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS}) |
366 | LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS}) | |
fd2d11a1 CMN |
367 | LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) |
368 | #SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}") | |
7369b3c3 | 369 | SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES}) |
1679ec12 | 370 | |
c27b4afc | 371 | CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) |
1679ec12 MG |
372 | IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS) |
373 | ADD_DEFINITIONS(-DGIT_SSH_MEMORY_CREDENTIALS) | |
374 | ENDIF() | |
e15a0849 YK |
375 | ELSE() |
376 | MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") | |
7369b3c3 BM |
377 | ENDIF() |
378 | ||
315cb38e ET |
379 | # Optional external dependency: libgssapi |
380 | IF (USE_GSSAPI) | |
381 | FIND_PACKAGE(GSSAPI) | |
382 | ENDIF() | |
383 | IF (GSSAPI_FOUND) | |
384 | ADD_DEFINITIONS(-DGIT_GSSAPI) | |
385 | ENDIF() | |
386 | ||
726b75d1 RB |
387 | # Optional external dependency: iconv |
388 | IF (USE_ICONV) | |
6bcb0987 | 389 | FIND_PACKAGE(Iconv) |
726b75d1 RB |
390 | ENDIF() |
391 | IF (ICONV_FOUND) | |
392 | ADD_DEFINITIONS(-DGIT_USE_ICONV) | |
6e0ff093 | 393 | INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) |
fd2d11a1 | 394 | LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES}) |
726b75d1 | 395 | ENDIF() |
d10de8bd | 396 | |
502dd2da | 397 | # Platform specific compilation flags |
dcd62cb2 | 398 | IF (MSVC) |
dcd62cb2 | 399 | |
ccf1a2ba | 400 | STRING(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
94155e2f | 401 | |
19be3f9e PK |
402 | # /GF - String pooling |
403 | # /MP - Parallel build | |
404 | SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") | |
405 | ||
1b5078f6 | 406 | IF (STDCALL) |
19be3f9e PK |
407 | # /Gz - stdcall calling convention |
408 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz") | |
1b5078f6 | 409 | ENDIF () |
19be3f9e | 410 | |
08f32085 Q |
411 | IF (STATIC_CRT) |
412 | SET(CRT_FLAG_DEBUG "/MTd") | |
413 | SET(CRT_FLAG_RELEASE "/MT") | |
414 | ELSE() | |
ccf1a2ba | 415 | SET(CRT_FLAG_DEBUG "/MDd") |
08f32085 Q |
416 | SET(CRT_FLAG_RELEASE "/MD") |
417 | ENDIF() | |
418 | ||
d06c589f JH |
419 | IF (MSVC_CRTDBG) |
420 | SET(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} /DGIT_MSVC_CRTDBG") | |
93b42728 | 421 | SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES}" "Dbghelp.lib") |
d06c589f JH |
422 | ENDIF() |
423 | ||
19be3f9e PK |
424 | # /Zi - Create debugging information |
425 | # /Od - Disable optimization | |
426 | # /D_DEBUG - #define _DEBUG | |
427 | # /MTd - Statically link the multithreaded debug version of the CRT | |
08f32085 | 428 | # /MDd - Dynamically link the multithreaded debug version of the CRT |
19be3f9e | 429 | # /RTC1 - Run time checks |
08f030ce | 430 | SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") |
19be3f9e | 431 | |
69c28b75 | 432 | # /DNDEBUG - Disables asserts |
19be3f9e | 433 | # /MT - Statically link the multithreaded release version of the CRT |
08f32085 | 434 | # /MD - Dynamically link the multithreaded release version of the CRT |
19be3f9e PK |
435 | # /O2 - Optimize for speed |
436 | # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) | |
437 | # /GL - Link time code generation (whole program optimization) | |
438 | # /Gy - Function-level linking | |
08f32085 | 439 | SET(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
440 | |
441 | # /Oy- - Disable frame pointer omission (FPO) | |
08f32085 | 442 | SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
443 | |
444 | # /O1 - Optimize for size | |
08f32085 | 445 | SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
446 | |
447 | # /DYNAMICBASE - Address space load randomization (ASLR) | |
448 | # /NXCOMPAT - Data execution prevention (DEP) | |
449 | # /LARGEADDRESSAWARE - >2GB user address space on x86 | |
450 | # /VERSION - Embed version information in PE header | |
451 | SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}") | |
452 | ||
453 | # /DEBUG - Create a PDB | |
454 | # /LTCG - Link time code generation (whole program optimization) | |
455 | # /OPT:REF /OPT:ICF - Fold out duplicate code at link step | |
456 | # /INCREMENTAL:NO - Required to use /LTCG | |
457 | # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) | |
458 | SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") | |
459 | SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
460 | SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") | |
461 | SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
462 | ||
463 | # Same linker settings for DLL as EXE | |
464 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") | |
465 | SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") | |
466 | SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") | |
467 | SET(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") | |
468 | SET(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") | |
469 | ||
502dd2da | 470 | SET(WIN_RC "src/win32/git2.rc") |
e233fa6f | 471 | ELSE () |
a02e8a38 PS |
472 | SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") |
473 | ||
474 | ADD_C_FLAG_IF_SUPPORTED(-Wall) | |
475 | ADD_C_FLAG_IF_SUPPORTED(-Wextra) | |
19be3f9e | 476 | |
98b8fcff JG |
477 | IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") |
478 | SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") | |
479 | ENDIF() | |
480 | ||
61399953 | 481 | SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") |
19be3f9e | 482 | |
b6a2fd0e | 483 | IF (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to |
2eb18449 | 484 | STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") |
b41e24a6 | 485 | ELSEIF (BUILD_SHARED_LIBS) |
5c8d5eac | 486 | ADD_C_FLAG_IF_SUPPORTED(-fvisibility=hidden) |
c6cd3f8b JG |
487 | |
488 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | |
39cdf272 | 489 | ENDIF () |
c6cd3f8b | 490 | |
b6a2fd0e PS |
491 | IF (MINGW) |
492 | # MinGW >= 3.14 uses the C99-style stdio functions | |
493 | # automatically, but forks like mingw-w64 still want | |
494 | # us to define this in order to use them | |
495 | ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1) | |
496 | ENDIF () | |
497 | ||
2da64edb | 498 | ADD_C_FLAG_IF_SUPPORTED(-Wdocumentation) |
5c8d5eac JG |
499 | ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers) |
500 | ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2) | |
501 | ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes) | |
502 | ADD_C_FLAG_IF_SUPPORTED(-Wdeclaration-after-statement) | |
503 | ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable) | |
504 | ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function) | |
c6cd3f8b | 505 | |
364ef528 | 506 | IF (APPLE) # Apple deprecated OpenSSL |
5c8d5eac | 507 | ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations) |
c6cd3f8b | 508 | ENDIF() |
823c0e9c | 509 | |
706a9974 RB |
510 | IF (PROFILE) |
511 | SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}") | |
512 | SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}") | |
513 | ENDIF () | |
90412507 | 514 | ENDIF() |
5b8bb8e7 | 515 | |
36117978 | 516 | CHECK_SYMBOL_EXISTS(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L) |
ab96ca55 AS |
517 | IF (HAVE_REGCOMP_L) |
518 | ADD_DEFINITIONS(-DHAVE_REGCOMP_L) | |
519 | ENDIF () | |
520 | ||
e683d152 ET |
521 | CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) |
522 | IF (HAVE_FUTIMENS) | |
523 | ADD_DEFINITIONS(-DHAVE_FUTIMENS) | |
524 | ENDIF () | |
525 | ||
526 | CHECK_FUNCTION_EXISTS(qsort_r HAVE_QSORT_R) | |
527 | IF (HAVE_QSORT_R) | |
528 | ADD_DEFINITIONS(-DHAVE_QSORT_R) | |
529 | ENDIF () | |
530 | ||
531 | CHECK_FUNCTION_EXISTS(qsort_s HAVE_QSORT_S) | |
532 | IF (HAVE_QSORT_S) | |
533 | ADD_DEFINITIONS(-DHAVE_QSORT_S) | |
534 | ENDIF () | |
535 | ||
88149fae PT |
536 | IF( NOT CMAKE_CONFIGURATION_TYPES ) |
537 | # Build Debug by default | |
538 | IF (NOT CMAKE_BUILD_TYPE) | |
539 | SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) | |
540 | ENDIF () | |
541 | ELSE() | |
542 | # Using a multi-configuration generator eg MSVC or Xcode | |
543 | # that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE | |
544 | ENDIF() | |
583cf169 | 545 | |
6bb54cbf CMN |
546 | IF (SECURITY_FOUND) |
547 | ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT) | |
a4de1ae3 | 548 | ADD_DEFINITIONS(-DGIT_HTTPS) |
6bb54cbf CMN |
549 | INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR}) |
550 | ENDIF () | |
551 | ||
96ef3d84 | 552 | IF (OPENSSL_FOUND) |
24e53d2f | 553 | ADD_DEFINITIONS(-DGIT_OPENSSL) |
a4de1ae3 | 554 | ADD_DEFINITIONS(-DGIT_HTTPS) |
96ef3d84 CY |
555 | INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) |
556 | SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) | |
41cbbea8 | 557 | ENDIF() |
66024c7c | 558 | |
6bb54cbf CMN |
559 | |
560 | ||
70236bab VM |
561 | IF (THREADSAFE) |
562 | IF (NOT WIN32) | |
48ce93e0 | 563 | FIND_PACKAGE(Threads REQUIRED) |
70236bab VM |
564 | ENDIF() |
565 | ||
566 | ADD_DEFINITIONS(-DGIT_THREADS) | |
567 | ENDIF() | |
568 | ||
e7de893e AR |
569 | IF (USE_NSEC) |
570 | ADD_DEFINITIONS(-DGIT_USE_NSEC) | |
571 | ENDIF() | |
572 | ||
3d6a42d1 ET |
573 | IF (HAVE_STRUCT_STAT_ST_MTIM) |
574 | ADD_DEFINITIONS(-DGIT_USE_STAT_MTIM) | |
575 | ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) | |
576 | ADD_DEFINITIONS(-DGIT_USE_STAT_MTIMESPEC) | |
577 | ELSEIF (HAVE_STRUCT_STAT_ST_MTIME_NSEC) | |
578 | ADD_DEFINITIONS(-DGIT_USE_STAT_MTIME_NSEC) | |
eb11fac6 JG |
579 | ENDIF() |
580 | ||
678e9e04 VM |
581 | ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) |
582 | ||
583cf169 | 583 | # Collect sourcefiles |
cdacd3d9 | 584 | FILE(GLOB SRC_H include/git2.h include/git2/*.h include/git2/sys/*.h) |
583cf169 PD |
585 | |
586 | # On Windows use specific platform sources | |
5b8bb8e7 | 587 | IF (WIN32 AND NOT CYGWIN) |
19be3f9e | 588 | ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501) |
cdacd3d9 | 589 | FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h) |
96ef3d84 | 590 | ELSEIF (AMIGA) |
7697e541 | 591 | ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP) |
678e9e04 | 592 | ELSE() |
7697e541 RB |
593 | IF (VALGRIND) |
594 | ADD_DEFINITIONS(-DNO_MMAP) | |
595 | ENDIF() | |
cdacd3d9 | 596 | FILE(GLOB SRC_OS src/unix/*.c src/unix/*.h) |
521479b1 | 597 | ENDIF() |
cdacd3d9 | 598 | FILE(GLOB SRC_GIT2 src/*.c src/*.h src/transports/*.c src/transports/*.h src/xdiff/*.c src/xdiff/*.h) |
5b8bb8e7 | 599 | |
eb63fda2 ET |
600 | # Determine architecture of the machine |
601 | IF (CMAKE_SIZEOF_VOID_P EQUAL 8) | |
602 | ADD_DEFINITIONS(-DGIT_ARCH_64) | |
603 | ELSEIF (CMAKE_SIZEOF_VOID_P EQUAL 4) | |
604 | ADD_DEFINITIONS(-DGIT_ARCH_32) | |
035430b7 | 605 | ELSEIF (CMAKE_SIZEOF_VOID_P) |
f9601e6f | 606 | MESSAGE(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)") |
035430b7 SS |
607 | ELSE() |
608 | MESSAGE(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)") | |
eb63fda2 ET |
609 | ENDIF() |
610 | ||
583cf169 | 611 | # Compile and link libgit2 |
01fe8374 | 612 | ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1} ${WIN_RC}) |
6bb54cbf CMN |
613 | TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS}) |
614 | TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS}) | |
94243295 | 615 | TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES}) |
7369b3c3 | 616 | TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES}) |
315cb38e | 617 | TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES}) |
726b75d1 | 618 | TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES}) |
94243295 | 619 | TARGET_OS_LIBRARIES(git2) |
39cdf272 | 620 | |
d66a7c06 Q |
621 | # Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) |
622 | # Win64+MSVC+static libs = linker error | |
ac1d85cf | 623 | IF(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS) |
d66a7c06 Q |
624 | SET_TARGET_PROPERTIES(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64") |
625 | ENDIF() | |
626 | ||
7208ff4d | 627 | IDE_SPLIT_SOURCES(git2) |
523a3ae5 | 628 | |
e7da9acd NO |
629 | IF (SONAME) |
630 | SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING}) | |
99807672 | 631 | SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION}) |
c1cf1af4 | 632 | IF (LIBGIT2_FILENAME) |
633 | ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") | |
634 | SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) | |
059f33bf MS |
635 | ELSEIF (DEFINED LIBGIT2_PREFIX) |
636 | SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}") | |
3bbc87d6 | 637 | ENDIF() |
e7da9acd | 638 | ENDIF() |
fd2d11a1 | 639 | STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}") |
4fd486e0 | 640 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY) |
583cf169 | 641 | |
26d9e317 | 642 | IF (MSVC_IDE) |
73aaf674 BS |
643 | # Precompiled headers |
644 | SET_TARGET_PROPERTIES(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") | |
645 | SET_SOURCE_FILES_PROPERTIES(src/win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") | |
646 | ENDIF () | |
647 | ||
583cf169 | 648 | # Install |
932d1baf | 649 | INSTALL(TARGETS git2 |
9795a40f | 650 | RUNTIME DESTINATION ${BIN_INSTALL_DIR} |
b3237ac3 ICQ |
651 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
652 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} | |
583cf169 | 653 | ) |
b3237ac3 | 654 | INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig ) |
9795a40f VP |
655 | INSTALL(DIRECTORY include/git2 DESTINATION ${INCLUDE_INSTALL_DIR} ) |
656 | INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} ) | |
583cf169 PD |
657 | |
658 | # Tests | |
3fd1520c | 659 | IF (BUILD_CLAR) |
e3f94c71 CMN |
660 | FIND_PACKAGE(PythonInterp) |
661 | ||
662 | IF(NOT PYTHONINTERP_FOUND) | |
663 | MESSAGE(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. " | |
664 | "Make sure python is available, or pass -DBUILD_CLAR=OFF to skip building the tests") | |
665 | ENDIF() | |
86a459a8 | 666 | |
83e1efbf BS |
667 | SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/") |
668 | SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests") | |
669 | SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.") | |
3fd1520c | 670 | ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") |
e0799b6c | 671 | ADD_DEFINITIONS(-DCLAR_RESOURCES=\"${TEST_RESOURCES}\") |
29eed1c7 | 672 | ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\") |
11385c3c | 673 | |
3fd1520c | 674 | INCLUDE_DIRECTORIES(${CLAR_PATH}) |
cdacd3d9 | 675 | FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h) |
9a859ef5 | 676 | SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c") |
f1558d9b | 677 | |
86a459a8 | 678 | ADD_CUSTOM_COMMAND( |
156cfec0 | 679 | OUTPUT ${CLAR_PATH}/clar.suite |
e8242022 | 680 | COMMAND ${PYTHON_EXECUTABLE} generate.py -f -xonline -xstress . |
39444bea | 681 | DEPENDS ${SRC_TEST} |
3fd1520c | 682 | WORKING_DIRECTORY ${CLAR_PATH} |
86a459a8 | 683 | ) |
156cfec0 | 684 | |
5c2d3f6d | 685 | SET_SOURCE_FILES_PROPERTIES( |
2e6f06a8 | 686 | ${CLAR_PATH}/clar.c |
5c2d3f6d VM |
687 | PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite) |
688 | ||
01fe8374 | 689 | ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1}) |
5c2d3f6d | 690 | |
6bb54cbf CMN |
691 | TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS}) |
692 | TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS}) | |
94243295 | 693 | TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES}) |
7369b3c3 | 694 | TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES}) |
315cb38e | 695 | TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES}) |
726b75d1 | 696 | TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES}) |
94243295 | 697 | TARGET_OS_LIBRARIES(libgit2_clar) |
7208ff4d | 698 | IDE_SPLIT_SOURCES(libgit2_clar) |
73aaf674 | 699 | |
156cfec0 VM |
700 | IF (MSVC_IDE) |
701 | # Precompiled headers | |
702 | SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") | |
703 | ENDIF () | |
73aaf674 | 704 | |
f1558d9b | 705 | ENABLE_TESTING() |
6bb54cbf | 706 | IF (WINHTTP OR OPENSSL_FOUND OR SECURITY_FOUND) |
f218508f | 707 | ADD_TEST(libgit2_clar libgit2_clar -ionline -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style) |
06353282 | 708 | ELSE () |
f218508f | 709 | ADD_TEST(libgit2_clar libgit2_clar -v -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style) |
06353282 | 710 | ENDIF () |
ba9bb664 CMN |
711 | |
712 | # Add a test target which runs the cred callback tests, to be | |
713 | # called after setting the url and user | |
714 | ADD_TEST(libgit2_clar-cred_callback libgit2_clar -v -sonline::clone::cred_callback) | |
b8353236 CMN |
715 | ADD_TEST(libgit2_clar-proxy_credentials_in_url libgit2_clar -v -sonline::clone::proxy_credentials_in_url) |
716 | ADD_TEST(libgit2_clar-proxy_credentials_request libgit2_clar -v -sonline::clone::proxy_credentials_request) | |
f1558d9b | 717 | ENDIF () |
e632f687 CB |
718 | |
719 | IF (TAGS) | |
720 | FIND_PROGRAM(CTAGS ctags) | |
721 | IF (NOT CTAGS) | |
48ce93e0 | 722 | MESSAGE(FATAL_ERROR "Could not find ctags command") |
e632f687 CB |
723 | ENDIF () |
724 | ||
725 | FILE(GLOB_RECURSE SRC_ALL *.[ch]) | |
726 | ||
727 | ADD_CUSTOM_COMMAND( | |
728 | OUTPUT tags | |
729 | COMMAND ${CTAGS} -a ${SRC_ALL} | |
730 | DEPENDS ${SRC_ALL} | |
731 | ) | |
732 | ADD_CUSTOM_TARGET( | |
733 | do_tags ALL | |
734 | DEPENDS tags | |
735 | ) | |
736 | ENDIF () | |
62986ff6 SG |
737 | |
738 | IF (BUILD_EXAMPLES) | |
60ee53df | 739 | ADD_SUBDIRECTORY(examples) |
583cf169 | 740 | ENDIF () |