]> git.proxmox.com Git - libgit2.git/blob - src/CMakeLists.txt
New upstream version 1.5.0+ds
[libgit2.git] / src / CMakeLists.txt
1 # The main libgit2 source tree: this CMakeLists.txt identifies platform
2 # support and includes the subprojects that make up core libgit2 support.
3
4 #
5 # Optional build configuration settings
6 #
7
8 if(DEPRECATE_HARD)
9 add_definitions(-DGIT_DEPRECATE_HARD)
10 endif()
11
12 if(USE_LEAK_CHECKER STREQUAL "valgrind")
13 add_definitions(-DVALGRIND)
14 endif()
15
16 #
17 # Optional debugging functionality
18 #
19
20 if(DEBUG_POOL)
21 set(GIT_DEBUG_POOL 1)
22 endif()
23 add_feature_info(debugpool GIT_DEBUG_POOL "debug pool allocator")
24
25 if(DEBUG_STRICT_ALLOC)
26 set(GIT_DEBUG_STRICT_ALLOC 1)
27 endif()
28 add_feature_info(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators")
29
30 if(DEBUG_STRICT_OPEN)
31 set(GIT_DEBUG_STRICT_OPEN 1)
32 endif()
33 add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
34
35 #
36 # Optional feature enablement
37 #
38
39 include(SelectGSSAPI)
40 include(SelectHTTPSBackend)
41 include(SelectHashes)
42 include(SelectHTTPParser)
43 include(SelectRegex)
44 include(SelectSSH)
45 include(SelectWinHTTP)
46 include(SelectZlib)
47
48 #
49 # Platform support
50 #
51
52 # futimes/futimens
53
54 if(HAVE_FUTIMENS)
55 set(GIT_USE_FUTIMENS 1)
56 endif ()
57 add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
58
59 # qsort
60
61 check_prototype_definition(qsort_r
62 "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
63 "" "stdlib.h" GIT_QSORT_R_BSD)
64
65 check_prototype_definition(qsort_r
66 "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
67 "" "stdlib.h" GIT_QSORT_R_GNU)
68
69 check_function_exists(qsort_s GIT_QSORT_S)
70
71 # random / entropy data
72
73 check_function_exists(getentropy GIT_RAND_GETENTROPY)
74 check_function_exists(getloadavg GIT_RAND_GETLOADAVG)
75
76 # determine architecture of the machine
77
78 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
79 set(GIT_ARCH_64 1)
80 elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
81 set(GIT_ARCH_32 1)
82 elseif(CMAKE_SIZEOF_VOID_P)
83 message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)")
84 else()
85 message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
86 endif()
87
88 # nanosecond mtime/ctime support
89
90 if(USE_NSEC)
91 set(GIT_USE_NSEC 1)
92 endif()
93
94 # high-resolution stat support
95
96 if(HAVE_STRUCT_STAT_ST_MTIM)
97 set(GIT_USE_STAT_MTIM 1)
98 elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
99 set(GIT_USE_STAT_MTIMESPEC 1)
100 elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC)
101 set(GIT_USE_STAT_MTIME_NSEC 1)
102 endif()
103
104 # realtime support
105
106 check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
107 if(NEED_LIBRT)
108 list(APPEND LIBGIT2_SYSTEM_LIBS rt)
109 list(APPEND LIBGIT2_PC_LIBS "-lrt")
110 endif()
111
112 # platform libraries
113
114 if(WIN32)
115 list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
116 endif()
117
118 if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
119 list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
120 list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
121 endif()
122
123 if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
124 list(APPEND LIBGIT2_SYSTEM_LIBS gnu network)
125 list(APPEND LIBGIT2_PC_LIBS "-lgnu -lnetwork")
126 endif()
127
128 if(AMIGA)
129 add_definitions(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
130 endif()
131
132 # threads
133
134 if(USE_THREADS)
135 if(NOT WIN32)
136 find_package(Threads REQUIRED)
137 list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
138 list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
139 endif()
140
141 set(GIT_THREADS 1)
142 endif()
143 add_feature_info(threadsafe USE_THREADS "threadsafe support")
144
145 #
146 # Optional bundled features
147 #
148
149 # ntlmclient
150 if(USE_NTLMCLIENT)
151 set(GIT_NTLM 1)
152 add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient")
153 list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/ntlmclient")
154 list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
155 endif()
156 add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
157
158 #
159 # Optional external dependencies
160
161 # iconv
162 if(USE_ICONV)
163 find_package(Iconv)
164 endif()
165 if(ICONV_FOUND)
166 set(GIT_USE_ICONV 1)
167 list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
168 list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
169 list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
170 endif()
171 add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
172
173 #
174 # Configure support
175 #
176
177 configure_file(features.h.in git2/sys/features.h)
178
179 #
180 # Include child projects
181 #
182
183 add_subdirectory(libgit2)
184 add_subdirectory(util)
185
186 if(BUILD_CLI)
187 add_subdirectory(cli)
188 endif()
189
190 # re-export these to the root so that peer projects (tests, fuzzers,
191 # examples) can use them
192 set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
193 set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
194 set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE)
195 set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
196 set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
197 set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)