44
55#[[
66
7- Instructions to run CMake :
7+ Instructions how to use this in Visual Studio :
88
9- cmake `relative-path-to-CMakeLists.txt` -DCMAKE_BUILD_TYPE=Release
10- Eg.
11- From the root of git source tree
12- `cmake contrib/buildsystems/ `
13- This will build the git binaries at the root
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.
1412
15- For out of source builds, say build in 'git/git-build/'
16- `mkdir git-build;cd git-build; cmake ../contrib/buildsystems/`
17- This will build the git binaries in git-build directory
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).
1826
1927Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
2028compiler flags
@@ -40,8 +48,19 @@ cmake_minimum_required(VERSION 3.14)
4048
4149#set the source directory to root of git
4250set (CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} /../..)
51+ if (WIN32 )
52+ set (VCPKG_DIR "${CMAKE_SOURCE_DIR} /compat/vcbuild/vcpkg" )
53+ if (MSVC AND NOT EXISTS ${VCPKG_DIR} )
54+ message ("Initializing vcpkg and building the Git's dependencies (this will take a while...)" )
55+ execute_process (COMMAND ${CMAKE_SOURCE_DIR} /compat/vcbuild/vcpkg_install.bat)
56+ endif ()
57+ list (APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR} /installed/x64-windows" )
4358
44- find_program (SH_EXE sh)
59+ # In the vcpkg edition, we need this to be able to link to libcurl
60+ set (CURL_NO_CURL_CMAKE ON )
61+ endif ()
62+
63+ find_program (SH_EXE sh PATHS "C:/Program Files/Git/bin" )
4564if (NOT SH_EXE)
4665 message (FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
4766 "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/" )
@@ -145,7 +164,11 @@ endif()
145164
146165find_program (MSGFMT_EXE msgfmt)
147166if (NOT MSGFMT_EXE)
148- message (WARNING "Text Translations won't be build" )
167+ set (MSGFMT_EXE ${CMAKE_SOURCE_DIR} /compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
168+ if (NOT EXISTS ${MSGFMT_EXE} )
169+ message (WARNING "Text Translations won't be built" )
170+ unset (MSGFMT_EXE)
171+ endif ()
149172endif ()
150173
151174#Force all visual studio outputs to CMAKE_BINARY_DIR
@@ -606,6 +629,8 @@ if(WIN32)
606629 target_link_options (common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
607630 elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC" )
608631 target_link_options (common-main PUBLIC /IGNORE :4217 /IGNORE :4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj)
632+ else ()
633+ message (FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID} " )
609634 endif ()
610635elseif (UNIX )
611636 target_link_libraries (common-main pthread rt)
@@ -928,6 +953,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
928953file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD -OPTIONS "NO_GETTEXT='${NO_GETTEXT} '\n " )
929954file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD -OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX} '\n " )
930955file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD -OPTIONS "NO_PYTHON='${NO_PYTHON} '\n " )
956+ if (WIN32 )
957+ file (APPEND ${CMAKE_BINARY_DIR} /GIT-BUILD -OPTIONS "PATH=\" $PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n " )
958+ endif ()
931959
932960#Make the tests work when building out of the source tree
933961get_filename_component (CACHE_PATH ${CMAKE_CURRENT_LIST_DIR} /../../CMakeCache.txt ABSOLUTE )
@@ -938,7 +966,7 @@ if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
938966 file (WRITE ${CMAKE_BINARY_DIR} /CTestCustom.cmake
939967 "file(STRINGS ${CMAKE_SOURCE_DIR} /t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \" GIT_BUILD_DIR=(.*)\" )\n "
940968 "file(STRINGS ${CMAKE_SOURCE_DIR} /t/test-lib.sh content NEWLINE_CONSUME)\n "
941- "string(REPLACE \"\$ {GIT_BUILD_DIR_REPL}\" \" GIT_BUILD_DIR=\\\" $TEST_DIRECTORY\\\" /../${BUILD_DIR_RELATIVE} \" content \"\$ {content}\" )\n "
969+ "string(REPLACE \"\$ {GIT_BUILD_DIR_REPL}\" \" GIT_BUILD_DIR=\\\" $TEST_DIRECTORY/../${BUILD_DIR_RELATIVE} \\\" \" content \"\$ {content}\" )\n "
942970 "file(WRITE ${CMAKE_SOURCE_DIR} /t/test-lib.sh \$ {content})" )
943971 #misc copies
944972 file (COPY ${CMAKE_SOURCE_DIR} /t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR} /t/)
0 commit comments