[CMake] execute_process, cmd /c and vcvarsall

Kristian kristianonline28 at gmail.com
Fri Jun 10 06:21:52 EDT 2016


After some tries I found maybe a solution for you. In my small example, I
had these lines, which are working:


> set(HELLO1 "C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/vcvarsall.bat")
> execute_process(COMMAND ${HELLO1} && msbuild /help WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}")

So for you, it would look like this (I am not very sure about it):

==========


execute_process( COMMAND $ENV{VS${VS_IDE_VERSION}
0COMNTOOLS}../../VC/vcvarsall.bat x86_amd64 &&  ${CUDA_NVCC_EXECUTABLE}
${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu --run

                 WORKING_DIRECTORY
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"

                 RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out

                 OUTPUT_STRIP_TRAILING_WHITESPACE)

==========

Anyhow, when I tried several types of your presentation, I got always some
errors. I do not know, if this is a bug or not, but I will write them down
here. Maybe some of the others could write something about it.


*** First try ***

> set(HELLO1 "C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/vcvarsall.bat")
> execute_process(COMMAND cmd /c "call ${HELLO1}" WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE
_nvcc_out)
> message("${_nvcc_out}")

When I call these lines on a windows machine, I am getting the error

> 'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

*** Second try ***

When I change the execute_process to this

> execute_process(COMMAND cmd /c "call \"${HELLO1}\"" WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE
_nvcc_out)

then I am getting this error

> '\"C:/Program Files (x86)/Microsoft Visual Studio
14.0/VC/vcvarsall.bat\"' is not recognized as an internal or external
command, operable program or batch file.

So now, CMake / Batch recognizes the right path, but somehow there are the
characters \".

*** Third try ***

I changed the definition of the variable HELLO1 into (because of some hints
here
https://superuser.com/questions/279008/how-do-i-escape-spaces-in-command-line-in-windows-without-using-quotation-marks
)

> set(HELLO1 "C:/Program^ Files^ (x86)/Microsoft^ Visual^ Studio^
14.0/VC/vcvarsall.bat")

But here, I am also getting the error

> 'C:/Program' is not recognized as an internal or external command,
operable program or batch file.

Even, when I double the carets ^^, then the same error occurs


2016-06-09 22:41 GMT+02:00 Adam Rankin <arankin at robarts.ca>:

> Hello all,
>
>
>
> I am trying to develop a execute_process command that will first load the
> env variables set by the appropriate vcvarsall, and then run a compile
> command. See here for my progress so far:
>
>
>
> set(cuda_generation_command cmd /c "\"call
> \"$ENV{VS${VS_IDE_VERSION}0COMNTOOLS}../../VC/vcvarsall.bat\" x86_amd64 &&
> \"${CUDA_NVCC_EXECUTABLE}\"
> \"${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu\" \"--run\"\"")
>
>
>
> execute_process( COMMAND ${cuda_generation_command}
>
>                  WORKING_DIRECTORY
> "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
>
>                  RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out
>
>                  OUTPUT_STRIP_TRAILING_WHITESPACE)
>
>
>
> When run at a command prompt, the command works as expected. When called
> from CMake, the output is:
>
> The filename, directory name, or volume label syntax is incorrect.
>
>
>
> Has anyone ever succeeded with something like this?
>
>
>
> Cheers,
>
> Adam
>
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160610/f81b8981/attachment.html>


More information about the CMake mailing list