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