[CMake] Execute CMake process not working: source directory confusion

Michael Powell mwpowellhtx at gmail.com
Thu Sep 28 13:01:11 EDT 2017


On Thu, Sep 28, 2017 at 12:53 PM, Michael Powell <mwpowellhtx at gmail.com> wrote:
> On Thu, Sep 28, 2017 at 12:36 PM, Petr Kmoch <petr.kmoch at gmail.com> wrote:
>> Hi Michael.
>>
>> On 28 September 2017 at 18:18, Michael Powell <mwpowellhtx at gmail.com> wrote:
>>>
>>> On Thu, Sep 28, 2017 at 12:06 PM, Michael Powell <mwpowellhtx at gmail.com>
>>> wrote:
>>> > ---------- Forwarded message ----------
>>> > From: Michael Powell <mwpowellhtx at gmail.com>
>>> > Date: Thu, Sep 28, 2017 at 12:06 PM
>>> > Subject: Execute CMake process not working: source directory confusion
>>> > To: cmake at cmake.org
>>> >
>>> >
>>> > Hello,
>>> >
>>> > This is fairly long, but this is intentional. I message the "Invoking"
>>> > message.
>>>
>>> Ah, I figured it out!
>>>
>>> From the help:
>>>
>>> cmake [options] <path-to-source>
>>>
>>> So I simply tacked on a "\"${GIT_SUBMODULE_NNG_REPO_DIR}\"" where
>>> <path-to-source> was expected.
>>>
>>> Curious CMake would "see" the ENTIRE argument string as
>>> "path-to-source" though. Not sure quite what's going on with that,
>>> though.
>>
>>
>> That's because you're constructing CPPNNG_NNG_CMAKE_OPTIONS as a single
>> string containing spaces. Spaces *in strings* do not delimit CMake
>> arguments, even if spaces in CMake file syntax do. In other words:
>>
>>  foo(a b c)
>>
>> calls 'foo' with 3 arguments: "a", "b", and "c".
>>
>>  set(args a b c)
>>  foo(${args})
>>
>> also calls 'foo' with these 3 arguments.
>>
>> However,
>>
>>   set(args "a b c")
>>   foo(${args})
>>
>> calls 'foo' with only ONE argument: the string "a b c".
>>
>> You need to drop one level of quoting inside your cppnng_nng_add_* macros.
>>
>>>
>>>
>>> The outcome wasn't quite what I expected. How do I specify "path to
>>> source", where the source CMakeLists.txt is, properly. And the path to
>>> the build, where I want the build environment to land?
>>>
>>> With this scenario, currently things are landing "in the source
>>> directory", which is incorrect, not what I am expecting.
>>
>>
>> Once you solve the quoting issue, you should be able to pass what you want
>> as the source directory. It's effectively the first non-option argument to
>> 'cmake'.
>>
>> The generated buildsystem lands in the working directory from which cmake
>> was invoked. So what you want is this:
>>
>> execute_process(
>>   ${CMAKE_COMMAND} ${CPPNNG_NNG_CMAKE_OPTIONS} ${GIT_SUBMODULE_NNG_REPO_DIR}
>>   WORKING_DIRECTORY wherever/you/want/the/buildystem/to/end/up
>> )
>
> Thanks for that insight!
>
> I ended up with something like this:
>
> message (STATUS "Invoking CMake: \"${CMAKE_COMMAND}\"
> ${CPPNNG_NNG_CMAKE_OPTIONS} \"${GIT_SUBMODULE_NNG_REPO_DIR}\"")
>
> execute_process (
>     COMMAND "\"${CMAKE_COMMAND}\" ${CPPNNG_NNG_CMAKE_OPTIONS}
> \"${GIT_SUBMODULE_NNG_REPO_DIR}\""
>     WORKING_DIRECTORY "${GIT_SUBMODULE_NNG_REPO_DIR}"
>     RESULT_VARIABLE CPPNN_NNG_CONFIG_EC
>     OUTPUT_VARIABLE CPPNN_NNG_CONFIG_MSG
> )
>
> But which is now yielding an output message " (Access is denied)" (no EC).

Out of curiosity, how strong is the file lock CMake is maintaining
internally? i.e. with allowance for shared read?

In this instance, I am running the parent CMake process from CMake
GUI, which it then invokes another instance of CMake on the submodule,
or at least that's the intention.

If that's a non-starter in its current form, no big deal; worst case
scenario I can take precautions to include the submodule source at
strategic points in my consumer solution.

