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