简体   繁体   English

如何强制重新运行cmake,或通过CMakeLists.txt将功能添加到makefile

[英]How to force re-run of cmake, or add functions to makefile through CMakeLists.txt

I'd like to keep very close track of what version of my code I'm using for documentation purposes. 我想密切跟踪我用于文档目的的代码版本。 Therefore I'd like to display the version of code I have compiled every time I run my program.. 因此,我想在每次运行程序时显示我编译的代码版本。

I've been using this previous question as reference. 我一直在用这个先前的问题作为参考。

How can I pass git SHA1 to compiler as definition using cmake? 如何使用cmake将git SHA1作为定义传递给编译器?

I am using the two files that Ryan Pavlik suggested from his github repo, seen below: https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake.in#L13 https://github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake 我正在使用Ryan Pavlik从他的github存储库中建议的两个文件,如下所示: https : //github.com/rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake.in#L13 https://github.com /rpavlik/cmake-modules/blob/master/GetGitRevisionDescription.cmake

And I have the following: 我有以下内容:

CMakeLists.txt CMakeLists.txt

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GITHASH)

set(test_GITHASH "\"${GITHASH}\"")

include_directories("${PROJECT_BINARY_DIR}")
configure_file ("${PROJECT_SOURCE_DIR}/testgithash.h.in"
                "${PROJECT_BINARY_DIR}/testgithash.h" )

testgithash.h.in 在testgithash.h

#define test_GITHASH @test_GITHASH@

So far I have my final executable displaying the hash from my testgithash.h file that is generated, but that header file is only refreshed when I run cmake . 到目前为止,我的最终可执行文件显示了生成的testgithash.h文件中的哈希,但是仅在运行cmake时才刷新该头文件。 So really my question is, does anyone know of way that I can force cmake to re-run when I run make if my hash has changed? 所以,实际上我的问题是,如果哈希值发生更改,有人知道在我运行make时可以强制cmake重新运行的方式吗? Or is there a way I can put the git hash functionality I'm looking for directly into my generated makefile rather than in my CMakeLists.txt? 还是有一种方法可以将要查找的git hash功能直接放入生成的makefile中,而不是放在CMakeLists.txt中?

Thanks in advance for any help! 在此先感谢您的帮助!

As far as I've been able to figure out, the only way to force CMake to be rerun on some external condition is to have it include a file whose timestamp has been modified. 据我所知,强制CMake在某些外部条件下重新运行的唯一方法是使它include时间戳已被修改的文件。 Something like this: 像这样:

# Somewhere in your CMakeLists.txt
include(external.stamp)

Then CMake will be rerun when external.stamp is updated. 然后,在更新external.stamp时,CMake将重新运行。

In your case, maybe you could have a post-commit hook in git touch an (empty) file when a commit is made, then include that in your CMakeLists.txt . 在您的情况下,也许您可​​以在进行提交时在git touch中有一个(空)文件提交后的钩子,然后将其包含在CMakeLists.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM