Re: [PATCH 7/8] cmake: support for building git on windows with msvc and clang.
- From
Sibi Siddharthan <sibisiddharthan.github@gmail.com>
- Date
- Apr 24, 2020, 21:35 UTC
- Message-ID
- <CAKiG+9Wr+-ax_2=eK+n0Kt50hafTZd-xwxNf5cG96a-RCFP_jA@mail.gmail.com>
- In-Reply-To
- <20200424173951.GM1949@danh.dev>
On Fri, Apr 24, 2020 at 11:09 PM Danh Doan <congdanhqx@gmail.com> wrote:
Show 109 quoted lines
>
> On 2020-04-24 04:01:36+0000, Sibi Siddharthan via GitGitGadget <gitgitgadget@gmail.com> wrote:
> > From: Sibi Siddharthan <sibisiddharthan.github@gmail.com>
> >
> > This patch adds support for Visual Studio and Clang builds
> >
> > The minimum required version of CMake is upgraded to 3.15 because
> > this version offers proper support for Clang builds on Windows.
> >
> > Libintl is not searched for when building with Visual Studio or Clang
> > because there is no binary compatible version available yet.
> >
> > NOTE: In the link options invalidcontinue.obj has to be included.
> > The reason for this is because by default, Windows calls abort()'s
> > instead of setting errno=EINVAL when invalid arguments are passed to
> > standard functions.
> > This commit explains it in detail:
> > 4b623d80f73528a632576990ca51e34c333d5dd6
> >
> > On Windows the default generator is Visual Studio,so for Visual Studio
> > builds do this:
> >
> > cmake `relative-path-to-srcdir`
> >
> > NOTE: Visual Studio generator is a multi config generator, which means
> > that Debug and Release builds can be done on the same build directory.
> >
> > For Clang builds do this:
> >
> > On bash
> > CC=Clang cmake `relative-path-to-srcdir` -G Ninja
> > -DCMAKE_BUILD_TYPE=[Debug or Release]
> >
> > On cmd
> > set CC=Clang
> > cmake `relative-path-to-srcdir` -G Ninja
> > -DCMAKE_BUILD_TYPE=[Debug or Release]
> >
> > Signed-off-by: Sibi Siddharthan <sibisiddharthan.github@gmail.com>
> > ---
> > CMakeLists.txt | 57 ++++++++++++++++++++++++++++++++++++++++----------
> > 1 file changed, 46 insertions(+), 11 deletions(-)
> >
> > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > index d9eb1060390..5ad3a2557f7 100644
> > --- a/CMakeLists.txt
> > +++ b/CMakeLists.txt
> > @@ -2,7 +2,7 @@
> > # Copyright (c) 2020 Sibi Siddharthan
> > #
> >
> > -cmake_minimum_required(VERSION 3.14)
> > +cmake_minimum_required(VERSION 3.15)
>
> 3.14 is a step too far, and, now, we want CMake 3.15?
>
> >
> > #Parse GIT-VERSION-GEN to get the version
> > file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN git_version REGEX "DEF_VER=v(.*)")
> > @@ -32,8 +32,11 @@ find_package(ZLIB REQUIRED)
> > find_package(CURL)
> > find_package(EXPAT)
> > find_package(Iconv)
> > -find_package(Intl)
> >
> > +#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")))
> > + find_package(Intl)
> > +endif()
> >
> > if(NOT Intl_FOUND)
> > add_compile_definitions(NO_GETTEXT)
> > @@ -61,7 +64,7 @@ if(NOT SH_EXE)
> > message(FATAL_ERROR "sh interpreter was not found in your path, please install one. On Windows you can get it from here https://gitforwindows.org/")
> > endif()
> >
> > -if(WIN32)
> > +if(WIN32 AND NOT MSVC)#not required for visual studio builds
> > find_program(WINDRES_EXE windres)
> > if(NOT WINDRES_EXE)
> > message(FATAL_ERROR "Install windres on Windows for resource files")
> > @@ -73,6 +76,13 @@ if(NOT MSGFMT_EXE)
> > message(WARNING "Text Translations won't be build")
> > endif()
> >
> > +#Force all visual studio outputs to CMAKE_BINARY_DIR
> > +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
> > + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
> > + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
> > + add_compile_options(/MP)
> > +endif()
> > +
> > #default behaviour
> > include_directories(${CMAKE_SOURCE_DIR})
> > add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
> > @@ -110,6 +120,10 @@ endif()
> >
> > #Platform Specific
> > if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
> > + if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
> > + include_directories(compat/vcbuild/include)
> > + add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
>
> This is fair, I hate those warning, too.
>
> Is _CRT_NONSTDC_NO_DEPRECATE implied when _CRT_SECURE_NO_WARNINGS
> defined? Or otherwise around?
>
>They both are independent
> -- > Danh
Thank You, Sibi Siddharthan