相关疑难解决方法(0)

如何在构建时始终运行命令而不管任何依赖?

我想运行一个解析整个源代码树的cmake命令,所以我无法在cmake的add_custom_command/add_custom_target命令中列出所有可能的依赖项.

有没有可能告诉cmake只是在没有任何条件的情况下运行命令?我尝试了在网上找到的所有解决方案(包括SO),但他们都假设该命令依赖于几个已知的最新文件.

我找到了一个解决方案,但它无法可靠地工作:

cmake_minimum_required(VERSION 2.6)

project(main)

add_custom_command(
   OUTPUT file1
   COMMAND echo touching file1
   COMMAND touch file1
   DEPENDS file2)
add_custom_target(dep ALL DEPENDS file1 file2)

# this command re-touches file2 after dep target is "built"
# and thus forces its rebuild
ADD_CUSTOM_COMMAND(TARGET dep
          POST_BUILD
          COMMAND echo touching file2
          COMMAND touch file2
)
Run Code Online (Sandbox Code Playgroud)

这是输出:

queen3@queen3-home:~/testlib$ make
[100%] Generating file1
touching file1
touching file2
[100%] Built target dep
queen3@queen3-home:~/testlib$ make
[100%] Generating file1
touching file1
touching file2
[100%] Built target dep
queen3@queen3-home:~/testlib$ make
touching …
Run Code Online (Sandbox Code Playgroud)

cmake

15
推荐指数
4
解决办法
2万
查看次数

标签 统计

cmake ×1