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