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