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*/ diff --git a/compat/vcbuild/vcpkg_install.bat b/compat/vcbuild/vcpkg_install.bat index 575c65c20ba307..52d987d59ef4f3 100644 --- a/compat/vcbuild/vcpkg_install.bat +++ b/compat/vcbuild/vcpkg_install.bat @@ -40,38 +40,46 @@ REM ================================================================ @FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD cd %cwd% - dir vcpkg\vcpkg.exe >nul 2>nul && 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. + exit /B 1 + )) + + IF EXIST %VCPKG_ROOT%\vcpkg.exe goto :install_libraries 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 + 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..d7e77d9a1573a3 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -44,8 +44,15 @@ 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 `-DNO_VCPKG=TRUE` to the command line when configuring. +NOTE: By default CMake will install vcpkg locally to your source tree on +configuration, to use your own VCPKG tree, set `$env:VCPKG_ROOT` to the +path or pass `VCPKG_DIR`. + +To set the vcpkg arch (target triplet) pass `VCPKG_ARCH` e.g.: +`-DVCPKG_ARCH=x64-windows`. + +To not use VCPKG, 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. @@ -67,7 +74,27 @@ if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) endif() if(USE_VCPKG) - set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") + if(NOT DEFINED VCPKG_DIR) + if(DEFINED ENV{VCPKG_ROOT}) + set(VCPKG_DIR "$ENV{VCPKG_ROOT}") + else() + set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg") + endif() + + # Make sure ENV{VCPKG_ROOT} is set for vcpkg_install.bat + # and anything else that may need it. + set(ENV{VCPKG_ROOT} "${VCPKG_DIR}") + endif() + + if(NOT DEFINED VCPKG_ARCH) + if(DEFINED VCPKG_TARGET_TRIPLET) + set(VCPKG_ARCH "${VCPKG_TARGET_TRIPLET}") + else() + message("VCPKG_ARCH: unset, using 'x64-windows'") + set(VCPKG_ARCH "x64-windows") + endif() + endif() + message("WIN32: ${WIN32}") # show its underlying text values message("VCPKG_DIR: ${VCPKG_DIR}") message("VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset @@ -77,14 +104,8 @@ if(USE_VCPKG) 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}") - if(NOT EXISTS ${VCPKG_DIR}) - message("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'") - set(VCPKG_ARCH "x64-windows") # default from vcpkg_install.bat - endif() + message("Initializing vcpkg and building the Git's dependencies (this may take a while...)") + 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 @@ -207,19 +228,50 @@ 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() +macro(get_nuget) + if(NOT EXISTS ${CMAKE_BINARY_DIR}/nuget.exe) + file(DOWNLOAD "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" ${CMAKE_BINARY_DIR}/nuget.exe) + endif() + + # Add nuget package source. + execute_process( + COMMAND nuget sources add -Name "NuGet official package source" -Source "https://api.nuget.org/v3/index.json" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endmacro() + +macro(nuget_install pkg) + execute_process( + COMMAND nuget.exe install ${pkg} -OutputDirectory ${CMAKE_BINARY_DIR}/nuget + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + # Find the path to the binaries in the package and add them to find path. + file(GLOB pkg_dir ${CMAKE_BINARY_DIR}/nuget/${pkg}*) + + list(APPEND CMAKE_PROGRAM_PATH ${pkg_dir}/tools/bin) + + set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH}" CACHE STRING "External Program Search Path" FORCE) +endmacro() + +find_program(msgfmt msgfmt) +if(NOT msgfmt) + if(WIN32) + get_nuget() + nuget_install(Gettext.Tools) + endif() + 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() +else() + set(MSGFMT_EXE ${msgfmt}) +endif() + +if(MSGFMT_EXE) + set(MSGFMT_EXE ${MSGFMT_EXE} CACHE STRING "gettext msgfmt utility path" FORCE) endif() #Force all visual studio outputs to CMAKE_BINARY_DIR @@ -813,7 +865,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}) @@ -1074,7 +1127,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