1

在 Unix Makefile 中,我可以在配方行前面加上前缀-以忽略将发生的任何错误(如配方中的错误中所述)。

hello_world: hello_world.cxx
    -$(CXX) $(CXXFLAGS) $^ -o $@

我将我的 Makefile 转换为 CMake:

cmake_minimum_required(VERSION 3.0)
project(HelloWorld)

add_executable(hello_world hello_world.cxx)

并运行cmake,生成的 Makefile 看起来很好,除了缺少的-.

是否可以使用 CMake 生成忽略错误的 Unix Makefile(在配方行前加上-)?最好的办法是按目标级别指定它。我知道我可以运行make -i以具有相同的行为,但这并不方便。

4

1 回答 1

2

You cannot.

make is designed to give the user a fine control over commands it runs. CMake's under-the-hood commands are supposed to always succeed.

As a hack, you can generate makefiles and run make --ignore-errors.

But I advice making each of your examples that would fail a separate project, and run them from an external script.

于 2019-10-02T17:01:33.343 回答