如何告诉 CMake 安装目录依赖于虚假目标?
如何在 CMake 中实现以下功能(使用版本 2.8.5)?我有一个由名为 doc
的自定义目标生成的文档,我希望在安装或 CPack'ing 时包含该文档的输出。
add_custom_target( doc "${DOXYGEN_EXECUTABLE}" Doxyfile )
install( DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION doc )
Doxyfile
告诉 Doxygen 将文档放在 ${CMAKE_BINARY_DIR}/doc
中。
如果我在构建目录中执行此操作:
make doc
cpack
一切正常,因为第一行创建 install
目标所依赖的目录。
但是,如果我有一个新的构建(因此 ${CMAKE_BINARY_DIR}/doc
尚不存在),并且我直接调用 CPack:
cpack
那么它会抱怨找不到 ${CMAKE_BINARY_DIR}/ doc
:
CMake Error at <snip>/build/cmake_install.cmake:36 (FILE):
file INSTALL cannot find "<snip>/build/doc".
我也尝试了以下操作:
add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile )
install( DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION doc )
但我仍然遇到相同的 CPack 错误,并且在构建目录中执行 make doc
也不起作用。
因此,如果我在 cpack
之前手动执行 make doc
,它可以与本文顶部的配置配合使用,但是我如何告诉 cmake/cpack install
指令依赖于自定义目标 doc
,以便在调用 cpack
或 make install
时自动生成文档?
谢谢!
How do I achieve the following in CMake (using version 2.8.5)? I have documentation generated by a custom target named doc
, the output of which I would like to include when installing or CPack'ing.
add_custom_target( doc "${DOXYGEN_EXECUTABLE}" Doxyfile )
install( DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION doc )
The Doxyfile
tells Doxygen to put out the documentation at ${CMAKE_BINARY_DIR}/doc
.
If I do this in the build directory:
make doc
cpack
things works fine, because the first line creates the directory on which the install
target depends.
However, if I have a fresh build (so ${CMAKE_BINARY_DIR}/doc
does not exist yet), and I invoke CPack directly:
cpack
then it complains that it cannot find ${CMAKE_BINARY_DIR}/doc
:
CMake Error at <snip>/build/cmake_install.cmake:36 (FILE):
file INSTALL cannot find "<snip>/build/doc".
I have also tried the following:
add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile )
install( DIRECTORY ${CMAKE_BINARY_DIR}/doc DESTINATION doc )
but I still get the same CPack error, and doing make doc
in the build directory does not work either.
So if I do the make doc
manually before cpack
it works with the configuration at the top of this post, but how can I tell cmake/cpack that the install
directive depends on the custom target doc
, so that building the documentation happens automatically when calling cpack
or make install
?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能您需要
ALL
关键字:更新:
目前 cmake 不提供向其内置目标添加自定义依赖项的选项(例如
all
、安装
、测试
等)。而且似乎在不久的将来它不会提供此选项 - 请参阅 http:// public.kitware.com/Bug/view.php?id=8438但是,仍然可以通过一些技巧/解决方法来实现所需的行为。例如,您可以在安装步骤开始时直接运行 make 工具。
因此使用风险自负:
Probably you need
ALL
keyword:Update:
Currently cmake does not provide an option to add custom dependencies to its built-in targets (such as
all
,install
,test
, etc). And it seems that it will not provide this option in near future - see http://public.kitware.com/Bug/view.php?id=8438However it is still possible to achieve desired behavior with some hacks/workarounds. For example you can directly run make tool at the beginning of install step.
So use on your own risk:
我在 CMakeList.txt 中对此进行了一些更改,以便在 Linux 和 Windows 上构建
这是我的解决方案。仅当需要 doc 或安装目标时(在 Visual Studio 上,编译 INSTALL 项目时),它才不会始终构建“全部”文档。
这个解决方案并不完整。例如,它不适用于 MinGW,但是......
希望它对某人有用。
问候,
亚历克斯
I have changed this a bit in my CMakeList.txt in order to build on both Linux and Windows
This is my solution. It doesn't build the documentation always "ALL" only when doc or install target are required (On Visual Studio, whe INSTALL project is compiled).
This solution is not complete. It will not work with MinGW, for instance, but...
Hope it will be useful for someone.
Regards,
Alex