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