> Console output:
>
> Invoking CMake: "C:/Dev/CMake/bin/cmake.exe" -G "Visual Studio 14 2015
> Win64" --build "G:/Source/Spikes/nanomsg/cppnngswig-testing/build/nng"
> -D CMAKE_CONFIGURATION_TYPES:STRING="Debug\;Release\;MinSizeRel\;RelWithDebInfo"
> -D CMAKE_INSTALL_PREFIX:STRING="G:/Source/Spikes/nanomsg/cppnngswig-testing/build/nng"
> -D NNG_ENABLE_COVERAGE:BOOL=OFF -D NNG_ENABLE_DOC:BOOL=OFF -D
> NNG_ENABLE_NNGCAT:BOOL=OFF -D NNG_ENABLE_TESTS:BOOL=OFF -D
> NNG_ENABLE_TOOLS:BOOL=OFF -D NNG_ENABLE_ZEROTIER:BOOL=OFF
> "G:/Source/Spikes/nanomsg/cppnngswig-testing/repos/nng"
>
>> Petr
>>
>>>
>>>
>>> Probably my confusion over, prefix directory? Or is "source" directory
>>> where things actually land?
>>>
>>> Thanks!
>>>
>>> > Invoking CMake: C:/Dev/CMake/bin/cmake.exe -G "Visual Studio 14 2015
>>> > Win64" -D
>>> > CMAKE_CONFIGURATION_TYPES:STRING="Debug;Release;MinSizeRel;RelWithDebInfo"
>>> > -D
>>> > CMAKE_INSTALL_PREFIX:STRING="G:/Source/Spikes/nanomsg/cppnngswig-testing/build/nng"
>>> > -D NNG_ENABLE_COVERAGE:BOOL=OFF -D NNG_ENABLE_DOC:BOOL=OFF -D
>>> > NNG_ENABLE_NNGCAT:BOOL=OFF -D NNG_ENABLE_TESTS:BOOL=OFF -D
>>> > NNG_ENABLE_TOOLS:BOOL=OFF -D NNG_ENABLE_ZEROTIER:BOOL=OFF
>>> >
>>> > Prior to running:
>>> >
>>> > execute_process (
>>> >     COMMAND "${CMAKE_COMMAND}" ${CPPNNG_NNG_CMAKE_OPTIONS}
>>> >     WORKING_DIRECTORY "${GIT_SUBMODULE_NNG_REPO_DIR}"
>>> >     RESULT_VARIABLE CPPNN_NNG_CONFIG_EC
>>> >     OUTPUT_VARIABLE CPPNN_NNG_CONFIG_MSG
>>> > )
>>> >
>>> > Which is yielding:
>>> >
>>> > CMake Error: The source directory
>>> > "G:/Source/Spikes/nanomsg/cppnngswig-testing/repos/nng/ -G "Visual
>>> > Studio 14 2015 Win64" -D
>>> >
>>> > CMAKE_CONFIGURATION_TYPES:STRING="Debug;Release;MinSizeRel;RelWithDebInfo"
>>> > -D
>>> > CMAKE_INSTALL_PREFIX:STRING="G:/Source/Spikes/nanomsg/cppnngswig-testing/build/nng"
>>> > -D NNG_ENABLE_COVERAGE:BOOL=OFF -D NNG_ENABLE_DOC:BOOL=OFF -D
>>> > NNG_ENABLE_NNGCAT:BOOL=OFF -D NNG_ENABLE_TESTS:BOOL=OFF -D
>>> > NNG_ENABLE_TOOLS:BOOL=OFF -D NNG_ENABLE_ZEROTIER:BOOL=OFF" does not
>>> > exist.
>>> >
>>> > The GIT_SUBMODULE_NNG_REPO_DIR is indeed set to
>>> > G:/Source/Spikes/nanomsg/cppnngswig-testing/repos/nng/, so how can
>>> > that not be the source directory? But further, how is it seeing the
>>> > rest of the options as "source directory"?
>>> >
>>> > I only got to this point by doing what seems like extreme string
>>> > gymnastics just to arrive at what I think is an appropriate command.
>>> >
>>> > i.e.
>>> >
>>> > macro (cppnng_nng_add_cmake_generator GEN)
>>> >     set (CPPNNG_NNG_CMAKE_OPTIONS "${CPPNNG_NNG_CMAKE_OPTIONS} -G
>>> > \"${GEN}\"")
>>> > endmacro ()
>>> >
>>> > macro (cppnng_nng_add_cmake_var OPT TYPE VALUE)
>>> >     set (CPPNNG_NNG_CMAKE_OPTIONS "${CPPNNG_NNG_CMAKE_OPTIONS} -D
>>> > ${OPT}:${TYPE}=${VALUE}")
>>> > endmacro ()
>>> >
>>> >     cppnng_nng_add_cmake_generator ("${CMAKE_GENERATOR}")
>>> >
>>> >     # This is like string GYMNASTICS in order to allow semi-colons to
>>> > properly pass through.
>>> >     string(REPLACE ";" "\;" REPLACED_TYPES
>>> > "${CMAKE_CONFIGURATION_TYPES}")
>>> >     cppnng_nng_add_cmake_var ("CMAKE_CONFIGURATION_TYPES" STRING
>>> > "\"${REPLACED_TYPES}\"")
>>> >
>>> >     cppnng_nng_add_cmake_var ("CMAKE_INSTALL_PREFIX" STRING
>>> > "\"${cppnng_SOURCE_DIR}/build/nng\"")
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_COVERAGE" BOOL OFF)
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_DOC" BOOL OFF)
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_NNGCAT" BOOL OFF)
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_TESTS" BOOL OFF)
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_TOOLS" BOOL OFF)
>>> >     # TODO: TBD: at the moment we do not care about ZeroTier, but this
>>> > could change moving forward.
>>> >     cppnng_nng_add_cmake_var ("NNG_ENABLE_ZEROTIER" BOOL OFF)
>>> >
>>> >     # message (FATAL_ERROR "options: ${CPPNNG_NNG_CMAKE_OPTIONS}")
>>> >
>>> >     # message (STATUS "${REPLACED_TYPES}")
>>> >
>>> >     message (STATUS "Invoking CMake: " "${CMAKE_COMMAND}"
>>> > ${CPPNNG_NNG_CMAKE_OPTIONS})
>>> >
>>> > Cheers,
>>> >
>>> > Michael Powell
>>> --
>>>
>>> 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
>>
>>


More information about the CMake mailing list