From c0265595da9dd0b010136f6ce8a1406736326334 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 02:15:01 +0000 Subject: [PATCH 01/19] build: ignore build*/ for out-of-source builds Add build*/ to .gitignore to support the typical commandline cmake workflow for out-of-source builds. That is, something like: mkdir build-x64-static cd build-x64-static cmake ../contrib/buildsystems -DCMAKE_BUILD_TYPE=Release ` -DVCPKG_ARCH=x64-windows-static ` -G Ninja ninja Signed-off-by: Rafael Kitover --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff241d0cec571f..0ba169f30a5830 100644 --- a/.gitignore +++ b/.gitignore @@ -245,3 +245,4 @@ Release/ *.dSYM /contrib/buildsystems/out CMakeSettings.json +build*/ From 2472dc4c60e3e171993b9e8b48e22f08bcffd663 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 02:26:55 +0000 Subject: [PATCH 02/19] build: add -static triplets in vcpkg_install usage Change the usage message that is printed when the arch is not passed in in vcpkg_install.bat to mention the -static vcpkg triplets for static builds. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 575c65c20ba307..a150be7af61feb 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -33,7 +33,7 @@ REM ================================================================ SET arch=%1 IF NOT DEFINED arch ( - echo defaulting to 'x64-windows`. Invoke %0 with 'x86-windows', 'x64-windows', or 'arm64-windows' + echo defaulting to 'x64-windows`. Invoke %0 with 'x86-windows', 'x64-windows', or 'arm64-windows', append '-static' for static builds. set arch=x64-windows ) From 4f6e1648d1383079ec4f9b9d9590987f1bb77e9f Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 02:31:15 +0000 Subject: [PATCH 03/19] build: improve check for built vcpkg.exe Use IF EXIST path/vcpkg.exe instead of dir path/vcpkg.exe && to check for an existing vcpkg.exe which is the typical way to do these tests in cmd scripts. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index a150be7af61feb..50946a369e7b62 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -40,7 +40,7 @@ REM ================================================================ @FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD cd %cwd% - dir vcpkg\vcpkg.exe >nul 2>nul && GOTO :install_libraries + IF EXIST vcpkg\vcpkg.exe goto :install_libraries git.exe version 2>nul IF ERRORLEVEL 1 ( From b024210d4cf831bea631745648a771c41516c01f Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 02:33:59 +0000 Subject: [PATCH 04/19] build: reformat git check in vcpkg_install.bat Indent and format the code in the IF statement checking for the non-existence of git.exe. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 50946a369e7b62..95c673626f8008 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -44,10 +44,11 @@ REM ================================================================ git.exe version 2>nul IF ERRORLEVEL 1 ( - echo "***" - echo "Git not found. Please adjust your CMD path or Git install option." - echo "***" - EXIT /B 1 ) + echo *** + echo Git not found. Please adjust your CMD path or Git install option. + echo *** + EXIT /B 1 + ) echo Fetching vcpkg in %cwd%vcpkg git.exe clone https://github.com/Microsoft/vcpkg vcpkg From bea48ac7455c1fea2f385f82b37907867450b097 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 03:05:48 +0000 Subject: [PATCH 05/19] build: error/usage to stderr in vcpkg_install.bat Append >&2 to the echo statements for the missing arch message and the git not found messages to send them to stderr instead of stdout which is the typical practice. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 95c673626f8008..d703d2986e58c3 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -33,7 +33,7 @@ REM ================================================================ SET arch=%1 IF NOT DEFINED arch ( - echo defaulting to 'x64-windows`. Invoke %0 with 'x86-windows', 'x64-windows', or 'arm64-windows', append '-static' for static builds. + echo defaulting to 'x64-windows`. Invoke %0 with 'x86-windows', 'x64-windows', or 'arm64-windows', append '-static' for static builds. >&2 set arch=x64-windows ) @@ -44,9 +44,9 @@ REM ================================================================ git.exe version 2>nul IF ERRORLEVEL 1 ( - echo *** - echo Git not found. Please adjust your CMD path or Git install option. - echo *** + echo *** >&2 + echo Git not found. Please adjust your CMD path or Git install option. >&2 + echo *** >&2 EXIT /B 1 ) From 155b5b1acecd00cafc6fc6335d7f023530caa794 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 15 Feb 2022 08:15:55 +0000 Subject: [PATCH 06/19] build: support VCPKG_ROOT env in vcpkg_install.bat If %VCPKG_ROOT% environment variable is set, check that the parent directory exists and throw an error if it does not. If %VCPKG_ROOT% is not set, set it to %cwd%\vcpkg, which was the previous behavior. Change all references to %cwd%\vcpkg to %VCPKG_ROOT%. Change the documentation in the top comment to refer to %VCPKG_ROOT%. This allows a developer to maintain his or her own vcpkg clone and not have to unnecessarily repeat the very time-consuming process of compiling the dependencies. Set ENV{VCPKG_ROOT} to the VCPKG_DIR default in CMakeLists.txt, because the cmake code does not support this yet, this is introduced in a subsequent commit. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 38 +++++++++++++++++------------ contrib/buildsystems/CMakeLists.txt | 1 + 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index d703d2986e58c3..20eed39b7aca93 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -4,25 +4,26 @@ REM This script installs the "vcpkg" source package manager and uses REM it to build the third-party libraries that git requires when it REM is built using MSVC. REM -REM [1] Install VCPKG. -REM [a] Create /compat/vcbuild/vcpkg/ +REM [1] Install VCPKG (unless already exists.) +REM [a] Create %VCPKG_ROOT% defaulting to +REM /compat/vcbuild/vcpkg/. REM [b] Download "vcpkg". REM [c] Compile using the currently installed version of VS. -REM [d] Create /compat/vcbuild/vcpkg/vcpkg.exe +REM [d] Create %VCPKG_ROOT%/vcpkg.exe REM -REM [2] Install third-party libraries. +REM [2] Install third-party libraries (unless already installed.) REM [a] Download each (which may also install CMAKE). REM [b] Compile in RELEASE mode and install in: -REM vcpkg/installed//{bin,lib} +REM %VCPKG_ROOT%/installed//{bin,lib} REM [c] Compile in DEBUG mode and install in: -REM vcpkg/installed//debug/{bin,lib} +REM %VCPKG_ROOT%/installed//debug/{bin,lib} REM [d] Install headers in: -REM vcpkg/installed//include +REM %VCPKG_ROOT%/installed//include REM REM [3] Create a set of MAKE definitions for the top-level REM Makefile to allow "make MSVC=1" to find the above REM third-party libraries. -REM [a] Write vcpkg/VCPGK-DEFS +REM [a] Write %VCPKG_ROOT%/VCPGK-DEFS REM REM https://blogs.msdn.microsoft.com/vcblog/2016/09/19/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows/ REM https://github.com/Microsoft/vcpkg @@ -40,7 +41,14 @@ REM ================================================================ @FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD cd %cwd% - IF EXIST vcpkg\vcpkg.exe goto :install_libraries + IF NOT DEFINED VCPKG_ROOT ( + set VCPKG_ROOT=%cwd%\vcpkg + ) ELSE (IF NOT EXIST %VCPKG_ROOT%\..\ ( + echo Invalid VCPKG_ROOT: %VCPKG_ROOT%, not under a valid directory. >&2 + exit /B 1 + )) + + IF EXIST %VCPKG_ROOT%\vcpkg.exe goto :install_libraries git.exe version 2>nul IF ERRORLEVEL 1 ( @@ -50,29 +58,29 @@ REM ================================================================ EXIT /B 1 ) - echo Fetching vcpkg in %cwd%vcpkg - git.exe clone https://github.com/Microsoft/vcpkg vcpkg + echo Fetching vcpkg in %VCPKG_ROOT% + git.exe clone https://github.com/Microsoft/vcpkg %VCPKG_ROOT% IF ERRORLEVEL 1 ( EXIT /B 1 ) - cd vcpkg + cd %VCPKG_ROOT% echo Building vcpkg powershell -exec bypass scripts\bootstrap.ps1 IF ERRORLEVEL 1 ( EXIT /B 1 ) - echo Successfully installed %cwd%vcpkg\vcpkg.exe + echo Successfully installed %VCPKG_ROOT%\vcpkg.exe :install_libraries echo Installing third-party libraries(%arch%)... FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO ( - cd %cwd%vcpkg + cd %VCPKG_ROOT% IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i IF ERRORLEVEL 1 ( EXIT /B 1 ) ) :install_defines cd %cwd% - SET inst=%cwd%vcpkg\installed\%arch% + SET inst=%VCPKG_ROOT%\installed\%arch% echo vcpkg_inc=-I"%inst%\include">VCPKG-DEFS echo vcpkg_rel_lib=-L"%inst%\lib">>VCPKG-DEFS diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 8ee457258485b9..2e6df8b59d738c 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -68,6 +68,7 @@ endif() if(USE_VCPKG) set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") + set(ENV{VCPKG_ROOT} "${VCPKG_DIR}") message("WIN32: ${WIN32}") # show its underlying text values message("VCPKG_DIR: ${VCPKG_DIR}") message("VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset From 77a16b6fe5d59c2c10054035f6fb1c481bd52897 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 10 Feb 2022 14:54:28 +0000 Subject: [PATCH 07/19] doc: correct NO_VCPKG to USE_VCPKG USE_VCPKG is the current variable used to disable vcpkg. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 2e6df8b59d738c..ca1189c7373390 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -45,7 +45,7 @@ Run `make` to build Git on Linux/*BSD/MacOS. Open git.sln on Windows and build Git. NOTE: By default CMake will install vcpkg locally to your source tree on configuration, -to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring. +to avoid this, add `-DUSE_VCPKG=FALSE` to the command line when configuring. The Visual Studio default generator changed in v16.6 from its Visual Studio implemenation to `Ninja` This required changes to many CMake scripts. From 392055f38f61f875482fda2128b6d8f3705fbc53 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 03:13:49 +0000 Subject: [PATCH 08/19] build: add vim modeline to CMakeLists.txt Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index ca1189c7373390..a706163691fe1b 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1107,3 +1107,5 @@ foreach(tsh ${test_scipts}) endforeach() endif()#BUILD_TESTING + +# vim:set sw=8 ts=8 noet: From 3e50ee2546b4930b1a5fc3a0fafa1b92c33314a8 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 8 Feb 2022 03:15:57 +0000 Subject: [PATCH 09/19] build: add workdir to CreateLinks.cmake call Add WORKING_DIRECTORY to the add_custom_command() call that launches CreateLinks.cmake, which is a script that creates some hard links to built git executables. This allows the script to not fail for build directories other than the default. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index a706163691fe1b..7ea54ec9de9938 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -814,7 +814,8 @@ endif() add_custom_command(OUTPUT ${git_links} ${git_http_links} COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake - DEPENDS git git-remote-http) + DEPENDS git git-remote-http + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links}) From cd2842089ede30fe43c70d503b3219641507d66e Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 15 Feb 2022 10:15:53 +0000 Subject: [PATCH 10/19] build: log some cmake vars after project() Stop displaying the variables MSVC, CMAKE_CXX_COMPILER_ID, CMAKE_GENERATOR_PLATFORM in the vcpkg setup section, as this section runs before project() and they are not yet initialized. Instead display them after the project() call, and use CMAKE_C_COMPILER_ID instead of CMAKE_CXX_COMPILER_ID as this is a C project. Also change all variable log message() calls to message(STATUS ...) calls. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 7ea54ec9de9938..feaf9b0cfa2fd9 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -69,21 +69,18 @@ endif() if(USE_VCPKG) set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") set(ENV{VCPKG_ROOT} "${VCPKG_DIR}") - message("WIN32: ${WIN32}") # show its underlying text values - message("VCPKG_DIR: ${VCPKG_DIR}") - message("VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset - message("MSVC: ${MSVC}") - message("CMAKE_GENERATOR: ${CMAKE_GENERATOR}") - message("CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") - message("CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}") - message("CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}") - message("ENV(CMAKE_EXPORT_COMPILE_COMMANDS): $ENV{CMAKE_EXPORT_COMPILE_COMMANDS}") + message(STATUS "WIN32: ${WIN32}") # show its underlying text values + message(STATUS "VCPKG_DIR: ${VCPKG_DIR}") + message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset + message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") + message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}") + message(STATUS "ENV(CMAKE_EXPORT_COMPILE_COMMANDS): $ENV{CMAKE_EXPORT_COMPILE_COMMANDS}") if(NOT EXISTS ${VCPKG_DIR}) - message("Initializing vcpkg and building the Git's dependencies (this will take a while...)") + message(STATUS "Initializing vcpkg and building the Git's dependencies (this will take a while...)") execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH}) endif() if(NOT EXISTS ${VCPKG_ARCH}) - message("VCPKG_ARCH: unset, using 'x64-windows'") + message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'") set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat endif() list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/${VCPKG_ARCH}") @@ -124,6 +121,14 @@ project(git VERSION ${git_version} LANGUAGES C) +# Some diagnostic output about the detected toolchain, must be +# below project() call. +if(WIN32) + message(STATUS "MSVC: ${MSVC}") +endif() +message(STATUS "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}") +message(STATUS "CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}") + #TODO gitk git-gui gitweb #TODO Enable NLS on windows natively From c2b23c76d1b0ff12bc92042ec8fb85312d3e5222 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 10 Feb 2022 14:07:24 +0000 Subject: [PATCH 11/19] build: use VCPKG_DIR instead of constant Use VCPKG_DIR instead of relative path to the default vcpkg clone for appending the vcpkg bin to PATH when writing GIT-BUILD-OPTIONS in cmake. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index feaf9b0cfa2fd9..0adb256889fe03 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -1081,7 +1081,7 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PRE file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n") if(USE_VCPKG) - file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/${VCPKG_ARCH}/bin\"\n") + file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:${VCPKG_DIR}/installed/${VCPKG_ARCH}/bin\"\n") endif() #Make the tests work when building out of the source tree From b21f8b657f4007ee58a0bde53a9bb7a6b36b4c27 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 10 Feb 2022 14:11:50 +0000 Subject: [PATCH 12/19] build: fix check for VCPKG_ARCH Use DEFINED instead of EXISTS (EXISTS is for checking if a filesystem path exists, DEFINED is for variables.) Also move the check to above the call to vcpkg_install.bat where it is used from its previous location below. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 0adb256889fe03..570f4ba0da79a8 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -75,14 +75,14 @@ if(USE_VCPKG) message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}") message(STATUS "ENV(CMAKE_EXPORT_COMPILE_COMMANDS): $ENV{CMAKE_EXPORT_COMPILE_COMMANDS}") + if(NOT DEFINED VCPKG_ARCH) + message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'") + set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat + endif() if(NOT EXISTS ${VCPKG_DIR}) message(STATUS "Initializing vcpkg and building the Git's dependencies (this will take a while...)") execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH}) endif() - if(NOT EXISTS ${VCPKG_ARCH}) - message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'") - set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat - endif() list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/${VCPKG_ARCH}") # In the vcpkg edition, we need this to be able to link to libcurl From dcb576a439962e6a35bd045c2ee24495d9cc2239 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 15 Feb 2022 07:22:20 +0000 Subject: [PATCH 13/19] build: always call vcpkg_install.bat from cmake Instead of checking if VCPKG_DIR exists first, always call vcpkg_install.bat, which will create a new vcpkg clone as well as perform any necessary actions on an existing clone, and will do nothing if nothing needs to be done. Remove the "Initializing vcpkg..." message from cmake and change the "installing libraries" message from the cmd script to say that it may take a while. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 2 +- contrib/buildsystems/CMakeLists.txt | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 20eed39b7aca93..bc37584d4970ba 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -71,7 +71,7 @@ REM ================================================================ :install_libraries - echo Installing third-party libraries(%arch%)... + echo Installing third-party libraries(%arch%), this may take a while... FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO ( cd %VCPKG_ROOT% IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 570f4ba0da79a8..c2b9492470229d 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -79,10 +79,7 @@ if(USE_VCPKG) message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'") set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat endif() - if(NOT EXISTS ${VCPKG_DIR}) - message(STATUS "Initializing vcpkg and building the Git's dependencies (this will take a while...)") - execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH}) - endif() + execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH}) list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/${VCPKG_ARCH}") # In the vcpkg edition, we need this to be able to link to libcurl From fa1a687481e13ad3810dab7eb1667c9578cf4d16 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Mon, 21 Mar 2022 16:31:18 +0000 Subject: [PATCH 14/19] build: add build_option() to cmake/Utilities.cmake Add the build_option() function which is similar to the cmake option() command, but allows adding alias variables and alias environment variables. The option and all aliases are set to the first found value by listed sequence in the option and all aliases, followed by the default if provided, or 'OFF' if not provided, with cache variables having precedence over normal variables. In the case of environment variables or aliases, if the type is BOOL and the found/default value is OFF/FALSE unset the environment variable. Signed-off-by: Rafael Kitover --- contrib/buildsystems/cmake/Utilities.cmake | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 contrib/buildsystems/cmake/Utilities.cmake diff --git a/contrib/buildsystems/cmake/Utilities.cmake b/contrib/buildsystems/cmake/Utilities.cmake new file mode 100644 index 00000000000000..f90019b7b20c52 --- /dev/null +++ b/contrib/buildsystems/cmake/Utilities.cmake @@ -0,0 +1,102 @@ +# +# build_option( +# opt_name type help_string [default] +# ALIASES alias1 [alias2 ...]] +# ) +# +# If PRIMARY_OPT is not set, uses the value of any alias name +# provided, in order of precedence provides, to set PRIMARY_OPT and +# all listed aliases. Otherwise set all aliases to the value of +# PRIMARY_OPT, or the default if not set either. If the default is +# empty string or not provided, the value "OFF" is used, this is +# the behavior of option() in cmake. +# +# An alias can be an environment variable, specify ENV{ENV_VAR} in +# this case. If the type is BOOL and the found/default value is +# OFF/FALSE the environment variable will be unset. +# +# On cmake >= 3.13 precedence is given to CACHE variables, and the +# namesake normal variable is overwritten with the CACHE value. On +# earlier versions, the cache variable will be overwritten with the +# normal variable. +# +function(build_option opt type help_string default) + set(aliases "${ARGN}") + + if(default STREQUAL ALIASES) + if(ARGC LESS 5) + message(FATAL_ERROR "build_option: ALIASES specified with no alias names.") + endif() + + unset(default) + elseif(NOT ARGV4 STREQUAL ALIASES) + message(FATAL_ERROR "build_option: Syntax error.") + elseif(ARGC LESS 6) + message(FATAL_ERROR "build_option: ALIASES specified with no alias names.") + else() + list(REMOVE_AT aliases 0) + endif() + + if(default STREQUAL "") + if(NOT type STREQUAL BOOL) + message(FATAL_ERROR "build_option: Empty or unspecified default options must be of type BOOL.") + endif() + + set(default OFF) + endif() + + # First find the first non-empty value in the option and + # aliases, with the priority being the order listed. + # If not found, use the default. + unset(val) + + foreach(var IN LISTS opt aliases) + if(var STREQUAL "") + message(FATAL_ERROR "build_option: Option or alias names cannot be empty string.") + endif() + + set(env_var "") + if(var MATCHES "^ENV\\{") + string( + REGEX REPLACE "^ENV\\{([^}]+)}$" + "\\1" env_var "${var}" + ) + endif() + + if(NOT env_var STREQUAL "") + set(val "$ENV{${env_var}}") + else() + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + set(val "$CACHE{${var}}") + endif() + + if(val STREQUAL "") + set(val "${${var}}") + endif() + endif() + + if(NOT val STREQUAL "") + break() + endif() + endforeach() + + if(val STREQUAL "") + set(val "${default}") + endif() + + foreach(var IN LISTS opt aliases) + if(var MATCHES "^ENV\\{") + # Unset env var for bool OFF/FALSE. + if(type STREQUAL BOOL AND NOT val) + unset("${var}") + else() + set("${var}" "${val}") + endif() + else() + set("${var}" "${val}" PARENT_SCOPE) + set("${var}" "${val}" CACHE "${type}" "${help_string}" FORCE) + endif() + endforeach() +endfunction() + +# vim:set sw=8 ts=8 noet: From 312a4f1d778540d2a6bef60693e5bbeda035ff93 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 10 Feb 2022 15:33:50 +0000 Subject: [PATCH 15/19] build: alias VCPKG_TARGET_TRIPLET to VCPKG_ARCH Include the build_option() function introduced in b0d325d4bd (Add build_option() to cmake/Utilities.cmake., 2022-02-10). Initialize VCPKG_ARCH with an alias to VCPKG_TARGET_TRIPLET with build_option(). Add a note about this to the cmake doc. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index c2b9492470229d..32db475208e686 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -47,6 +47,9 @@ Open git.sln on Windows and build Git. NOTE: By default CMake will install vcpkg locally to your source tree on configuration, to avoid this, add `-DUSE_VCPKG=FALSE` to the command line when configuring. +To set the vcpkg arch (target triplet) pass `VCPKG_ARCH` or +`VCPKG_TARGET_TRIPLET` e.g.: `-DVCPKG_ARCH=x64-windows`. + The Visual Studio default generator changed in v16.6 from its Visual Studio implemenation to `Ninja` This required changes to many CMake scripts. @@ -56,6 +59,10 @@ cmake_minimum_required(VERSION 3.14) #set the source directory to root of git set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) + +include(Utilities) + option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON) if(NOT WIN32) set(USE_VCPKG OFF CACHE BOOL FORCE) @@ -67,18 +74,21 @@ if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) endif() if(USE_VCPKG) + build_option( + VCPKG_ARCH + STRING "vcpkg arch/triplet, e.g. x64-windows." + x64-windows + ALIASES VCPKG_TARGET_TRIPLET + ) + set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") set(ENV{VCPKG_ROOT} "${VCPKG_DIR}") message(STATUS "WIN32: ${WIN32}") # show its underlying text values message(STATUS "VCPKG_DIR: ${VCPKG_DIR}") - message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset + message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}") message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}") message(STATUS "ENV(CMAKE_EXPORT_COMPILE_COMMANDS): $ENV{CMAKE_EXPORT_COMPILE_COMMANDS}") - if(NOT DEFINED VCPKG_ARCH) - message(STATUS "VCPKG_ARCH: unset, using 'x64-windows'") - set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat - endif() execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat ${VCPKG_ARCH}) list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/${VCPKG_ARCH}") From 575a968702bc120e8c1c3dbb6ef83d6a0fa2bf19 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 10 Feb 2022 15:34:29 +0000 Subject: [PATCH 16/19] build: alias VCPKG_ROOT env variable to VCPKG_DIR Use the build_option() function introduced in 3db0658495 (build: add build_option() to cmake/Utilities.cmake, 2022-02-10) to alias the VCPKG_ROOT environment variable to VCPKG_DIR. Support for VCPKG_ROOT was added to vcpkg_install.bat in 98c6a0d92a (build: support VCPKG_ROOT env in vcpkg_install.bat, 2022-02-08). Add a note about VCPKG_DIR and ENV{VCPKG_ROOT} to the cmake doc. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 32db475208e686..e13fc8bfe69591 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -44,8 +44,12 @@ This process generates a Makefile(Linux/*BSD/MacOS), Visual Studio solution(Wind Run `make` to build Git on Linux/*BSD/MacOS. Open git.sln on Windows and build Git. -NOTE: By default CMake will install vcpkg locally to your source tree on configuration, -to avoid this, add `-DUSE_VCPKG=FALSE` to the command line when configuring. +NOTE: By default CMake will install vcpkg locally to your source +tree on configuration, to avoid this, add `-DUSE_VCPKG=FALSE` to +the command line when configuring. + +To use your own vcpkg clone, set the environment variable VCPKG_ROOT +to the path or pass the path as `-DVCPKG_DIR=/your/clone/of/vcpkg`. To set the vcpkg arch (target triplet) pass `VCPKG_ARCH` or `VCPKG_TARGET_TRIPLET` e.g.: `-DVCPKG_ARCH=x64-windows`. @@ -74,6 +78,13 @@ if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) endif() if(USE_VCPKG) + build_option( + VCPKG_DIR + PATH "Path to vcpkg clone." + "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg" + ALIASES ENV{VCPKG_ROOT} + ) + build_option( VCPKG_ARCH STRING "vcpkg arch/triplet, e.g. x64-windows." @@ -81,9 +92,7 @@ if(USE_VCPKG) ALIASES VCPKG_TARGET_TRIPLET ) - set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") - set(ENV{VCPKG_ROOT} "${VCPKG_DIR}") - message(STATUS "WIN32: ${WIN32}") # show its underlying text values + message(STATUS "WIN32: ${WIN32}") message(STATUS "VCPKG_DIR: ${VCPKG_DIR}") message(STATUS "VCPKG_ARCH: ${VCPKG_ARCH}") message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") From d654bcc31cb320b076d65883a2ccb31951d6f071 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 17 Mar 2022 17:40:57 +0000 Subject: [PATCH 17/19] build: support NO_LIB env to disable vcpkg deps Check if NO_ environment variable is defined to skip vcpkg deps, this is needed to implement cmake support for NO_GETTEXT properly in a subsequent commit. Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index bc37584d4970ba..64f53b697e56bc 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -73,9 +73,11 @@ REM ================================================================ echo Installing third-party libraries(%arch%), this may take a while... FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO ( - cd %VCPKG_ROOT% - IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i - IF ERRORLEVEL 1 ( EXIT /B 1 ) + IF NOT DEFINED NO_%%i ( + cd %VCPKG_ROOT% + IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i + IF ERRORLEVEL 1 ( EXIT /B 1 ) + ) ) :install_defines From 55ec81d65673e06d9db50ca47cc4e97ff6017478 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 17 Mar 2022 17:41:53 +0000 Subject: [PATCH 18/19] build: add gettext[tools] vcpkg dep Add gettext vcpkg dependency lib with the [tools] feature for the msgfmt utility to build the translations. Can be disabled by setting the NO_GETTEXT environment variable, support for which was added in 2cd6269eb0 (build: support NO_LIB env to disable vcpkg deps, 2022-03-17). Signed-off-by: Rafael Kitover --- compat/vcbuild/vcpkg_install.bat | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 64f53b697e56bc..ac06d6ac012c3b 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -72,7 +72,7 @@ REM ================================================================ :install_libraries echo Installing third-party libraries(%arch%), this may take a while... - FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO ( + FOR %%i IN (zlib expat libiconv openssl libssh2 curl gettext) DO ( IF NOT DEFINED NO_%%i ( cd %VCPKG_ROOT% IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i @@ -140,3 +140,7 @@ goto :EOF :curl_features set features=[core,openssl,schannel] goto :EOF + +:gettext_features +set features=[tools] +goto :EOF From 52921991591c2167e46fcd3d14e2ac7fc4f13fe7 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Wed, 23 Mar 2022 00:16:00 +0000 Subject: [PATCH 19/19] build: clean up NO_GETTEXT cmake support Make NO_GETTEXT a build option aliased to ENV{NO_GETTEXT} to pass to vcpkg_install.bat to skip building gettext. Turn it off by default when vcpkg is in-use because it's a very long compile. Do not build translations if NO_GETTEXT is set. Add a note about NO_GETTEXT to the docs at the top of CMakeLists.txt. Signed-off-by: Rafael Kitover --- contrib/buildsystems/CMakeLists.txt | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index e13fc8bfe69591..c0d0888f3e35d0 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -54,6 +54,10 @@ to the path or pass the path as `-DVCPKG_DIR=/your/clone/of/vcpkg`. To set the vcpkg arch (target triplet) pass `VCPKG_ARCH` or `VCPKG_TARGET_TRIPLET` e.g.: `-DVCPKG_ARCH=x64-windows`. +By default for vcpkg, gettext is not built and translations do not +work because gettext is a very long compile. To enable translations +pass `-DNO_GETTEXT=FALSE`. + The Visual Studio default generator changed in v16.6 from its Visual Studio implemenation to `Ninja` This required changes to many CMake scripts. @@ -72,6 +76,21 @@ if(NOT WIN32) set(USE_VCPKG OFF CACHE BOOL FORCE) endif() +set(gettext_default TRUE) + +# Turn off gettext by default when using vcpkg because it's a very +# long compile. +if(NOT USE_VCPKG) + set(gettext_default FALSE) +endif() + +build_option( + NO_GETTEXT + BOOL "Set to TRUE/ON to disable internationalization support using gettext and building translations using msgfmt from gettext-tools." + ${gettext_default} + ALIASES ENV{NO_GETTEXT} +) + if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) message("settting CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}") @@ -195,8 +214,7 @@ find_package(CURL) find_package(EXPAT) find_package(Iconv) -#Don't use libintl on Windows Visual Studio and Clang builds -if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))) +if(NOT NO_GETTEXT) find_package(Intl) endif() @@ -229,18 +247,10 @@ if(WIN32 AND NOT MSVC)#not required for visual studio builds endif() endif() -if(NO_GETTEXT) - message(STATUS "msgfmt not used under NO_GETTEXT") -else() +if(NOT NO_GETTEXT) find_program(MSGFMT_EXE msgfmt) if(NOT MSGFMT_EXE) - if(USE_VCPKG) - set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe) - endif() - if(NOT EXISTS ${MSGFMT_EXE}) - message(WARNING "Text Translations won't be built") - unset(MSGFMT_EXE) - endif() + message(WARNING "msgfmt not available and/or could not be installed, text translations won't be built.") endif() endif() @@ -1056,7 +1066,6 @@ set(NO_PYTHON ) set(PAGER_ENV "LESS=FRX LV=-c") set(DC_SHA1 YesPlease) set(RUNTIME_PREFIX true) -set(NO_GETTEXT ) if(NOT CURL_FOUND) set(NO_CURL 1) @@ -1066,10 +1075,6 @@ if(NOT EXPAT_FOUND) set(NO_EXPAT 1) endif() -if(NOT Intl_FOUND) - set(NO_GETTEXT 1) -endif() - if(NOT PERL_TESTS) set(NO_PERL 1) endif()