Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CMake work out of the box #970

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,27 @@ NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studi
to use another tool say `ninja` add this to the command line when configuring.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Fri, Jun 4, 2021 at 1:44 PM Matthew Rogers via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> When building on windows users have the option to use vcpkg to provide
> the dependencies needed to compile.  Previously, this was used only when
> using the Visual Studio generator which was not ideal because:
>
>   - Not all users who want to use vcpkg use the Visual Studio
>     generators.
>
>   - Some versions of Visual Studio 2019 moved away from using the
>     VS 2019 by default, making it impossible for Visual Studio to
>     configure the project in the likely event that it couldn't find the
>     dependencies.

Is there something missing between "using the" and "VS 2019"? I'm
having a hard time trying to understand what this bullet point is
saying due to this apparent gap.

>   - Inexperienced users of CMake are very likely to get tripped up by
>     the errors caused by a lack of vcpkg, making the above bullet point
>     both annoying and hard to debug.
>
> As such, lets make using vcpkg the default on windows.  Users who want
> to avoid using vcpkg can disable it by passing -DNO_VCPKG=TRUE.

s/lets/let's/

> Signed-off-by: Matthew Rogers <mattr94@gmail.com>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Matt Rogers wrote (reply to this):

On Fri, Jun 4, 2021 at 2:03 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> On Fri, Jun 4, 2021 at 1:44 PM Matthew Rogers via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > When building on windows users have the option to use vcpkg to provide
> > the dependencies needed to compile.  Previously, this was used only when
> > using the Visual Studio generator which was not ideal because:
> >
> >   - Not all users who want to use vcpkg use the Visual Studio
> >     generators.
> >
> >   - Some versions of Visual Studio 2019 moved away from using the
> >     VS 2019 by default, making it impossible for Visual Studio to
> >     configure the project in the likely event that it couldn't find the
> >     dependencies.
>
> Is there something missing between "using the" and "VS 2019"? I'm
> having a hard time trying to understand what this bullet point is
> saying due to this apparent gap.
>

Yeah, this should really read
- Some versions of Visual Studio 2019 moved away from using the
     VS 2019 _Generator_ by default, making it impossible for Visual Studio to
     configure the project in the likely event that it couldn't find the
     dependencies.


> >   - Inexperienced users of CMake are very likely to get tripped up by
> >     the errors caused by a lack of vcpkg, making the above bullet point
> >     both annoying and hard to debug.
> >
> > As such, lets make using vcpkg the default on windows.  Users who want
> > to avoid using vcpkg can disable it by passing -DNO_VCPKG=TRUE.
>
> s/lets/let's/
>
> > Signed-off-by: Matthew Rogers <mattr94@gmail.com>



-- 
Matthew Rogers

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Fri, Jun 4, 2021 at 1:44 PM Matthew Rogers via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> Some users have expressed interest in a more "batteries included" way of
> building via CMake[1], and a big part of that is providing easier access
> to tooling external tools.
>
> A straightforward way to accomplish this is to make it as simple as
> possible is to enable the generation of the compile_commands.json file,
> which is supported by many tools such as: clang-tidy, clang-format,
> sourcetrail, etc.
>
> This does come with a small run-time overhead during the configuration
> step (~6 seconds on my machine):
>     [...]
> This seems like a small enough price to pay to make the project more
> accessible to newer users.  Additionally there are other large projects
> like llvm [2] which has had this enabled by default for >6 years at the
> time of this writing, and no real negative consequences that I can find
> with my search-skills.
>
> NOTE: That the comppile_commands.json is currenntly produced only when
> using the Ninja and Makefile generators.  See The CMake documentation[3]
> for more info.

s/comppile/compile/
s/currenntly/currently/

> Signed-off-by: Matthew Rogers <mattr94@gmail.com>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Eric Sunshine wrote (reply to this):

On Fri, Jun 4, 2021 at 1:44 PM Matthew Rogers via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> It does not make sense to attempt to set MSGFMT_EXE when NO_GETTEXT is
> configured, as such add a check for NO_GETTEXT before attempting to set
> it.

This would be easier to digest if "as such" is the start of a new
sentence: "As such...". Or "Therefore, add a check...".

> suggested-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: Matthew Rogers <mattr94@gmail.com>

s/suggested-by/Suggested-by:/

