cmake - gnu 使 : use wildcard twice in rule dependency

标签 cmake makefile gnu-make pandoc

我想要一些形式的make规则

build/file_a.pdf: text/file_a/file_a.md
    pandoc -o build/file_a.pdf text/file_a/file_a.md

build/file_b.pdf: text/file_b/file_b.md
    pandoc -o build/file_b.pdf text/file_a/file_b.md

...

每当我更改它们时,将几个 Markdown 文件转换为 PDF。我想指定一个规则,比如

build/%.pdf: text/%/%.md
    ....

不工作。有没有一种方法可以生成与我拥有的特殊模式相匹配的规则? cmake 能更好地处理这种情况吗?

最佳答案

您可以使用 define 动态生成规则, eval , 和 call .

define build_rule
    build/$1.pdf: text/$1/$1.md
        ....
endef

$(foreach f,file_a file_b,$(eval $(call build_rule,$f)))

关于cmake - gnu 使 : use wildcard twice in rule dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008031/

相关文章:

ios - OS X 上 OpenCL 的 CMakeListx.txt 文件

c++ - Makefile : Undefined symbols for architecture x86_64

makefile - 使用 make 将目标文件存储在单独的目录中

makefile - 如何从命令行覆盖特定于目标的变量?

c++ - 如何检查是否安装了libc++?

boost - 在Linux上使用Cmake进行 boost (ubuntu)

c++ - 带有 gtest(C++) 的 CMakeLists C 程序

macos - 在 Mac 上安装 "make"

Makefile 匹配命令中的模式

string - GMSL seq函数的实现