diff mbox series

[3/4] cmake: add a preparatory work-around to accommodate `vcpkg`

Message ID 543fd0f5d7e5ee297364d1d28091f2004a35f2d0.1616886386.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series cmake: learn to optionally skip linking dashed built-ins | expand

Commit Message

Johannes Schindelin March 27, 2021, 11:06 p.m. UTC
From: Johannes Schindelin <johannes.schindelin@gmx.de>

We are about to add support for installing the `.dll` files of Git's
dependencies (such as libcurl) in the CMake configuration. The `vcpkg`
ecosystem from which we get said dependencies makes that relatively
easy: simply turn on `X_VCPKG_APPLOCAL_DEPS_INSTALL`.

However, current `vcpkg` introduces a limitation if one does that:
While it is totally cool with CMake to specify multiple targets within
one invocation of `install(TARGETS ...) (at least according to
https://cmake.org/cmake/help/latest/command/install.html#command:install),
`vcpkg`'s parser insists on a single target per `install(TARGETS ...)`
invocation.

Well, that's easily accomplished: Let's feed the targets individually to
the `install(TARGETS ...)` function in a `foreach()` look.

This also has the advantage that we do not have to manually cull off the
two entries from the `${PROGRAMS_BUILT}` array before scheduling the
remainder to be installed into `libexec/git-core`. Instead, we iterate
through the array and decide for each entry where it wants to go.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 contrib/buildsystems/CMakeLists.txt | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Đoàn Trần Công Danh March 28, 2021, 3:19 a.m. UTC | #1
On 2021-03-27 23:06:24+0000, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> We are about to add support for installing the `.dll` files of Git's
> dependencies (such as libcurl) in the CMake configuration. The `vcpkg`
> ecosystem from which we get said dependencies makes that relatively
> easy: simply turn on `X_VCPKG_APPLOCAL_DEPS_INSTALL`.
> 
> However, current `vcpkg` introduces a limitation if one does that:
> While it is totally cool with CMake to specify multiple targets within
> one invocation of `install(TARGETS ...) (at least according to
> https://cmake.org/cmake/help/latest/command/install.html#command:install),
> `vcpkg`'s parser insists on a single target per `install(TARGETS ...)`
> invocation.
> 
> Well, that's easily accomplished: Let's feed the targets individually to
> the `install(TARGETS ...)` function in a `foreach()` look.
> 
> This also has the advantage that we do not have to manually cull off the
> two entries from the `${PROGRAMS_BUILT}` array before scheduling the
> remainder to be installed into `libexec/git-core`. Instead, we iterate
> through the array and decide for each entry where it wants to go.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  contrib/buildsystems/CMakeLists.txt | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
> index da2811ae3aad..a166be0eb1b8 100644
> --- a/contrib/buildsystems/CMakeLists.txt
> +++ b/contrib/buildsystems/CMakeLists.txt
> @@ -811,15 +811,19 @@ list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
>  list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
>  
>  #install
> -install(TARGETS git git-shell
> +foreach(program ${PROGRAMS_BUILT})
> +if(${program} STREQUAL git OR ${program} STREQUAL git-shell)

Please don't use `${}` around variable inside `if()`, and quote the
string. CMake has a quirk with the `${}` inside if (expanded variable
will be treated as a variable if it is defined, or string otherwise).
Unquoted string will be seen as a variable if it's defined, string
otherwise. IOW, suggested command:

	if (program STREQUAL "git" OR program STREQUAL "git-shell")

We also have another problem with quoted arguments could be interpreted
as variable or keyword if CMP0054 policy not enabled, too.
I think it's better to have it enabled, but it's not in the scope of
this patch.

 https://cmake.org/cmake/help/latest/policy/CMP0054.html
Johannes Schindelin March 29, 2021, 1:36 p.m. UTC | #2
Hi Danh,

On Sun, 28 Mar 2021, Đoàn Trần Công Danh wrote:

> On 2021-03-27 23:06:24+0000, Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com> wrote:
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > We are about to add support for installing the `.dll` files of Git's
> > dependencies (such as libcurl) in the CMake configuration. The `vcpkg`
> > ecosystem from which we get said dependencies makes that relatively
> > easy: simply turn on `X_VCPKG_APPLOCAL_DEPS_INSTALL`.
> >
> > However, current `vcpkg` introduces a limitation if one does that:
> > While it is totally cool with CMake to specify multiple targets within
> > one invocation of `install(TARGETS ...) (at least according to
> > https://cmake.org/cmake/help/latest/command/install.html#command:install),
> > `vcpkg`'s parser insists on a single target per `install(TARGETS ...)`
> > invocation.
> >
> > Well, that's easily accomplished: Let's feed the targets individually to
> > the `install(TARGETS ...)` function in a `foreach()` look.
> >
> > This also has the advantage that we do not have to manually cull off the
> > two entries from the `${PROGRAMS_BUILT}` array before scheduling the
> > remainder to be installed into `libexec/git-core`. Instead, we iterate
> > through the array and decide for each entry where it wants to go.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >  contrib/buildsystems/CMakeLists.txt | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
> > index da2811ae3aad..a166be0eb1b8 100644
> > --- a/contrib/buildsystems/CMakeLists.txt
> > +++ b/contrib/buildsystems/CMakeLists.txt
> > @@ -811,15 +811,19 @@ list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
> >  list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
> >
> >  #install
> > -install(TARGETS git git-shell
> > +foreach(program ${PROGRAMS_BUILT})
> > +if(${program} STREQUAL git OR ${program} STREQUAL git-shell)
>
> Please don't use `${}` around variable inside `if()`, and quote the
> string. CMake has a quirk with the `${}` inside if (expanded variable
> will be treated as a variable if it is defined, or string otherwise).
> Unquoted string will be seen as a variable if it's defined, string
> otherwise. IOW, suggested command:
>
> 	if (program STREQUAL "git" OR program STREQUAL "git-shell")
>
> We also have another problem with quoted arguments could be interpreted
> as variable or keyword if CMP0054 policy not enabled, too.
> I think it's better to have it enabled, but it's not in the scope of
> this patch.
>
>  https://cmake.org/cmake/help/latest/policy/CMP0054.html

Thank you for this information! I've sent out v2 based on your suggestion.

Thanks,
Dscho
diff mbox series

Patch

diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index da2811ae3aad..a166be0eb1b8 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -811,15 +811,19 @@  list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
 list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
 
 #install
-install(TARGETS git git-shell
+foreach(program ${PROGRAMS_BUILT})
+if(${program} STREQUAL git OR ${program} STREQUAL git-shell)
+install(TARGETS ${program}
 	RUNTIME DESTINATION bin)
+else()
+install(TARGETS ${program}
+	RUNTIME DESTINATION libexec/git-core)
+endif()
+endforeach()
+
 install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver
 	DESTINATION bin)
 
-list(REMOVE_ITEM PROGRAMS_BUILT git git-shell)
-install(TARGETS ${PROGRAMS_BUILT}
-	RUNTIME DESTINATION libexec/git-core)
-
 set(bin_links
 	git-receive-pack git-upload-archive git-upload-pack)