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