我希望密切关注我用于文档目的的代码版本。因此,我希望每次运行程序时都显示我编译的代码版本。
我一直在使用上一个问题作为参考。
How can I pass git SHA1 to compiler as definition using 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
我有以下内容:
的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
#define test_GITHASH @test_GITHASH@
到目前为止,我的最终可执行文件显示了生成的 testgithash.h 文件中的哈希值,但该头文件仅在运行 cmake 时刷新。所以我的问题是,如果我的哈希值发生了变化,那么当我运行 make 时,是否有人知道我可以强制 cmake 重新运行的方式?或者有没有办法可以将git哈希函数直接放入我生成的makefile而不是我的CMakeLists.txt?
提前感谢您的帮助!
答案 0 :(得分:0)
据我所知,迫使CMake在某些外部条件下重新运行的唯一方法是让<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1, user-scalable=0" name="viewport">
<title>Title</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/mobiel.css">
<link rel="stylesheet" href="css/tablet.css">
<link rel="stylesheet" href="css/desktop.css">
<link rel="stylesheet" href="typography.css">
<link href='######' rel='stylesheet' type='text/css'>
<!--[if gte IE 9]><style type="text/css">.gradient {filter: none;}</style><![endif]-->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<body>
<header>
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-4">
<a class="navbar-brand" href="#">
<img src="http://itavisen.no/wp-content/uploads/imported/5064692.jpg">
</a>
</div>
<div class="col-sm-2">
<i class="fa fa-phone" aria-hidden="true"></i><p>06 12345678</p>
</div>
<div class="col-sm-2">
<i class="fa fa-envelope" aria-hidden="true"></i><p>@mail.nl</p>
</div>
</div>
</div>
</header>
<div class="container">
<nav class="navbar">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu" aria-expanded="false">
<span>Menu</span>
<span class="glyphicon glyphicon-menu-hamburger">
</button>
</div>
<div class="collapse navbar-collapse" id="main-menu">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" class="nav-selected">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">page2 <span class="caret"></span></a>
<ul class="dropdown-menu arrow_box">
<li><a href="#">page1drop</a></li>
<li><a href="#">page2drop</a></li>
</ul>
</li>
<li><a href="#">page3</a></li>
<li><a href="#">Page4</a></li>
<li role="separator" class="divider"><a href="#">Contact</a></li>
</ul>
</div>
</nav>
</div>
<div class="intro-top">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
文件的时间戳已被修改。像这样:
include
然后在# Somewhere in your CMakeLists.txt
include(external.stamp)
更新时重新运行CMake。
在你的情况下,也许你可以在提交时在git touch(空)文件中使用post-commit钩子,然后将其包含在external.stamp
中。