我如何在 CMake 中使用 message()?

How do I use message() in CMake?

我有一个包含以下代码的 CMakeLists:

macro(set_up_additional_targets)
    add_custom_target(generate_things
        message("Generating stuff")
        COMMAND python3 generator.py --outfile ${CMAKE_CURRENT_SOURCE_DIR}/sources/stuff
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools/generator/
    )
endmacro(set_up_additional_targets)

我收到这个错误:

/bin/sh: -c: line 0: syntax error near unexpected token `Generating\ stuff'
/bin/sh: -c: line 0: `cd /home/me/workspaces/foo/tools/generator && message ( Generating\ stuff )'
make[3]: *** [CMakeFiles/generate_things.dir/build.make:70: CMakeFiles/generate_things] Error 1
make[2]: *** [CMakeFiles/Makefile2:699: CMakeFiles/generate_things.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:706: CMakeFiles/generate_things.dir/rule] Error 2
make: *** [Makefile:439: generate_things] Error 2

我从COMMAND echo "Generating stuff"改成了message("Generating stuff")来变得更加平台无关,但是显然不行。从 CMake 手册中不清楚这可能是错误的,但是,与 CMake 一样,手册中没有示例。

我的错误是什么?

COMMENT 在这里应该符合您的目的,see

MESSAGE 在 CMake 解析步骤进行评估,see.