2 # Copyright (c) 2020 Sibi Siddharthan
7 Instructions to run CMake:
9 cmake `relative-path-to-CMakeLists.txt` -DCMAKE_BUILD_TYPE=Release
11 From the root of git source tree
12 `cmake contrib/buildsystems/ `
13 This will build the git binaries at the root
15 For out of source builds, say build in 'git/git-build/'
16 `mkdir git-build;cd git-build; cmake ../contrib/buildsystems/`
17 This will build the git binaries in git-build directory
19 Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
23 RelWithDebInfo : -O2 -g
27 NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio
28 this option is ignored
30 This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.
31 Run `make` to build Git on Linux/*BSD/MacOS.
32 Open git.sln on Windows and build Git.
34 NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,
35 to use another tool say `ninja` add this to the command line when configuring.
39 cmake_minimum_required(VERSION 3.14)
41 #set the source directory to root of git
42 set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
44 find_program(SH_EXE sh)
46 #Create GIT-VERSION-FILE using GIT-VERSION-GEN
47 if(NOT EXISTS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE)
48 message("Generating GIT-VERSION-FILE")
49 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN
50 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
53 #Parse GIT-VERSION-FILE to get the version
54 file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE git_version REGEX "GIT_VERSION = (.*)")
55 string(REPLACE "GIT_VERSION = " "" git_version ${git_version})
56 string(FIND ${git_version} "GIT" location)
58 string(REGEX MATCH "[0-9]*\\.[0-9]*\\.[0-9]*" git_version ${git_version})
60 string(REGEX MATCH "[0-9]*\\.[0-9]*" git_version ${git_version})
61 string(APPEND git_version ".0") #for building from a snapshot
65 VERSION ${git_version}
68 #TODO gitk git-gui gitweb
69 #TODO Add pcre support
71 #macros for parsing the Makefile for sources and scripts
72 macro(parse_makefile_for_sources list_var regex)
73 file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
74 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
75 string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit.
76 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
77 string(REPLACE ".o" ".c;" ${list_var} ${${list_var}}) #change .o to .c, ; is for converting the string into a list
78 list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
79 list(REMOVE_ITEM ${list_var} "") #remove empty list elements
82 macro(parse_makefile_for_scripts list_var regex lang)
83 file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
84 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
85 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
86 string(REPLACE " " ";" ${list_var} ${${list_var}}) #convert string to a list
87 if(NOT ${lang}) #exclude for SCRIPT_LIB
88 list(TRANSFORM ${list_var} REPLACE "${lang}" "") #do the replacement
92 include(CheckTypeSize)
93 include(CheckCSourceRuns)
94 include(CheckCSourceCompiles)
95 include(CheckIncludeFile)
96 include(CheckFunctionExists)
97 include(CheckSymbolExists)
98 include(CheckStructHasMember)
101 find_package(ZLIB REQUIRED)
108 add_compile_definitions(NO_GETTEXT)
110 add_compile_definitions(NO_ICONV)
114 include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
116 include_directories(SYSTEM ${CURL_INCLUDE_DIRS})
119 include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS})
122 include_directories(SYSTEM ${Iconv_INCLUDE_DIRS})
125 include_directories(SYSTEM ${Intl_INCLUDE_DIRS})
128 find_program(MSGFMT_EXE msgfmt)
130 message(WARNING "Text Translations won't be build")
134 include_directories(${CMAKE_SOURCE_DIR})
135 add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
136 add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
137 add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
138 SHA1DC_INIT_SAFE_HASH_DEFAULT=0
139 SHA1DC_CUSTOM_INCLUDE_SHA1_C="cache.h"
140 SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
141 list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
144 add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
145 ETC_GITATTRIBUTES="etc/gitattributes"
146 ETC_GITCONFIG="etc/gitconfig"
147 GIT_EXEC_PATH="libexec/git-core"
148 GIT_LOCALE_PATH="share/locale"
149 GIT_MAN_PATH="share/man"
150 GIT_INFO_PATH="share/info"
151 GIT_HTML_PATH="share/doc/git-doc"
152 DEFAULT_HELP_FORMAT="html"
153 DEFAULT_GIT_TEMPLATE_DIR="share/git-core/templates"
154 GIT_VERSION="${PROJECT_VERSION}.GIT"
155 GIT_USER_AGENT="git/${PROJECT_VERSION}.GIT"
157 GIT_BUILT_FROM_COMMIT="")
159 set(FALLBACK_RUNTIME_PREFIX /home/$ENV{USER})
160 add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}")
162 add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY )
163 list(APPEND compat_SOURCES unix-socket.c)
166 check_include_file(libgen.h HAVE_LIBGEN_H)
167 if(NOT HAVE_LIBGEN_H)
168 add_compile_definitions(NO_LIBGEN_H)
169 list(APPEND compat_SOURCES compat/basename.c)
172 check_include_file(sys/sysinfo.h HAVE_SYSINFO)
174 add_compile_definitions(HAVE_SYSINFO)
177 check_c_source_compiles("
182 char *p = (char *) alloca(2 * sizeof(int));
190 add_compile_definitions(HAVE_ALLOCA_H)
193 check_include_file(strings.h HAVE_STRINGS_H)
195 add_compile_definitions(HAVE_STRINGS_H)
198 check_include_file(sys/select.h HAVE_SYS_SELECT_H)
199 if(NOT HAVE_SYS_SELECT_H)
200 add_compile_definitions(NO_SYS_SELECT_H)
203 check_include_file(sys/poll.h HAVE_SYS_POLL_H)
204 if(NOT HAVE_SYS_POLL_H)
205 add_compile_definitions(NO_SYS_POLL_H)
208 check_include_file(poll.h HAVE_POLL_H)
210 add_compile_definitions(NO_POLL_H)
213 check_include_file(inttypes.h HAVE_INTTYPES_H)
214 if(NOT HAVE_INTTYPES_H)
215 add_compile_definitions(NO_INTTYPES_H)
218 check_include_file(paths.h HAVE_PATHS_H)
220 add_compile_definitions(HAVE_PATHS_H)
225 strcasestr memmem strlcpy strtoimax strtoumax strtoull
226 setenv mkdtemp poll pread memmem unsetenv hstrerror)
228 foreach(f ${function_checks})
229 string(TOUPPER ${f} uf)
230 check_function_exists(${f} HAVE_${uf})
232 add_compile_definitions(NO_${uf})
236 if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL)
237 include_directories(${CMAKE_SOURCE_DIR}/compat/poll)
238 add_compile_definitions(NO_POLL)
239 list(APPEND compat_SOURCES compat/poll/poll.c)
242 if(NOT HAVE_STRCASESTR)
243 list(APPEND compat_SOURCES compat/strcasestr.c)
247 list(APPEND compat_SOURCES compat/strlcpy.c)
250 if(NOT HAVE_STRTOUMAX)
251 list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c)
255 list(APPEND compat_SOURCES compat/setenv.c)
259 list(APPEND compat_SOURCES compat/mkdtemp.c)
263 list(APPEND compat_SOURCES compat/pread.c)
267 list(APPEND compat_SOURCES compat/memmem.c)
271 if(NOT HAVE_UNSETENV)
272 list(APPEND compat_SOURCES compat/unsetenv.c)
275 if(NOT HAVE_HSTRERROR)
276 list(APPEND compat_SOURCES compat/hstrerror.c)
280 check_function_exists(getdelim HAVE_GETDELIM)
282 add_compile_definitions(HAVE_GETDELIM)
285 check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
286 check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
287 if(HAVE_CLOCK_GETTIME)
288 add_compile_definitions(HAVE_CLOCK_GETTIME)
290 if(HAVE_CLOCK_MONOTONIC)
291 add_compile_definitions(HAVE_CLOCK_MONOTONIC)
294 #check for st_blocks in struct stat
295 check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS)
296 if(NOT STRUCT_STAT_HAS_ST_BLOCKS)
297 add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT)
301 check_c_source_runs("
307 int test_vsnprintf(char *str, size_t maxsize, const char *format, ...)
312 va_start(ap, format);
313 ret = vsnprintf(str, maxsize, format, ap);
322 if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5
323 || strcmp(buf, \"12\"))
325 if (snprintf(buf, 3, \"%s\", \"12345\") != 5
326 || strcmp(buf, \"12\"))
332 add_compile_definitions(SNPRINTF_RETURNS_BOGUS)
333 list(APPEND compat_SOURCES compat/snprintf.c)
336 check_c_source_runs("
341 FILE *f = fopen(\".\", \"r\");
345 FREAD_READS_DIRECTORIES_NO)
346 if(NOT FREAD_READS_DIRECTORIES_NO)
347 add_compile_definitions(FREAD_READS_DIRECTORIES)
348 list(APPEND compat_SOURCES compat/fopen.c)
351 check_c_source_compiles("
354 #error oops we dont have it
363 include_directories(${CMAKE_SOURCE_DIR}/compat/regex)
364 list(APPEND compat_SOURCES compat/regex/regex.c )
365 add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK)
369 check_c_source_compiles("
371 #include <sys/types.h>
372 #include <sys/sysctl.h>
382 return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
386 add_compile_definitions(HAVE_BSD_SYSCTL)
389 set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES})
390 set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS})
392 check_c_source_compiles("
395 extern size_t iconv(iconv_t cd,
396 char **inbuf, size_t *inbytesleft,
397 char **outbuf, size_t *outbytesleft);
405 set(HAVE_OLD_ICONV 0)
407 set(HAVE_OLD_ICONV 1)
410 check_c_source_runs("
412 #if ${HAVE_OLD_ICONV}
413 typedef const char *iconv_ibp;
415 typedef char *iconv_ibp;
426 size_t isz = sizeof(in);
427 size_t osz = sizeof(out);
429 conv = iconv_open(\"UTF-16\", \"UTF-8\");
430 iconv(conv, &pin, &isz, &pout, &osz);
432 v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
433 return v != 0xfe + 0xff;
435 ICONV_DOESNOT_OMIT_BOM)
436 if(NOT ICONV_DOESNOT_OMIT_BOM)
437 add_compile_definitions(ICONV_OMITS_BOM)
440 unset(CMAKE_REQUIRED_LIBRARIES)
441 unset(CMAKE_REQUIRED_INCLUDES)
446 git git-bugreport git-credential-store git-daemon git-fast-import git-http-backend git-sh-i18n--envsubst
447 git-shell git-remote-testsvn git-credential-cache git-credential-cache--daemon)
450 list(APPEND excluded_progs git-http-fetch git-http-push)
451 add_compile_definitions(NO_CURL)
452 message(WARNING "git-http-push and git-http-fetch will not be built")
454 list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http)
455 if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0)
456 add_compile_definitions(USE_CURL_FOR_IMAP_SEND)
461 list(APPEND excluded_progs git-http-push)
462 add_compile_definitions(NO_EXPAT)
464 list(APPEND PROGRAMS_BUILT git-http-push)
465 if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2)
466 add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H)
470 list(REMOVE_DUPLICATES excluded_progs)
471 list(REMOVE_DUPLICATES PROGRAMS_BUILT)
474 foreach(p ${excluded_progs})
475 list(APPEND EXCLUSION_PROGS --exclude-program ${p} )
478 #for comparing null values
479 list(APPEND EXCLUSION_PROGS empty)
480 set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE)
482 if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS)
483 list(REMOVE_ITEM EXCLUSION_PROGS empty)
484 message("Generating command-list.h")
485 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt
486 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
487 OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h)
490 if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
491 message("Generating config-list.h")
492 execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh
493 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
494 OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h)
497 include_directories(${CMAKE_BINARY_DIR})
501 parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS")
503 list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
504 list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
505 add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
508 parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
510 list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
511 add_library(xdiff STATIC ${libxdiff_SOURCES})
514 parse_makefile_for_sources(libvcs-svn_SOURCES "VCSSVN_OBJS")
516 list(TRANSFORM libvcs-svn_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
517 add_library(vcs-svn STATIC ${libvcs-svn_SOURCES})
519 #link all required libraries to common-main
520 add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
521 target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES} pthread rt)
523 target_link_libraries(common-main ${Intl_LIBRARIES})
526 target_link_libraries(common-main ${Iconv_LIBRARIES})
530 parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS")
532 list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
533 add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
534 target_link_libraries(git common-main)
536 add_executable(git-bugreport ${CMAKE_SOURCE_DIR}/bugreport.c)
537 target_link_libraries(git-bugreport common-main)
539 add_executable(git-credential-store ${CMAKE_SOURCE_DIR}/credential-store.c)
540 target_link_libraries(git-credential-store common-main)
542 add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
543 target_link_libraries(git-daemon common-main)
545 add_executable(git-fast-import ${CMAKE_SOURCE_DIR}/fast-import.c)
546 target_link_libraries(git-fast-import common-main)
548 add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c)
549 target_link_libraries(git-http-backend common-main)
551 add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c)
552 target_link_libraries(git-sh-i18n--envsubst common-main)
554 add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c)
555 target_link_libraries(git-shell common-main)
558 add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c)
560 add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c)
561 target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES})
563 add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c)
564 target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES})
566 add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c)
567 target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} )
570 add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c)
571 target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES})
575 add_executable(git-remote-testsvn ${CMAKE_SOURCE_DIR}/remote-testsvn.c)
576 target_link_libraries(git-remote-testsvn common-main vcs-svn)
578 add_executable(git-credential-cache ${CMAKE_SOURCE_DIR}/credential-cache.c)
579 target_link_libraries(git-credential-cache common-main)
581 add_executable(git-credential-cache--daemon ${CMAKE_SOURCE_DIR}/credential-cache--daemon.c)
582 target_link_libraries(git-credential-cache--daemon common-main)
585 set(git_builtin_extra
586 cherry cherry-pick format-patch fsck-objects
587 init merge-subtree restore show
588 stage status switch whatchanged)
591 foreach(s ${git_SOURCES} ${git_builtin_extra})
592 string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s})
593 string(REPLACE ".c" "" s ${s})
594 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git git-${s})\n")
595 list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s})
600 git-remote-https git-remote-ftp git-remote-ftps)
601 foreach(s ${remote_exes})
602 file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http ${s})\n")
603 list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s})
607 add_custom_command(OUTPUT ${git_links} ${git_http_links}
608 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake
609 DEPENDS git git-remote-http)
610 add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})
613 #creating required scripts
614 set(SHELL_PATH /bin/sh)
615 set(PERL_PATH /usr/bin/perl)
616 set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
617 set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
618 set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5)
621 parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh")
622 parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "")
623 set(git_shell_scripts
624 ${git_sh_scripts} ${git_shlib_scripts} git-instaweb)
626 foreach(script ${git_shell_scripts})
627 file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.sh content NEWLINE_CONSUME)
628 string(REPLACE "@SHELL_PATH@" "${SHELL_PATH}" content "${content}")
629 string(REPLACE "@@DIFF@@" "diff" content "${content}")
630 string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}")
631 string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" content "${content}")
632 string(REPLACE "@@NO_CURL@@" "" content "${content}")
633 string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}")
634 string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}")
635 string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}")
636 string(REPLACE "@@SANE_TEXT_GREP@@" "-a" content "${content}")
637 string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}")
638 file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
642 parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl")
645 file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
646 string(REPLACE "@@PATHSEP@@" ":" perl_header "${perl_header}")
647 string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}")
649 foreach(script ${git_perl_scripts})
650 file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)
651 string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}")
652 string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}")
653 file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
657 file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
658 string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}")
659 file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})
662 file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
664 foreach(pm ${perl_modules})
665 string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm})
666 file(STRINGS ${pm} content NEWLINE_CONSUME)
667 string(REPLACE "@@LOCALEDIR@@" "${LOCALEDIR}" content "${content}")
668 string(REPLACE "@@NO_PERL_CPAN_FALLBACKS@@" "" content "${content}")
669 file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content})
670 #test-lib.sh requires perl/build/lib to be the build directory of perl modules
675 file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
676 list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
677 list(REMOVE_ITEM templates ".gitignore")
678 list(REMOVE_ITEM templates "Makefile")
679 list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds
681 list(REMOVE_ITEM templates "branches--")
682 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches
684 #templates have @.*@ replacement so use configure_file instead
685 foreach(tm ${templates})
686 string(REPLACE "--" "/" blt_tm ${tm})
687 string(REPLACE "this" "" blt_tm ${blt_tm})# for this--
688 configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY)
694 file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
695 list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "")
696 list(TRANSFORM po_files REPLACE ".po" "")
697 foreach(po ${po_files})
698 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)
699 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo
700 COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)
701 list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)
703 add_custom_target(po-gen ALL DEPENDS ${po_gen})
707 #to help with the install
708 list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
709 list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
712 install(TARGETS git git-shell
713 RUNTIME DESTINATION bin)
714 install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver
717 list(REMOVE_ITEM PROGRAMS_BUILT git git-shell)
718 install(TARGETS ${PROGRAMS_BUILT}
719 RUNTIME DESTINATION libexec/git-core)
722 git-receive-pack git-upload-archive git-upload-pack)
724 foreach(b ${bin_links})
725 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git ${CMAKE_INSTALL_PREFIX}/bin/${b})")
728 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git)")
729 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell)")
731 foreach(b ${git_links})
732 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
733 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
736 foreach(b ${git_http_links})
737 string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
738 install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-remote-http ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
741 install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4
742 DESTINATION libexec/git-core)
744 install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core)
745 install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5
746 FILES_MATCHING PATTERN "*.pm")
747 install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates)
750 install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share)
757 add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
758 target_link_libraries(test-fake-ssh common-main)
760 add_executable(test-line-buffer ${CMAKE_SOURCE_DIR}/t/helper/test-line-buffer.c)
761 target_link_libraries(test-line-buffer common-main vcs-svn)
763 add_executable(test-svn-fe ${CMAKE_SOURCE_DIR}/t/helper/test-svn-fe.c)
764 target_link_libraries(test-svn-fe common-main vcs-svn)
767 parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
769 list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
770 add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
771 target_link_libraries(test-tool common-main)
773 set_target_properties(test-fake-ssh test-line-buffer test-svn-fe test-tool
774 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
778 git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext)
780 set(wrapper_test_scripts
781 test-fake-ssh test-line-buffer test-svn-fe test-tool)
784 foreach(script ${wrapper_scripts})
785 file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
786 string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
787 string(REPLACE "@@PROG@@" "${script}" content "${content}")
788 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
791 foreach(script ${wrapper_test_scripts})
792 file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
793 string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
794 string(REPLACE "@@PROG@@" "t/helper/${script}" content "${content}")
795 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
798 file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
799 string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
800 string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
801 file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
803 #options for configuring test options
804 option(PERL_TESTS "Perform tests that use perl" ON)
805 option(PYTHON_TESTS "Perform tests that use python" ON)
808 set(TEST_SHELL_PATH ${SHELL_PATH})
810 set(PYTHON_PATH /usr/bin/python)
816 set(NO_LIBPCRE1_JIT )
820 set(PAGER_ENV "LESS=FRX LV=-c")
821 set(DC_SHA1 YesPlease)
822 set(RUNTIME_PREFIX true)
845 file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n")
846 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n")
847 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n")
848 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n")
849 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n")
850 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n")
851 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n")
852 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n")
853 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "USE_LIBPCRE1='${USE_LIBPCRE1}'\n")
854 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_LIBPCRE1_JIT='${NO_LIBPCRE1_JIT}'\n")
855 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
856 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
857 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
858 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n")
859 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n")
860 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X=''\n")
861 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
862 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
863 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
865 #Make the tests work when building out of the source tree
866 get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)
867 if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
868 file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)
869 string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})
870 #Setting the build directory in test-lib.sh before running tests
871 file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
872 "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n"
873 "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n"
874 "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY\\\"/../${BUILD_DIR_RELATIVE}\" content \"\${content}\")\n"
875 "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})")
877 file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/)
878 file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)
879 file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
880 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
881 file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
882 file(COPY ${CMAKE_SOURCE_DIR}/contrib/svn-fe/svnrdump_sim.py DESTINATION ${CMAKE_BINARY_DIR}/contrib/svn-fe/)
885 file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
888 foreach(tsh ${test_scipts})
890 COMMAND ${SH_EXE} ${tsh}
891 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
894 endif()#BUILD_TESTING