From a561962479cc2c1063babeeaf0e6491fd4b8b2e8 Mon Sep 17 00:00:00 2001 From: Yuyi Wang Date: Tue, 24 May 2022 06:38:47 +0000 Subject: [PATCH 1/3] cmake: fix CMakeLists.txt on Linux CMakeLists.txt didn't follow the grammar of `set`, and it will fail when setting `USE_VCPKG` off on non-Windows platforms. When the platform is Linux, the Makefile adds `compat/linux/procinfo.o` to `COMPAT_OBJS`, but the CMakeLists.txt didn't add `compat/linux/procinfo.c` to `compat_SOURCES`. It would cause linkage error. Signed-off-by: Yuyi Wang Signed-off-by: Junio C Hamano --- contrib/buildsystems/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 185f56f414..7f333e303c 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -54,7 +54,7 @@ set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) 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) + set(USE_VCPKG OFF CACHE BOOL "" FORCE) endif() if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS) @@ -277,7 +277,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY ) - list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c) + list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Windows") From 80431510a2b97e08bd577f39934e2b5ea9a43034 Mon Sep 17 00:00:00 2001 From: Yuyi Wang Date: Tue, 24 May 2022 06:38:48 +0000 Subject: [PATCH 2/3] cmake: add pcre2 support Fix one of the TODOs listed in the CMakeLists.txt by adding support for building with pcre2. As pcre2 doesn't provide cmake find module, we find it with pkgconf. This patch also works with vcpkg on Windows, with pkgconf and pcre2 installed. Pkgconf and pcre2 is detected automatically just like curl, expat and iconv. The output of CMake indicates whether pcre2 is found. Signed-off-by: Yuyi Wang Signed-off-by: Junio C Hamano --- contrib/buildsystems/CMakeLists.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 7f333e303c..2844dd6c88 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -108,7 +108,6 @@ project(git #TODO gitk git-gui gitweb #TODO Enable NLS on windows natively -#TODO Add pcre support #macros for parsing the Makefile for sources and scripts macro(parse_makefile_for_sources list_var regex) @@ -160,6 +159,14 @@ if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID ST find_package(Intl) endif() +find_package(PkgConfig) +if(PkgConfig_FOUND) + pkg_check_modules(PCRE2 libpcre2-8) + if(PCRE2_FOUND) + add_compile_definitions(USE_LIBPCRE2) + endif() +endif() + if(NOT Intl_FOUND) add_compile_definitions(NO_GETTEXT) if(NOT Iconv_FOUND) @@ -180,6 +187,9 @@ endif() if(Intl_FOUND) include_directories(SYSTEM ${Intl_INCLUDE_DIRS}) endif() +if(PCRE2_FOUND) + include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS}) +endif() if(WIN32 AND NOT MSVC)#not required for visual studio builds @@ -700,6 +710,10 @@ endif() if(Iconv_FOUND) target_link_libraries(common-main ${Iconv_LIBRARIES}) endif() +if(PCRE2_FOUND) + target_link_libraries(common-main ${PCRE2_LIBRARIES}) + target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS}) +endif() if(WIN32) target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res) add_dependencies(common-main git-rc) From 5ec711082255d1a580e3270c40ca76d655a3dd7c Mon Sep 17 00:00:00 2001 From: Yuyi Wang Date: Tue, 24 May 2022 12:57:01 +0000 Subject: [PATCH 3/3] cmake: remove (_)UNICODE def on Windows in CMakeLists.txt `UNICODE` and `_UNICODE` are not required when building git on Windows. Actually, they should not be predefined at all. There're 2 evidences that `(_)UNICODE` is supposed to be nonexist: compat/win32/trace2_win32_process_info.c:83: It uses jw_array_string which accepts pe32.szExeFile as const char*. t/helper/test-drop-caches.c:16: Calling to GetCurrentDirectory with Buffer as char*. The autotools build system never defines `UNICODE` and `_UNICODE` and builds on Windows well. Signed-off-by: Yuyi Wang Acked-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- 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 2844dd6c88..29acc4f0e1 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -270,7 +270,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0 USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP - UNICODE _UNICODE HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) + HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) list(APPEND compat_SOURCES compat/mingw.c compat/winansi.c