]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/buildsystems/CMakeLists.txt
Merge branch 'jk/clone-allow-bare-and-o-together'
[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
230 SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h"
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)
d33c804d
JH
311
312 add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
313 list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c)
f67df255
JH
314 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
315 add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
316 list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
d0605550 317 list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c)
a85ad67b
JH
318
319 add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
320 list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c)
62c73671
JH
321 endif()
322endif()
323
f7adba41 324set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
061c2240
SS
325
326#header checks
327check_include_file(libgen.h HAVE_LIBGEN_H)
328if(NOT HAVE_LIBGEN_H)
329 add_compile_definitions(NO_LIBGEN_H)
330 list(APPEND compat_SOURCES compat/basename.c)
331endif()
332
333check_include_file(sys/sysinfo.h HAVE_SYSINFO)
334if(HAVE_SYSINFO)
335 add_compile_definitions(HAVE_SYSINFO)
336endif()
337
338check_c_source_compiles("
339#include <alloca.h>
340
341int main(void)
342{
343 char *p = (char *) alloca(2 * sizeof(int));
344
345 if (p)
346 return 0;
347 return 0;
348}"
349HAVE_ALLOCA_H)
350if(HAVE_ALLOCA_H)
351 add_compile_definitions(HAVE_ALLOCA_H)
352endif()
353
354check_include_file(strings.h HAVE_STRINGS_H)
355if(HAVE_STRINGS_H)
356 add_compile_definitions(HAVE_STRINGS_H)
357endif()
358
359check_include_file(sys/select.h HAVE_SYS_SELECT_H)
360if(NOT HAVE_SYS_SELECT_H)
361 add_compile_definitions(NO_SYS_SELECT_H)
362endif()
363
364check_include_file(sys/poll.h HAVE_SYS_POLL_H)
365if(NOT HAVE_SYS_POLL_H)
366 add_compile_definitions(NO_SYS_POLL_H)
367endif()
368
369check_include_file(poll.h HAVE_POLL_H)
370if(NOT HAVE_POLL_H)
371 add_compile_definitions(NO_POLL_H)
372endif()
373
374check_include_file(inttypes.h HAVE_INTTYPES_H)
375if(NOT HAVE_INTTYPES_H)
376 add_compile_definitions(NO_INTTYPES_H)
377endif()
378
379check_include_file(paths.h HAVE_PATHS_H)
380if(HAVE_PATHS_H)
381 add_compile_definitions(HAVE_PATHS_H)
382endif()
383
384#function checks
385set(function_checks
386 strcasestr memmem strlcpy strtoimax strtoumax strtoull
f7adba41
SS
387 setenv mkdtemp poll pread memmem)
388
389#unsetenv,hstrerror are incompatible with windows build
390if(NOT WIN32)
391 list(APPEND function_checks unsetenv hstrerror)
392endif()
061c2240
SS
393
394foreach(f ${function_checks})
395 string(TOUPPER ${f} uf)
396 check_function_exists(${f} HAVE_${uf})
397 if(NOT HAVE_${uf})
398 add_compile_definitions(NO_${uf})
399 endif()
400endforeach()
401
402if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL)
403 include_directories(${CMAKE_SOURCE_DIR}/compat/poll)
404 add_compile_definitions(NO_POLL)
405 list(APPEND compat_SOURCES compat/poll/poll.c)
406endif()
407
408if(NOT HAVE_STRCASESTR)
409 list(APPEND compat_SOURCES compat/strcasestr.c)
410endif()
411
412if(NOT HAVE_STRLCPY)
413 list(APPEND compat_SOURCES compat/strlcpy.c)
414endif()
415
416if(NOT HAVE_STRTOUMAX)
417 list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c)
418endif()
419
420if(NOT HAVE_SETENV)
421 list(APPEND compat_SOURCES compat/setenv.c)
422endif()
423
424if(NOT HAVE_MKDTEMP)
425 list(APPEND compat_SOURCES compat/mkdtemp.c)
426endif()
427
428if(NOT HAVE_PREAD)
429 list(APPEND compat_SOURCES compat/pread.c)
430endif()
431
432if(NOT HAVE_MEMMEM)
433 list(APPEND compat_SOURCES compat/memmem.c)
434endif()
435
436if(NOT WIN32)
437 if(NOT HAVE_UNSETENV)
438 list(APPEND compat_SOURCES compat/unsetenv.c)
439 endif()
440
441 if(NOT HAVE_HSTRERROR)
442 list(APPEND compat_SOURCES compat/hstrerror.c)
443 endif()
444endif()
445
446check_function_exists(getdelim HAVE_GETDELIM)
447if(HAVE_GETDELIM)
448 add_compile_definitions(HAVE_GETDELIM)
449endif()
450
451check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
452check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
453if(HAVE_CLOCK_GETTIME)
454 add_compile_definitions(HAVE_CLOCK_GETTIME)
455endif()
456if(HAVE_CLOCK_MONOTONIC)
457 add_compile_definitions(HAVE_CLOCK_MONOTONIC)
458endif()
459
460#check for st_blocks in struct stat
461check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS)
462if(NOT STRUCT_STAT_HAS_ST_BLOCKS)
463 add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT)
464endif()
465
466#compile checks
467check_c_source_runs("
468#include<stdio.h>
469#include<stdarg.h>
470#include<string.h>
471#include<stdlib.h>
472
473int test_vsnprintf(char *str, size_t maxsize, const char *format, ...)
474{
475 int ret;
476 va_list ap;
477
478 va_start(ap, format);
479 ret = vsnprintf(str, maxsize, format, ap);
480 va_end(ap);
481 return ret;
482}
483
484int main(void)
485{
486 char buf[6];
487
488 if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5
489 || strcmp(buf, \"12\"))
490 return 1;
491 if (snprintf(buf, 3, \"%s\", \"12345\") != 5
492 || strcmp(buf, \"12\"))
493 return 1;
494 return 0;
495}"
496SNPRINTF_OK)
497if(NOT SNPRINTF_OK)
498 add_compile_definitions(SNPRINTF_RETURNS_BOGUS)
499 list(APPEND compat_SOURCES compat/snprintf.c)
500endif()
501
502check_c_source_runs("
503#include<stdio.h>
504
505int main(void)
506{
507 FILE *f = fopen(\".\", \"r\");
508
509 return f != NULL;
510}"
511FREAD_READS_DIRECTORIES_NO)
512if(NOT FREAD_READS_DIRECTORIES_NO)
513 add_compile_definitions(FREAD_READS_DIRECTORIES)
514 list(APPEND compat_SOURCES compat/fopen.c)
515endif()
516
517check_c_source_compiles("
518#include <regex.h>
519#ifndef REG_STARTEND
520#error oops we dont have it
521#endif
522
523int main(void)
524{
525 return 0;
526}"
527HAVE_REGEX)
528if(NOT HAVE_REGEX)
529 include_directories(${CMAKE_SOURCE_DIR}/compat/regex)
530 list(APPEND compat_SOURCES compat/regex/regex.c )
531 add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK)
532endif()
533
534
535check_c_source_compiles("
536#include <stddef.h>
537#include <sys/types.h>
538#include <sys/sysctl.h>
539
540int main(void)
541{
542 int val, mib[2];
543 size_t len;
544
545 mib[0] = CTL_HW;
546 mib[1] = 1;
547 len = sizeof(val);
548 return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
549}"
550HAVE_BSD_SYSCTL)
551if(HAVE_BSD_SYSCTL)
552 add_compile_definitions(HAVE_BSD_SYSCTL)
553endif()
554
555set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES})
556set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS})
557
558check_c_source_compiles("
559#include <iconv.h>
560
561extern size_t iconv(iconv_t cd,
562 char **inbuf, size_t *inbytesleft,
563 char **outbuf, size_t *outbytesleft);
564
565int main(void)
566{
567 return 0;
568}"
569HAVE_NEW_ICONV)
570if(HAVE_NEW_ICONV)
571 set(HAVE_OLD_ICONV 0)
572else()
573 set(HAVE_OLD_ICONV 1)
574endif()
575
576check_c_source_runs("
577#include <iconv.h>
578#if ${HAVE_OLD_ICONV}
579typedef const char *iconv_ibp;
580#else
581typedef char *iconv_ibp;
582#endif
583
584int main(void)
585{
586 int v;
587 iconv_t conv;
588 char in[] = \"a\";
589 iconv_ibp pin = in;
590 char out[20] = \"\";
591 char *pout = out;
592 size_t isz = sizeof(in);
593 size_t osz = sizeof(out);
594
595 conv = iconv_open(\"UTF-16\", \"UTF-8\");
596 iconv(conv, &pin, &isz, &pout, &osz);
597 iconv_close(conv);
598 v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
599 return v != 0xfe + 0xff;
600}"
601ICONV_DOESNOT_OMIT_BOM)
602if(NOT ICONV_DOESNOT_OMIT_BOM)
603 add_compile_definitions(ICONV_OMITS_BOM)
604endif()
605
606unset(CMAKE_REQUIRED_LIBRARIES)
607unset(CMAKE_REQUIRED_INCLUDES)
608
609
610#programs
611set(PROGRAMS_BUILT
a006f875 612 git git-daemon git-http-backend git-sh-i18n--envsubst
7b5c93c6 613 git-shell scalar)
f7adba41 614
061c2240
SS
615if(NOT CURL_FOUND)
616 list(APPEND excluded_progs git-http-fetch git-http-push)
617 add_compile_definitions(NO_CURL)
618 message(WARNING "git-http-push and git-http-fetch will not be built")
619else()
620 list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http)
621 if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0)
622 add_compile_definitions(USE_CURL_FOR_IMAP_SEND)
623 endif()
624endif()
625
626if(NOT EXPAT_FOUND)
627 list(APPEND excluded_progs git-http-push)
628 add_compile_definitions(NO_EXPAT)
629else()
630 list(APPEND PROGRAMS_BUILT git-http-push)
631 if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2)
632 add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H)
633 endif()
634endif()
635
636list(REMOVE_DUPLICATES excluded_progs)
637list(REMOVE_DUPLICATES PROGRAMS_BUILT)
638
639
640foreach(p ${excluded_progs})
641 list(APPEND EXCLUSION_PROGS --exclude-program ${p} )
642endforeach()
643
644#for comparing null values
645list(APPEND EXCLUSION_PROGS empty)
646set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE)
647
648if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS)
649 list(REMOVE_ITEM EXCLUSION_PROGS empty)
650 message("Generating command-list.h")
651 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt
652 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
653 OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h)
654endif()
655
656if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
657 message("Generating config-list.h")
658 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh
659 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
660 OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h)
661endif()
662
cfe853e6
ÆAB
663if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h)
664 message("Generating hook-list.h")
665 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh
666 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
667 OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h)
668endif()
669
061c2240
SS
670include_directories(${CMAKE_BINARY_DIR})
671
672#build
673#libgit
674parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS")
675
676list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
677list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
678add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
679
680#libxdiff
681parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
682
683list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
684add_library(xdiff STATIC ${libxdiff_SOURCES})
685
ef8a6c62
HWN
686#reftable
687parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
688
689list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
690add_library(reftable STATIC ${reftable_SOURCES})
691
f7adba41 692if(WIN32)
7f475e27
SS
693 if(NOT MSVC)#use windres when compiling with gcc and clang
694 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
695 COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR}
696 -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\""
697 -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res
698 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
699 VERBATIM)
700 else()#MSVC use rc
701 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
702 COMMAND ${CMAKE_RC_COMPILER} /d MAJOR=${PROJECT_VERSION_MAJOR} /d MINOR=${PROJECT_VERSION_MINOR}
703 /d MICRO=${PROJECT_VERSION_PATCH} /d PATCHLEVEL=0 /d GIT_VERSION="${PROJECT_VERSION}.GIT"
704 /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_SOURCE_DIR}/git.rc
705 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
706 VERBATIM)
707 endif()
f7adba41
SS
708 add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res)
709endif()
710
061c2240
SS
711#link all required libraries to common-main
712add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
f7adba41 713
ef8a6c62 714target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES})
061c2240
SS
715if(Intl_FOUND)
716 target_link_libraries(common-main ${Intl_LIBRARIES})
717endif()
718if(Iconv_FOUND)
719 target_link_libraries(common-main ${Iconv_LIBRARIES})
720endif()
80431510
YW
721if(PCRE2_FOUND)
722 target_link_libraries(common-main ${PCRE2_LIBRARIES})
723 target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS})
724endif()
f7adba41
SS
725if(WIN32)
726 target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
727 add_dependencies(common-main git-rc)
7f475e27
SS
728 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
729 target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
730 elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
731 target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
732 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
733 target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj)
2d9eb4ed
JS
734 else()
735 message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
7f475e27 736 endif()
f7adba41
SS
737elseif(UNIX)
738 target_link_libraries(common-main pthread rt)
739endif()
061c2240
SS
740
741#git
742parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS")
743
744list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
745add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
746target_link_libraries(git common-main)
747
061c2240
SS
748add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
749target_link_libraries(git-daemon common-main)
750
061c2240
SS
751add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c)
752target_link_libraries(git-http-backend common-main)
753
754add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c)
755target_link_libraries(git-sh-i18n--envsubst common-main)
756
757add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c)
758target_link_libraries(git-shell common-main)
759
7b5c93c6
VD
760add_executable(scalar ${CMAKE_SOURCE_DIR}/scalar.c)
761target_link_libraries(scalar common-main)
762
061c2240
SS
763if(CURL_FOUND)
764 add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c)
765
766 add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c)
767 target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES})
768
769 add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c)
770 target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES})
771
772 add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c)
773 target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} )
774
775 if(EXPAT_FOUND)
776 add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c)
777 target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES})
778 endif()
779endif()
780
7fe07275 781parse_makefile_for_executables(git_builtin_extra "BUILT_INS")
061c2240 782
7bb544a4
JS
783option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins")
784
061c2240 785#Creating hardlinks
7bb544a4 786if(NOT SKIP_DASHED_BUILT_INS)
061c2240
SS
787foreach(s ${git_SOURCES} ${git_builtin_extra})
788 string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s})
789 string(REPLACE ".c" "" s ${s})
f7adba41
SS
790 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION})\n")
791 list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s}${EXE_EXTENSION})
061c2240 792endforeach()
7bb544a4 793endif()
061c2240
SS
794
795if(CURL_FOUND)
796 set(remote_exes
797 git-remote-https git-remote-ftp git-remote-ftps)
798 foreach(s ${remote_exes})
f7adba41
SS
799 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION})\n")
800 list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s}${EXE_EXTENSION})
061c2240
SS
801 endforeach()
802endif()
803
804add_custom_command(OUTPUT ${git_links} ${git_http_links}
805 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake
806 DEPENDS git git-remote-http)
807add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})
afa45fe5
SS
808
809
810#creating required scripts
811set(SHELL_PATH /bin/sh)
812set(PERL_PATH /usr/bin/perl)
813set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
814set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
815set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5)
816
817#shell scripts
818parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh")
819parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "")
820set(git_shell_scripts
821 ${git_sh_scripts} ${git_shlib_scripts} git-instaweb)
822
823foreach(script ${git_shell_scripts})
824 file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.sh content NEWLINE_CONSUME)
825 string(REPLACE "@SHELL_PATH@" "${SHELL_PATH}" content "${content}")
826 string(REPLACE "@@DIFF@@" "diff" content "${content}")
827 string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}")
828 string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" content "${content}")
829 string(REPLACE "@@NO_CURL@@" "" content "${content}")
830 string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}")
831 string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}")
832 string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}")
afa45fe5
SS
833 string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}")
834 file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
835endforeach()
836
837#perl scripts
838parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl")
839
840#create perl header
841file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
842string(REPLACE "@@PATHSEP@@" ":" perl_header "${perl_header}")
843string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}")
844
845foreach(script ${git_perl_scripts})
846 file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)
847 string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}")
848 string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}")
849 file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
850endforeach()
851
852#python script
853file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
854string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}")
855file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})
856
857#perl modules
858file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
859
860foreach(pm ${perl_modules})
861 string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm})
862 file(STRINGS ${pm} content NEWLINE_CONSUME)
863 string(REPLACE "@@LOCALEDIR@@" "${LOCALEDIR}" content "${content}")
864 string(REPLACE "@@NO_PERL_CPAN_FALLBACKS@@" "" content "${content}")
865 file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content})
866#test-lib.sh requires perl/build/lib to be the build directory of perl modules
867endforeach()
868
869
870#templates
871file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
872list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
873list(REMOVE_ITEM templates ".gitignore")
874list(REMOVE_ITEM templates "Makefile")
875list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds
876
877list(REMOVE_ITEM templates "branches--")
878file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches
879
880#templates have @.*@ replacement so use configure_file instead
881foreach(tm ${templates})
882 string(REPLACE "--" "/" blt_tm ${tm})
883 string(REPLACE "this" "" blt_tm ${blt_tm})# for this--
884 configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY)
885endforeach()
886
887
888#translations
889if(MSGFMT_EXE)
890 file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
891 list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "")
892 list(TRANSFORM po_files REPLACE ".po" "")
893 foreach(po ${po_files})
894 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)
895 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo
896 COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)
897 list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)
898 endforeach()
899 add_custom_target(po-gen ALL DEPENDS ${po_gen})
900endif()
f1f5dff9
SS
901
902
903#to help with the install
904list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
905list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
906
907#install
e8772a7a 908foreach(program ${PROGRAMS_BUILT})
7b5c93c6 909if(program MATCHES "^(git|git-shell|scalar)$")
e8772a7a 910install(TARGETS ${program}
f1f5dff9 911 RUNTIME DESTINATION bin)
e8772a7a
JS
912else()
913install(TARGETS ${program}
914 RUNTIME DESTINATION libexec/git-core)
915endif()
916endforeach()
917
f1f5dff9
SS
918install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver
919 DESTINATION bin)
920
f1f5dff9
SS
921set(bin_links
922 git-receive-pack git-upload-archive git-upload-pack)
923
924foreach(b ${bin_links})
f7adba41 925install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/bin/${b}${EXE_EXTENSION})")
f1f5dff9
SS
926endforeach()
927
f7adba41
SS
928install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git${EXE_EXTENSION})")
929install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell${EXE_EXTENSION})")
f1f5dff9
SS
930
931foreach(b ${git_links})
932 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
569f8d18 933 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
f1f5dff9
SS
934endforeach()
935
936foreach(b ${git_http_links})
937 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
569f8d18 938 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
939endforeach()
940
941install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4
942 DESTINATION libexec/git-core)
943
944install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core)
945install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5
946 FILES_MATCHING PATTERN "*.pm")
947install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates)
948
949if(MSGFMT_EXE)
950 install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share)
951endif()
c4b2f41b
SS
952
953
954if(BUILD_TESTING)
955
956#tests-helpers
957add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
958target_link_libraries(test-fake-ssh common-main)
959
ef8a6c62
HWN
960#reftable-tests
961parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
962list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
963
c4b2f41b
SS
964#test-tool
965parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
966
967list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
ef8a6c62 968add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES})
c4b2f41b
SS
969target_link_libraries(test-tool common-main)
970
fc47391e 971set_target_properties(test-fake-ssh test-tool
c4b2f41b
SS
972 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
973
7f475e27 974if(MSVC)
fc47391e 975 set_target_properties(test-fake-ssh test-tool
7f475e27 976 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
fc47391e 977 set_target_properties(test-fake-ssh test-tool
7f475e27
SS
978 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
979endif()
980
c4b2f41b
SS
981#wrapper scripts
982set(wrapper_scripts
7b5c93c6 983 git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext scalar)
c4b2f41b
SS
984
985set(wrapper_test_scripts
fc47391e 986 test-fake-ssh test-tool)
c4b2f41b
SS
987
988
989foreach(script ${wrapper_scripts})
990 file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
991 string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
f7adba41 992 string(REPLACE "@@PROG@@" "${script}${EXE_EXTENSION}" content "${content}")
c4b2f41b
SS
993 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
994endforeach()
995
996foreach(script ${wrapper_test_scripts})
997 file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
998 string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
f7adba41 999 string(REPLACE "@@PROG@@" "t/helper/${script}${EXE_EXTENSION}" content "${content}")
c4b2f41b
SS
1000 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
1001endforeach()
1002
1003file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
1004string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
1005string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
1006file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
1007
1008#options for configuring test options
1009option(PERL_TESTS "Perform tests that use perl" ON)
1010option(PYTHON_TESTS "Perform tests that use python" ON)
1011
1012#GIT-BUILD-OPTIONS
1013set(TEST_SHELL_PATH ${SHELL_PATH})
1014set(DIFF diff)
1015set(PYTHON_PATH /usr/bin/python)
1016set(TAR tar)
1017set(NO_CURL )
1018set(NO_EXPAT )
c4b2f41b 1019set(USE_LIBPCRE2 )
c4b2f41b
SS
1020set(NO_PERL )
1021set(NO_PTHREADS )
1022set(NO_PYTHON )
1023set(PAGER_ENV "LESS=FRX LV=-c")
1024set(DC_SHA1 YesPlease)
1025set(RUNTIME_PREFIX true)
1026set(NO_GETTEXT )
1027
1028if(NOT CURL_FOUND)
1029 set(NO_CURL 1)
1030endif()
1031
1032if(NOT EXPAT_FOUND)
1033 set(NO_EXPAT 1)
1034endif()
1035
1036if(NOT Intl_FOUND)
1037 set(NO_GETTEXT 1)
1038endif()
1039
1040if(NOT PERL_TESTS)
1041 set(NO_PERL 1)
1042endif()
1043
1044if(NOT PYTHON_TESTS)
1045 set(NO_PYTHON 1)
1046endif()
1047
1048file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n")
1049file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n")
1050file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n")
1051file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n")
1052file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n")
1053file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n")
1054file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n")
1055file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n")
c4b2f41b
SS
1056file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
1057file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
1058file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
1059file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n")
1060file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n")
f7adba41 1061file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
c4b2f41b
SS
1062file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
1063file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
1064file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
6aac70a8 1065file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
cd0a8529 1066if(USE_VCPKG)
8c35e828
JS
1067 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
1068endif()
c4b2f41b 1069
7f5397a0
SS
1070#Make the tests work when building out of the source tree
1071get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)
1072if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
1073 file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)
1074 string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})
1075 #Setting the build directory in test-lib.sh before running tests
1076 file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
1077 "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n"
1078 "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n"
f1bd7379 1079 "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\"\" content \"\${content}\")\n"
7f5397a0
SS
1080 "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})")
1081 #misc copies
23a14f30 1082 file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)
7f5397a0
SS
1083 file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)
1084 file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
1085 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
1086 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
7f5397a0
SS
1087endif()
1088
c4b2f41b
SS
1089file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
1090
1091#test
1092foreach(tsh ${test_scipts})
1093 add_test(NAME ${tsh}
1094 COMMAND ${SH_EXE} ${tsh}
1095 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
1096endforeach()
1097
1098endif()#BUILD_TESTING