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