我是CMake的新手,我用它进行交叉编译。
我在Debian下一起使用clang和wclang分别为Linux和Windows编译。
我的问题 - 因为我是CMake的交叉编译流程的新手 - 是我:
(a)在CMakeLists.txt期间某处的编译器之间切换,
(b)仅运行一次cmake
,但每个平台运行make install
,或
(c)为每个平台运行一次cmake
和make install
,例如
$ export CC=/usr/bin/clang
$ cmake ..
$ make install
$ export CC=/usr/bin/wclang
$ cmake ..
$ make install
(等)
答案 0 :(得分:2)
C),每个平台单独调用。我还建议在构建之间清除二进制目录,或者如果要保留构建,则为每个构建使用单独的目录。
设置通常在工具链文件中完成,而不是命令行(用于可重复性):
$ cmake --help-variable CMAKE_TOOLCHAIN_FILE
CMAKE_TOOLCHAIN_FILE
--------------------
Path to toolchain file supplied to ``cmake(1)``.
This variable is specified on the command line when cross-compiling with CMake.
It is the path to a file which is read early in the CMake run and which specifies
locations for compilers and toolchain utilities, and other target platform and
compiler related information.
一个简单的工具链文件可能如下所示:
# Name of the target operating system
set( CMAKE_SYSTEM_NAME Windows )
# Which compilers to use
find_program( CMAKE_C_COMPILER NAMES /opt/mxe/usr/bin/x86_64-w64-mingw32.static-gcc )
find_program( CMAKE_CXX_COMPILER NAMES x86_64-w64-mingw32.static-g++ )
find_program( CMAKE_RC_COMPILER NAMES x86_64-w64-mingw32.static-windres )
# Where to look for resources
set( CMAKE_FIND_ROOT_PATH /opt/mxe/usr/x86_64-w64-mingw32.static/ )
# Adjust find_*() behavior:
# Headers and libs from the target environment,
# programs from the host environment.
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
某些交叉编译环境(如MXE)附带预先制作的工具链文件和调用它们的包装器。 (特别是MXE,您运行i686-w64-mingw32.static-cmake
而不是标准cmake
来配置您的构建。)
答案 1 :(得分:1)
应为每个目标重复所有步骤(cmake - make - install)。也就是说," c"在你的清单中。
某些开发环境,例如Visual Studio,支持多配置,即项目可以配置一次,每个目标配置只需要构建。这种方式项目可以在Debug和Release模式下编译,也可以在x86和x86-64中编译。
但Windows和Linux目标在任何情况下都需要不同的配置步骤(cmake
运行)。