交叉编译时如何使用CMake管理安装目录? [英] How can I manage the installation directory with CMake when cross-compiling?

查看:97
本文介绍了交叉编译时如何使用CMake管理安装目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CMake和工具链文件交叉编译C库.我的工具链文件将 CMAKE_SYSROOT 设置为适当的值,因此编译没有问题.但是,在安装时,该库不会安装到 CMAKE_SYSROOT 指向的目录中.我可以通过运行 make install DESTDIR = xxx 来达到这种效果.

I am cross-compiling a C library using CMake and a toolchain file. My toolchain file sets CMAKE_SYSROOT to the appropriate value so compilation works with no issues. However, when installing, the library does not install to the directory pointed to by CMAKE_SYSROOT. I can achieve that effect by running make install DESTDIR=xxx though.

我了解这里有两个独立的概念:

I understand that there are two separate concepts here:

  • 交叉编译工具链,其中包含可以在我的本地体系结构上运行的二进制文件
  • CMAKE_SYSROOT 是目标体系结构文件系统的根目录,包含标头文件和库,并传递给例如gcc通过-sysroot 标志.
  • The cross-compilation toolchain, which consists of binaries that can be run on my local architecture
  • The CMAKE_SYSROOT which is the root directory of a target-architecture filesystems, containing header files and libraries, passed to e.g. gcc through the --sysroot flag.

我有两个问题:

  • 将交叉编译工具链所在的sysroot与将安装所有交叉编译库的sysroot混合起来是一个好主意吗?在我看来,它应该是相同的,但不能确定,对CMake来说,它们是不同的概念.在以下评论中更新: 已回答,这些确实是不同的概念.

  • Is it a good idea to conflate the sysroot where my cross-compilation toolchain lives, with the sysroot where all my cross-compiled libraries will be installed? It feels to me like it should be the same, but am not sure, and to CMake it appears they are distinct concepts. Update: answered in the comments below, these are indeed distinct concepts.

如上所述的交叉编译时,现代的CMake指定安装目录的方式是什么?更新:我认为这应该与 CMAKE_SYSROOT 相同,并且我认为CMake应该提供一种仅在某处定义一次的方法.

What is the modern CMake way to specify the installation directory when cross-compiling like described above? Update: I believe this should be the same as CMAKE_SYSROOT, and I feel CMake should offer a way to only define this once somewhere.

谢谢!

推荐答案

sysroot与安装目录(前缀)之间没有没有干扰.

There is no interference between sysroot and install directory (prefix).

Sysroot由 CMAKE_SYSROOT 变量给出,表示构建过程中使用的工具的前缀.

Sysroot is given by CMAKE_SYSROOT variable and denotes prefix for tools used during build process.

安装目录(前缀)由 CMAKE_INSTALL_PREFIX 变量给出,并表示安装时将在其中使用项目的路径.例如.带有安装前缀/usr/local 的项目的可执行文件 foo 预计将以/usr/local/bin/foo 的身份运行.

Install directory(prefix) is given by CMAKE_INSTALL_PREFIX variable and denotes the path, where the project will be used upon installation. E.g. with install prefix /usr/local the project's executable foo expects to be run as /usr/local/bin/foo.

请注意,通过默认的安装过程,CMake将文件安装到主机计算机上.要将文件安装到目标计算机上,需要调整此过程.用于 make install 的参数 DESTDIR = xxx 是一种将文件直接安装到目标计算机的方法.另一种方法是在主机上创建一个程序包(例如,使用CPack),然后将该程序包安装在 target 计算机上.

Note, that with default installation procedure, CMake installs files to the host machine. For install files onto the target machine, this procedure is needed to be adjusted. Parameter DESTDIR=xxx for make install is a way for install files directly to the target machine. Another way is to create a package (e.g. with CPack) on host, and install that package on target machine.

请注意,在上段中,交叉编译是否已无关紧要:可以在一台计算机上构建项目并安装到另一个,但类似的一个,没有任何交叉编译.

Note, that in the above paragraph it is irrelevant, whether cross-compilation took a place or not: it is possible to build the project on one machine and install it to the other, but similar one, without any cross-compilation.

这篇关于交叉编译时如何使用CMake管理安装目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