CMAKE包括SRC并在不同的操作系统上安装目录
我正在学习使用cmake,并试图了解下载不同开源库中的文件应该在哪里放置文件。我说的是安装位置。
在Linux上包含目录,这是conduntion:/usr/local/includ/
Windows和Mac OS的默认位置是什么? 我知道这些位置可以改变,但是我应该放置它们的最常见位置是什么?
像这样的事情可以工作吗?
install(FILES include/sort/sort.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/sort)
I am learning to use CMake and trying to understand where should I place files from different open-source libraries when I download them. I am talking about install location.
On linux include directory is this by convention: /usr/local/include/
What is default location for Windows and Mac OS?
I know that these locations can change, but what is the most common location I should place them?
Can something like this work?
install(FILES include/sort/sort.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/sort)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在Windows上,安装前缀通常类似于
c:/program Files/< package name>
,unix上通常的安装前缀为/usr/usr/local
。通常,此目录包含之类的子目录,包括
包含标题,lib
包含(import)库,ect ..使用MSVC对Windows目标使用这些Incliption Directories的Windows目标无自动使用 。编译器。
这就是为什么您应该尝试使用
find_package
的原因,如果安装提供了软件包配置脚本或查找脚本,该脚本或查找脚本是在您的CMake Project中只有2个命令添加任何依赖项的附加益处((find_package
和target_link_libraries
)。如果软件包是在默认位置安装的,则find_package
应该能够找到要加载的脚本,而无需手动指定安装位置。对于不提供此类信息的软件包,编写自己创建导入目标的查找脚本可以轻松重复使用。
通常,您应该避免将绝对目标路径进行硬编码进入安装路径。而是使用相对于安装前缀的目标路径,因为安装前缀可能会被覆盖,例如,如果用户通过
cmake -install< build build dir> - prefix<安装目录>
或使用cpack
生成软件包时。通常,即使在源(似乎正在这样做)中,您将库的公共标头放在单独的目录中,并安装目录,从而根据
CMAKE根据其默认位置选择目标系统的Include Files的默认位置。
On windows usually the install prefix is something like
C:/Program Files/<Package Name>
, the usual install prefix on Unix being/usr/local
. Usually this directory contains subdirectories likeinclude
containing the headers,lib
containing (import) libraries, ect..Using MSVC for the Windows targets those include directories are not automatically available to the compiler.
This is the reason why you should try to use
find_package
, if package configuration scripts or find scripts are provided by the installation which has the added benefit of also adding any dependencies with just 2 commands in your cmake project (find_package
andtarget_link_libraries
). If the package is installed in the default location,find_package
should be able to locate the scripts to load without specifying the install location manually.For packages not providing this kind of info, writing a find script of your own creating imported targets allows for easy reuse.
In general you should avoid hardcoding absolute destination paths into your install paths. Instead use destination paths relative to the install prefix, since the install prefix may be overwritten, e.g. if the user runs the installation via
cmake --install <build dir> --prefix <install directory>
or when usingcpack
to generate a package.Usually you place public headers of your library in a separate directory, even in your sources (which you seem to be doing) and install the directory with
Resulting in cmake choosing the exact location based on its defaults for the include files for the target system.
使用跨平台软件包管理器,而不是手动管理随附的目录。它处理不同平台之间的差异。
vcpkg 是当前可用的最好的软件包管理器之一。您可以通过
Use a cross-platform package manager instead of manually managing the included directories. It handles the differences between different platforms.
vcpkg is one of the best package managers currently available. You can easily use it via project_options.