我应该在哪里安装 myproj-config.cmake 和 myproj-version-config.cmake?
假设您使用cmake进行构建配置来开发一些库,myproj
;支持cmake -install
(使用install()
命令);并通过CMake Config模式支持myproj
,即通过使相关.cmake
文件可访问相关项目。
现在,给定一个安装根目录 - 我应该在哪里安装项目的配置.cmake
文件?是否有惯用标准(ISH)位置?
- Sorush Khajepor的R& d博客建议 myproj - 这是最新的。
- Foonathan的博客建议放置config config
.cmake
coce>$ {lib_install_dir}/
中的文件。 falkor's Blog 。 - 文档 page 建议:
$ {lib_install_dir}/myproj/cmake
。
最受欢迎/最惯用的选择是什么?相对于其他方面的利弊是什么?
Suppose you're developing some library, myproj
, using CMake for build configuration; supporting the cmake --install
(using install()
commands); and supporting use of myproj
with CMake config mode, i.e. by making relevant .cmake
files accessible to dependent projects.
Now, ,given an install root directory - where should I install my project's configuration .cmake
files? Is there an idiomatic standard(ish) location?
- Sorush Khajepor's R&D blog suggests
${LIB_INSTALL_DIR}/cmake/myproj
- and it's the newest. - Foonathan's blog suggests placing the config
.cmake
files in${LIB_INSTALL_DIR}/
. So does Falkor's blog. - The documentation page for the
CMakePackageConfigHelpers
module suggests:${LIB_INSTALL_DIR}/myproj/cmake
.
What's the most popular/idiomatic choice? And what are its pros and cons relative to the other ones?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我主张设置一个缓存变量来覆盖它,并将其默认为
/cmake/ProjName
(正如您在答案中所建议的那样):我写了一篇博客文章,其中包含此内容的扩展版本回来时: https://alexreinking.com/blog/building-a-dual-shared-and-static-library-with-cmake.html
一般来说,设置一个
install()
除了“${SOME_CACHE_VARIABLE}”
之外的任何目标肯定会让某些软件包维护者感到头疼。如果GNUInstallDirs
未提供有效的配置点,您必须创建自己的配置点。I advocate for setting a cache variable to override this and defaulting it to
<LIBDIR>/cmake/ProjName
(as you suggest in your answer):I wrote a blog post with an expanded version of this a while back: https://alexreinking.com/blog/building-a-dual-shared-and-static-library-with-cmake.html
In general, setting an
install()
destination to anything other than"${SOME_CACHE_VARIABLE}"
is bound to cause headaches for some package maintainer. WhereGNUInstallDirs
doesn't provide a valid configuration point, you must create your own.我会赞成
${LIB_INSTALL_DIR}/cmake/myproj
。如果您要安装到某个特定于库的安装位置,例如
/opt/myproj
- 那么它实际上并不那么重要。但想一想当您安装到/usr/local
时会发生什么。${LIB_INSTALL_DIR}
中,该库现在将充满foo-config.cmake
和foo-version-config.cmake
>,而不仅仅是库文件(和一些子目录)。浏览和搜索的乐趣减少。myproj
和cmake
的路径元素,这样我们就会得到cmake/ 目录。恕我直言,这更干净、更方便。
I'll argue in favor of
${LIB_INSTALL_DIR}/cmake/myproj
.If you're installing to some library-specific install location, e.g.
/opt/myproj
- then it doesn't really matter all that much anyway. But think about what happens when you install to, say,/usr/local
.${LIB_INSTALL_DIR}
, that library now becomes full offoo-config.cmake
andfoo-version-config.cmake
, instead of just library files (and some subdirs). Less fun for browsing and searching.${LIB_INSTALL_DIR}/myproj/cmake
, then - the same thing happens, but with per-project subdirs instead of sets of files. Better, perhaps, but instead - why don't we just replace the path elements ofmyproj
andcmake
, and that way we would get acmake/
directory with many subdirs, instead. That's cleaner and more convenient IMHO.