]>
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 PD |
14 | PROJECT(libgit2 C) |
15 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | |
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) |
5c8d5eac | 22 | INCLUDE(AddCFlagIfSupported) |
6e1205ef | 23 | INCLUDE(FindPkgConfig) |
5bda607c | 24 | |
19a766a2 SC |
25 | # Build options |
26 | # | |
058956ce | 27 | OPTION( SONAME "Set the (SO)VERSION of the target" ON ) |
19a766a2 | 28 | OPTION( BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON ) |
79b0ae4e | 29 | OPTION( THREADSAFE "Build libgit2 as threadsafe" ON ) |
19a766a2 SC |
30 | OPTION( BUILD_CLAR "Build Tests using the Clar suite" ON ) |
31 | OPTION( BUILD_EXAMPLES "Build library usage example apps" OFF ) | |
32 | OPTION( TAGS "Generate tags" OFF ) | |
33 | OPTION( PROFILE "Generate profiling information" OFF ) | |
b5ec5430 | 34 | OPTION( ENABLE_TRACE "Enables tracing support" OFF ) |
92dac975 | 35 | OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF ) |
c1cf1af4 | 36 | |
92dac975 | 37 | OPTION( USE_ICONV "Link with and use iconv library" OFF ) |
73291aff | 38 | OPTION( USE_SSH "Link with libssh to enable SSH support" ON ) |
23135afa | 39 | OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF ) |
7697e541 | 40 | OPTION( VALGRIND "Configure build for valgrind" OFF ) |
cf9d5f76 | 41 | OPTION( CURL "User curl for HTTP if available" ON) |
73291aff | 42 | |
726b75d1 | 43 | IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
92dac975 | 44 | SET( USE_ICONV ON ) |
6bb54cbf CMN |
45 | FIND_PACKAGE(Security) |
46 | FIND_PACKAGE(CoreFoundation REQUIRED) | |
92dac975 | 47 | ENDIF() |
82b2fc2c | 48 | |
19a766a2 | 49 | IF(MSVC) |
275d8d55 | 50 | # This option is only available when building with MSVC. By default, libgit2 |
e49dc687 BS |
51 | # is build using the cdecl calling convention, which is useful if you're |
52 | # writing C. However, the CLR and Win32 API both expect stdcall. | |
19a766a2 | 53 | # |
e49dc687 BS |
54 | # If you are writing a CLR program and want to link to libgit2, you'll want |
55 | # to turn this on by invoking CMake with the "-DSTDCALL=ON" argument. | |
56 | OPTION( STDCALL "Build libgit2 with the __stdcall convention" OFF ) | |
08f32085 Q |
57 | |
58 | # This option must match the settings used in your program, in particular if you | |
59 | # are linking statically | |
60 | OPTION( STATIC_CRT "Link the static CRT libraries" ON ) | |
1bfe7133 | 61 | |
6874cafd | 62 | ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS) |
300f4412 M |
63 | ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) |
64 | ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE) | |
19a766a2 SC |
65 | ENDIF() |
66 | ||
6bb54cbf | 67 | |
8f426d7d PK |
68 | IF(WIN32) |
69 | # By default, libgit2 is built with WinHTTP. To use the built-in | |
70 | # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. | |
71 | OPTION( WINHTTP "Use Win32 WinHTTP routines" ON ) | |
72 | ENDIF() | |
73 | ||
d06c589f JH |
74 | IF(MSVC) |
75 | # Enable MSVC CRTDBG memory leak reporting when in debug mode. | |
76 | OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF) | |
77 | ENDIF() | |
78 | ||
6bb54cbf CMN |
79 | IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
80 | OPTION( USE_OPENSSL "Link with and use openssl library" ON ) | |
81 | ENDIF() | |
82 | ||
1ecda61e CMN |
83 | # This variable will contain the libraries we need to put into |
84 | # libgit2.pc's Requires.private. That is, what we're linking to or | |
85 | # what someone who's statically linking us needs to link to. | |
86 | SET(LIBGIT2_PC_REQUIRES "") | |
87 | # This will be set later if we use the system's http-parser library or | |
88 | # use iconv (OSX) and will be written to the Libs.private field in the | |
89 | # pc file. | |
90 | SET(LIBGIT2_PC_LIBS "") | |
91 | ||
19a766a2 SC |
92 | # Installation paths |
93 | # | |
94 | SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.") | |
95 | SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.") | |
96 | SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.") | |
97 | ||
94243295 SC |
98 | FUNCTION(TARGET_OS_LIBRARIES target) |
99 | IF(WIN32) | |
100 | TARGET_LINK_LIBRARIES(${target} ws2_32) | |
101 | ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") | |
102 | TARGET_LINK_LIBRARIES(${target} socket nsl) | |
474c8cf8 | 103 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lsocket -lnsl" PARENT_SCOPE) |
5bda607c TM |
104 | ENDIF() |
105 | CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" NEED_LIBRT) | |
106 | IF(NEED_LIBRT) | |
b176eded | 107 | TARGET_LINK_LIBRARIES(${target} rt) |
474c8cf8 | 108 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE) |
92dac975 RB |
109 | ENDIF() |
110 | ||
94243295 SC |
111 | IF(THREADSAFE) |
112 | TARGET_LINK_LIBRARIES(${target} ${CMAKE_THREAD_LIBS_INIT}) | |
113 | ENDIF() | |
114 | ENDFUNCTION() | |
115 | ||
d335e73a ET |
116 | # For the MSVC IDE, this function splits up the source files like windows |
117 | # explorer does. This is esp. useful with the libgit2_clar project, were | |
118 | # usually 2 or more files share the same name. Sadly, this file grouping | |
119 | # is a per-directory option in cmake and not per-target, resulting in | |
83e1efbf | 120 | # empty virtual folders "tests" for the git2.dll |
523a3ae5 SC |
121 | FUNCTION(MSVC_SPLIT_SOURCES target) |
122 | IF(MSVC_IDE) | |
123 | GET_TARGET_PROPERTY(sources ${target} SOURCES) | |
124 | FOREACH(source ${sources}) | |
125 | IF(source MATCHES ".*/") | |
126 | STRING(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/ "" rel ${source}) | |
127 | IF(rel) | |
128 | STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) | |
129 | IF(rel) | |
130 | STRING(REPLACE "/" "\\\\" rel ${rel}) | |
131 | SOURCE_GROUP(${rel} FILES ${source}) | |
132 | ENDIF() | |
133 | ENDIF() | |
134 | ENDIF() | |
135 | ENDFOREACH() | |
136 | ENDIF() | |
137 | ENDFUNCTION() | |
138 | ||
96fab093 | 139 | FILE(STRINGS "include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$") |
9d1dcca2 VM |
140 | |
141 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}") | |
142 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}") | |
143 | STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") | |
144 | SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") | |
145 | ||
99807672 CMN |
146 | FILE(STRINGS "include/git2/version.h" GIT2_HEADER_SOVERSION REGEX "^#define LIBGIT2_SOVERSION [0-9]+$") |
147 | STRING(REGEX REPLACE "^.*LIBGIT2_SOVERSION ([0-9]+)$" "\\1" LIBGIT2_SOVERSION "${GIT2_HEADER_SOVERSION}") | |
148 | ||
7cbdaf7f | 149 | # Find required dependencies |
8d457891 | 150 | INCLUDE_DIRECTORIES(src include) |
20e83aa4 | 151 | |
6bb54cbf CMN |
152 | IF (SECURITY_FOUND) |
153 | MESSAGE("-- Found Security ${SECURITY_DIRS}") | |
7a5c7559 | 154 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -framework Security") |
6bb54cbf CMN |
155 | ENDIF() |
156 | ||
157 | IF (COREFOUNDATION_FOUND) | |
158 | MESSAGE("-- Found CoreFoundation ${COREFOUNDATION_DIRS}") | |
7a5c7559 | 159 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -framework CoreFoundation") |
6bb54cbf CMN |
160 | ENDIF() |
161 | ||
162 | ||
8f426d7d | 163 | IF (WIN32 AND WINHTTP) |
3ce22c74 | 164 | ADD_DEFINITIONS(-DGIT_WINHTTP) |
2d1feaa2 BS |
165 | INCLUDE_DIRECTORIES(deps/http-parser) |
166 | FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h) | |
8f426d7d PK |
167 | |
168 | # Since MinGW does not come with headers or an import library for winhttp, | |
169 | # we have to include a private header and generate our own import library | |
170 | IF (MINGW) | |
171 | FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH) | |
172 | IF (NOT DLLTOOL) | |
173 | MESSAGE(FATAL_ERROR "Could not find dlltool command") | |
174 | ENDIF () | |
175 | ||
d612e48e TK |
176 | SET(LIBWINHTTP_PATH "${CMAKE_CURRENT_BINARY_DIR}/deps/winhttp") |
177 | FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH}) | |
8f426d7d | 178 | |
547517d7 TK |
179 | IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") |
180 | set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp64.def") | |
181 | ELSE() | |
182 | set(WINHTTP_DEF "${CMAKE_CURRENT_SOURCE_DIR}/deps/winhttp/winhttp.def") | |
183 | ENDIF() | |
184 | ||
8f426d7d PK |
185 | ADD_CUSTOM_COMMAND( |
186 | OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a | |
547517d7 TK |
187 | COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a |
188 | DEPENDS ${WINHTTP_DEF} | |
8f426d7d PK |
189 | WORKING_DIRECTORY ${LIBWINHTTP_PATH} |
190 | ) | |
191 | ||
192 | SET_SOURCE_FILES_PROPERTIES( | |
193 | ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c | |
194 | PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a | |
195 | ) | |
196 | ||
197 | INCLUDE_DIRECTORIES(deps/winhttp) | |
d612e48e | 198 | LINK_DIRECTORIES(${LIBWINHTTP_PATH}) |
8f426d7d PK |
199 | ENDIF () |
200 | ||
b631e0d9 | 201 | LINK_LIBRARIES(winhttp rpcrt4 crypt32) |
3ce22c74 | 202 | ELSE () |
cf9d5f76 | 203 | IF (CURL) |
790cabf0 | 204 | PKG_CHECK_MODULES(CURL libcurl) |
cf9d5f76 CMN |
205 | ENDIF () |
206 | ||
7641327c | 207 | IF (NOT AMIGA AND USE_OPENSSL) |
c57c4af3 SB |
208 | FIND_PACKAGE(OpenSSL) |
209 | ENDIF () | |
7a6e0281 | 210 | |
cf9d5f76 CMN |
211 | IF (CURL_FOUND) |
212 | ADD_DEFINITIONS(-DGIT_CURL) | |
213 | INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) | |
214 | LINK_LIBRARIES(${CURL_LIBRARIES}) | |
790cabf0 | 215 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${CURL_LDFLAGS}") |
cf9d5f76 CMN |
216 | ENDIF() |
217 | ||
04739e9f | 218 | FIND_PACKAGE(HTTP_Parser) |
7a6e0281 VP |
219 | IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) |
220 | INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS}) | |
221 | LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES}) | |
1ecda61e | 222 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lhttp_parser") |
7a6e0281 | 223 | ELSE() |
86f92b74 | 224 | MESSAGE(STATUS "http-parser was not found or is too old; using bundled 3rd-party sources.") |
7a6e0281 | 225 | INCLUDE_DIRECTORIES(deps/http-parser) |
cdacd3d9 | 226 | FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h) |
7a6e0281 | 227 | ENDIF() |
3ce22c74 | 228 | ENDIF() |
20e83aa4 | 229 | |
c3f7a938 | 230 | # Specify sha1 implementation |
8f09f464 | 231 | IF (WIN32 AND NOT MINGW AND NOT SHA1_TYPE STREQUAL "builtin") |
ccf1a2ba | 232 | ADD_DEFINITIONS(-DWIN32_SHA1) |
233 | FILE(GLOB SRC_SHA1 src/hash/hash_win32.c) | |
2d2aa1ff LY |
234 | ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
235 | ADD_DEFINITIONS(-DGIT_COMMON_CRYPTO) | |
d6fb0924 ET |
236 | ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin") |
237 | ADD_DEFINITIONS(-DOPENSSL_SHA1) | |
096ac799 TWL |
238 | IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") |
239 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lssl") | |
240 | ELSE() | |
241 | SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl") | |
242 | ENDIF () | |
d6fb0924 ET |
243 | ELSE() |
244 | FILE(GLOB SRC_SHA1 src/hash/hash_generic.c) | |
c3f7a938 CY |
245 | ENDIF() |
246 | ||
b5ec5430 ET |
247 | # Enable tracing |
248 | IF (ENABLE_TRACE STREQUAL "ON") | |
249 | ADD_DEFINITIONS(-DGIT_TRACE) | |
250 | ENDIF() | |
251 | ||
3d007f4f | 252 | # Include POSIX regex when it is required |
57aa839c | 253 | IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") |
c17b1d00 CMN |
254 | INCLUDE_DIRECTORIES(deps/regex) |
255 | SET(SRC_REGEX deps/regex/regex.c) | |
1f4f4d17 | 256 | ENDIF() |
f443a879 | 257 | |
b53671ae | 258 | # Optional external dependency: zlib |
04739e9f | 259 | FIND_PACKAGE(ZLIB) |
1f4f4d17 TH |
260 | IF (ZLIB_FOUND) |
261 | INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) | |
262 | LINK_LIBRARIES(${ZLIB_LIBRARIES}) | |
096ac799 | 263 | IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") |
474c8cf8 CMN |
264 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lz") |
265 | ELSE() | |
266 | SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib") | |
267 | ENDIF() | |
c41281ad | 268 | ELSE() |
86f92b74 | 269 | MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." ) |
1f4f4d17 TH |
270 | INCLUDE_DIRECTORIES(deps/zlib) |
271 | ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) | |
cdacd3d9 | 272 | FILE(GLOB SRC_ZLIB deps/zlib/*.c deps/zlib/*.h) |
c9f79972 | 273 | ENDIF() |
f443a879 | 274 | |
726b75d1 | 275 | # Optional external dependency: libssh2 |
f5fc63bc | 276 | IF (USE_SSH) |
4f91bfa3 | 277 | PKG_CHECK_MODULES(LIBSSH2 libssh2) |
5be622fb | 278 | ENDIF() |
7369b3c3 BM |
279 | IF (LIBSSH2_FOUND) |
280 | ADD_DEFINITIONS(-DGIT_SSH) | |
461fd5a0 RKC |
281 | INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIRS}) |
282 | LINK_DIRECTORIES(${LIBSSH2_LIBRARY_DIRS}) | |
790cabf0 | 283 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}") |
7369b3c3 | 284 | SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES}) |
1679ec12 | 285 | |
e488bef4 | 286 | CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "" HAVE_LIBSSH2_MEMORY_CREDENTIALS) |
1679ec12 MG |
287 | IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS) |
288 | ADD_DEFINITIONS(-DGIT_SSH_MEMORY_CREDENTIALS) | |
289 | ENDIF() | |
e15a0849 YK |
290 | ELSE() |
291 | MESSAGE(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") | |
7369b3c3 BM |
292 | ENDIF() |
293 | ||
315cb38e ET |
294 | # Optional external dependency: libgssapi |
295 | IF (USE_GSSAPI) | |
296 | FIND_PACKAGE(GSSAPI) | |
297 | ENDIF() | |
298 | IF (GSSAPI_FOUND) | |
299 | ADD_DEFINITIONS(-DGIT_GSSAPI) | |
300 | ENDIF() | |
301 | ||
726b75d1 RB |
302 | # Optional external dependency: iconv |
303 | IF (USE_ICONV) | |
6bcb0987 | 304 | FIND_PACKAGE(Iconv) |
726b75d1 RB |
305 | ENDIF() |
306 | IF (ICONV_FOUND) | |
307 | ADD_DEFINITIONS(-DGIT_USE_ICONV) | |
6e0ff093 | 308 | INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) |
4bc94eb5 | 309 | SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${ICONV_LIBRARIES}") |
726b75d1 | 310 | ENDIF() |
d10de8bd | 311 | |
502dd2da | 312 | # Platform specific compilation flags |
dcd62cb2 | 313 | IF (MSVC) |
dcd62cb2 | 314 | |
ccf1a2ba | 315 | STRING(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
94155e2f | 316 | |
19be3f9e PK |
317 | # /GF - String pooling |
318 | # /MP - Parallel build | |
319 | SET(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") | |
320 | ||
1b5078f6 | 321 | IF (STDCALL) |
19be3f9e PK |
322 | # /Gz - stdcall calling convention |
323 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz") | |
1b5078f6 | 324 | ENDIF () |
19be3f9e | 325 | |
08f32085 Q |
326 | IF (STATIC_CRT) |
327 | SET(CRT_FLAG_DEBUG "/MTd") | |
328 | SET(CRT_FLAG_RELEASE "/MT") | |
329 | ELSE() | |
ccf1a2ba | 330 | SET(CRT_FLAG_DEBUG "/MDd") |
08f32085 Q |
331 | SET(CRT_FLAG_RELEASE "/MD") |
332 | ENDIF() | |
333 | ||
d06c589f JH |
334 | IF (MSVC_CRTDBG) |
335 | SET(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} /DGIT_MSVC_CRTDBG") | |
336 | ENDIF() | |
337 | ||
19be3f9e PK |
338 | # /Zi - Create debugging information |
339 | # /Od - Disable optimization | |
340 | # /D_DEBUG - #define _DEBUG | |
341 | # /MTd - Statically link the multithreaded debug version of the CRT | |
08f32085 | 342 | # /MDd - Dynamically link the multithreaded debug version of the CRT |
19be3f9e | 343 | # /RTC1 - Run time checks |
08f32085 | 344 | SET(CMAKE_C_FLAGS_DEBUG "/Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") |
19be3f9e | 345 | |
69c28b75 | 346 | # /DNDEBUG - Disables asserts |
19be3f9e | 347 | # /MT - Statically link the multithreaded release version of the CRT |
08f32085 | 348 | # /MD - Dynamically link the multithreaded release version of the CRT |
19be3f9e PK |
349 | # /O2 - Optimize for speed |
350 | # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) | |
351 | # /GL - Link time code generation (whole program optimization) | |
352 | # /Gy - Function-level linking | |
08f32085 | 353 | SET(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
354 | |
355 | # /Oy- - Disable frame pointer omission (FPO) | |
08f32085 | 356 | SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
357 | |
358 | # /O1 - Optimize for size | |
08f32085 | 359 | SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") |
19be3f9e PK |
360 | |
361 | # /DYNAMICBASE - Address space load randomization (ASLR) | |
362 | # /NXCOMPAT - Data execution prevention (DEP) | |
363 | # /LARGEADDRESSAWARE - >2GB user address space on x86 | |
364 | # /VERSION - Embed version information in PE header | |
365 | SET(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}") | |
366 | ||
367 | # /DEBUG - Create a PDB | |
368 | # /LTCG - Link time code generation (whole program optimization) | |
369 | # /OPT:REF /OPT:ICF - Fold out duplicate code at link step | |
370 | # /INCREMENTAL:NO - Required to use /LTCG | |
371 | # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) | |
372 | SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") | |
373 | SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
374 | SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") | |
375 | SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
376 | ||
377 | # Same linker settings for DLL as EXE | |
378 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") | |
379 | SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") | |
380 | SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") | |
381 | SET(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") | |
382 | SET(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") | |
383 | ||
502dd2da | 384 | SET(WIN_RC "src/win32/git2.rc") |
9f75a9ce BS |
385 | |
386 | # Precompiled headers | |
94155e2f | 387 | |
e233fa6f | 388 | ELSE () |
c6cd3f8b | 389 | SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -Wall -Wextra ${CMAKE_C_FLAGS}") |
19be3f9e | 390 | |
98b8fcff JG |
391 | IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") |
392 | SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") | |
393 | ENDIF() | |
394 | ||
19be3f9e PK |
395 | IF (WIN32 AND NOT CYGWIN) |
396 | SET(CMAKE_C_FLAGS_DEBUG "-D_DEBUG") | |
397 | ENDIF () | |
398 | ||
2eb18449 SG |
399 | IF (MINGW) # MinGW always does PIC and complains if we tell it to |
400 | STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") | |
0887b580 CMN |
401 | # MinGW >= 3.14 uses the C99-style stdio functions |
402 | # automatically, but forks like mingw-w64 still want | |
403 | # us to define this in order to use them | |
404 | ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO=1) | |
405 | ||
b41e24a6 | 406 | ELSEIF (BUILD_SHARED_LIBS) |
5c8d5eac | 407 | ADD_C_FLAG_IF_SUPPORTED(-fvisibility=hidden) |
c6cd3f8b JG |
408 | |
409 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | |
39cdf272 | 410 | ENDIF () |
c6cd3f8b | 411 | |
5c8d5eac JG |
412 | ADD_C_FLAG_IF_SUPPORTED(-Wno-missing-field-initializers) |
413 | ADD_C_FLAG_IF_SUPPORTED(-Wstrict-aliasing=2) | |
414 | ADD_C_FLAG_IF_SUPPORTED(-Wstrict-prototypes) | |
415 | ADD_C_FLAG_IF_SUPPORTED(-Wdeclaration-after-statement) | |
416 | ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-const-variable) | |
417 | ADD_C_FLAG_IF_SUPPORTED(-Wno-unused-function) | |
c6cd3f8b | 418 | |
364ef528 | 419 | IF (APPLE) # Apple deprecated OpenSSL |
5c8d5eac | 420 | ADD_C_FLAG_IF_SUPPORTED(-Wno-deprecated-declarations) |
c6cd3f8b | 421 | ENDIF() |
823c0e9c | 422 | |
706a9974 RB |
423 | IF (PROFILE) |
424 | SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}") | |
425 | SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}") | |
426 | ENDIF () | |
90412507 | 427 | ENDIF() |
5b8bb8e7 | 428 | |
88149fae PT |
429 | IF( NOT CMAKE_CONFIGURATION_TYPES ) |
430 | # Build Debug by default | |
431 | IF (NOT CMAKE_BUILD_TYPE) | |
432 | SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) | |
433 | ENDIF () | |
434 | ELSE() | |
435 | # Using a multi-configuration generator eg MSVC or Xcode | |
436 | # that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE | |
437 | ENDIF() | |
583cf169 | 438 | |
6bb54cbf CMN |
439 | IF (SECURITY_FOUND) |
440 | ADD_DEFINITIONS(-DGIT_SECURE_TRANSPORT) | |
441 | INCLUDE_DIRECTORIES(${SECURITY_INCLUDE_DIR}) | |
442 | ENDIF () | |
443 | ||
96ef3d84 | 444 | IF (OPENSSL_FOUND) |
24e53d2f | 445 | ADD_DEFINITIONS(-DGIT_OPENSSL) |
96ef3d84 CY |
446 | INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) |
447 | SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES}) | |
41cbbea8 | 448 | ENDIF() |
66024c7c | 449 | |
6bb54cbf CMN |
450 | |
451 | ||
70236bab VM |
452 | IF (THREADSAFE) |
453 | IF (NOT WIN32) | |
48ce93e0 | 454 | FIND_PACKAGE(Threads REQUIRED) |
70236bab VM |
455 | ENDIF() |
456 | ||
457 | ADD_DEFINITIONS(-DGIT_THREADS) | |
458 | ENDIF() | |
459 | ||
678e9e04 VM |
460 | ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) |
461 | ||
583cf169 | 462 | # Collect sourcefiles |
cdacd3d9 | 463 | FILE(GLOB SRC_H include/git2.h include/git2/*.h include/git2/sys/*.h) |
583cf169 PD |
464 | |
465 | # On Windows use specific platform sources | |
5b8bb8e7 | 466 | IF (WIN32 AND NOT CYGWIN) |
19be3f9e | 467 | ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501) |
cdacd3d9 | 468 | FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h) |
96ef3d84 | 469 | ELSEIF (AMIGA) |
7697e541 | 470 | ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP) |
678e9e04 | 471 | ELSE() |
7697e541 RB |
472 | IF (VALGRIND) |
473 | ADD_DEFINITIONS(-DNO_MMAP) | |
474 | ENDIF() | |
cdacd3d9 | 475 | FILE(GLOB SRC_OS src/unix/*.c src/unix/*.h) |
521479b1 | 476 | ENDIF() |
cdacd3d9 | 477 | FILE(GLOB SRC_GIT2 src/*.c src/*.h src/transports/*.c src/transports/*.h src/xdiff/*.c src/xdiff/*.h) |
5b8bb8e7 | 478 | |
eb63fda2 ET |
479 | # Determine architecture of the machine |
480 | IF (CMAKE_SIZEOF_VOID_P EQUAL 8) | |
481 | ADD_DEFINITIONS(-DGIT_ARCH_64) | |
482 | ELSEIF (CMAKE_SIZEOF_VOID_P EQUAL 4) | |
483 | ADD_DEFINITIONS(-DGIT_ARCH_32) | |
484 | ELSE() | |
48ce93e0 | 485 | MESSAGE(FATAL_ERROR "Unsupported architecture") |
eb63fda2 ET |
486 | ENDIF() |
487 | ||
583cf169 | 488 | # Compile and link libgit2 |
20dcb731 | 489 | ADD_LIBRARY(git2 ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1} ${WIN_RC}) |
6bb54cbf CMN |
490 | TARGET_LINK_LIBRARIES(git2 ${SECURITY_DIRS}) |
491 | TARGET_LINK_LIBRARIES(git2 ${COREFOUNDATION_DIRS}) | |
94243295 | 492 | TARGET_LINK_LIBRARIES(git2 ${SSL_LIBRARIES}) |
7369b3c3 | 493 | TARGET_LINK_LIBRARIES(git2 ${SSH_LIBRARIES}) |
315cb38e | 494 | TARGET_LINK_LIBRARIES(git2 ${GSSAPI_LIBRARIES}) |
726b75d1 | 495 | TARGET_LINK_LIBRARIES(git2 ${ICONV_LIBRARIES}) |
94243295 | 496 | TARGET_OS_LIBRARIES(git2) |
39cdf272 | 497 | |
d66a7c06 Q |
498 | # Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) |
499 | # Win64+MSVC+static libs = linker error | |
ac1d85cf | 500 | IF(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS) |
d66a7c06 Q |
501 | SET_TARGET_PROPERTIES(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64") |
502 | ENDIF() | |
503 | ||
523a3ae5 SC |
504 | MSVC_SPLIT_SOURCES(git2) |
505 | ||
e7da9acd NO |
506 | IF (SONAME) |
507 | SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING}) | |
99807672 | 508 | SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_SOVERSION}) |
c1cf1af4 | 509 | IF (LIBGIT2_FILENAME) |
510 | ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") | |
511 | SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) | |
3bbc87d6 | 512 | ENDIF() |
e7da9acd | 513 | ENDIF() |
4fd486e0 | 514 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY) |
583cf169 | 515 | |
26d9e317 | 516 | IF (MSVC_IDE) |
73aaf674 BS |
517 | # Precompiled headers |
518 | SET_TARGET_PROPERTIES(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") | |
519 | SET_SOURCE_FILES_PROPERTIES(src/win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") | |
520 | ENDIF () | |
521 | ||
583cf169 | 522 | # Install |
932d1baf | 523 | INSTALL(TARGETS git2 |
9795a40f | 524 | RUNTIME DESTINATION ${BIN_INSTALL_DIR} |
b3237ac3 ICQ |
525 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
526 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} | |
583cf169 | 527 | ) |
b3237ac3 | 528 | INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig ) |
9795a40f VP |
529 | INSTALL(DIRECTORY include/git2 DESTINATION ${INCLUDE_INSTALL_DIR} ) |
530 | INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} ) | |
583cf169 PD |
531 | |
532 | # Tests | |
3fd1520c | 533 | IF (BUILD_CLAR) |
86a459a8 CB |
534 | FIND_PACKAGE(PythonInterp REQUIRED) |
535 | ||
83e1efbf BS |
536 | SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/") |
537 | SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests") | |
538 | SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.") | |
3fd1520c | 539 | ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") |
e0799b6c | 540 | ADD_DEFINITIONS(-DCLAR_RESOURCES=\"${TEST_RESOURCES}\") |
29eed1c7 | 541 | ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\") |
11385c3c | 542 | |
3fd1520c | 543 | INCLUDE_DIRECTORIES(${CLAR_PATH}) |
cdacd3d9 | 544 | FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h) |
9a859ef5 | 545 | 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 | 546 | |
86a459a8 | 547 | ADD_CUSTOM_COMMAND( |
156cfec0 | 548 | OUTPUT ${CLAR_PATH}/clar.suite |
e8242022 | 549 | COMMAND ${PYTHON_EXECUTABLE} generate.py -f -xonline -xstress . |
39444bea | 550 | DEPENDS ${SRC_TEST} |
3fd1520c | 551 | WORKING_DIRECTORY ${CLAR_PATH} |
86a459a8 | 552 | ) |
156cfec0 | 553 | |
5c2d3f6d | 554 | SET_SOURCE_FILES_PROPERTIES( |
2e6f06a8 | 555 | ${CLAR_PATH}/clar.c |
5c2d3f6d VM |
556 | PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite) |
557 | ||
20dcb731 | 558 | ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SHA1}) |
5c2d3f6d | 559 | |
6bb54cbf CMN |
560 | TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS}) |
561 | TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS}) | |
94243295 | 562 | TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES}) |
7369b3c3 | 563 | TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES}) |
315cb38e | 564 | TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES}) |
726b75d1 | 565 | TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES}) |
94243295 | 566 | TARGET_OS_LIBRARIES(libgit2_clar) |
523a3ae5 | 567 | MSVC_SPLIT_SOURCES(libgit2_clar) |
73aaf674 | 568 | |
156cfec0 VM |
569 | IF (MSVC_IDE) |
570 | # Precompiled headers | |
571 | SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") | |
572 | ENDIF () | |
73aaf674 | 573 | |
f1558d9b | 574 | ENABLE_TESTING() |
6bb54cbf | 575 | IF (WINHTTP OR OPENSSL_FOUND OR SECURITY_FOUND) |
06353282 TK |
576 | ADD_TEST(libgit2_clar libgit2_clar -ionline) |
577 | ELSE () | |
578 | ADD_TEST(libgit2_clar libgit2_clar -v) | |
579 | ENDIF () | |
f1558d9b | 580 | ENDIF () |
e632f687 CB |
581 | |
582 | IF (TAGS) | |
583 | FIND_PROGRAM(CTAGS ctags) | |
584 | IF (NOT CTAGS) | |
48ce93e0 | 585 | MESSAGE(FATAL_ERROR "Could not find ctags command") |
e632f687 CB |
586 | ENDIF () |
587 | ||
588 | FILE(GLOB_RECURSE SRC_ALL *.[ch]) | |
589 | ||
590 | ADD_CUSTOM_COMMAND( | |
591 | OUTPUT tags | |
592 | COMMAND ${CTAGS} -a ${SRC_ALL} | |
593 | DEPENDS ${SRC_ALL} | |
594 | ) | |
595 | ADD_CUSTOM_TARGET( | |
596 | do_tags ALL | |
597 | DEPENDS tags | |
598 | ) | |
599 | ENDIF () | |
62986ff6 SG |
600 | |
601 | IF (BUILD_EXAMPLES) | |
60ee53df | 602 | ADD_SUBDIRECTORY(examples) |
583cf169 | 603 | ENDIF () |