]>
Commit | Line | Data |
---|---|---|
061c2240 SS |
1 | # |
2 | # Copyright (c) 2020 Sibi Siddharthan | |
3 | # | |
4 | ||
5 | #[[ | |
6 | ||
f2f1250c | 7 | Instructions how to use this in Visual Studio: |
061c2240 | 8 | |
f2f1250c JS |
9 | Open the worktree as a folder. Visual Studio 2019 and later will detect |
10 | the CMake configuration automatically and set everything up for you, | |
11 | ready to build. You can then run the tests in `t/` via a regular Git Bash. | |
061c2240 | 12 | |
f2f1250c JS |
13 | Note: Visual Studio also has the option of opening `CMakeLists.txt` |
14 | directly; Using this option, Visual Studio will not find the source code, | |
15 | though, therefore the `File>Open>Folder...` option is preferred. | |
16 | ||
17 | Instructions to run CMake manually: | |
18 | ||
19 | mkdir -p contrib/buildsystems/out | |
20 | cd contrib/buildsystems/out | |
21 | cmake ../ -DCMAKE_BUILD_TYPE=Release | |
22 | ||
23 | This will build the git binaries in contrib/buildsystems/out | |
24 | directory (our top-level .gitignore file knows to ignore contents of | |
25 | this directory). | |
061c2240 SS |
26 | |
27 | Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding | |
28 | compiler flags | |
29 | Debug : -g | |
30 | Release: -O3 | |
31 | RelWithDebInfo : -O2 -g | |
32 | MinSizeRel : -Os | |
33 | empty(default) : | |
34 | ||
35 | NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio | |
36 | this option is ignored | |
37 | ||
38 | This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default. | |
39 | Run `make` to build Git on Linux/*BSD/MacOS. | |
40 | Open git.sln on Windows and build Git. | |
41 | ||
42 | NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows, | |
43 | to use another tool say `ninja` add this to the command line when configuring. | |
44 | `-G Ninja` | |
45 | ||
cd0a8529 MR |
46 | NOTE: By default CMake will install vcpkg locally to your source tree on configuration, |
47 | to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring. | |
48 | ||
061c2240 SS |
49 | ]] |
50 | cmake_minimum_required(VERSION 3.14) | |
51 | ||
52 | #set the source directory to root of git | |
53 | set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) | |
cd0a8529 MR |
54 | |
55 | option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON) | |
56 | if(NOT WIN32) | |
a5619624 | 57 | set(USE_VCPKG OFF CACHE BOOL "" FORCE) |
cd0a8529 MR |
58 | endif() |
59 | ||
409047a2 MR |
60 | if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) |
61 | set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) | |
62 | endif() | |
63 | ||
cd0a8529 | 64 | if(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 | 78 | endif() |
061c2240 | 79 | |
476e54b1 | 80 | find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin" "$ENV{LOCALAPPDATA}/Programs/Git/bin") |
f7adba41 SS |
81 | if(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/") | |
84 | endif() | |
061c2240 SS |
85 | |
86 | #Create GIT-VERSION-FILE using GIT-VERSION-GEN | |
87 | if(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}) | |
91 | endif() | |
92 | ||
93 | #Parse GIT-VERSION-FILE to get the version | |
94 | file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE git_version REGEX "GIT_VERSION = (.*)") | |
95 | string(REPLACE "GIT_VERSION = " "" git_version ${git_version}) | |
96 | string(FIND ${git_version} "GIT" location) | |
97 | if(location EQUAL -1) | |
98 | string(REGEX MATCH "[0-9]*\\.[0-9]*\\.[0-9]*" git_version ${git_version}) | |
99 | else() | |
100 | string(REGEX MATCH "[0-9]*\\.[0-9]*" git_version ${git_version}) | |
101 | string(APPEND git_version ".0") #for building from a snapshot | |
102 | endif() | |
103 | ||
104 | project(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 |
113 | macro(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 | |
121 | endmacro() | |
122 | ||
afa45fe5 SS |
123 | macro(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() | |
131 | endmacro() | |
132 | ||
7fe07275 JS |
133 | macro(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 | |
141 | endmacro() | |
142 | ||
061c2240 SS |
143 | include(CheckTypeSize) |
144 | include(CheckCSourceRuns) | |
145 | include(CheckCSourceCompiles) | |
146 | include(CheckIncludeFile) | |
147 | include(CheckFunctionExists) | |
148 | include(CheckSymbolExists) | |
149 | include(CheckStructHasMember) | |
c4b2f41b | 150 | include(CTest) |
061c2240 SS |
151 | |
152 | find_package(ZLIB REQUIRED) | |
153 | find_package(CURL) | |
154 | find_package(EXPAT) | |
155 | find_package(Iconv) | |
061c2240 | 156 | |
7f475e27 SS |
157 | #Don't use libintl on Windows Visual Studio and Clang builds |
158 | if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))) | |
159 | find_package(Intl) | |
160 | endif() | |
f7adba41 | 161 | |
80431510 YW |
162 | find_package(PkgConfig) |
163 | if(PkgConfig_FOUND) | |
164 | pkg_check_modules(PCRE2 libpcre2-8) | |
165 | if(PCRE2_FOUND) | |
166 | add_compile_definitions(USE_LIBPCRE2) | |
167 | endif() | |
168 | endif() | |
169 | ||
061c2240 SS |
170 | if(NOT Intl_FOUND) |
171 | add_compile_definitions(NO_GETTEXT) | |
172 | if(NOT Iconv_FOUND) | |
173 | add_compile_definitions(NO_ICONV) | |
174 | endif() | |
175 | endif() | |
176 | ||
177 | include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS}) | |
178 | if(CURL_FOUND) | |
179 | include_directories(SYSTEM ${CURL_INCLUDE_DIRS}) | |
180 | endif() | |
181 | if(EXPAT_FOUND) | |
182 | include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS}) | |
183 | endif() | |
184 | if(Iconv_FOUND) | |
185 | include_directories(SYSTEM ${Iconv_INCLUDE_DIRS}) | |
186 | endif() | |
187 | if(Intl_FOUND) | |
188 | include_directories(SYSTEM ${Intl_INCLUDE_DIRS}) | |
189 | endif() | |
80431510 YW |
190 | if(PCRE2_FOUND) |
191 | include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS}) | |
192 | endif() | |
061c2240 | 193 | |
f7adba41 | 194 | |
7f475e27 | 195 | if(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() | |
200 | endif() | |
201 | ||
ce24797d MR |
202 | if(NO_GETTEXT) |
203 | message(STATUS "msgfmt not used under NO_GETTEXT") | |
204 | else() | |
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 |
215 | endif() |
216 | ||
7f475e27 SS |
217 | #Force all visual studio outputs to CMAKE_BINARY_DIR |
218 | if(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 |
222 | endif() |
223 | ||
061c2240 SS |
224 | #default behaviour |
225 | include_directories(${CMAKE_SOURCE_DIR}) | |
226 | add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}") | |
227 | add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX) | |
228 | add_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" ) | |
232 | 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) | |
233 | ||
234 | ||
235 | add_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 |
248 | if(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 |
254 | else() |
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 |
259 | endif() |
260 | ||
261 | ||
262 | #Platform Specific | |
263 | if(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 | ||
288 | elseif(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 | 291 | endif() |
061c2240 | 292 | |
59c7b881 JH |
293 | if(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 | 297 | else() |
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 | 304 | endif() |
061c2240 | 305 | |
62c73671 JH |
306 | if(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) |
508c1a57 | 311 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c) |
d33c804d JH |
312 | |
313 | add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) | |
314 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c) | |
f67df255 JH |
315 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
316 | add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND) | |
317 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c) | |
d0605550 | 318 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c) |
508c1a57 | 319 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c) |
a85ad67b JH |
320 | |
321 | add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS) | |
322 | list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c) | |
62c73671 JH |
323 | endif() |
324 | endif() | |
325 | ||
f7adba41 | 326 | set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX}) |
061c2240 SS |
327 | |
328 | #header checks | |
329 | check_include_file(libgen.h HAVE_LIBGEN_H) | |
330 | if(NOT HAVE_LIBGEN_H) | |
331 | add_compile_definitions(NO_LIBGEN_H) | |
332 | list(APPEND compat_SOURCES compat/basename.c) | |
333 | endif() | |
334 | ||
335 | check_include_file(sys/sysinfo.h HAVE_SYSINFO) | |
336 | if(HAVE_SYSINFO) | |
337 | add_compile_definitions(HAVE_SYSINFO) | |
338 | endif() | |
339 | ||
340 | check_c_source_compiles(" | |
341 | #include <alloca.h> | |
342 | ||
343 | int main(void) | |
344 | { | |
345 | char *p = (char *) alloca(2 * sizeof(int)); | |
346 | ||
347 | if (p) | |
348 | return 0; | |
349 | return 0; | |
350 | }" | |
351 | HAVE_ALLOCA_H) | |
352 | if(HAVE_ALLOCA_H) | |
353 | add_compile_definitions(HAVE_ALLOCA_H) | |
354 | endif() | |
355 | ||
356 | check_include_file(strings.h HAVE_STRINGS_H) | |
357 | if(HAVE_STRINGS_H) | |
358 | add_compile_definitions(HAVE_STRINGS_H) | |
359 | endif() | |
360 | ||
361 | check_include_file(sys/select.h HAVE_SYS_SELECT_H) | |
362 | if(NOT HAVE_SYS_SELECT_H) | |
363 | add_compile_definitions(NO_SYS_SELECT_H) | |
364 | endif() | |
365 | ||
366 | check_include_file(sys/poll.h HAVE_SYS_POLL_H) | |
367 | if(NOT HAVE_SYS_POLL_H) | |
368 | add_compile_definitions(NO_SYS_POLL_H) | |
369 | endif() | |
370 | ||
371 | check_include_file(poll.h HAVE_POLL_H) | |
372 | if(NOT HAVE_POLL_H) | |
373 | add_compile_definitions(NO_POLL_H) | |
374 | endif() | |
375 | ||
376 | check_include_file(inttypes.h HAVE_INTTYPES_H) | |
377 | if(NOT HAVE_INTTYPES_H) | |
378 | add_compile_definitions(NO_INTTYPES_H) | |
379 | endif() | |
380 | ||
381 | check_include_file(paths.h HAVE_PATHS_H) | |
382 | if(HAVE_PATHS_H) | |
383 | add_compile_definitions(HAVE_PATHS_H) | |
384 | endif() | |
385 | ||
386 | #function checks | |
387 | set(function_checks | |
388 | strcasestr memmem strlcpy strtoimax strtoumax strtoull | |
f7adba41 SS |
389 | setenv mkdtemp poll pread memmem) |
390 | ||
391 | #unsetenv,hstrerror are incompatible with windows build | |
392 | if(NOT WIN32) | |
393 | list(APPEND function_checks unsetenv hstrerror) | |
394 | endif() | |
061c2240 SS |
395 | |
396 | foreach(f ${function_checks}) | |
397 | string(TOUPPER ${f} uf) | |
398 | check_function_exists(${f} HAVE_${uf}) | |
399 | if(NOT HAVE_${uf}) | |
400 | add_compile_definitions(NO_${uf}) | |
401 | endif() | |
402 | endforeach() | |
403 | ||
404 | if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL) | |
405 | include_directories(${CMAKE_SOURCE_DIR}/compat/poll) | |
406 | add_compile_definitions(NO_POLL) | |
407 | list(APPEND compat_SOURCES compat/poll/poll.c) | |
408 | endif() | |
409 | ||
410 | if(NOT HAVE_STRCASESTR) | |
411 | list(APPEND compat_SOURCES compat/strcasestr.c) | |
412 | endif() | |
413 | ||
414 | if(NOT HAVE_STRLCPY) | |
415 | list(APPEND compat_SOURCES compat/strlcpy.c) | |
416 | endif() | |
417 | ||
418 | if(NOT HAVE_STRTOUMAX) | |
419 | list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c) | |
420 | endif() | |
421 | ||
422 | if(NOT HAVE_SETENV) | |
423 | list(APPEND compat_SOURCES compat/setenv.c) | |
424 | endif() | |
425 | ||
426 | if(NOT HAVE_MKDTEMP) | |
427 | list(APPEND compat_SOURCES compat/mkdtemp.c) | |
428 | endif() | |
429 | ||
430 | if(NOT HAVE_PREAD) | |
431 | list(APPEND compat_SOURCES compat/pread.c) | |
432 | endif() | |
433 | ||
434 | if(NOT HAVE_MEMMEM) | |
435 | list(APPEND compat_SOURCES compat/memmem.c) | |
436 | endif() | |
437 | ||
438 | if(NOT WIN32) | |
439 | if(NOT HAVE_UNSETENV) | |
440 | list(APPEND compat_SOURCES compat/unsetenv.c) | |
441 | endif() | |
442 | ||
443 | if(NOT HAVE_HSTRERROR) | |
444 | list(APPEND compat_SOURCES compat/hstrerror.c) | |
445 | endif() | |
446 | endif() | |
447 | ||
448 | check_function_exists(getdelim HAVE_GETDELIM) | |
449 | if(HAVE_GETDELIM) | |
450 | add_compile_definitions(HAVE_GETDELIM) | |
451 | endif() | |
452 | ||
453 | check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) | |
454 | check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC) | |
455 | if(HAVE_CLOCK_GETTIME) | |
456 | add_compile_definitions(HAVE_CLOCK_GETTIME) | |
457 | endif() | |
458 | if(HAVE_CLOCK_MONOTONIC) | |
459 | add_compile_definitions(HAVE_CLOCK_MONOTONIC) | |
460 | endif() | |
461 | ||
462 | #check for st_blocks in struct stat | |
463 | check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS) | |
464 | if(NOT STRUCT_STAT_HAS_ST_BLOCKS) | |
465 | add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT) | |
466 | endif() | |
467 | ||
468 | #compile checks | |
469 | check_c_source_runs(" | |
470 | #include<stdio.h> | |
471 | #include<stdarg.h> | |
472 | #include<string.h> | |
473 | #include<stdlib.h> | |
474 | ||
475 | int test_vsnprintf(char *str, size_t maxsize, const char *format, ...) | |
476 | { | |
477 | int ret; | |
478 | va_list ap; | |
479 | ||
480 | va_start(ap, format); | |
481 | ret = vsnprintf(str, maxsize, format, ap); | |
482 | va_end(ap); | |
483 | return ret; | |
484 | } | |
485 | ||
486 | int main(void) | |
487 | { | |
488 | char buf[6]; | |
489 | ||
490 | if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5 | |
491 | || strcmp(buf, \"12\")) | |
492 | return 1; | |
493 | if (snprintf(buf, 3, \"%s\", \"12345\") != 5 | |
494 | || strcmp(buf, \"12\")) | |
495 | return 1; | |
496 | return 0; | |
497 | }" | |
498 | SNPRINTF_OK) | |
499 | if(NOT SNPRINTF_OK) | |
500 | add_compile_definitions(SNPRINTF_RETURNS_BOGUS) | |
501 | list(APPEND compat_SOURCES compat/snprintf.c) | |
502 | endif() | |
503 | ||
504 | check_c_source_runs(" | |
505 | #include<stdio.h> | |
506 | ||
507 | int main(void) | |
508 | { | |
509 | FILE *f = fopen(\".\", \"r\"); | |
510 | ||
511 | return f != NULL; | |
512 | }" | |
513 | FREAD_READS_DIRECTORIES_NO) | |
514 | if(NOT FREAD_READS_DIRECTORIES_NO) | |
515 | add_compile_definitions(FREAD_READS_DIRECTORIES) | |
516 | list(APPEND compat_SOURCES compat/fopen.c) | |
517 | endif() | |
518 | ||
519 | check_c_source_compiles(" | |
520 | #include <regex.h> | |
521 | #ifndef REG_STARTEND | |
522 | #error oops we dont have it | |
523 | #endif | |
524 | ||
525 | int main(void) | |
526 | { | |
527 | return 0; | |
528 | }" | |
529 | HAVE_REGEX) | |
530 | if(NOT HAVE_REGEX) | |
531 | include_directories(${CMAKE_SOURCE_DIR}/compat/regex) | |
532 | list(APPEND compat_SOURCES compat/regex/regex.c ) | |
533 | add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK) | |
534 | endif() | |
535 | ||
536 | ||
537 | check_c_source_compiles(" | |
538 | #include <stddef.h> | |
539 | #include <sys/types.h> | |
540 | #include <sys/sysctl.h> | |
541 | ||
542 | int main(void) | |
543 | { | |
544 | int val, mib[2]; | |
545 | size_t len; | |
546 | ||
547 | mib[0] = CTL_HW; | |
548 | mib[1] = 1; | |
549 | len = sizeof(val); | |
550 | return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0; | |
551 | }" | |
552 | HAVE_BSD_SYSCTL) | |
553 | if(HAVE_BSD_SYSCTL) | |
554 | add_compile_definitions(HAVE_BSD_SYSCTL) | |
555 | endif() | |
556 | ||
557 | set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES}) | |
558 | set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS}) | |
559 | ||
560 | check_c_source_compiles(" | |
561 | #include <iconv.h> | |
562 | ||
563 | extern size_t iconv(iconv_t cd, | |
564 | char **inbuf, size_t *inbytesleft, | |
565 | char **outbuf, size_t *outbytesleft); | |
566 | ||
567 | int main(void) | |
568 | { | |
569 | return 0; | |
570 | }" | |
571 | HAVE_NEW_ICONV) | |
572 | if(HAVE_NEW_ICONV) | |
573 | set(HAVE_OLD_ICONV 0) | |
574 | else() | |
575 | set(HAVE_OLD_ICONV 1) | |
576 | endif() | |
577 | ||
578 | check_c_source_runs(" | |
579 | #include <iconv.h> | |
580 | #if ${HAVE_OLD_ICONV} | |
581 | typedef const char *iconv_ibp; | |
582 | #else | |
583 | typedef char *iconv_ibp; | |
584 | #endif | |
585 | ||
586 | int main(void) | |
587 | { | |
588 | int v; | |
589 | iconv_t conv; | |
590 | char in[] = \"a\"; | |
591 | iconv_ibp pin = in; | |
592 | char out[20] = \"\"; | |
593 | char *pout = out; | |
594 | size_t isz = sizeof(in); | |
595 | size_t osz = sizeof(out); | |
596 | ||
597 | conv = iconv_open(\"UTF-16\", \"UTF-8\"); | |
598 | iconv(conv, &pin, &isz, &pout, &osz); | |
599 | iconv_close(conv); | |
600 | v = (unsigned char)(out[0]) + (unsigned char)(out[1]); | |
601 | return v != 0xfe + 0xff; | |
602 | }" | |
603 | ICONV_DOESNOT_OMIT_BOM) | |
604 | if(NOT ICONV_DOESNOT_OMIT_BOM) | |
605 | add_compile_definitions(ICONV_OMITS_BOM) | |
606 | endif() | |
607 | ||
608 | unset(CMAKE_REQUIRED_LIBRARIES) | |
609 | unset(CMAKE_REQUIRED_INCLUDES) | |
610 | ||
611 | ||
612 | #programs | |
613 | set(PROGRAMS_BUILT | |
a006f875 | 614 | git git-daemon git-http-backend git-sh-i18n--envsubst |
fc47391e | 615 | git-shell) |
f7adba41 | 616 | |
061c2240 SS |
617 | if(NOT CURL_FOUND) |
618 | list(APPEND excluded_progs git-http-fetch git-http-push) | |
619 | add_compile_definitions(NO_CURL) | |
620 | message(WARNING "git-http-push and git-http-fetch will not be built") | |
621 | else() | |
622 | list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http) | |
623 | if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0) | |
624 | add_compile_definitions(USE_CURL_FOR_IMAP_SEND) | |
625 | endif() | |
626 | endif() | |
627 | ||
628 | if(NOT EXPAT_FOUND) | |
629 | list(APPEND excluded_progs git-http-push) | |
630 | add_compile_definitions(NO_EXPAT) | |
631 | else() | |
632 | list(APPEND PROGRAMS_BUILT git-http-push) | |
633 | if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2) | |
634 | add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H) | |
635 | endif() | |
636 | endif() | |
637 | ||
638 | list(REMOVE_DUPLICATES excluded_progs) | |
639 | list(REMOVE_DUPLICATES PROGRAMS_BUILT) | |
640 | ||
641 | ||
642 | foreach(p ${excluded_progs}) | |
643 | list(APPEND EXCLUSION_PROGS --exclude-program ${p} ) | |
644 | endforeach() | |
645 | ||
646 | #for comparing null values | |
647 | list(APPEND EXCLUSION_PROGS empty) | |
648 | set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE) | |
649 | ||
650 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS) | |
651 | list(REMOVE_ITEM EXCLUSION_PROGS empty) | |
652 | message("Generating command-list.h") | |
653 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt | |
654 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
655 | OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h) | |
656 | endif() | |
657 | ||
658 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h) | |
659 | message("Generating config-list.h") | |
660 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh | |
661 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
662 | OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h) | |
663 | endif() | |
664 | ||
cfe853e6 ÆAB |
665 | if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h) |
666 | message("Generating hook-list.h") | |
667 | execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh | |
668 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
669 | OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h) | |
670 | endif() | |
671 | ||
061c2240 SS |
672 | include_directories(${CMAKE_BINARY_DIR}) |
673 | ||
674 | #build | |
675 | #libgit | |
676 | parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS") | |
677 | ||
678 | list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
679 | list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
680 | add_library(libgit ${libgit_SOURCES} ${compat_SOURCES}) | |
681 | ||
682 | #libxdiff | |
683 | parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS") | |
684 | ||
685 | list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
686 | add_library(xdiff STATIC ${libxdiff_SOURCES}) | |
687 | ||
ef8a6c62 HWN |
688 | #reftable |
689 | parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS") | |
690 | ||
691 | list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
692 | add_library(reftable STATIC ${reftable_SOURCES}) | |
693 | ||
f7adba41 | 694 | if(WIN32) |
7f475e27 SS |
695 | if(NOT MSVC)#use windres when compiling with gcc and clang |
696 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res | |
697 | COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR} | |
698 | -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\"" | |
699 | -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res | |
700 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
701 | VERBATIM) | |
702 | else()#MSVC use rc | |
703 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res | |
704 | COMMAND ${CMAKE_RC_COMPILER} /d MAJOR=${PROJECT_VERSION_MAJOR} /d MINOR=${PROJECT_VERSION_MINOR} | |
705 | /d MICRO=${PROJECT_VERSION_PATCH} /d PATCHLEVEL=0 /d GIT_VERSION="${PROJECT_VERSION}.GIT" | |
706 | /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_SOURCE_DIR}/git.rc | |
707 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
708 | VERBATIM) | |
709 | endif() | |
f7adba41 SS |
710 | add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res) |
711 | endif() | |
712 | ||
061c2240 SS |
713 | #link all required libraries to common-main |
714 | add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c) | |
f7adba41 | 715 | |
ef8a6c62 | 716 | target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES}) |
061c2240 SS |
717 | if(Intl_FOUND) |
718 | target_link_libraries(common-main ${Intl_LIBRARIES}) | |
719 | endif() | |
720 | if(Iconv_FOUND) | |
721 | target_link_libraries(common-main ${Iconv_LIBRARIES}) | |
722 | endif() | |
80431510 YW |
723 | if(PCRE2_FOUND) |
724 | target_link_libraries(common-main ${PCRE2_LIBRARIES}) | |
725 | target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS}) | |
726 | endif() | |
f7adba41 SS |
727 | if(WIN32) |
728 | target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res) | |
729 | add_dependencies(common-main git-rc) | |
7f475e27 SS |
730 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") |
731 | target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup) | |
732 | elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") | |
733 | target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj) | |
734 | elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") | |
735 | target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj) | |
2d9eb4ed JS |
736 | else() |
737 | message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}") | |
7f475e27 | 738 | endif() |
f7adba41 SS |
739 | elseif(UNIX) |
740 | target_link_libraries(common-main pthread rt) | |
741 | endif() | |
061c2240 SS |
742 | |
743 | #git | |
744 | parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS") | |
745 | ||
746 | list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
747 | add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES}) | |
748 | target_link_libraries(git common-main) | |
749 | ||
061c2240 SS |
750 | add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c) |
751 | target_link_libraries(git-daemon common-main) | |
752 | ||
061c2240 SS |
753 | add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c) |
754 | target_link_libraries(git-http-backend common-main) | |
755 | ||
756 | add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c) | |
757 | target_link_libraries(git-sh-i18n--envsubst common-main) | |
758 | ||
759 | add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c) | |
760 | target_link_libraries(git-shell common-main) | |
761 | ||
762 | if(CURL_FOUND) | |
763 | add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c) | |
764 | ||
765 | add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c) | |
766 | target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES}) | |
767 | ||
768 | add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c) | |
769 | target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES}) | |
770 | ||
771 | add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c) | |
772 | target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} ) | |
773 | ||
774 | if(EXPAT_FOUND) | |
775 | add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c) | |
776 | target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES}) | |
777 | endif() | |
778 | endif() | |
779 | ||
7fe07275 | 780 | parse_makefile_for_executables(git_builtin_extra "BUILT_INS") |
061c2240 | 781 | |
7bb544a4 JS |
782 | option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins") |
783 | ||
061c2240 | 784 | #Creating hardlinks |
7bb544a4 | 785 | if(NOT SKIP_DASHED_BUILT_INS) |
061c2240 SS |
786 | foreach(s ${git_SOURCES} ${git_builtin_extra}) |
787 | string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s}) | |
788 | string(REPLACE ".c" "" s ${s}) | |
f7adba41 SS |
789 | file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION})\n") |
790 | list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s}${EXE_EXTENSION}) | |
061c2240 | 791 | endforeach() |
7bb544a4 | 792 | endif() |
061c2240 SS |
793 | |
794 | if(CURL_FOUND) | |
795 | set(remote_exes | |
796 | git-remote-https git-remote-ftp git-remote-ftps) | |
797 | foreach(s ${remote_exes}) | |
f7adba41 SS |
798 | file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION})\n") |
799 | list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s}${EXE_EXTENSION}) | |
061c2240 SS |
800 | endforeach() |
801 | endif() | |
802 | ||
803 | add_custom_command(OUTPUT ${git_links} ${git_http_links} | |
804 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake | |
805 | DEPENDS git git-remote-http) | |
806 | add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links}) | |
afa45fe5 SS |
807 | |
808 | ||
809 | #creating required scripts | |
810 | set(SHELL_PATH /bin/sh) | |
811 | set(PERL_PATH /usr/bin/perl) | |
812 | set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale) | |
813 | set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale) | |
814 | set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5) | |
815 | ||
816 | #shell scripts | |
817 | parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh") | |
818 | parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "") | |
819 | set(git_shell_scripts | |
820 | ${git_sh_scripts} ${git_shlib_scripts} git-instaweb) | |
821 | ||
822 | foreach(script ${git_shell_scripts}) | |
823 | file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.sh content NEWLINE_CONSUME) | |
824 | string(REPLACE "@SHELL_PATH@" "${SHELL_PATH}" content "${content}") | |
825 | string(REPLACE "@@DIFF@@" "diff" content "${content}") | |
826 | string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}") | |
827 | string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" content "${content}") | |
828 | string(REPLACE "@@NO_CURL@@" "" content "${content}") | |
829 | string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}") | |
830 | string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}") | |
831 | string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}") | |
afa45fe5 SS |
832 | string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}") |
833 | file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content}) | |
834 | endforeach() | |
835 | ||
836 | #perl scripts | |
837 | parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl") | |
838 | ||
839 | #create perl header | |
840 | file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header ) | |
841 | string(REPLACE "@@PATHSEP@@" ":" perl_header "${perl_header}") | |
842 | string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}") | |
843 | ||
844 | foreach(script ${git_perl_scripts}) | |
845 | file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME) | |
846 | string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}") | |
847 | string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}") | |
848 | file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content}) | |
849 | endforeach() | |
850 | ||
851 | #python script | |
852 | file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME) | |
853 | string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}") | |
854 | file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content}) | |
855 | ||
856 | #perl modules | |
857 | file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm") | |
858 | ||
859 | foreach(pm ${perl_modules}) | |
860 | string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm}) | |
861 | file(STRINGS ${pm} content NEWLINE_CONSUME) | |
862 | string(REPLACE "@@LOCALEDIR@@" "${LOCALEDIR}" content "${content}") | |
863 | string(REPLACE "@@NO_PERL_CPAN_FALLBACKS@@" "" content "${content}") | |
864 | file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content}) | |
865 | #test-lib.sh requires perl/build/lib to be the build directory of perl modules | |
866 | endforeach() | |
867 | ||
868 | ||
869 | #templates | |
870 | file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*") | |
871 | list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "") | |
872 | list(REMOVE_ITEM templates ".gitignore") | |
873 | list(REMOVE_ITEM templates "Makefile") | |
874 | list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds | |
875 | ||
876 | list(REMOVE_ITEM templates "branches--") | |
877 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches | |
878 | ||
879 | #templates have @.*@ replacement so use configure_file instead | |
880 | foreach(tm ${templates}) | |
881 | string(REPLACE "--" "/" blt_tm ${tm}) | |
882 | string(REPLACE "this" "" blt_tm ${blt_tm})# for this-- | |
883 | configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY) | |
884 | endforeach() | |
885 | ||
886 | ||
887 | #translations | |
888 | if(MSGFMT_EXE) | |
889 | file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po") | |
890 | list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "") | |
891 | list(TRANSFORM po_files REPLACE ".po" "") | |
892 | foreach(po ${po_files}) | |
893 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES) | |
894 | add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo | |
895 | COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po) | |
896 | list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo) | |
897 | endforeach() | |
898 | add_custom_target(po-gen ALL DEPENDS ${po_gen}) | |
899 | endif() | |
f1f5dff9 SS |
900 | |
901 | ||
902 | #to help with the install | |
903 | list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/") | |
904 | list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/") | |
905 | ||
906 | #install | |
e8772a7a JS |
907 | foreach(program ${PROGRAMS_BUILT}) |
908 | if(program STREQUAL "git" OR program STREQUAL "git-shell") | |
909 | install(TARGETS ${program} | |
f1f5dff9 | 910 | RUNTIME DESTINATION bin) |
e8772a7a JS |
911 | else() |
912 | install(TARGETS ${program} | |
913 | RUNTIME DESTINATION libexec/git-core) | |
914 | endif() | |
915 | endforeach() | |
916 | ||
f1f5dff9 SS |
917 | install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver |
918 | DESTINATION bin) | |
919 | ||
f1f5dff9 SS |
920 | set(bin_links |
921 | git-receive-pack git-upload-archive git-upload-pack) | |
922 | ||
923 | foreach(b ${bin_links}) | |
f7adba41 | 924 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/bin/${b}${EXE_EXTENSION})") |
f1f5dff9 SS |
925 | endforeach() |
926 | ||
f7adba41 SS |
927 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git${EXE_EXTENSION})") |
928 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell${EXE_EXTENSION})") | |
f1f5dff9 SS |
929 | |
930 | foreach(b ${git_links}) | |
931 | string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b}) | |
569f8d18 | 932 | install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})") |
f1f5dff9 SS |
933 | endforeach() |
934 | ||
935 | foreach(b ${git_http_links}) | |
936 | string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b}) | |
569f8d18 | 937 | 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 |
938 | endforeach() |
939 | ||
940 | install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4 | |
941 | DESTINATION libexec/git-core) | |
942 | ||
943 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core) | |
944 | install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5 | |
945 | FILES_MATCHING PATTERN "*.pm") | |
946 | install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates) | |
947 | ||
948 | if(MSGFMT_EXE) | |
949 | install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share) | |
950 | endif() | |
c4b2f41b SS |
951 | |
952 | ||
953 | if(BUILD_TESTING) | |
954 | ||
955 | #tests-helpers | |
956 | add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) | |
957 | target_link_libraries(test-fake-ssh common-main) | |
958 | ||
ef8a6c62 HWN |
959 | #reftable-tests |
960 | parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS") | |
961 | list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") | |
962 | ||
c4b2f41b SS |
963 | #test-tool |
964 | parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") | |
965 | ||
966 | list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/") | |
ef8a6c62 | 967 | add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES}) |
c4b2f41b SS |
968 | target_link_libraries(test-tool common-main) |
969 | ||
fc47391e | 970 | set_target_properties(test-fake-ssh test-tool |
c4b2f41b SS |
971 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper) |
972 | ||
7f475e27 | 973 | if(MSVC) |
fc47391e | 974 | set_target_properties(test-fake-ssh test-tool |
7f475e27 | 975 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper) |
fc47391e | 976 | set_target_properties(test-fake-ssh test-tool |
7f475e27 SS |
977 | PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper) |
978 | endif() | |
979 | ||
c4b2f41b SS |
980 | #wrapper scripts |
981 | set(wrapper_scripts | |
982 | git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext) | |
983 | ||
984 | set(wrapper_test_scripts | |
fc47391e | 985 | test-fake-ssh test-tool) |
c4b2f41b SS |
986 | |
987 | ||
988 | foreach(script ${wrapper_scripts}) | |
989 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
990 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
f7adba41 | 991 | string(REPLACE "@@PROG@@" "${script}${EXE_EXTENSION}" content "${content}") |
c4b2f41b SS |
992 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content}) |
993 | endforeach() | |
994 | ||
995 | foreach(script ${wrapper_test_scripts}) | |
996 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
997 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
f7adba41 | 998 | string(REPLACE "@@PROG@@" "t/helper/${script}${EXE_EXTENSION}" content "${content}") |
c4b2f41b SS |
999 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content}) |
1000 | endforeach() | |
1001 | ||
1002 | file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME) | |
1003 | string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}") | |
1004 | string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}") | |
1005 | file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content}) | |
1006 | ||
1007 | #options for configuring test options | |
1008 | option(PERL_TESTS "Perform tests that use perl" ON) | |
1009 | option(PYTHON_TESTS "Perform tests that use python" ON) | |
1010 | ||
1011 | #GIT-BUILD-OPTIONS | |
1012 | set(TEST_SHELL_PATH ${SHELL_PATH}) | |
1013 | set(DIFF diff) | |
1014 | set(PYTHON_PATH /usr/bin/python) | |
1015 | set(TAR tar) | |
1016 | set(NO_CURL ) | |
1017 | set(NO_EXPAT ) | |
c4b2f41b | 1018 | set(USE_LIBPCRE2 ) |
c4b2f41b SS |
1019 | set(NO_PERL ) |
1020 | set(NO_PTHREADS ) | |
1021 | set(NO_PYTHON ) | |
1022 | set(PAGER_ENV "LESS=FRX LV=-c") | |
1023 | set(DC_SHA1 YesPlease) | |
1024 | set(RUNTIME_PREFIX true) | |
1025 | set(NO_GETTEXT ) | |
1026 | ||
1027 | if(NOT CURL_FOUND) | |
1028 | set(NO_CURL 1) | |
1029 | endif() | |
1030 | ||
1031 | if(NOT EXPAT_FOUND) | |
1032 | set(NO_EXPAT 1) | |
1033 | endif() | |
1034 | ||
1035 | if(NOT Intl_FOUND) | |
1036 | set(NO_GETTEXT 1) | |
1037 | endif() | |
1038 | ||
1039 | if(NOT PERL_TESTS) | |
1040 | set(NO_PERL 1) | |
1041 | endif() | |
1042 | ||
1043 | if(NOT PYTHON_TESTS) | |
1044 | set(NO_PYTHON 1) | |
1045 | endif() | |
1046 | ||
1047 | file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n") | |
1048 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n") | |
1049 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n") | |
1050 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n") | |
1051 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n") | |
1052 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n") | |
1053 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n") | |
1054 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n") | |
c4b2f41b SS |
1055 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n") |
1056 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n") | |
1057 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n") | |
1058 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n") | |
1059 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DC_SHA1='${DC_SHA1}'\n") | |
f7adba41 | 1060 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n") |
c4b2f41b SS |
1061 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n") |
1062 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n") | |
1063 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n") | |
6aac70a8 | 1064 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n") |
cd0a8529 | 1065 | if(USE_VCPKG) |
8c35e828 JS |
1066 | file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n") |
1067 | endif() | |
c4b2f41b | 1068 | |
7f5397a0 SS |
1069 | #Make the tests work when building out of the source tree |
1070 | get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE) | |
1071 | if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH}) | |
1072 | file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt) | |
1073 | string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE}) | |
1074 | #Setting the build directory in test-lib.sh before running tests | |
1075 | file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake | |
1076 | "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n" | |
1077 | "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n" | |
f1bd7379 | 1078 | "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\"\" content \"\${content}\")\n" |
7f5397a0 SS |
1079 | "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})") |
1080 | #misc copies | |
1081 | file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/) | |
1082 | file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/) | |
1083 | file(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/) | |
1084 | file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) | |
1085 | file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/) | |
7f5397a0 SS |
1086 | endif() |
1087 | ||
c4b2f41b SS |
1088 | file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh") |
1089 | ||
1090 | #test | |
1091 | foreach(tsh ${test_scipts}) | |
1092 | add_test(NAME ${tsh} | |
1093 | COMMAND ${SH_EXE} ${tsh} | |
1094 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t) | |
1095 | endforeach() | |
1096 | ||
1097 | endif()#BUILD_TESTING |