2

There is this project kept in a git repository, which we build with cmake and ninja. We are using globbing expressions/functions to collect all the source files to be compiled. That means that every time a file is added/removed, cmake has to be called to re-parse the directories.

We have seen this is bringing some time loss when somebody pulls after somebody has pushed some new file, without modifications to any of the cmake files. I say this last thing because a modification to any of the cmake files would trigger a call to cmake (by ninja), and everything would be fine.

How can I obtain that cmake is called before/when I start building again my project after pulling? (Note: it does not matter if cmake is run a little bit more than necessary, as long as it is not always)

I am building out of source, furthermore using several build directory where for example I test different compilers.

I am exploring some solutions. One using git hooks script, namely post-merge (but how can I guarantee I will retrieve the path to source/CMakeLists.txt to touch it? Can I commit the script so that it runs for everybody? It is not a public project). I don't know if it is relevant, we mainly use git through graphic interface (TortoiseGit).

The other possible solution would be using in cmake a custom target dependent on the content of .git\refs\heads directory, but I cannot think of a combination that could really work...

Some links:

  1. http://git-scm.com/book/en/Customizing-Git-Git-Hooks
  2. https://www.kernel.org/pub/software/scm/git/docs/githooks.html

CMake commands: http://www.cmake.org/cmake/help/v2.8.11/cmake.html

4

1 回答 1

1

放入post-merge脚本文件.git/hooks似乎可以解决问题:

#!/bin/sh
#

touch source/CMakeLists.txt

执行路径显然是项目的根目录,非常适合这种操作。我通过从项目的一个“随机”子文件夹中调用 TartoiseGit 上下文菜单中的“pull”来测试这一点。这里有一些关于如何测试脚本的说明

缺点:如果有人在他的编辑器中修改 CMakeLists.txt,有一些未保存的修改,如果太快回答“磁盘上的文件已更改...”提示,他可能会丢失一些工作。


然后,为了使这个脚本成为存储库的一部分,我发现以下解决方案似乎对我们的(非公共)项目有好处。

1) 为 git hook 脚本创建一个文件夹(例如 zz_gitHookScripts)并放置每个人都应该使用的文件。将其添加到存储库。
2)在 CMakeLists.txt 中添加这样的内容,以便在第一次运行 cmake 时将文件放在有效目录中(并且,鉴于上述情况,这将在我们拉后第一次构建时发生,也是第一次时间,因为 CMakeLists.txt 通过此编辑被修改):

file(GLOB HOOK_SCRIPTS zz_gitHookScripts/*)
if (HOOK_SCRIPTS)
    file(COPY ${HOOK_SCRIPTS} DESTINATION ${CMAKE_SOURCE_DIR}/../.git/hooks) 
endif (HOOK_SCRIPTS)

post-applypatch在补丁的情况下,可能会使用等效的钩子。

缺点:

  • 它不会在 stash 的情况下触发(用户存储添加/删除文件的更改,必须仍然记得手动运行 cmake),或者在补丁的情况下
  • 用户无法个性化挂钩脚本
  • 删除一些我们不想再使用的钩子脚本可能很复杂
  • 一般来说,所有分支都必须共享相同的钩子

无论如何,像这样它对我们的需求有好处。

于 2013-07-24T15:49:01.013 回答