How do you build a CMake target or not depending on an environment variable?

Viewed 16

I have a target which generates some code, however, I do not always want to generate the code, because it is time consuming, and causes lots of recompilation. I want to build like this:

NOGEN=true make

But CMake is thwarting me:

    add_custom_target(gen_messages
        if (NOT DEFINED ENV{NOGEN})
            COMMAND echo "Generating messages"
            COMMAND ...
            ...
        endif()
    )

It doesn't like it inside the custom target. I can't make out why. As usual, the ìf documentation does not explain. I am able to use it outside the target.

How do I do this?

0 Answers
Related