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