Tiny little nits, both. Don't know if it's worth a re-roll, but if you
happen to re-roll for some other reason, perhaps these could be
tweaked.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Sibi Siddharthan wrote (reply to this):

On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
<gitgitgadget@gmail.com> wrote:

> -if(WIN32)
> +
> +if (WIN32 AND NOT NO_VCPKG)
> +       set(USING_VCPKG TRUE)
> +else()
> +       set(USING_VCPKG FALSE)
> +endif()

I think it would be better if we could have an option for this knob.
Maybe like this

option(NO_VCPKG "Don't use vcpkg for obtaining dependencies. Only
applicable to Windows platforms" OFF)

I would prefer to use `USE_VCPKG`.

Thank You,
Sibi Siddharthan

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Matt Rogers wrote (reply to this):

On Fri, Jun 4, 2021 at 4:55 PM Sibi Siddharthan
<sibisiddharthan.github@gmail.com> wrote:
>
> On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>
> > -if(WIN32)
> > +
> > +if (WIN32 AND NOT NO_VCPKG)
> > +       set(USING_VCPKG TRUE)
> > +else()
> > +       set(USING_VCPKG FALSE)
> > +endif()
>
> I think it would be better if we could have an option for this knob.
> Maybe like this
>
> option(NO_VCPKG "Don't use vcpkg for obtaining dependencies. Only
> applicable to Windows platforms" OFF)

Option would definitely be the better tool to use here, I just didn't
think about
it when originally writing it, so I'll send a reroll with that and the spelling
corrections suggested by Eric Sunshine.  I assume you'd prefer something
with a final form more like:

option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies.
Only applicable to Windows platforms" ON)


>
> I would prefer to use `USE_VCPKG`.
>
> Thank You,
> Sibi Siddharthan



-- 
Matthew Rogers

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Sibi Siddharthan wrote (reply to this):

On Sun, Jun 6, 2021 at 4:01 AM Matt Rogers <mattr94@gmail.com> wrote:
>
> On Fri, Jun 4, 2021 at 4:55 PM Sibi Siddharthan
> <sibisiddharthan.github@gmail.com> wrote:
> >
> > On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
> > <gitgitgadget@gmail.com> wrote:
> >
> > > -if(WIN32)
> > > +
> > > +if (WIN32 AND NOT NO_VCPKG)
> > > +       set(USING_VCPKG TRUE)
> > > +else()
> > > +       set(USING_VCPKG FALSE)
> > > +endif()
> >
> > I think it would be better if we could have an option for this knob.
> > Maybe like this
> >
> > option(NO_VCPKG "Don't use vcpkg for obtaining dependencies. Only
> > applicable to Windows platforms" OFF)
>
> Option would definitely be the better tool to use here, I just didn't
> think about
> it when originally writing it, so I'll send a reroll with that and the spelling
> corrections suggested by Eric Sunshine.  I assume you'd prefer something
> with a final form more like:
>
> option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies.
> Only applicable to Windows platforms" ON)
>

Yes, this would be better.

Thank You,
Sibi Siddharthan

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Sibi Siddharthan wrote (reply to this):

On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> A straightforward way to accomplish this is to make it as simple as
> possible is to enable the generation of the compile_commands.json file,
> which is supported by many tools such as: clang-tidy, clang-format,
> sourcetrail, etc.
>
> This does come with a small run-time overhead during the configuration
> step (~6 seconds on my machine):
>
>     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=TRUE
>
>     real    1m9.840s
>     user    0m0.031s
>     sys     0m0.031s
>
>     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=FALSE
>
>     real    1m3.195s
>     user    0m0.015s
>     sys     0m0.015s
>
> This seems like a small enough price to pay to make the project more
> accessible to newer users.  Additionally there are other large projects
> like llvm [2] which has had this enabled by default for >6 years at the
> time of this writing, and no real negative consequences that I can find
> with my search-skills.
>

The overhead is actually much smaller than that. In my system it is
less than 150ms.
The first configure takes this long because we generate command-list.h
and config-list.h.
This process is really slow under Windows.

Thank You,
Sibi Siddharthan

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Matt Rogers wrote (reply to this):

On Fri, Jun 4, 2021 at 5:09 PM Sibi Siddharthan
<sibisiddharthan.github@gmail.com> wrote:
>
> On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> >
> > A straightforward way to accomplish this is to make it as simple as
> > possible is to enable the generation of the compile_commands.json file,
> > which is supported by many tools such as: clang-tidy, clang-format,
> > sourcetrail, etc.
> >
> > This does come with a small run-time overhead during the configuration
> > step (~6 seconds on my machine):
> >
> >     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=TRUE
> >
> >     real    1m9.840s
> >     user    0m0.031s
> >     sys     0m0.031s
> >
> >     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=FALSE
> >
> >     real    1m3.195s
> >     user    0m0.015s
> >     sys     0m0.015s
> >
> > This seems like a small enough price to pay to make the project more
> > accessible to newer users.  Additionally there are other large projects
> > like llvm [2] which has had this enabled by default for >6 years at the
> > time of this writing, and no real negative consequences that I can find
> > with my search-skills.
> >
>
> The overhead is actually much smaller than that. In my system it is
> less than 150ms.

Is that 150 ms for the whole process or just the difference between the two
options?  I'm running this on windows via the git bash provided by the
git sdk.

> The first configure takes this long because we generate command-list.h
> and config-list.h.
> This process is really slow under Windows.
>

I used two different build directories for both my invocations specifically
to avoid having to account for cache variables and other side effects
from earlier configurations.  The variation could also be from network
latency since in this test I was downloading vcpkg, etc.

> Thank You,
> Sibi Siddharthan



-- 
Matthew Rogers

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Sibi Siddharthan wrote (reply to this):

On Sun, Jun 6, 2021 at 4:06 AM Matt Rogers <mattr94@gmail.com> wrote:
>
> On Fri, Jun 4, 2021 at 5:09 PM Sibi Siddharthan
> <sibisiddharthan.github@gmail.com> wrote:
> >
> > On Fri, Jun 4, 2021 at 11:13 PM Matthew Rogers via GitGitGadget
> > <gitgitgadget@gmail.com> wrote:
> > >
> > > A straightforward way to accomplish this is to make it as simple as
> > > possible is to enable the generation of the compile_commands.json file,
> > > which is supported by many tools such as: clang-tidy, clang-format,
> > > sourcetrail, etc.
> > >
> > > This does come with a small run-time overhead during the configuration
> > > step (~6 seconds on my machine):
> > >
> > >     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=TRUE
> > >
> > >     real    1m9.840s
> > >     user    0m0.031s
> > >     sys     0m0.031s
> > >
> > >     Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=FALSE
> > >
> > >     real    1m3.195s
> > >     user    0m0.015s
> > >     sys     0m0.015s
> > >
> > > This seems like a small enough price to pay to make the project more
> > > accessible to newer users.  Additionally there are other large projects
> > > like llvm [2] which has had this enabled by default for >6 years at the
> > > time of this writing, and no real negative consequences that I can find
> > > with my search-skills.
> > >
> >
> > The overhead is actually much smaller than that. In my system it is
> > less than 150ms.
>
> Is that 150 ms for the whole process or just the difference between the two
> options?  I'm running this on windows via the git bash provided by the
> git sdk.

The difference between the two. Without exporting compile_commands.json
it takes around 650ms, with it around 750ms.
NOTE: This is for subsequent CMake runs. (Excludes the initial run)

Thank You,
Sibi Siddharthan

`-G Ninja`

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.

]]
cmake_minimum_required(VERSION 3.14)

#set the source directory to root of git
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
if(WIN32)

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)
endif()

if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
endif()

if(USE_VCPKG)
set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
if(MSVC AND NOT EXISTS ${VCPKG_DIR})
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)
endif()
Expand Down Expand Up @@ -176,12 +189,18 @@ if(WIN32 AND NOT MSVC)#not required for visual studio builds
endif()
endif()

find_program(MSGFMT_EXE msgfmt)
if(NOT MSGFMT_EXE)
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)
if(NO_GETTEXT)
message(STATUS "msgfmt not used under NO_GETTEXT")
else()
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a missing endif() here, I think, for the else() above.

And I'd like to avoid find_program(MSGFMT_EXE) altogether if NO_GETTEXT is set...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some updates with your comments in mind, I think the version I have is a bit more what we want, I changed the text output from a warning to a status because this should be normal operation if we're operating under NO_GETTEXT and I felt issuing a warning for that would be a bit weird.

endif()
endif()

Expand Down Expand Up @@ -982,7 +1001,7 @@ 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 "NO_PYTHON='${NO_PYTHON}'\n")
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
if(WIN32)
if(USE_VCPKG)
file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
endif()

Expand Down