@@ -42,6 +42,10 @@ cmake_minimum_required(VERSION 3.14)
42
42
set (CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} /../.. )
43
43
44
44
find_program (SH_EXE sh )
45
+ if (NOT SH_EXE )
46
+ message (FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
47
+ "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/" )
48
+ endif ()
45
49
46
50
#Create GIT-VERSION-FILE using GIT-VERSION-GEN
47
51
if (NOT EXISTS ${CMAKE_SOURCE_DIR} /GIT-VERSION-FILE )
@@ -65,7 +69,9 @@ project(git
65
69
VERSION ${git_version}
66
70
LANGUAGES C )
67
71
72
+
68
73
#TODO gitk git-gui gitweb
74
+ #TODO Enable NLS on windows natively
69
75
#TODO Add pcre support
70
76
71
77
#macros for parsing the Makefile for sources and scripts
@@ -104,6 +110,7 @@ find_package(EXPAT)
104
110
find_package (Iconv )
105
111
find_package (Intl )
106
112
113
+
107
114
if (NOT Intl_FOUND )
108
115
add_compile_definitions (NO_GETTEXT )
109
116
if (NOT Iconv_FOUND )
@@ -125,6 +132,14 @@ if(Intl_FOUND)
125
132
include_directories (SYSTEM ${Intl_INCLUDE_DIRS} )
126
133
endif ()
127
134
135
+
136
+ if (WIN32 )
137
+ find_program (WINDRES_EXE windres )
138
+ if (NOT WINDRES_EXE )
139
+ message (FATAL_ERROR "Install windres on Windows for resource files" )
140
+ endif ()
141
+ endif ()
142
+
128
143
find_program (MSGFMT_EXE msgfmt )
129
144
if (NOT MSGFMT_EXE )
130
145
message (WARNING "Text Translations won't be build" )
@@ -156,11 +171,35 @@ add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
156
171
BINDIR= "bin"
157
172
GIT_BUILT_FROM_COMMIT= "" )
158
173
159
- set (FALLBACK_RUNTIME_PREFIX /home/$ENV{USER} )
160
- add_compile_definitions (FALLBACK_RUNTIME_PREFIX= "${FALLBACK_RUNTIME_PREFIX} " )
174
+ if (WIN32 )
175
+ set (FALLBACK_RUNTIME_PREFIX /mingw64 )
176
+ add_compile_definitions (FALLBACK_RUNTIME_PREFIX= "${FALLBACK_RUNTIME_PREFIX} " )
177
+ else ()
178
+ set (FALLBACK_RUNTIME_PREFIX /home/$ENV{USER} )
179
+ add_compile_definitions (FALLBACK_RUNTIME_PREFIX= "${FALLBACK_RUNTIME_PREFIX} " )
180
+ endif ()
181
+
182
+
183
+ #Platform Specific
184
+ if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
185
+ include_directories (${CMAKE_SOURCE_DIR} /compat/win32 )
186
+ add_compile_definitions (HAVE_ALLOCA_H NO_POSIX_GOODIES NATIVE_CRLF NO_UNIX_SOCKETS WIN32
187
+ _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION= ".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT
188
+ NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0
189
+ USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
190
+ UNICODE _UNICODE HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET )
191
+ list (APPEND compat_SOURCES compat/mingw.c compat/winansi.c compat/win32/path-utils.c
192
+ compat/win32/pthread.c compat/win32mmap.c compat/win32/syslog.c
193
+ compat/win32/trace2_win32_process_info.c compat/win32/dirent.c
194
+ compat/nedmalloc/nedmalloc.c compat/strdup.c )
195
+ set (NO_UNIX_SOCKETS 1 )
196
+
197
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
198
+ add_compile_definitions (PROCFS_EXECUTABLE_PATH= "/proc/self/exe" HAVE_DEV_TTY )
199
+ list (APPEND compat_SOURCES unix -socket.c )
200
+ endif ()
161
201
162
- add_compile_definitions (PROCFS_EXECUTABLE_PATH= "/proc/self/exe" HAVE_DEV_TTY )
163
- list (APPEND compat_SOURCES unix -socket.c )
202
+ set (EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX} )
164
203
165
204
#header checks
166
205
check_include_file (libgen.h HAVE_LIBGEN_H )
@@ -223,7 +262,12 @@ endif()
223
262
#function checks
224
263
set (function_checks
225
264
strcasestr memmem strlcpy strtoimax strtoumax strtoull
226
- setenv mkdtemp poll pread memmem unsetenv hstrerror )
265
+ setenv mkdtemp poll pread memmem )
266
+
267
+ #unsetenv,hstrerror are incompatible with windows build
268
+ if (NOT WIN32 )
269
+ list (APPEND function_checks unsetenv hstrerror )
270
+ endif ()
227
271
228
272
foreach (f ${function_checks} )
229
273
string (TOUPPER ${f} uf )
@@ -444,7 +488,13 @@ unset(CMAKE_REQUIRED_INCLUDES)
444
488
#programs
445
489
set (PROGRAMS_BUILT
446
490
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 )
491
+ git-shell git-remote-testsvn )
492
+
493
+ if (NO_UNIX_SOCKETS )
494
+ list (APPEND excluded_progs git-credential-cache git-credential-cache--daemon )
495
+ else ()
496
+ list (APPEND PROGRAMS_BUILT git-credential-cache git-credential-cache--daemon )
497
+ endif ()
448
498
449
499
if (NOT CURL_FOUND )
450
500
list (APPEND excluded_progs git-http-fetch git-http-push )
@@ -516,15 +566,34 @@ parse_makefile_for_sources(libvcs-svn_SOURCES "VCSSVN_OBJS")
516
566
list (TRANSFORM libvcs-svn_SOURCES PREPEND "${CMAKE_SOURCE_DIR} /" )
517
567
add_library (vcs-svn STATIC ${libvcs-svn_SOURCES} )
518
568
569
+ #add git.rc for gcc
570
+ if (WIN32 )
571
+ add_custom_command (OUTPUT ${CMAKE_BINARY_DIR} /git.res
572
+ COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR}
573
+ -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION= "\\\" ${PROJECT_VERSION} .GIT\\\" "
574
+ -i ${CMAKE_SOURCE_DIR} /git.rc -o ${CMAKE_BINARY_DIR} /git.res
575
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
576
+ VERBATIM )
577
+ add_custom_target (git-rc DEPENDS ${CMAKE_BINARY_DIR} /git.res )
578
+ endif ()
579
+
519
580
#link all required libraries to common-main
520
581
add_library (common-main OBJECT ${CMAKE_SOURCE_DIR} /common-main.c )
521
- target_link_libraries (common-main libgit xdiff ${ZLIB_LIBRARIES} pthread rt )
582
+
583
+ target_link_libraries (common-main libgit xdiff ${ZLIB_LIBRARIES} )
522
584
if (Intl_FOUND )
523
585
target_link_libraries (common-main ${Intl_LIBRARIES} )
524
586
endif ()
525
587
if (Iconv_FOUND )
526
588
target_link_libraries (common-main ${Iconv_LIBRARIES} )
527
589
endif ()
590
+ if (WIN32 )
591
+ target_link_libraries (common-main ws2_32 ntdll ${CMAKE_BINARY_DIR} /git.res )
592
+ add_dependencies (common-main git-rc )
593
+ target_link_options (common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup )
594
+ elseif (UNIX )
595
+ target_link_libraries (common-main pthread rt )
596
+ endif ()
528
597
529
598
#git
530
599
parse_makefile_for_sources (git_SOURCES "BUILTIN_OBJS" )
@@ -575,11 +644,13 @@ endif()
575
644
add_executable (git-remote-testsvn ${CMAKE_SOURCE_DIR} /remote-testsvn.c )
576
645
target_link_libraries (git-remote-testsvn common-main vcs-svn )
577
646
578
- add_executable (git-credential-cache ${CMAKE_SOURCE_DIR} /credential-cache.c )
579
- target_link_libraries (git-credential-cache common-main )
647
+ if (NOT NO_UNIX_SOCKETS )
648
+ add_executable (git-credential-cache ${CMAKE_SOURCE_DIR} /credential-cache.c )
649
+ target_link_libraries (git-credential-cache common-main )
580
650
581
- add_executable (git-credential-cache--daemon ${CMAKE_SOURCE_DIR} /credential-cache--daemon.c )
582
- target_link_libraries (git-credential-cache--daemon common-main )
651
+ add_executable (git-credential-cache--daemon ${CMAKE_SOURCE_DIR} /credential-cache--daemon.c )
652
+ target_link_libraries (git-credential-cache--daemon common-main )
653
+ endif ()
583
654
584
655
585
656
set (git_builtin_extra
@@ -591,16 +662,16 @@ set(git_builtin_extra
591
662
foreach (s ${git_SOURCES} ${git_builtin_extra} )
592
663
string (REPLACE "${CMAKE_SOURCE_DIR} /builtin/" "" s ${s} )
593
664
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} )
665
+ file (APPEND ${CMAKE_BINARY_DIR} /CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION } )\n " )
666
+ list (APPEND git_links ${CMAKE_BINARY_DIR} /git-${s}${EXE_EXTENSION} )
596
667
endforeach ()
597
668
598
669
if (CURL_FOUND )
599
670
set (remote_exes
600
671
git-remote-https git-remote-ftp git-remote-ftps )
601
672
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} )
673
+ file (APPEND ${CMAKE_BINARY_DIR} /CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION } )\n " )
674
+ list (APPEND git_http_links ${CMAKE_BINARY_DIR} /${s}${EXE_EXTENSION} )
604
675
endforeach ()
605
676
endif ()
606
677
@@ -722,20 +793,20 @@ set(bin_links
722
793
git-receive-pack git-upload-archive git-upload-pack )
723
794
724
795
foreach (b ${bin_links} )
725
- install (CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX} /bin/git ${CMAKE_INSTALL_PREFIX} /bin/${b} )" )
796
+ install (CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX} /bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX} /bin/${b}${EXE_EXTENSION } )" )
726
797
endforeach ()
727
798
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)" )
799
+ install (CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX} /bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX} /libexec/git-core/git${EXE_EXTENSION} )" )
800
+ install (CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX} /bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX} /libexec/git-core/git-shell${EXE_EXTENSION} )" )
730
801
731
802
foreach (b ${git_links} )
732
803
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} )" )
804
+ install (CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX} /bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX} /libexec/git-core/${b}${EXE_EXTENSION } )" )
734
805
endforeach ()
735
806
736
807
foreach (b ${git_http_links} )
737
808
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} )" )
809
+ 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 } )" )
739
810
endforeach ()
740
811
741
812
install (PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR} /git-p4
@@ -784,14 +855,14 @@ set(wrapper_test_scripts
784
855
foreach (script ${wrapper_scripts} )
785
856
file (STRINGS ${CMAKE_SOURCE_DIR} /wrap-for-bin.sh content NEWLINE_CONSUME )
786
857
string (REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR} " content "${content} " )
787
- string (REPLACE "@@PROG@@" "${script} " content "${content} " )
858
+ string (REPLACE "@@PROG@@" "${script}${EXE_EXTENSION} " content "${content} " )
788
859
file (WRITE ${CMAKE_BINARY_DIR} /bin-wrappers/${script} ${content} )
789
860
endforeach ()
790
861
791
862
foreach (script ${wrapper_test_scripts} )
792
863
file (STRINGS ${CMAKE_SOURCE_DIR} /wrap-for-bin.sh content NEWLINE_CONSUME )
793
864
string (REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR} " content "${content} " )
794
- string (REPLACE "@@PROG@@" "t/helper/${script} " content "${content} " )
865
+ string (REPLACE "@@PROG@@" "t/helper/${script}${EXE_EXTENSION} " content "${content} " )
795
866
file (WRITE ${CMAKE_BINARY_DIR} /bin-wrappers/${script} ${content} )
796
867
endforeach ()
797
868
@@ -857,7 +928,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\
857
928
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS} '\n " )
858
929
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV} '\n " )
859
930
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1} '\n " )
860
- file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "X=''\n " )
931
+ file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "X='${EXE_EXTENSION} '\n " )
861
932
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT} '\n " )
862
933
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX} '\n " )
863
934
file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON} '\n " )
0 commit comments