[CMake] Need suggestions for implementation of new feature in cmake.

Carlo Wood carlo at alinoe.com
Fri Mar 27 15:04:52 EDT 2020


On Fri, 27 Mar 2020 07:18:11 +0100
Hendrik Sattler <post at hendrik-sattler.de> wrote:

> Hi Carlo,
> 
> The answer is already right in front of you: "a && b" executes b only
> if a returns positive (zero exit code). This is already done for the
> mkdir.
> 
> And to answer the other question: no, you cannot assume a POSIX shell
> in a Makefile.
> 
> HS

Hi Hendrik,

thank you for your reply :). I kinda overlooked that I have to admit.
I think my brain saw the '&&' as shell scripting and the question
was if that is portable, or that the generated Makefile on my system
made use of that because of the platform that I am using.

So, for clarity, I can use:

    add_custom_command(
      ...
      COMMAND ${cmd} && ${CMAKE_COMMAND} -E touch ${stamp_file}
    )

Where ${cmd} is the user defined command,
and that will work portably on all supported platforms?

How should I do this for GENERATOR_IS_MULTI_CONFIG?

Carlo Wood

PS I assume that '||' also works then. Namely I also need the
   stamp file to be created when it doesn't exist.

   So really I need in addition

   COMMAND test -e ${stamp_file} || ${CMAKE_COMMAND} -E touch ${stamp_file}

Is 'test -e' also portable?



More information about the CMake mailing list