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