]>
Commit | Line | Data |
---|---|---|
061c2240 SS |
1 | # |
2 | # Copyright (c) 2020 Sibi Siddharthan | |
3 | # | |
4 | ||
5 | #[[ | |
6 | ||
7 | Instructions to run CMake: | |
8 | ||
9 | cmake `relative-path-to-CMakeLists.txt` -DCMAKE_BUILD_TYPE=Release | |
10 | Eg. | |
11 | From the root of git source tree | |
12 | `cmake contrib/buildsystems/ ` | |
13 | This will build the git binaries at the root | |
14 | ||
15 | For out of source builds, say build in 'git/git-build/' | |
16 | `mkdir git-build;cd git-build; cmake ../contrib/buildsystems/` | |
17 | This will build the git binaries in git-build directory | |
18 | ||
19 | Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding | |
20 | compiler flags | |
21 | Debug : -g | |
22 | Release: -O3 | |
23 | RelWithDebInfo : -O2 -g | |
24 | MinSizeRel : -Os | |
25 | empty(default) : | |
26 | ||
27 | NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio | |
28 | this option is ignored | |
29 | ||
30 | This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default. | |
31 | Run `make` to build Git on Linux/*BSD/MacOS. | |
32 | Open git.sln on Windows and build Git. | |
33 | ||
34 | NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows, | |
35 | to use another tool say `ninja` add this to the command line when configuring. | |
36 | `-G Ninja` | |
37 | ||
38 | ]] | |
39 | cmake_minimum_required(VERSION 3.14) | |
40 | ||
41 | #set the source directory to root of git | |
42 | set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) | |
e18ae4e7 JS |
43 | if(WIN32) |
44 | set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") | |
45 | list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/x64-windows") | |
46 | ||
47 | # In the vcpkg edition, we need this to be able to link to libcurl | |
48 | set(CURL_NO_CURL_CMAKE ON) | |
49 | endif() | |
061c2240 | 50 | |
72b6eeb8 | 51 | find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin") |
f7adba41 SS |
52 | if(NOT SH_EXE) |
53 | message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one." | |
54 | "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/") | |
55 | endif() | |
061c2240 SS |
56 | |
57 | #Create GIT-VERSION-FILE using GIT-VERSION-GEN | |
58 | if(NOT EXISTS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE) | |
59 | message("Generating GIT-VERSION-FILE") | |
60 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN | |
61 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | |
62 | endif() | |
63 | ||
64 | #Parse GIT-VERSION-FILE to get the version | |
65 | file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE git_version REGEX "GIT_VERSION = (.*)") | |
66 | string(REPLACE "GIT_VERSION = " "" git_version ${git_version}) | |
67 | string(FIND ${git_version} "GIT" location) | |
68 | if(location EQUAL -1) | |
69 | string(REGEX MATCH "[0-9]*\\.[0-9]*\\.[0-9]*" git_version ${git_version}) | |
70 | else() | |
71 | string(REGEX MATCH "[0-9]*\\.[0-9]*" git_version ${git_version}) | |
72 | string(APPEND git_version ".0") #for building from a snapshot | |
73 | endif() | |
74 | ||
75 | project(git | |
76 | VERSION ${git_version} | |
77 | LANGUAGES C) | |
78 | ||
f7adba41 | 79 | |
f1f5dff9 | 80 | #TODO gitk git-gui gitweb |
f7adba41 | 81 | #TODO Enable NLS on windows natively |
f1f5dff9 | 82 | #TODO Add pcre support |
061c2240 | 83 | |
afa45fe5 | 84 | #macros for parsing the Makefile for sources and scripts |
061c2240 SS |
85 | macro(parse_makefile_for_sources list_var regex) |
86 | file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)") | |
87 | string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}}) | |
88 | string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit. | |
89 | string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces | |
90 | string(REPLACE ".o" ".c;" ${list_var} ${${list_var}}) #change .o to .c, ; is for converting the string into a list | |
91 | list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list | |
92 | list(REMOVE_ITEM ${list_var} "") #remove empty list elements | |
93 | endmacro() | |
94 | ||
afa45fe5 SS |
95 | macro(parse_makefile_for_scripts list_var regex lang) |
96 | file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)") | |
97 | string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}}) | |
98 | string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces | |
99 | string(REPLACE " " ";" ${list_var} ${${list_var}}) #convert string to a list | |
100 | if(NOT ${lang}) #exclude for SCRIPT_LIB | |
101 | list(TRANSFORM ${list_var} REPLACE "${lang}" "") #do the replacement | |
102 | endif() | |
103 | endmacro() | |
104 | ||
061c2240 SS |
105 | include(CheckTypeSize) |
106 | include(CheckCSourceRuns) | |
107 | include(CheckCSourceCompiles) | |
108 | include(CheckIncludeFile) | |
109 | include(CheckFunctionExists) | |
110 | include(CheckSymbolExists) | |
111 | include(CheckStructHasMember) | |
c4b2f41b | 112 | include(CTest) |
061c2240 SS |
113 | |
114 | find_package(ZLIB REQUIRED) | |
115 | find_package(CURL) | |
116 | find_package(EXPAT) | |
117 | find_package(Iconv) | |
061c2240 | 118 | |
7f475e27 SS |
119 | #Don't use libintl on Windows Visual Studio and Clang builds |
120 | if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))) | |
121 | find_package(Intl) | |
122 | endif() | |
f7adba41 | 123 | |
061c2240 SS |
124 | if(NOT Intl_FOUND) |
125 | add_compile_definitions(NO_GETTEXT) | |
126 | if(NOT Iconv_FOUND) | |
127 | add_compile_definitions(NO_ICONV) | |
128 | endif() | |
129 | endif() | |
130 | ||
131 | include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS}) | |
132 | if(CURL_FOUND) | |
133 | include_directories(SYSTEM ${CURL_INCLUDE_DIRS}) | |
134 | endif() | |
135 | if(EXPAT_FOUND) | |
136 | include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS}) | |
137 | endif() | |
138 | if(Iconv_FOUND) | |
139 | include_directories(SYSTEM ${Iconv_INCLUDE_DIRS}) | |
140 | endif() | |
141 | if(Intl_FOUND) | |
142 | include_directories(SYSTEM ${Intl_INCLUDE_DIRS}) | |
143 | endif() | |
144 | ||
f7adba41 | 145 | |
7f475e27 | 146 | if(WIN32 AND NOT MSVC)#not required for visual studio builds |
f7adba41 SS |
147 | find_program(WINDRES_EXE windres) |
148 | if(NOT WINDRES_EXE) | |
149 | message(FATAL_ERROR "Install windres on Windows for resource files") | |
150 | endif() | |
151 | endif() | |
152 | ||
afa45fe5 SS |
153 | find_program(MSGFMT_EXE msgfmt) |
154 | if(NOT MSGFMT_EXE) | |
155 | message(WARNING "Text Translations won't be build") | |
156 | endif() | |
157 | ||
7f475e27 SS |
158 | #Force all visual studio outputs to CMAKE_BINARY_DIR |
159 | if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") | |
160 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}) | |
161 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}) | |
162 | add_compile_options(/MP) | |
163 | endif() | |
164 | ||
061c2240 SS |
165 | #default behaviour |
166 | include_directories(${CMAKE_SOURCE_DIR}) | |
167 | add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}") | |
168 | add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX) | |
169 | add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES | |
170 | SHA1DC_INIT_SAFE_HASH_DEFAULT=0 | |
171 | SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h" | |
172 | SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" ) | |
173 | list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c) | |
174 | ||
175 | ||
176 | add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c" | |
177 | ETC_GITATTRIBUTES="etc/gitattributes" | |
178 | ETC_GITCONFIG="etc/gitconfig" | |
179 | GIT_EXEC_PATH="libexec/git-core" | |
180 | GIT_LOCALE_PATH="share/locale" | |
181 | GIT_MAN_PATH="share/man" | |
182 | GIT_INFO_PATH="share/info" | |
183 | GIT_HTML_PATH="share/doc/git-doc" | |
184 | DEFAULT_HELP_FORMAT="html" | |
185 | DEFAULT_GIT_TEMPLATE_DIR="share/git-core/templates" | |
186 | GIT_VERSION="${PROJECT_VERSION}.GIT" | |
187 | GIT_USER_AGENT="git/${PROJECT_VERSION}.GIT" | |
188 | BINDIR="bin" | |
189 | GIT_BUILT_FROM_COMMIT="") | |
190 | ||
f7adba41 SS |
191 | if(WIN32) |
192 | set(FALLBACK_RUNTIME_PREFIX /mingw64) | |
193 | add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}") | |
194 | else() | |
195 | set(FALLBACK_RUNTIME_PREFIX /home/$ENV{USER}) | |
196 | add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}") | |
197 | endif() | |
198 | ||
199 | ||
200 | #Platform Specific | |
201 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | |
7f475e27 SS |
202 | if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") |
203 | include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include) | |
204 | add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE) | |
205 | endif() | |
f7adba41 SS |
206 | include_directories(${CMAKE_SOURCE_DIR}/compat/win32) |
207 | add_compile_definitions(HAVE_ALLOCA_H NO_POSIX_GOODIES NATIVE_CRLF NO_UNIX_SOCKETS WIN32 | |
208 | _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT | |
209 | NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0 | |
210 | USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP | |
211 | UNICODE _UNICODE HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET) | |
212 | list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c compat/win32/path-utils.c | |
213 | compat/win32/pthread.c compat/win32mmap.c compat/win32/syslog.c | |
214 | compat/win32/trace2_win32_process_info.c compat/win32/dirent.c | |
215 | compat/nedmalloc/nedmalloc.c compat/strdup.c) | |
216 | set(NO_UNIX_SOCKETS 1) | |
217 | ||
218 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
219 | add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY ) | |
220 | list(APPEND compat_SOURCES unix-socket.c) | |
221 | endif() | |
061c2240 | 222 | |
f7adba41 | 223 | set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX}) |
061c2240 SS |
224 | |
225 | #header checks | |
226 | check_include_file(libgen.h HAVE_LIBGEN_H) | |
227 | if(NOT HAVE_LIBGEN_H) | |
228 | add_compile_definitions(NO_LIBGEN_H) | |
229 | list(APPEND compat_SOURCES compat/basename.c) | |
230 | endif() | |
231 | ||
232 | check_include_file(sys/sysinfo.h HAVE_SYSINFO) | |
233 | if(HAVE_SYSINFO) | |
234 | add_compile_definitions(HAVE_SYSINFO) | |
235 | endif() | |
236 | ||
237 | check_c_source_compiles(" | |
238 | #include <alloca.h> | |
239 | ||
240 | int main(void) | |
241 | { | |
242 | char *p = (char *) alloca(2 * sizeof(int)); | |
243 | ||
244 | if (p) | |
245 | return 0; | |
246 | return 0; | |
247 | }" | |
248 | HAVE_ALLOCA_H) | |
249 | if(HAVE_ALLOCA_H) | |
250 | add_compile_definitions(HAVE_ALLOCA_H) | |
251 | endif() | |
252 | ||
253 | check_include_file(strings.h HAVE_STRINGS_H) | |
254 | if(HAVE_STRINGS_H) | |
255 | add_compile_definitions(HAVE_STRINGS_H) | |
256 | endif() | |
257 | ||
258 | check_include_file(sys/select.h HAVE_SYS_SELECT_H) | |
259 | if(NOT HAVE_SYS_SELECT_H) | |
260 | add_compile_definitions(NO_SYS_SELECT_H) | |
261 | endif() | |
262 | ||
263 | check_include_file(sys/poll.h HAVE_SYS_POLL_H) | |
264 | if(NOT HAVE_SYS_POLL_H) | |
265 | add_compile_definitions(NO_SYS_POLL_H) | |
266 | endif() | |
267 | ||
268 | check_include_file(poll.h HAVE_POLL_H) | |
269 | if(NOT HAVE_POLL_H) | |
270 | add_compile_definitions(NO_POLL_H) | |
271 | endif() | |
272 | ||
273 | check_include_file(inttypes.h HAVE_INTTYPES_H) | |
274 | if(NOT HAVE_INTTYPES_H) | |
275 | add_compile_definitions(NO_INTTYPES_H) | |
276 | endif() | |
277 | ||
278 | check_include_file(paths.h HAVE_PATHS_H) | |
279 | if(HAVE_PATHS_H) | |
280 | add_compile_definitions(HAVE_PATHS_H) | |
281 | endif() | |
282 | ||
283 | #function checks | |
284 | set(function_checks | |
285 | strcasestr memmem strlcpy strtoimax strtoumax strtoull | |
f7adba41 SS |
286 | setenv mkdtemp poll pread memmem) |
287 | ||
288 | #unsetenv,hstrerror are incompatible with windows build | |
289 | if(NOT WIN32) | |
290 | list(APPEND function_checks unsetenv hstrerror) | |
291 | endif() | |
061c2240 SS |
292 | |
293 | foreach(f ${function_checks}) | |
294 | string(TOUPPER ${f} uf) | |
295 | check_function_exists(${f} HAVE_${uf}) | |
296 | if(NOT HAVE_${uf}) | |
297 | add_compile_definitions(NO_${uf}) | |
298 | endif() | |
299 | endforeach() | |
300 | ||
301 | if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL) | |
302 | include_directories(${CMAKE_SOURCE_DIR}/compat/poll) | |
303 | add_compile_definitions(NO_POLL) | |
304 | list(APPEND compat_SOURCES compat/poll/poll.c) | |
305 | endif() | |
306 | ||
307 | if(NOT HAVE_STRCASESTR) | |
308 | list(APPEND compat_SOURCES compat/strcasestr.c) | |
309 | endif() | |
310 | ||
311 | if(NOT HAVE_STRLCPY) | |
312 | list(APPEND compat_SOURCES compat/strlcpy.c) | |
313 | endif() | |
314 | ||
315 | if(NOT HAVE_STRTOUMAX) | |
316 | list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c) | |
317 | endif() | |
318 | ||
319 | if(NOT HAVE_SETENV) | |
320 | list(APPEND compat_SOURCES compat/setenv.c) | |
321 | endif() | |
322 | ||
323 | if(NOT HAVE_MKDTEMP) | |
324 | list(APPEND compat_SOURCES compat/mkdtemp.c) | |
325 | endif() | |
326 | ||
327 | if(NOT HAVE_PREAD) | |
328 | list(APPEND compat_SOURCES compat/pread.c) | |
329 | endif() | |
330 | ||
331 | if(NOT HAVE_MEMMEM) | |
332 | list(APPEND compat_SOURCES compat/memmem.c) | |
333 | endif() | |
334 | ||
335 | if(NOT WIN32) | |
336 | if(NOT HAVE_UNSETENV) | |
337 | list(APPEND compat_SOURCES compat/unsetenv.c) | |
338 | endif() | |
339 | ||
340 | if(NOT HAVE_HSTRERROR) | |
341 | list(APPEND compat_SOURCES compat/hstrerror.c) | |
342 | endif() | |
343 | endif() | |
344 | ||
345 | check_function_exists(getdelim HAVE_GETDELIM) | |
346 | if(HAVE_GETDELIM) | |
347 | add_compile_definitions(HAVE_GETDELIM) | |
348 | endif() | |
349 | ||
350 | check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) | |
351 | check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC) | |
352 | if(HAVE_CLOCK_GETTIME) | |
353 | add_compile_definitions(HAVE_CLOCK_GETTIME) | |
354 | endif() | |
355 | if(HAVE_CLOCK_MONOTONIC) | |
356 | add_compile_definitions(HAVE_CLOCK_MONOTONIC) | |
357 | endif() | |
358 | ||
359 | #check for st_blocks in struct stat | |
360 | check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS) | |
361 | if(NOT STRUCT_STAT_HAS_ST_BLOCKS) | |
362 | add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT) | |
363 | endif() | |
364 | ||
365 | #compile checks | |
366 | check_c_source_runs(" | |
367 | #include<stdio.h> | |
368 | #include<stdarg.h> | |
369 | #include<string.h> | |
370 | #include<stdlib.h> | |
371 | ||
372 | int test_vsnprintf(char *str, size_t maxsize, const char *format, ...) | |
373 | { | |
374 | int ret; | |
375 | va_list ap; | |
376 | ||
377 | va_start(ap, format); | |
378 | ret = vsnprintf(str, maxsize, format, ap); | |
379 | va_end(ap); | |
380 | return ret; | |
381 | } | |
382 | ||
383 | int main(void) | |
384 | { | |
385 | char buf[6]; | |
386 | ||
387 | if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5 | |
388 | || strcmp(buf, \"12\")) | |
389 | return 1; | |
390 | if (snprintf(buf, 3, \"%s\", \"12345\") != 5 | |
391 | || strcmp(buf, \"12\")) | |
392 | return 1; | |
393 | return 0; | |
394 | }" | |
395 | SNPRINTF_OK) | |
396 | if(NOT SNPRINTF_OK) | |
397 | add_compile_definitions(SNPRINTF_RETURNS_BOGUS) | |
398 | list(APPEND compat_SOURCES compat/snprintf.c) | |
399 | endif() | |
400 | ||
401 | check_c_source_runs(" | |
402 | #include<stdio.h> | |
403 | ||
404 | int main(void) | |
405 | { | |
406 | FILE *f = fopen(\".\", \"r\"); | |
407 | ||
408 | return f != NULL; | |
409 | }" | |
410 | FREAD_READS_DIRECTORIES_NO) | |
411 | if(NOT FREAD_READS_DIRECTORIES_NO) | |
412 | add_compile_definitions(FREAD_READS_DIRECTORIES) | |
413 | list(APPEND compat_SOURCES compat/fopen.c) | |
414 | endif() | |
415 | ||
416 | check_c_source_compiles(" | |
417 | #include <regex.h> | |
418 | #ifndef REG_STARTEND | |
419 | #error oops we dont have it | |
420 | #endif | |
421 | ||
422 | int main(void) | |
423 | { | |
424 | return 0; | |
425 | }" | |
426 | HAVE_REGEX) | |
427 | if(NOT HAVE_REGEX) | |
428 | include_directories(${CMAKE_SOURCE_DIR}/compat/regex) | |
429 | list(APPEND compat_SOURCES compat/regex/regex.c ) | |
430 | add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK) | |
431 | endif() | |
432 | ||
433 | ||
434 | check_c_source_compiles(" | |
435 | #include <stddef.h> | |
436 | #include <sys/types.h> | |
437 | #include <sys/sysctl.h> | |
438 | ||
439 | int main(void) | |
440 | { | |
441 | int val, mib[2]; | |
442 | size_t len; | |
443 | ||
444 | mib[0] = CTL_HW; | |
445 | mib[1] = 1; | |
446 | len = sizeof(val); | |
447 | return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0; | |
448 | }" | |
449 | HAVE_BSD_SYSCTL) | |
450 | if(HAVE_BSD_SYSCTL) | |
451 | add_compile_definitions(HAVE_BSD_SYSCTL) | |
452 | endif() | |
453 | ||
454 | set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES}) | |
455 | set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS}) | |
456 | ||
457 | check_c_source_compiles(" | |
458 | #include <iconv.h> | |
459 | ||
460 | extern size_t iconv(iconv_t cd, | |
461 | char **inbuf, size_t *inbytesleft, | |
462 | char **outbuf, size_t *outbytesleft); | |
463 | ||
464 | int main(void) | |
465 | { | |
466 | return 0; | |
467 | }" | |
468 | HAVE_NEW_ICONV) | |
469 | if(HAVE_NEW_ICONV) | |
470 | set(HAVE_OLD_ICONV 0) | |
471 | else() | |
472 | set(HAVE_OLD_ICONV 1) | |
473 | endif() | |
474 | ||
475 | check_c_source_runs(" | |
476 | #include <iconv.h> | |
477 | #if ${HAVE_OLD_ICONV} | |
478 | typedef const char *iconv_ibp; | |
479 | #else | |
480 | typedef char *iconv_ibp; | |
481 | #endif | |
482 | ||
483 | int main(void) | |
484 | { | |
485 | int v; | |
486 | iconv_t conv; | |
487 | char in[] = \"a\"; | |
488 | iconv_ibp pin = in; | |
489 | char out[20] = \"\"; | |
490 | char *pout = out; | |
491 | size_t isz = sizeof(in); | |
492 | size_t osz = sizeof(out); | |
493 | ||
494 | conv = iconv_open(\"UTF-16\", \"UTF-8\"); | |
495 | iconv(conv, &pin, &isz, &pout, &osz); | |
496 | iconv_close(conv); | |
497 | v = (unsigned char)(out[0]) + (unsigned char)(out[1]); | |
498 | return v != 0xfe + 0xff; | |
499 | }" | |
500 | ICONV_DOESNOT_OMIT_BOM) | |
501 | if(NOT ICONV_DOESNOT_OMIT_BOM) | |
502 | add_compile_definitions(ICONV_OMITS_BOM) | |
503 | endif() | |
504 | ||
505 | unset(CMAKE_REQUIRED_LIBRARIES) | |
506 | unset(CMAKE_REQUIRED_INCLUDES) | |
507 | ||
508 | ||
509 | #programs | |
510 | set(PROGRAMS_BUILT | |
a006f875 | 511 | git git-daemon git-http-backend git-sh-i18n--envsubst |
fc47391e | 512 | git-shell) |
f7adba41 | 513 | |
061c2240 SS |
514 | if(NOT CURL_FOUND) |
515 | list(APPEND excluded_progs git-http-fetch git-http-push) | |
516 | add_compile_definitions(NO_CURL) | |
517 | message(WARNING "git-http-push and git-http-fetch will not be built") | |
518 | else() | |
519 | list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http) | |
520 | if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0) | |
521 | add_compile_definitions(USE_CURL_FOR_IMAP_SEND) | |
522 | endif() | |
523 | endif() | |
524 | ||
525 | if(NOT EXPAT_FOUND) | |
526 | list(APPEND excluded_progs git-http-push) | |
527 | add_compile_definitions(NO_EXPAT) | |
528 | else() | |
529 | list(APPEND PROGRAMS_BUILT git-http-push) | |
530 | if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2) | |
531 | add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H) | |
532 | endif() | |
533 | endif() | |
534 | ||
535 | list(REMOVE_DUPLICATES excluded_progs) | |
536 | list(REMOVE_DUPLICATES PROGRAMS_BUILT) | |
537 | ||
538 | ||
539 | foreach(p ${excluded_progs}) | |
540 | list(APPEND EXCLUSION_PROGS --exclude-program ${p} ) | |
541 | endforeach() | |
542 | ||
543 | #for comparing null values | |
544 | list(APPEND EXCLUSION_PROGS empty) | |
545 | set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE) | |
546 | ||
547 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS) | |
548 | list(REMOVE_ITEM EXCLUSION_PROGS empty) | |
549 | message("Generating command-list.h") | |
550 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt | |
551 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
552 | OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h) | |
553 | endif() | |
554 | ||
555 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) | |
556 | message("Generating config-list.h") | |
557 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh | |
558 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
559 | OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h) | |
560 | endif() | |
561 | ||
562 | include_directories(${CMAKE_BINARY_DIR}) | |
563 | ||
564 | #build | |
565 | #libgit | |
566 | parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS") | |
567 | ||
568 | list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
569 | list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
570 | add_library(libgit ${libgit_SOURCES} ${compat_SOURCES}) | |
571 | ||
572 | #libxdiff | |
573 | parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS") | |
574 | ||
575 | list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
576 | add_library(xdiff STATIC ${libxdiff_SOURCES}) | |
577 | ||
f7adba41 | 578 | if(WIN32) |
7f475e27 SS |
579 | if(NOT MSVC)#use windres when compiling with gcc and clang |
580 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res | |
581 | COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR} | |
582 | -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\"" | |
583 | -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res | |
584 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
585 | VERBATIM) | |
586 | else()#MSVC use rc | |
587 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res | |
588 | COMMAND ${CMAKE_RC_COMPILER} /d MAJOR=${PROJECT_VERSION_MAJOR} /d MINOR=${PROJECT_VERSION_MINOR} | |
589 | /d MICRO=${PROJECT_VERSION_PATCH} /d PATCHLEVEL=0 /d GIT_VERSION="${PROJECT_VERSION}.GIT" | |
590 | /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_SOURCE_DIR}/git.rc | |
591 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
592 | VERBATIM) | |
593 | endif() | |
f7adba41 SS |
594 | add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res) |
595 | endif() | |
596 | ||
061c2240 SS |
597 | #link all required libraries to common-main |
598 | add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c) | |
f7adba41 SS |
599 | |
600 | target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES}) | |
061c2240 SS |
601 | if(Intl_FOUND) |
602 | target_link_libraries(common-main ${Intl_LIBRARIES}) | |
603 | endif() | |
604 | if(Iconv_FOUND) | |
605 | target_link_libraries(common-main ${Iconv_LIBRARIES}) | |
606 | endif() | |
f7adba41 SS |
607 | if(WIN32) |
608 | target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res) | |
609 | add_dependencies(common-main git-rc) | |
7f475e27 SS |
610 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
611 | target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup) | |
612 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") | |
613 | target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj) | |
614 | elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") | |
615 | target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj) | |
616 | endif() | |
f7adba41 SS |
617 | elseif(UNIX) |
618 | target_link_libraries(common-main pthread rt) | |
619 | endif() | |
061c2240 SS |
620 | |
621 | #git | |
622 | parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS") | |
623 | ||
624 | list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
625 | add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES}) | |
626 | target_link_libraries(git common-main) | |
627 | ||
061c2240 SS |
628 | add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c) |
629 | target_link_libraries(git-daemon common-main) | |
630 | ||
061c2240 SS |
631 | add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c) |
632 | target_link_libraries(git-http-backend common-main) | |
633 | ||
634 | add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c) | |
635 | target_link_libraries(git-sh-i18n--envsubst common-main) | |
636 | ||
637 | add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c) | |
638 | target_link_libraries(git-shell common-main) | |
639 | ||
640 | if(CURL_FOUND) | |
641 | add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c) | |
642 | ||
643 | add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c) | |
644 | target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES}) | |
645 | ||
646 | add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c) | |
647 | target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES}) | |
648 | ||
649 | add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c) | |
650 | target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} ) | |
651 | ||
652 | if(EXPAT_FOUND) | |
653 | add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c) | |
654 | target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES}) | |
655 | endif() | |
656 | endif() | |
657 | ||
061c2240 SS |
658 | set(git_builtin_extra |
659 | cherry cherry-pick format-patch fsck-objects | |
660 | init merge-subtree restore show | |
661 | stage status switch whatchanged) | |
662 | ||
663 | #Creating hardlinks | |
664 | foreach(s ${git_SOURCES} ${git_builtin_extra}) | |
665 | string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s}) | |
666 | string(REPLACE ".c" "" s ${s}) | |
f7adba41 SS |
667 | file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION})\n") |
668 | list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s}${EXE_EXTENSION}) | |
061c2240 SS |
669 | endforeach() |
670 | ||
671 | if(CURL_FOUND) | |
672 | set(remote_exes | |
673 | git-remote-https git-remote-ftp git-remote-ftps) | |
674 | foreach(s ${remote_exes}) | |
f7adba41 SS |
675 | file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION})\n") |
676 | list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s}${EXE_EXTENSION}) | |
061c2240 SS |
677 | endforeach() |
678 | endif() | |
679 | ||
680 | add_custom_command(OUTPUT ${git_links} ${git_http_links} | |
681 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake | |
682 | DEPENDS git git-remote-http) | |
683 | add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links}) | |
afa45fe5 SS |
684 | |
685 | ||
686 | #creating required scripts | |
687 | set(SHELL_PATH /bin/sh) | |
688 | set(PERL_PATH /usr/bin/perl) | |
689 | set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale) | |
690 | set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale) | |
691 | set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5) | |
692 | ||
693 | #shell scripts | |
694 | parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh") | |
695 | parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "") | |
696 | set(git_shell_scripts | |
697 | ${git_sh_scripts} ${git_shlib_scripts} git-instaweb) | |
698 | ||
699 | foreach(script ${git_shell_scripts}) | |
700 | file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.sh content NEWLINE_CONSUME) | |
701 | string(REPLACE "@SHELL_PATH@" "${SHELL_PATH}" content "${content}") | |
702 | string(REPLACE "@@DIFF@@" "diff" content "${content}") | |
703 | string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}") | |
704 | string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" content "${content}") | |
705 | string(REPLACE "@@NO_CURL@@" "" content "${content}") | |
706 | string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}") | |
707 | string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}") | |
708 | string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}") | |
709 | string(REPLACE "@@SANE_TEXT_GREP@@" "-a" content "${content}") | |
710 | string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}") | |
711 | file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content}) | |
712 | endforeach() | |
713 | ||
714 | #perl scripts | |
715 | parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl") | |
716 | ||
717 | #create perl header | |
718 | file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header ) | |
719 | string(REPLACE "@@PATHSEP@@" ":" perl_header "${perl_header}") | |
720 | string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}") | |
721 | ||
722 | foreach(script ${git_perl_scripts}) | |
723 | file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME) | |
724 | string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}") | |
725 | string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}") | |
726 | file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content}) | |
727 | endforeach() | |
728 | ||
729 | #python script | |
730 | file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME) | |
731 | string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}") | |
732 | file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content}) | |
733 | ||
734 | #perl modules | |
735 | file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm") | |
736 | ||
737 | foreach(pm ${perl_modules}) | |
738 | string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm}) | |
739 | file(STRINGS ${pm} content NEWLINE_CONSUME) | |
740 | string(REPLACE "@@LOCALEDIR@@" "${LOCALEDIR}" content "${content}") | |
741 | string(REPLACE "@@NO_PERL_CPAN_FALLBACKS@@" "" content "${content}") | |
742 | file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content}) | |
743 | #test-lib.sh requires perl/build/lib to be the build directory of perl modules | |
744 | endforeach() | |
745 | ||
746 | ||
747 | #templates | |
748 | file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*") | |
749 | list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "") | |
750 | list(REMOVE_ITEM templates ".gitignore") | |
751 | list(REMOVE_ITEM templates "Makefile") | |
752 | list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds | |
753 | ||
754 | list(REMOVE_ITEM templates "branches--") | |
755 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches | |
756 | ||
757 | #templates have @.*@ replacement so use configure_file instead | |
758 | foreach(tm ${templates}) | |
759 | string(REPLACE "--" "/" blt_tm ${tm}) | |
760 | string(REPLACE "this" "" blt_tm ${blt_tm})# for this-- | |
761 | configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY) | |
762 | endforeach() | |
763 | ||
764 | ||
765 | #translations | |
766 | if(MSGFMT_EXE) | |
767 | file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po") | |
768 | list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "") | |
769 | list(TRANSFORM po_files REPLACE ".po" "") | |
770 | foreach(po ${po_files}) | |
771 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES) | |
772 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo | |
773 | COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po) | |
774 | list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo) | |
775 | endforeach() | |
776 | add_custom_target(po-gen ALL DEPENDS ${po_gen}) | |
777 | endif() | |
f1f5dff9 SS |
778 | |
779 | ||
780 | #to help with the install | |
781 | list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/") | |
782 | list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/") | |
783 | ||
784 | #install | |
785 | install(TARGETS git git-shell | |
786 | RUNTIME DESTINATION bin) | |
787 | install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver | |
788 | DESTINATION bin) | |
789 | ||
790 | list(REMOVE_ITEM PROGRAMS_BUILT git git-shell) | |
791 | install(TARGETS ${PROGRAMS_BUILT} | |
792 | RUNTIME DESTINATION libexec/git-core) | |
793 | ||
794 | set(bin_links | |
795 | git-receive-pack git-upload-archive git-upload-pack) | |
796 | ||
797 | foreach(b ${bin_links}) | |
f7adba41 | 798 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/bin/${b}${EXE_EXTENSION})") |
f1f5dff9 SS |
799 | endforeach() |
800 | ||
f7adba41 SS |
801 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git${EXE_EXTENSION})") |
802 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell${EXE_EXTENSION})") | |
f1f5dff9 SS |
803 | |
804 | foreach(b ${git_links}) | |
805 | string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b}) | |
f7adba41 | 806 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b}${EXE_EXTENSION})") |
f1f5dff9 SS |
807 | endforeach() |
808 | ||
809 | foreach(b ${git_http_links}) | |
810 | string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b}) | |
f7adba41 | 811 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-remote-http${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b}${EXE_EXTENSION})") |
f1f5dff9 SS |
812 | endforeach() |
813 | ||
814 | install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4 | |
815 | DESTINATION libexec/git-core) | |
816 | ||
817 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core) | |
818 | install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5 | |
819 | FILES_MATCHING PATTERN "*.pm") | |
820 | install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates) | |
821 | ||
822 | if(MSGFMT_EXE) | |
823 | install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share) | |
824 | endif() | |
c4b2f41b SS |
825 | |
826 | ||
827 | if(BUILD_TESTING) | |
828 | ||
829 | #tests-helpers | |
830 | add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) | |
831 | target_link_libraries(test-fake-ssh common-main) | |
832 | ||
c4b2f41b SS |
833 | #test-tool |
834 | parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") | |
835 | ||
836 | list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/") | |
837 | add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES}) | |
838 | target_link_libraries(test-tool common-main) | |
839 | ||
fc47391e | 840 | set_target_properties(test-fake-ssh test-tool |
c4b2f41b SS |
841 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper) |
842 | ||
7f475e27 | 843 | if(MSVC) |
fc47391e | 844 | set_target_properties(test-fake-ssh test-tool |
7f475e27 | 845 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper) |
fc47391e | 846 | set_target_properties(test-fake-ssh test-tool |
7f475e27 SS |
847 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper) |
848 | endif() | |
849 | ||
c4b2f41b SS |
850 | #wrapper scripts |
851 | set(wrapper_scripts | |
852 | git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext) | |
853 | ||
854 | set(wrapper_test_scripts | |
fc47391e | 855 | test-fake-ssh test-tool) |
c4b2f41b SS |
856 | |
857 | ||
858 | foreach(script ${wrapper_scripts}) | |
859 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
860 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
f7adba41 | 861 | string(REPLACE "@@PROG@@" "${script}${EXE_EXTENSION}" content "${content}") |
c4b2f41b SS |
862 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content}) |
863 | endforeach() | |
864 | ||
865 | foreach(script ${wrapper_test_scripts}) | |
866 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
867 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
f7adba41 | 868 | string(REPLACE "@@PROG@@" "t/helper/${script}${EXE_EXTENSION}" content "${content}") |
c4b2f41b SS |
869 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content}) |
870 | endforeach() | |
871 | ||
872 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
873 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
874 | string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}") | |
875 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content}) | |
876 | ||
877 | #options for configuring test options | |
878 | option(PERL_TESTS "Perform tests that use perl" ON) | |
879 | option(PYTHON_TESTS "Perform tests that use python" ON) | |
880 | ||
881 | #GIT-BUILD-OPTIONS | |
882 | set(TEST_SHELL_PATH ${SHELL_PATH}) | |
883 | set(DIFF diff) | |
884 | set(PYTHON_PATH /usr/bin/python) | |
885 | set(TAR tar) | |
886 | set(NO_CURL ) | |
887 | set(NO_EXPAT ) | |
888 | set(USE_LIBPCRE1 ) | |
889 | set(USE_LIBPCRE2 ) | |
890 | set(NO_LIBPCRE1_JIT ) | |
891 | set(NO_PERL ) | |
892 | set(NO_PTHREADS ) | |
893 | set(NO_PYTHON ) | |
894 | set(PAGER_ENV "LESS=FRX LV=-c") | |
895 | set(DC_SHA1 YesPlease) | |
896 | set(RUNTIME_PREFIX true) | |
897 | set(NO_GETTEXT ) | |
898 | ||
899 | if(NOT CURL_FOUND) | |
900 | set(NO_CURL 1) | |
901 | endif() | |
902 | ||
903 | if(NOT EXPAT_FOUND) | |
904 | set(NO_EXPAT 1) | |
905 | endif() | |
906 | ||
907 | if(NOT Intl_FOUND) | |
908 | set(NO_GETTEXT 1) | |
909 | endif() | |
910 | ||
911 | if(NOT PERL_TESTS) | |
912 | set(NO_PERL 1) | |
913 | endif() | |
914 | ||
915 | if(NOT PYTHON_TESTS) | |
916 | set(NO_PYTHON 1) | |
917 | endif() | |
918 | ||
919 | file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n") | |
920 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n") | |
921 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n") | |
922 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n") | |
923 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n") | |
924 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n") | |
925 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n") | |
926 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n") | |
927 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "USE_LIBPCRE1='${USE_LIBPCRE1}'\n") | |
928 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_LIBPCRE1_JIT='${NO_LIBPCRE1_JIT}'\n") | |
929 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n") | |
930 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n") | |
931 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n") | |
932 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n") | |
933 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n") | |
f7adba41 | 934 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n") |
c4b2f41b SS |
935 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n") |
936 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n") | |
937 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n") | |
938 | ||
7f5397a0 SS |
939 | #Make the tests work when building out of the source tree |
940 | get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE) | |
941 | if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH}) | |
942 | file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt) | |
943 | string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE}) | |
944 | #Setting the build directory in test-lib.sh before running tests | |
945 | file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake | |
946 | "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n" | |
947 | "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n" | |
948 | "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY\\\"/../${BUILD_DIR_RELATIVE}\" content \"\${content}\")\n" | |
949 | "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})") | |
950 | #misc copies | |
951 | file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/) | |
952 | file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/) | |
953 | file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/) | |
954 | file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) | |
955 | file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) | |
7f5397a0 SS |
956 | endif() |
957 | ||
c4b2f41b SS |
958 | file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh") |
959 | ||
960 | #test | |
961 | foreach(tsh ${test_scipts}) | |
962 | add_test(NAME ${tsh} | |
963 | COMMAND ${SH_EXE} ${tsh} | |
964 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t) | |
965 | endforeach() | |
966 | ||
967 | endif()#BUILD_TESTING |