Discussion:
[cmake-developers] VS custom commands with VS variable containing space in executable path?
Robert Goulet
2016-08-26 16:43:38 UTC
Permalink
Hello,

I am trying to use a custom command to generate test certificate for a Universal Windows Platform app, and I can't find how to properly quote the executable paths from CMake. Here is how we add the custom command:

set(WIN64UWP_CERT_NAME "${PROJECT_NAME}_TemporaryKey")
add_custom_command(
OUTPUT "${PROJECT_BINARY_DIR}/${WIN64UWP_CERT_NAME}.pfx"
COMMAND "$(WindowsSdkDir)/bin/x64/makecert.exe" -cy end -eku 1.3.6.1.5.5.7.3.3 -r -n "CN=${PRODUCT_COMPANY}" -sv ${RESOURCES_DIR}/${WIN64UWP_CERT_NAME}.pvk ${WIN64UWP_CERT_NAME}.cer
COMMAND "$(WindowsSdkDir)/bin/x64/PVK2PFX.exe" -pvk ${RESOURCES_DIR}/${WIN64UWP_CERT_NAME}.pvk -spc ${WIN64UWP_CERT_NAME}.cer -pfx ${WIN64UWP_CERT_NAME}.pfx -f
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating Test Certificate..."
)

Because $(WindowsSdkDir) points within C:\Program Files\... Visual Studio is unable to execute these commands since the .vcxproj does not contain quotes around the executable paths.

First I tried using \" around the command, but CMake refuses to escape quotes on the command with error "COMMAND may not contain literal quotes".

Then I tried XML escaped character " but then CMake translate the ; as it if was a different element of an array surrounding both sides with quotes.

Then I tried %22 but CMake outputs % as %% in the vcxproj file.

So how do we setup a custom command that uses a Visual Studio variable that requires to be quoted to preserve spaces?

Thanks!
Brad King
2016-08-26 17:30:16 UTC
Permalink
Post by Robert Goulet
COMMAND "$(WindowsSdkDir)/bin/x64/makecert.exe"
So how do we setup a custom command that uses a Visual Studio variable
that requires to be quoted to preserve spaces?
I don't think it is supported. You could try adding a wrapper
around the call so that it appears as an argument instead of in
the command.

COMMAND ${CMAKE_COMMAND} -E env "$(WindowsSdkDir)/bin/x64/makecert.exe" ...

OTOH you're trying to pierce CMake's abstract model of a command
(which is why it's not supported). Instead you could find_program
the tools you need and reference them by absolute path.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Robert Goulet
2016-08-26 17:57:03 UTC
Permalink
Thanks, this worked:

COMMAND ${CMAKE_COMMAND} -E env "\"$(WindowsSdkDir)/bin/x64/makecert.exe\"" ...

I still believe that what I was trying to do was perfectly valid in the sense that it is using a VS environment variable $(WindowsSdkDir) that is not defined in the system environment variable, thus it exist only when command is executed from within VS. Normally we do use find_program(...) but this doesn't apply for this case because VS environment variables such as $(WindowsSdkDir) won't resolve outside of VS.

Thanks!

-----Original Message-----
From: Brad King [mailto:***@kitware.com]
Sent: Friday, August 26, 2016 1:30 PM
To: Robert Goulet <***@autodesk.com>
Cc: cmake-***@cmake.org
Subject: Re: [cmake-developers] VS custom commands with VS variable containing space in executable path?
Post by Robert Goulet
COMMAND "$(WindowsSdkDir)/bin/x64/makecert.exe"
So how do we setup a custom command that uses a Visual Studio variable
that requires to be quoted to preserve spaces?
I don't think it is supported. You could try adding a wrapper around the call so that it appears as an argument instead of in the command.

COMMAND ${CMAKE_COMMAND} -E env "$(WindowsSdkDir)/bin/x64/makecert.exe" ...

OTOH you're trying to pierce CMake's abstract model of a command (which is why it's not supported). Instead you could find_program the tools you need and reference them by absolute path.

-Brad
--
Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
Continue reading on narkive:
Search results for '[cmake-developers] VS custom commands with VS variable containing space in executable path?' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 2006-10-11 00:02:47 UTC
software
Loading...