Merge branch 'js/cmake-vs'

Using the CMake support we added some time ago for real with Visual
Studio build revealed there were lot of usability improvements
possible, which have been carried out.

* js/cmake-vs:
  hashmap_for_each_entry(): workaround MSVC's runtime check failure #3
  cmake (Windows): recommend using Visual Studio's built-in CMake support
  cmake (Windows): initialize vcpkg/build dependencies automatically
  cmake (Windows): complain when encountering an unknown compiler
  cmake (Windows): let the `.dll` files be found when running the tests
  cmake: quote the path accurately when editing `test-lib.sh`
  cmake: fall back to using `vcpkg`'s `msgfmt.exe` on Windows
  cmake: ensure that the `vcpkg` packages are found on Windows
  cmake: do find Git for Windows' shell interpreter
  cmake: ignore files generated by CMake as run in Visual Studio
This commit is contained in:
Junio C Hamano 2020-10-05 14:01:52 -07:00
commit 8250ab0b8c
3 changed files with 43 additions and 13 deletions

1
.gitignore vendored
View File

@ -242,3 +242,4 @@ Release/
/git.VC.VC.opendb /git.VC.VC.opendb
/git.VC.db /git.VC.db
*.dSYM *.dSYM
/contrib/buildsystems/out

View File

@ -4,17 +4,25 @@
#[[ #[[
Instructions to run CMake: Instructions how to use this in Visual Studio:
cmake `relative-path-to-CMakeLists.txt` -DCMAKE_BUILD_TYPE=Release Open the worktree as a folder. Visual Studio 2019 and later will detect
Eg. the CMake configuration automatically and set everything up for you,
From the root of git source tree ready to build. You can then run the tests in `t/` via a regular Git Bash.
`cmake contrib/buildsystems/ `
This will build the git binaries at the root
For out of source builds, say build in 'git/git-build/' Note: Visual Studio also has the option of opening `CMakeLists.txt`
`mkdir git-build;cd git-build; cmake ../contrib/buildsystems/` directly; Using this option, Visual Studio will not find the source code,
This will build the git binaries in git-build directory though, therefore the `File>Open>Folder...` option is preferred.
Instructions to run CMake manually:
mkdir -p contrib/buildsystems/out
cd contrib/buildsystems/out
cmake ../ -DCMAKE_BUILD_TYPE=Release
This will build the git binaries in contrib/buildsystems/out
directory (our top-level .gitignore file knows to ignore contents of
this directory).
Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
compiler flags compiler flags
@ -40,8 +48,19 @@ cmake_minimum_required(VERSION 3.14)
#set the source directory to root of git #set the source directory to root of git
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
if(WIN32)
set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
if(MSVC AND 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)
endif()
list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/x64-windows")
find_program(SH_EXE sh) # In the vcpkg edition, we need this to be able to link to libcurl
set(CURL_NO_CURL_CMAKE ON)
endif()
find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin")
if(NOT SH_EXE) if(NOT SH_EXE)
message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one." message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
"On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/") "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/")
@ -145,7 +164,11 @@ endif()
find_program(MSGFMT_EXE msgfmt) find_program(MSGFMT_EXE msgfmt)
if(NOT MSGFMT_EXE) if(NOT MSGFMT_EXE)
message(WARNING "Text Translations won't be build") set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
if(NOT EXISTS ${MSGFMT_EXE})
message(WARNING "Text Translations won't be built")
unset(MSGFMT_EXE)
endif()
endif() endif()
#Force all visual studio outputs to CMAKE_BINARY_DIR #Force all visual studio outputs to CMAKE_BINARY_DIR
@ -606,6 +629,8 @@ if(WIN32)
target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj) target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj) target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj)
else()
message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
endif() endif()
elseif(UNIX) elseif(UNIX)
target_link_libraries(common-main pthread rt) target_link_libraries(common-main pthread rt)
@ -928,6 +953,9 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n") file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
if(WIN32)
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
endif()
#Make the tests work when building out of the source tree #Make the tests work when building out of the source tree
get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE) get_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})
file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n" "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n"
"file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n" "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n"
"string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY\\\"/../${BUILD_DIR_RELATIVE}\" content \"\${content}\")\n" "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\"\" content \"\${content}\")\n"
"file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})") "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})")
#misc copies #misc copies
file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/) file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/)

View File

@ -449,7 +449,8 @@ static inline struct hashmap_entry *hashmap_iter_first(struct hashmap *map,
* containing a @member which is a "struct hashmap_entry" * containing a @member which is a "struct hashmap_entry"
*/ */
#define hashmap_for_each_entry(map, iter, var, member) \ #define hashmap_for_each_entry(map, iter, var, member) \
for (var = hashmap_iter_first_entry_offset(map, iter, \ for (var = NULL, /* for systems without typeof */ \
var = hashmap_iter_first_entry_offset(map, iter, \
OFFSETOF_VAR(var, member)); \ OFFSETOF_VAR(var, member)); \
var; \ var; \
var = hashmap_iter_next_entry_offset(iter, \ var = hashmap_iter_next_entry_offset(iter, \