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