interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / contrib / buildsystems / CMakeLists.txt

1252 lines · 45594 bytes Raw Blame History
1#
2# Copyright (c) 2020 Sibi Siddharthan
3#
4
5#[[
6
7Instructions how to use this in Visual Studio:
8
9Open the worktree as a folder. Visual Studio 2019 and later will detect
10the CMake configuration automatically and set everything up for you,
11ready to build. You can then run the tests in `t/` via a regular Git Bash.
12
13Note: Visual Studio also has the option of opening `CMakeLists.txt`
14directly; Using this option, Visual Studio will not find the source code,
15though, therefore the `File>Open>Folder...` option is preferred.
16
17Instructions to run CMake manually:
18
19 mkdir -p contrib/buildsystems/out
20 cd contrib/buildsystems/out
21 cmake ../ -DCMAKE_BUILD_TYPE=Release
22
23This will build the git binaries in contrib/buildsystems/out
24directory (our top-level .gitignore file knows to ignore contents of
25this directory).
26
27Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
28compiler flags
29Debug : -g
30Release: -O3
31RelWithDebInfo : -O2 -g
32MinSizeRel : -Os
33empty(default) :
34
35NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio
36this option is ignored
37
38This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.
39Run `make` to build Git on Linux/*BSD/MacOS.
40Open git.sln on Windows and build Git.
41
42NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,
43to use another tool say `ninja` add this to the command line when configuring.
44`-G Ninja`
45
46NOTE: By default CMake will install vcpkg locally to your source tree on configuration,
47to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.
48
49]]
50cmake_minimum_required(VERSION 3.14)
51
52#set the source directory to root of git
53set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
54
55option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON)
56if(NOT WIN32)
57 set(USE_VCPKG OFF CACHE BOOL "" FORCE)
58endif()
59
60if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
61 set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
62endif()
63
64if(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")
78endif()
79
80find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin" "$ENV{LOCALAPPDATA}/Programs/Git/bin")
81if(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/")
84endif()
85
86message("Generating Git version")
87execute_process(COMMAND ${SH_EXE} "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
88 "${CMAKE_SOURCE_DIR}"
89 "${CMAKE_SOURCE_DIR}/contrib/buildsystems/git-version.in"
90 "${CMAKE_BINARY_DIR}/git-version")
91file(STRINGS "${CMAKE_BINARY_DIR}/git-version" git_version)
92
93project(git
94 VERSION ${git_version}
95 LANGUAGES C)
96
97
98#TODO gitk git-gui gitweb
99#TODO Enable NLS on windows natively
100
101#macros for parsing the Makefile for sources and scripts
102macro(parse_makefile_for_sources list_var makefile regex)
103 file(STRINGS ${makefile} ${list_var} REGEX "^${regex} \\+=(.*)")
104 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
105 string(REGEX REPLACE "\\$\\([^)]*_OBJS\\)" "" ${list_var} ${${list_var}}) # remove any "$(*_OBJS)" variables
106 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
107 string(REPLACE ".o" ".c;" ${list_var} ${${list_var}}) #change .o to .c, ; is for converting the string into a list
108 list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
109 list(REMOVE_ITEM ${list_var} "") #remove empty list elements
110endmacro()
111
112macro(parse_makefile_for_scripts list_var regex lang)
113 file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
114 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
115 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
116 string(REPLACE " " ";" ${list_var} ${${list_var}}) #convert string to a list
117 if(NOT ${lang}) #exclude for SCRIPT_LIB
118 list(TRANSFORM ${list_var} REPLACE "${lang}" "") #do the replacement
119 endif()
120endmacro()
121
122macro(parse_makefile_for_executables list_var regex)
123 file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+= git-(.*)")
124 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
125 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
126 string(REPLACE "git-" "" ${list_var} ${${list_var}}) #strip `git-` prefix
127 string(REPLACE "\$X" ";" ${list_var} ${${list_var}}) #strip $X, ; is for converting the string into a list
128 list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
129 list(REMOVE_ITEM ${list_var} "") #remove empty list elements
130endmacro()
131
132include(CheckTypeSize)
133include(CheckCSourceRuns)
134include(CheckCSourceCompiles)
135include(CheckIncludeFile)
136include(CheckFunctionExists)
137include(CheckSymbolExists)
138include(CheckStructHasMember)
139include(CTest)
140
141find_package(ZLIB REQUIRED)
142find_package(CURL)
143find_package(EXPAT)
144find_package(Iconv)
145
146#Don't use libintl on Windows Visual Studio and Clang builds
147if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")))
148 find_package(Intl)
149endif()
150
151find_package(PkgConfig)
152if(PkgConfig_FOUND)
153 pkg_check_modules(PCRE2 libpcre2-8)
154 if(PCRE2_FOUND)
155 add_compile_definitions(USE_LIBPCRE2)
156 endif()
157endif()
158
159if(NOT Intl_FOUND)
160 add_compile_definitions(NO_GETTEXT)
161 if(NOT Iconv_FOUND)
162 add_compile_definitions(NO_ICONV)
163 endif()
164endif()
165
166include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
167if(CURL_FOUND)
168 include_directories(SYSTEM ${CURL_INCLUDE_DIRS})
169endif()
170if(EXPAT_FOUND)
171 include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS})
172endif()
173if(Iconv_FOUND)
174 include_directories(SYSTEM ${Iconv_INCLUDE_DIRS})
175endif()
176if(Intl_FOUND)
177 include_directories(SYSTEM ${Intl_INCLUDE_DIRS})
178endif()
179if(PCRE2_FOUND)
180 include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS})
181endif()
182
183
184if(WIN32 AND NOT MSVC)#not required for visual studio builds
185 find_program(WINDRES_EXE windres)
186 if(NOT WINDRES_EXE)
187 message(FATAL_ERROR "Install windres on Windows for resource files")
188 endif()
189endif()
190
191if(NO_GETTEXT)
192 message(STATUS "msgfmt not used under NO_GETTEXT")
193else()
194 find_program(MSGFMT_EXE msgfmt)
195 if(NOT MSGFMT_EXE)
196 if(USE_VCPKG)
197 set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
198 endif()
199 if(NOT EXISTS ${MSGFMT_EXE})
200 message(WARNING "Text Translations won't be built")
201 unset(MSGFMT_EXE)
202 endif()
203 endif()
204endif()
205
206#Force all visual studio outputs to CMAKE_BINARY_DIR
207if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
208 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
209 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
210 add_compile_options(/MP /std:c11)
211endif()
212
213#default behaviour
214include_directories(${CMAKE_SOURCE_DIR})
215add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
216add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
217add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
218 SHA1DC_INIT_SAFE_HASH_DEFAULT=0
219 SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
220 SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
221list(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)
222
223
224add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
225 GIT_EXEC_PATH="libexec/git-core"
226 GIT_LOCALE_PATH="share/locale"
227 GIT_MAN_PATH="share/man"
228 GIT_INFO_PATH="share/info"
229 GIT_HTML_PATH="share/doc/git-doc"
230 DEFAULT_HELP_FORMAT="html"
231 DEFAULT_GIT_TEMPLATE_DIR="share/git-core/templates"
232 BINDIR="bin")
233
234if(WIN32)
235 set(FALLBACK_RUNTIME_PREFIX /mingw64)
236 # Move system config into top-level /etc/
237 add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
238 ETC_GITATTRIBUTES="../etc/gitattributes"
239 ETC_GITCONFIG="../etc/gitconfig")
240else()
241 set(FALLBACK_RUNTIME_PREFIX /home/$ENV{USER})
242 add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
243 ETC_GITATTRIBUTES="etc/gitattributes"
244 ETC_GITCONFIG="etc/gitconfig")
245endif()
246
247
248#Platform Specific
249if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
250 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
251 include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include)
252 add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
253 endif()
254 include_directories(${CMAKE_SOURCE_DIR}/compat/win32)
255 add_compile_definitions(HAVE_ALLOCA_H NO_POSIX_GOODIES NATIVE_CRLF NO_UNIX_SOCKETS WIN32
256 _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT
257 NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0
258 OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
259 HAVE_WPGMPTR HAVE_RTLGENRANDOM)
260 if(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
261 add_compile_definitions(ENSURE_MSYSTEM_IS_SET="UCRT64" MINGW_PREFIX="ucrt64")
262 elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64")
263 add_compile_definitions(ENSURE_MSYSTEM_IS_SET="CLANGARM64" MINGW_PREFIX="clangarm64")
264 elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x86")
265 add_compile_definitions(ENSURE_MSYSTEM_IS_SET="MINGW32" MINGW_PREFIX="mingw32")
266 endif()
267 list(APPEND compat_SOURCES
268 compat/mingw.c
269 compat/winansi.c
270 compat/win32/flush.c
271 compat/win32/path-utils.c
272 compat/win32/pthread.c
273 compat/win32mmap.c
274 compat/win32/syslog.c
275 compat/win32/trace2_win32_process_info.c
276 compat/win32/dirent.c
277 compat/strdup.c)
278 set(NO_UNIX_SOCKETS 1)
279
280elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
281 add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY )
282 list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c)
283elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
284 list(APPEND compat_SOURCES compat/darwin/procinfo.c)
285endif()
286
287if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
288 list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-win32.c)
289 add_compile_definitions(SUPPORTS_SIMPLE_IPC)
290 set(SUPPORTS_SIMPLE_IPC 1)
291else()
292 # Simple IPC requires both Unix sockets and pthreads on Unix-based systems.
293 if(NOT NO_UNIX_SOCKETS AND NOT NO_PTHREADS)
294 list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
295 add_compile_definitions(SUPPORTS_SIMPLE_IPC)
296 set(SUPPORTS_SIMPLE_IPC 1)
297 endif()
298endif()
299
300if(SUPPORTS_SIMPLE_IPC)
301 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
302 set(FSMONITOR_DAEMON_BACKEND "win32")
303 set(FSMONITOR_OS_SETTINGS "win32")
304 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
305 set(FSMONITOR_DAEMON_BACKEND "darwin")
306 set(FSMONITOR_OS_SETTINGS "unix")
307 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
308 set(FSMONITOR_DAEMON_BACKEND "linux")
309 set(FSMONITOR_OS_SETTINGS "unix")
310 add_compile_definitions(HAVE_LINUX_MAGIC_H)
311 endif()
312
313 if(FSMONITOR_DAEMON_BACKEND)
314 add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
315 list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-${FSMONITOR_DAEMON_BACKEND}.c)
316 list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-${FSMONITOR_DAEMON_BACKEND}.c)
317 list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-${FSMONITOR_OS_SETTINGS}.c)
318 list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-${FSMONITOR_DAEMON_BACKEND}.c)
319
320 add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
321 list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-${FSMONITOR_OS_SETTINGS}.c)
322 endif()
323endif()
324
325set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
326
327#header checks
328check_include_file(libgen.h HAVE_LIBGEN_H)
329if(NOT HAVE_LIBGEN_H)
330 add_compile_definitions(NO_LIBGEN_H)
331 list(APPEND compat_SOURCES compat/basename.c)
332endif()
333
334check_include_file(sys/sysinfo.h HAVE_SYSINFO)
335if(HAVE_SYSINFO)
336 add_compile_definitions(HAVE_SYSINFO)
337endif()
338
339check_c_source_compiles("
340#include <alloca.h>
341
342int main(void)
343{
344 char *p = (char *) alloca(2 * sizeof(int));
345
346 if (p)
347 return 0;
348 return 0;
349}"
350HAVE_ALLOCA_H)
351if(HAVE_ALLOCA_H)
352 add_compile_definitions(HAVE_ALLOCA_H)
353endif()
354
355check_include_file(strings.h HAVE_STRINGS_H)
356if(HAVE_STRINGS_H)
357 add_compile_definitions(HAVE_STRINGS_H)
358endif()
359
360check_include_file(sys/select.h HAVE_SYS_SELECT_H)
361if(NOT HAVE_SYS_SELECT_H)
362 add_compile_definitions(NO_SYS_SELECT_H)
363endif()
364
365check_include_file(sys/poll.h HAVE_SYS_POLL_H)
366if(NOT HAVE_SYS_POLL_H)
367 add_compile_definitions(NO_SYS_POLL_H)
368endif()
369
370check_include_file(poll.h HAVE_POLL_H)
371if(NOT HAVE_POLL_H)
372 add_compile_definitions(NO_POLL_H)
373endif()
374
375check_include_file(inttypes.h HAVE_INTTYPES_H)
376if(NOT HAVE_INTTYPES_H)
377 add_compile_definitions(NO_INTTYPES_H)
378endif()
379
380check_include_file(paths.h HAVE_PATHS_H)
381if(HAVE_PATHS_H)
382 add_compile_definitions(HAVE_PATHS_H)
383endif()
384
385#function checks
386set(function_checks
387 strcasestr memmem strlcpy strtoimax strtoumax strtoull
388 setenv mkdtemp poll pread memmem writev)
389
390#unsetenv,hstrerror are incompatible with windows build
391if(NOT WIN32)
392 list(APPEND function_checks unsetenv hstrerror)
393endif()
394
395foreach(f ${function_checks})
396 string(TOUPPER ${f} uf)
397 check_function_exists(${f} HAVE_${uf})
398 if(NOT HAVE_${uf})
399 add_compile_definitions(NO_${uf})
400 endif()
401endforeach()
402
403if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL)
404 include_directories(${CMAKE_SOURCE_DIR}/compat/poll)
405 add_compile_definitions(NO_POLL)
406 list(APPEND compat_SOURCES compat/poll/poll.c)
407endif()
408
409if(NOT HAVE_STRCASESTR)
410 list(APPEND compat_SOURCES compat/strcasestr.c)
411endif()
412
413if(NOT HAVE_STRLCPY)
414 list(APPEND compat_SOURCES compat/strlcpy.c)
415endif()
416
417if(NOT HAVE_STRTOUMAX)
418 list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c)
419endif()
420
421if(NOT HAVE_SETENV)
422 list(APPEND compat_SOURCES compat/setenv.c)
423endif()
424
425if(NOT HAVE_PREAD)
426 list(APPEND compat_SOURCES compat/pread.c)
427endif()
428
429if(NOT HAVE_MEMMEM)
430 list(APPEND compat_SOURCES compat/memmem.c)
431endif()
432
433if(NOT HAVE_WRITEV)
434 list(APPEND compat_SOURCES compat/writev.c)
435endif()
436
437if(NOT WIN32)
438 if(NOT HAVE_UNSETENV)
439 list(APPEND compat_SOURCES compat/unsetenv.c)
440 endif()
441
442 if(NOT HAVE_HSTRERROR)
443 list(APPEND compat_SOURCES compat/hstrerror.c)
444 endif()
445endif()
446
447check_function_exists(getdelim HAVE_GETDELIM)
448if(HAVE_GETDELIM)
449 add_compile_definitions(HAVE_GETDELIM)
450endif()
451
452check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
453check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
454if(HAVE_CLOCK_GETTIME)
455 add_compile_definitions(HAVE_CLOCK_GETTIME)
456endif()
457if(HAVE_CLOCK_MONOTONIC)
458 add_compile_definitions(HAVE_CLOCK_MONOTONIC)
459endif()
460
461#check for st_blocks in struct stat
462check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS)
463if(NOT STRUCT_STAT_HAS_ST_BLOCKS)
464 add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT)
465endif()
466
467#compile checks
468check_c_source_runs("
469#include<stdio.h>
470#include<stdarg.h>
471#include<string.h>
472#include<stdlib.h>
473
474int test_vsnprintf(char *str, size_t maxsize, const char *format, ...)
475{
476 int ret;
477 va_list ap;
478
479 va_start(ap, format);
480 ret = vsnprintf(str, maxsize, format, ap);
481 va_end(ap);
482 return ret;
483}
484
485int main(void)
486{
487 char buf[6];
488
489 if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5
490 || strcmp(buf, \"12\"))
491 return 1;
492 if (snprintf(buf, 3, \"%s\", \"12345\") != 5
493 || strcmp(buf, \"12\"))
494 return 1;
495 return 0;
496}"
497SNPRINTF_OK)
498if(NOT SNPRINTF_OK)
499 add_compile_definitions(SNPRINTF_RETURNS_BOGUS)
500 list(APPEND compat_SOURCES compat/snprintf.c)
501endif()
502
503check_c_source_runs("
504#include<stdio.h>
505
506int main(void)
507{
508 FILE *f = fopen(\".\", \"r\");
509
510 return f != NULL;
511}"
512FREAD_READS_DIRECTORIES_NO)
513if(NOT FREAD_READS_DIRECTORIES_NO)
514 add_compile_definitions(FREAD_READS_DIRECTORIES)
515 list(APPEND compat_SOURCES compat/fopen.c)
516endif()
517
518check_c_source_compiles("
519#include <regex.h>
520#ifndef REG_STARTEND
521#error oops we dont have it
522#endif
523
524int main(void)
525{
526 return 0;
527}"
528HAVE_REGEX)
529if(NOT HAVE_REGEX)
530 include_directories(${CMAKE_SOURCE_DIR}/compat/regex)
531 list(APPEND compat_SOURCES compat/regex/regex.c )
532 add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK)
533endif()
534
535
536check_c_source_compiles("
537#include <stddef.h>
538#include <sys/types.h>
539#include <sys/sysctl.h>
540
541int main(void)
542{
543 int val, mib[2];
544 size_t len;
545
546 mib[0] = CTL_HW;
547 mib[1] = 1;
548 len = sizeof(val);
549 return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
550}"
551HAVE_BSD_SYSCTL)
552if(HAVE_BSD_SYSCTL)
553 add_compile_definitions(HAVE_BSD_SYSCTL)
554endif()
555
556set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES})
557set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS})
558
559check_c_source_compiles("
560#include <iconv.h>
561
562extern size_t iconv(iconv_t cd,
563 char **inbuf, size_t *inbytesleft,
564 char **outbuf, size_t *outbytesleft);
565
566int main(void)
567{
568 return 0;
569}"
570HAVE_NEW_ICONV)
571if(HAVE_NEW_ICONV)
572 set(HAVE_OLD_ICONV 0)
573else()
574 set(HAVE_OLD_ICONV 1)
575endif()
576
577check_c_source_runs("
578#include <iconv.h>
579#if ${HAVE_OLD_ICONV}
580typedef const char *iconv_ibp;
581#else
582typedef char *iconv_ibp;
583#endif
584
585int main(void)
586{
587 int v;
588 iconv_t conv;
589 char in[] = \"a\";
590 iconv_ibp pin = in;
591 char out[20] = \"\";
592 char *pout = out;
593 size_t isz = sizeof(in);
594 size_t osz = sizeof(out);
595
596 conv = iconv_open(\"UTF-16\", \"UTF-8\");
597 iconv(conv, &pin, &isz, &pout, &osz);
598 iconv_close(conv);
599 v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
600 return v != 0xfe + 0xff;
601}"
602ICONV_DOESNOT_OMIT_BOM)
603if(NOT ICONV_DOESNOT_OMIT_BOM)
604 add_compile_definitions(ICONV_OMITS_BOM)
605endif()
606
607unset(CMAKE_REQUIRED_LIBRARIES)
608unset(CMAKE_REQUIRED_INCLUDES)
609
610
611#programs
612set(PROGRAMS_BUILT
613 git git-daemon git-http-backend git-sh-i18n--envsubst
614 git-shell scalar)
615
616if(NOT CURL_FOUND)
617 list(APPEND excluded_progs git-http-fetch git-http-push)
618 add_compile_definitions(NO_CURL)
619 message(WARNING "git-http-push and git-http-fetch will not be built")
620else()
621 list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http)
622 if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0)
623 add_compile_definitions(USE_CURL_FOR_IMAP_SEND)
624 endif()
625endif()
626
627if(NOT EXPAT_FOUND)
628 list(APPEND excluded_progs git-http-push)
629 add_compile_definitions(NO_EXPAT)
630else()
631 list(APPEND PROGRAMS_BUILT git-http-push)
632 if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2)
633 add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H)
634 endif()
635endif()
636
637list(REMOVE_DUPLICATES excluded_progs)
638list(REMOVE_DUPLICATES PROGRAMS_BUILT)
639
640
641foreach(p ${excluded_progs})
642 list(APPEND EXCLUSION_PROGS --exclude-program ${p} )
643endforeach()
644
645#for comparing null values
646list(APPEND EXCLUSION_PROGS empty)
647set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE)
648
649if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS)
650 list(REMOVE_ITEM EXCLUSION_PROGS empty)
651 message("Generating command-list.h")
652 execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-cmdlist.sh"
653 ${EXCLUSION_PROGS}
654 "${CMAKE_SOURCE_DIR}"
655 "${CMAKE_BINARY_DIR}/command-list.h")
656endif()
657
658if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
659 message("Generating config-list.h")
660 execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-configlist.sh"
661 "${CMAKE_SOURCE_DIR}"
662 "${CMAKE_BINARY_DIR}/config-list.h")
663endif()
664
665if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h)
666 message("Generating hook-list.h")
667 execute_process(COMMAND "${SH_EXE}" ${CMAKE_SOURCE_DIR}/tools/generate-hooklist.sh
668 "${CMAKE_SOURCE_DIR}"
669 "${CMAKE_BINARY_DIR}/hook-list.h")
670endif()
671
672include_directories(${CMAKE_BINARY_DIR})
673
674#build
675#libgit
676parse_makefile_for_sources(libgit_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "LIB_OBJS")
677
678#reftable
679parse_makefile_for_sources(reftable_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "REFTABLE_OBJS")
680list(APPEND libgit_SOURCES ${reftable_SOURCES})
681
682list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
683list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
684
685add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/version-def.h"
686 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
687 "${CMAKE_SOURCE_DIR}"
688 "${CMAKE_SOURCE_DIR}/version-def.h.in"
689 "${CMAKE_BINARY_DIR}/version-def.h"
690 DEPENDS "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
691 "${CMAKE_SOURCE_DIR}/version-def.h.in"
692 VERBATIM)
693list(APPEND libgit_SOURCES "${CMAKE_BINARY_DIR}/version-def.h")
694
695add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
696
697if(WIN32)
698 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.rc
699 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
700 "${CMAKE_SOURCE_DIR}"
701 "${CMAKE_SOURCE_DIR}/git.rc.in"
702 "${CMAKE_BINARY_DIR}/git.rc"
703 DEPENDS "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
704 "${CMAKE_SOURCE_DIR}/git.rc.in"
705 VERBATIM)
706
707 if(NOT MSVC)#use windres when compiling with gcc and clang
708 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
709 COMMAND ${WINDRES_EXE} -O coff -i ${CMAKE_BINARY_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res
710 DEPENDS "${CMAKE_BINARY_DIR}/git.rc"
711 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
712 VERBATIM)
713 else()#MSVC use rc
714 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
715 COMMAND ${CMAKE_RC_COMPILER} /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_BINARY_DIR}/git.rc
716 DEPENDS "${CMAKE_BINARY_DIR}/git.rc"
717 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
718 VERBATIM)
719 endif()
720 add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res)
721endif()
722
723#link all required libraries to common-main
724add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
725
726target_link_libraries(common-main libgit ${ZLIB_LIBRARIES})
727if(Intl_FOUND)
728 target_link_libraries(common-main ${Intl_LIBRARIES})
729endif()
730if(Iconv_FOUND)
731 target_link_libraries(common-main ${Iconv_LIBRARIES})
732endif()
733if(PCRE2_FOUND)
734 target_link_libraries(common-main ${PCRE2_LIBRARIES})
735 target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS})
736endif()
737if(WIN32)
738 target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
739 add_dependencies(common-main git-rc)
740 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
741 target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
742 elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
743 target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
744 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
745 target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj)
746 else()
747 message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
748 endif()
749
750 add_executable(headless-git ${CMAKE_SOURCE_DIR}/compat/win32/headless.c)
751 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
752 target_link_options(headless-git PUBLIC -municode -Wl,-subsystem,windows)
753 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
754 target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS)
755 else()
756 message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
757 endif()
758elseif(UNIX)
759 target_link_libraries(common-main pthread rt)
760endif()
761
762#git
763parse_makefile_for_sources(git_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "BUILTIN_OBJS")
764
765list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
766add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
767target_link_libraries(git common-main)
768
769add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
770target_link_libraries(git-daemon common-main)
771
772add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c)
773target_link_libraries(git-http-backend common-main)
774
775add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c)
776target_link_libraries(git-sh-i18n--envsubst common-main)
777
778add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c)
779target_link_libraries(git-shell common-main)
780
781add_executable(scalar ${CMAKE_SOURCE_DIR}/scalar.c)
782target_link_libraries(scalar common-main)
783
784if(CURL_FOUND)
785 add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c)
786
787 add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c)
788 target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES})
789
790 add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c)
791 target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES})
792
793 add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c)
794 target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} )
795
796 if(EXPAT_FOUND)
797 add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c)
798 target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES})
799 endif()
800endif()
801
802parse_makefile_for_executables(git_builtin_extra "BUILT_INS")
803
804option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins")
805
806#Creating hardlinks
807if(NOT SKIP_DASHED_BUILT_INS)
808foreach(s ${git_SOURCES} ${git_builtin_extra})
809 string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s})
810 string(REPLACE ".c" "" s ${s})
811 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION})\n")
812 list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s}${EXE_EXTENSION})
813endforeach()
814endif()
815
816if(CURL_FOUND)
817 set(remote_exes
818 git-remote-https git-remote-ftp git-remote-ftps)
819 foreach(s ${remote_exes})
820 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION})\n")
821 list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s}${EXE_EXTENSION})
822 endforeach()
823endif()
824
825add_custom_command(OUTPUT ${git_links} ${git_http_links}
826 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake
827 DEPENDS git git-remote-http)
828add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})
829
830
831#creating required scripts
832set(SHELL_PATH /bin/sh)
833set(PERL_PATH /usr/bin/perl)
834set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
835set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
836set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5)
837
838#shell scripts
839parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh")
840parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "")
841set(git_shell_scripts
842 ${git_sh_scripts} ${git_shlib_scripts} git-instaweb)
843
844foreach(script ${git_shell_scripts})
845 if ("${script}" IN_LIST git_sh_scripts)
846 string(REPLACE ".sh" "" shell_gen_path "${script}")
847 else()
848 set(shell_gen_path "${script}")
849 endif()
850
851 add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${shell_gen_path}"
852 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-script.sh"
853 "${CMAKE_SOURCE_DIR}/${script}.sh"
854 "${CMAKE_BINARY_DIR}/${shell_gen_path}"
855 "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
856 DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-script.sh"
857 "${CMAKE_SOURCE_DIR}/${script}.sh"
858 VERBATIM)
859 list(APPEND shell_gen ${CMAKE_BINARY_DIR}/${shell_gen_path})
860endforeach()
861add_custom_target(shell-gen ALL DEPENDS ${shell_gen})
862
863#perl scripts
864parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" "")
865#perl modules
866file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
867list(TRANSFORM perl_modules REPLACE "${CMAKE_SOURCE_DIR}/" "")
868
869#create perl header
870file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
871string(REPLACE "@PATHSEP@" ":" perl_header "${perl_header}")
872string(REPLACE "@INSTLIBDIR@" "${INSTLIBDIR}" perl_header "${perl_header}")
873file(WRITE ${CMAKE_BINARY_DIR}/GIT-PERL-HEADER ${perl_header})
874
875add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
876 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
877 "${CMAKE_SOURCE_DIR}"
878 "${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
879 "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
880 DEPENDS ${SH_EXE} "${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN"
881 "${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE.in"
882 VERBATIM)
883
884foreach(script ${git_perl_scripts} ${perl_modules})
885 string(REPLACE ".perl" "" perl_gen_path "${script}")
886
887 get_filename_component(perl_gen_dir "${perl_gen_path}" DIRECTORY)
888 if(script MATCHES "\.pm$")
889 string(REGEX REPLACE "^perl" "perl/build/lib" perl_gen_dir "${perl_gen_dir}")
890 string(REGEX REPLACE "^perl" "perl/build/lib" perl_gen_path "${perl_gen_path}")
891 endif()
892 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${perl_gen_dir}")
893
894 add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/${perl_gen_path}"
895 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-perl.sh"
896 "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
897 "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
898 "${CMAKE_BINARY_DIR}/GIT-PERL-HEADER"
899 "${CMAKE_SOURCE_DIR}/${script}"
900 "${CMAKE_BINARY_DIR}/${perl_gen_path}"
901 DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-perl.sh"
902 "${CMAKE_SOURCE_DIR}/${script}"
903 "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
904 "${CMAKE_BINARY_DIR}/GIT-VERSION-FILE"
905 VERBATIM)
906 list(APPEND perl_gen ${CMAKE_BINARY_DIR}/${perl_gen_path})
907endforeach()
908add_custom_target(perl-gen ALL DEPENDS ${perl_gen})
909
910# Python script
911add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/git-p4"
912 COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/tools/generate-python.sh"
913 "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
914 "${CMAKE_SOURCE_DIR}/git-p4.py"
915 "${CMAKE_BINARY_DIR}/git-p4"
916 DEPENDS "${CMAKE_SOURCE_DIR}/tools/generate-python.sh"
917 "${CMAKE_SOURCE_DIR}/git-p4.py"
918 "${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS"
919 VERBATIM)
920add_custom_target(python-gen ALL DEPENDS "${CMAKE_BINARY_DIR}/git-p4")
921
922#${CMAKE_SOURCE_DIR}/Makefile templates
923parse_makefile_for_sources(templates ${CMAKE_SOURCE_DIR}/templates/Makefile "TEMPLATES")
924string(REPLACE " " ";" templates ${templates})
925#templates have @.*@ replacement so use configure_file instead
926foreach(tm ${templates})
927 configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${tm} @ONLY)
928endforeach()
929
930#translations
931if(MSGFMT_EXE)
932 file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
933 list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "")
934 list(TRANSFORM po_files REPLACE ".po" "")
935 foreach(po ${po_files})
936 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)
937 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo
938 COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)
939 list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)
940 endforeach()
941 add_custom_target(po-gen ALL DEPENDS ${po_gen})
942endif()
943
944
945#to help with the install
946list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
947list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
948
949#install
950foreach(program ${PROGRAMS_BUILT})
951if(program MATCHES "^(git|git-shell|scalar)$")
952install(TARGETS ${program}
953 RUNTIME DESTINATION bin)
954else()
955install(TARGETS ${program}
956 RUNTIME DESTINATION libexec/git-core)
957endif()
958endforeach()
959
960install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver
961 DESTINATION bin)
962
963set(bin_links
964 git-receive-pack git-upload-archive git-upload-pack)
965
966foreach(b ${bin_links})
967install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/bin/${b}${EXE_EXTENSION})")
968endforeach()
969
970install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git${EXE_EXTENSION})")
971install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell${EXE_EXTENSION})")
972
973foreach(b ${git_links})
974 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
975 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
976endforeach()
977
978foreach(b ${git_http_links})
979 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
980 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-remote-http${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
981endforeach()
982
983install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4
984 DESTINATION libexec/git-core)
985
986install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core)
987install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5
988 FILES_MATCHING PATTERN "*.pm")
989install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates)
990
991if(MSGFMT_EXE)
992 install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share)
993endif()
994
995
996if(BUILD_TESTING)
997
998#tests-helpers
999add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
1000target_link_libraries(test-fake-ssh common-main)
1001
1002#unit-tests
1003parse_makefile_for_sources(unit-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "UNIT_TEST_OBJS")
1004list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/")
1005add_library(unit-test-lib STATIC ${unit-test_SOURCES})
1006
1007parse_makefile_for_sources(clar-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "CLAR_TEST_OBJS")
1008list(TRANSFORM clar-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/")
1009add_library(clar-test-lib STATIC ${clar-test_SOURCES})
1010
1011file(GLOB unit_test_PROGRAMS "${CMAKE_SOURCE_DIR}/t/unit-tests/t-*.c")
1012list(TRANSFORM unit_test_PROGRAMS REPLACE "${CMAKE_SOURCE_DIR}/" "")
1013list(TRANSFORM unit_test_PROGRAMS REPLACE ".c" "")
1014foreach(unit_test ${unit_test_PROGRAMS})
1015 add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
1016 target_link_libraries("${unit_test}" unit-test-lib clar-test-lib common-main)
1017 set_target_properties("${unit_test}"
1018 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1019 if(MSVC)
1020 set_target_properties("${unit_test}"
1021 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1022 set_target_properties("${unit_test}"
1023 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1024 endif()
1025 list(APPEND PROGRAMS_BUILT "${unit_test}")
1026
1027 # t-basic intentionally fails tests, to validate the unit-test infrastructure.
1028 # Therefore, it should only be run as part of t0080, which verifies that it
1029 # fails only in the expected ways.
1030 #
1031 # All other unit tests should be run.
1032 if(NOT ${unit_test} STREQUAL "t-basic")
1033 add_test(NAME "t.unit-tests.${unit_test}"
1034 COMMAND "./${unit_test}"
1035 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t/unit-tests/bin)
1036 endif()
1037endforeach()
1038
1039parse_makefile_for_scripts(clar_test_SUITES "CLAR_TEST_SUITES" "")
1040list(TRANSFORM clar_test_SUITES PREPEND "${CMAKE_SOURCE_DIR}/t/unit-tests/")
1041list(TRANSFORM clar_test_SUITES APPEND ".c")
1042add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1043 COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh
1044 "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1045 ${clar_test_SUITES}
1046 DEPENDS ${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-decls.sh
1047 ${clar_test_SUITES}
1048 VERBATIM)
1049add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1050 COMMAND ${SH_EXE} "${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-suites.sh"
1051 "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1052 "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1053 DEPENDS "${CMAKE_SOURCE_DIR}/t/unit-tests/generate-clar-suites.sh"
1054 "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1055 VERBATIM)
1056
1057add_library(unit-tests-lib ${clar_test_SUITES}
1058 "${CMAKE_BINARY_DIR}/t/unit-tests/clar-decls.h"
1059 "${CMAKE_BINARY_DIR}/t/unit-tests/clar.suite"
1060)
1061target_include_directories(clar-test-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests")
1062target_include_directories(unit-tests-lib PUBLIC "${CMAKE_BINARY_DIR}/t/unit-tests")
1063add_executable(unit-tests)
1064target_link_libraries(unit-tests unit-tests-lib clar-test-lib common-main)
1065set_target_properties(unit-tests
1066 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1067if(MSVC)
1068 set_target_properties(unit-tests
1069 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1070 set_target_properties(unit-tests
1071 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
1072endif()
1073
1074#test-tool
1075parse_makefile_for_sources(test-tool_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "TEST_BUILTINS_OBJS")
1076add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
1077
1078list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
1079add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
1080target_link_libraries(test-tool test-lib common-main)
1081
1082set_target_properties(test-fake-ssh test-tool
1083 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
1084
1085if(MSVC)
1086 set_target_properties(test-fake-ssh test-tool
1087 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
1088 set_target_properties(test-fake-ssh test-tool
1089 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
1090endif()
1091
1092#wrapper scripts
1093set(wrapper_scripts
1094 git git-upload-pack git-receive-pack git-upload-archive git-shell scalar)
1095
1096set(wrapper_test_scripts
1097 test-fake-ssh test-tool)
1098
1099
1100foreach(script ${wrapper_scripts})
1101 file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
1102 string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1103 string(REPLACE "@TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" content "${content}")
1104 string(REPLACE "@PROG@" "${CMAKE_BINARY_DIR}/${script}${EXE_EXTENSION}" content "${content}")
1105 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
1106endforeach()
1107
1108foreach(script ${wrapper_test_scripts})
1109 file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
1110 string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1111 string(REPLACE "@TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" content "${content}")
1112 string(REPLACE "@PROG@" "${CMAKE_BINARY_DIR}/t/helper/${script}${EXE_EXTENSION}" content "${content}")
1113 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
1114endforeach()
1115
1116file(STRINGS ${CMAKE_SOURCE_DIR}/bin-wrappers/wrap-for-bin.sh content NEWLINE_CONSUME)
1117string(REPLACE "@BUILD_DIR@" "${CMAKE_BINARY_DIR}" content "${content}")
1118string(REPLACE "@TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" content "${content}")
1119string(REPLACE "@GIT_TEXTDOMAINDIR@" "${CMAKE_BINARY_DIR}/po/build/locale" content "${content}")
1120string(REPLACE "@GITPERLLIB@" "${CMAKE_BINARY_DIR}/perl/build/lib" content "${content}")
1121string(REPLACE "@MERGE_TOOLS_DIR@" "${CMAKE_SOURCE_DIR}/mergetools" content "${content}")
1122string(REPLACE "@PROG@" "${CMAKE_BINARY_DIR}/git-cvsserver" content "${content}")
1123file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
1124
1125#options for configuring test options
1126option(PERL_TESTS "Perform tests that use perl" ON)
1127option(PYTHON_TESTS "Perform tests that use python" ON)
1128
1129#GIT-BUILD-OPTIONS
1130set(TEST_SHELL_PATH ${SHELL_PATH})
1131set(DIFF diff)
1132set(PYTHON_PATH /usr/bin/python)
1133set(TAR tar)
1134set(NO_CURL )
1135set(NO_ICONV )
1136set(NO_EXPAT )
1137set(USE_LIBPCRE2 )
1138set(NO_PERL )
1139set(NO_PTHREADS )
1140set(NO_PYTHON )
1141set(PAGER_ENV "LESS=FRX LV=-c")
1142set(RUNTIME_PREFIX true)
1143set(NO_GETTEXT )
1144
1145if(NOT CURL_FOUND)
1146 set(NO_CURL 1)
1147endif()
1148
1149if(NOT Iconv_FOUND)
1150 SET(NO_ICONV 1)
1151endif()
1152
1153if(NOT EXPAT_FOUND)
1154 set(NO_EXPAT 1)
1155endif()
1156
1157if(NOT Intl_FOUND)
1158 set(NO_GETTEXT 1)
1159endif()
1160
1161if(NOT PERL_TESTS)
1162 set(NO_PERL 1)
1163endif()
1164
1165if(NOT PYTHON_TESTS)
1166 set(NO_PYTHON 1)
1167endif()
1168
1169file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-BUILD-OPTIONS.in git_build_options NEWLINE_CONSUME)
1170string(REPLACE "@BROKEN_PATH_FIX@" "" git_build_options "${git_build_options}")
1171string(REPLACE "@DIFF@" "'${DIFF}'" git_build_options "${git_build_options}")
1172string(REPLACE "@FSMONITOR_DAEMON_BACKEND@" "${FSMONITOR_DAEMON_BACKEND}" git_build_options "${git_build_options}")
1173string(REPLACE "@FSMONITOR_OS_SETTINGS@" "${FSMONITOR_OS_SETTINGS}" git_build_options "${git_build_options}")
1174string(REPLACE "@GITWEBDIR@" "'${GITWEBDIR}'" git_build_options "${git_build_options}")
1175string(REPLACE "@GIT_INTEROP_MAKE_OPTS@" "" git_build_options "${git_build_options}")
1176string(REPLACE "@GIT_PERF_LARGE_REPO@" "" git_build_options "${git_build_options}")
1177string(REPLACE "@GIT_PERF_MAKE_COMMAND@" "" git_build_options "${git_build_options}")
1178string(REPLACE "@GIT_PERF_MAKE_OPTS@" "" git_build_options "${git_build_options}")
1179string(REPLACE "@GIT_PERF_REPEAT_COUNT@" "" git_build_options "${git_build_options}")
1180string(REPLACE "@GIT_PERF_REPO@" "" git_build_options "${git_build_options}")
1181string(REPLACE "@GIT_SOURCE_DIR@" "${CMAKE_SOURCE_DIR}" git_build_options "${git_build_options}")
1182string(REPLACE "@GIT_TEST_CMP@" "" git_build_options "${git_build_options}")
1183string(REPLACE "@GIT_TEST_CMP_USE_COPIED_CONTEXT@" "" git_build_options "${git_build_options}")
1184string(REPLACE "@GIT_TEST_GITPERLLIB@" "'${CMAKE_BINARY_DIR}/perl/build/lib'" git_build_options "${git_build_options}")
1185string(REPLACE "@GIT_TEST_INDEX_VERSION@" "" git_build_options "${git_build_options}")
1186string(REPLACE "@GIT_TEST_OPTS@" "" git_build_options "${git_build_options}")
1187string(REPLACE "@GIT_TEST_PERL_FATAL_WARNINGS@" "" git_build_options "${git_build_options}")
1188string(REPLACE "@GIT_TEST_TEMPLATE_DIR@" "'${CMAKE_BINARY_DIR}/templates/blt'" git_build_options "${git_build_options}")
1189string(REPLACE "@GIT_TEST_TEXTDOMAINDIR@" "'${CMAKE_BINARY_DIR}/po/build/locale'" git_build_options "${git_build_options}")
1190string(REPLACE "@GIT_TEST_UTF8_LOCALE@" "" git_build_options "${git_build_options}")
1191string(REPLACE "@LOCALEDIR@" "'${LOCALEDIR}'" git_build_options "${git_build_options}")
1192string(REPLACE "@NO_CURL@" "${NO_CURL}" git_build_options "${git_build_options}")
1193string(REPLACE "@NO_EXPAT@" "${NO_EXPAT}" git_build_options "${git_build_options}")
1194string(REPLACE "@NO_GETTEXT@" "${NO_GETTEXT}" git_build_options "${git_build_options}")
1195string(REPLACE "@NO_GITWEB@" "1" git_build_options "${git_build_options}")
1196string(REPLACE "@NO_ICONV@" "${NO_ICONV}" git_build_options "${git_build_options}")
1197string(REPLACE "@NO_PERL@" "${NO_PERL}" git_build_options "${git_build_options}")
1198string(REPLACE "@NO_PERL_CPAN_FALLBACKS@" "" git_build_options "${git_build_options}")
1199string(REPLACE "@NO_PTHREADS@" "${NO_PTHREADS}" git_build_options "${git_build_options}")
1200string(REPLACE "@NO_PYTHON@" "${NO_PYTHON}" git_build_options "${git_build_options}")
1201string(REPLACE "@NO_REGEX@" "" git_build_options "${git_build_options}")
1202string(REPLACE "@NO_UNIX_SOCKETS@" "${NO_UNIX_SOCKETS}" git_build_options "${git_build_options}")
1203string(REPLACE "@PAGER_ENV@" "'${PAGER_ENV}'" git_build_options "${git_build_options}")
1204string(REPLACE "@PERL_LOCALEDIR@" "'${LOCALEDIR}'" git_build_options "${git_build_options}")
1205string(REPLACE "@PERL_PATH@" "'${PERL_PATH}'" git_build_options "${git_build_options}")
1206string(REPLACE "@PYTHON_PATH@" "'${PYTHON_PATH}'" git_build_options "${git_build_options}")
1207string(REPLACE "@RUNTIME_PREFIX@" "'${RUNTIME_PREFIX}'" git_build_options "${git_build_options}")
1208string(REPLACE "@SANITIZE_ADDRESS@" "" git_build_options "${git_build_options}")
1209string(REPLACE "@SANITIZE_LEAK@" "" git_build_options "${git_build_options}")
1210string(REPLACE "@SHELL_PATH@" "'${SHELL_PATH}'" git_build_options "${git_build_options}")
1211string(REPLACE "@TAR@" "'${TAR}'" git_build_options "${git_build_options}")
1212string(REPLACE "@TEST_OUTPUT_DIRECTORY@" "" git_build_options "${git_build_options}")
1213string(REPLACE "@TEST_SHELL_PATH@" "'${TEST_SHELL_PATH}'" git_build_options "${git_build_options}")
1214string(REPLACE "@USE_GETTEXT_SCHEME@" "" git_build_options "${git_build_options}")
1215string(REPLACE "@USE_LIBPCRE2@" "" git_build_options "${git_build_options}")
1216string(REPLACE "@WITH_BREAKING_CHANGES@" "" git_build_options "${git_build_options}")
1217string(REPLACE "@X@" "${EXE_EXTENSION}" git_build_options "${git_build_options}")
1218if(USE_VCPKG)
1219 string(APPEND git_build_options "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
1220endif()
1221file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS ${git_build_options})
1222
1223#Make the tests work when building out of the source tree
1224get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)
1225if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
1226 #Setting the build directory in test-lib.sh before running tests
1227 file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
1228 "file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \"${CMAKE_BINARY_DIR}\")")
1229 #misc copies
1230 file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)
1231 file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)
1232 file(GLOB mergetools "${CMAKE_SOURCE_DIR}/mergetools/*")
1233 file(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
1234 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
1235 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
1236endif()
1237
1238file(GLOB test_scripts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
1239
1240#test
1241foreach(tsh ${test_scripts})
1242 string(REGEX REPLACE ".*/(.*)\\.sh" "\\1" test_name ${tsh})
1243 add_test(NAME "t.suite.${test_name}"
1244 COMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx
1245 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
1246endforeach()
1247
1248# This test script takes an extremely long time and is known to time out even
1249# on fast machines because it requires in excess of one hour to run
1250set_tests_properties("t.suite.t7112-reset-submodule" PROPERTIES TIMEOUT 4000)
1251
1252endif()#BUILD_TESTING