Skip to content

Commit 8250ab0

Browse files
committed
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
2 parents 07601b5 + 0ad621f commit 8250ab0

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,4 @@ Release/
242242
/git.VC.VC.opendb
243243
/git.VC.db
244244
*.dSYM
245+
/contrib/buildsystems/out

contrib/buildsystems/CMakeLists.txt

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
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
1927
Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
2028
compiler flags
@@ -40,8 +48,19 @@ cmake_minimum_required(VERSION 3.14)
4048

4149
#set the source directory to root of git
4250
set(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")
4564
if(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

146165
find_program(MSGFMT_EXE msgfmt)
147166
if(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()
149172
endif()
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()
610635
elseif(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")
928953
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
929954
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
930955
file(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
933961
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})
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/)

hashmap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ static inline struct hashmap_entry *hashmap_iter_first(struct hashmap *map,
449449
* containing a @member which is a "struct hashmap_entry"
450450
*/
451451
#define hashmap_for_each_entry(map, iter, var, member) \
452-
for (var = hashmap_iter_first_entry_offset(map, iter, \
452+
for (var = NULL, /* for systems without typeof */ \
453+
var = hashmap_iter_first_entry_offset(map, iter, \
453454
OFFSETOF_VAR(var, member)); \
454455
var; \
455456
var = hashmap_iter_next_entry_offset(iter, \

0 commit comments

Comments
 (0)