简体   繁体   English

Metabuild工具可同时处理多个交叉构建

[英]Metabuild tool to handle multiple cross-builds simultaneously

I have a mid-sized C++ project that runs on Linux, Windows and Mac OS X, both 32- and 64-bit. 我有一个在Linux,Windows和Mac OS X(32位和64位)上运行的中型C ++项目。 On some platforms it has more than one variant (eg Gtk-2 and Gtk-3 variants on Linux). 在某些平台上,它具有多个变体(例如Linux上的Gtk-2和Gtk-3变体)。 Being mostly a hobby programmer, I don't have resources for dedicated build machines for each platform. 作为主要的业余程序员,我没有用于每个平台的专用构建机器的资源。 So I installed cross-compilers for each one so that all building takes place on my Linux box. 因此,我为每个安装了交叉编译器,以便所有构建都在我的Linux机器上进行。

I want to be able to build all ten or so variants with a single command. 我希望能够用一个命令来构建所有十个左右的变体。 Right now I achieve this with a quick and dirty Python script that creates a makefile (actually I switched to ninja recently but it's not very relevant I guess). 现在,我用一个快速而又肮脏的Python脚本来实现这个目的,该脚本创建了一个makefile(实际上,我最近切换到了ninja,但是我猜它并不十分相关)。 It creates Windows installers, Debian packages and whatnot for each variant. 它为每个变体创建Windows安装程序,Debian软件包以及诸如此类的东西。 But I want a cleaner solution because my script is not gonna scale well as the project grows. 但是我想要一个更清洁的解决方案,因为随着项目的发展,我的脚本无法很好地扩展。

So my question is: What metabuild tools are able to create a single Makefile (or similar, like a ninja build file) that can handle multiple toolkits (cross-compilers) and custom commands (to create installers etc.)? 所以我的问题是: 哪些metabuild工具能够创建一个可以处理多个工具包(交叉编译器)和自定义命令(以创建安装程序等)的Makefile(或类似的忍者构建文件)?

I tried CMake (and some others) but it's not obvious to me how to work with multiple toolkits. 我尝试了CMake(和其他一些工具),但是对我来说,如何使用多个工具包还不是很明显。 Most tools seem to create one Makefile per configuration. 大多数工具似乎为每个配置创建一个Makefile。

Edit: Now, this answer claims that it's not possible. 编辑:现在, 答案声称这是不可能的。 I don't understand why. 我不明白为什么。 If I can do it with my 15 minutes python script, I feel like there must be a tool able to do it for me. 如果我可以使用15分钟的python脚本来完成此操作,那么我觉得必须有一个能够为我执行此操作的工具。

You can get this behaviour with CMake, using Toolchains and ExternalProject . 您可以使用ToolchainsExternalProject使用CMake来获得此行为。 Different makefiles will still be created behind the scenes, but that doesn't affect the user or the scalability of the project. 仍然会在后台创建不同的makefile,但这不会影响用户或项目的可伸缩性。

First, you will need to turn your project into a CMake project, with all the ifs and elses needed to build on all the different platforms in the CMakeLists.txt file. 首先,您需要将您的项目转换为CMake项目,并在CMakeLists.txt文件的所有不同平台上构建所有ifs和else。

You can create a set of toolchain files eg named <target>.toolchain and your cross build CMakeLists.txt where all the magic is done: 您可以创建一组工具链文件,例如名为<target>.toolchain并交叉构建CMakeLists.txt ,在其中,所有的魔术都已完成:

cmake_minimum_required(VERSION 3.0.2)
project(cross-build-project)
include(ExternalProject)

set(project_dir <path to your CMake project>)
set(targets_dir ${CMAKE_SOURCE_DIR}/targets)

function(add_target target_toolchain)
  get_filename_component(target_name ${target_toolchain} NAME_WE)
  ExternalProject_Add(
      ${target_name}
      PREFIX ${targets_dir}/${target_name}
      SOURCE_DIR ${project_dir}
      CMAKE_ARGS -DTOOLCHAIN_FILE=${target_toolchain}
      BINARY_DIR ${targets_dir}/${target_name}
    )
endfunction(add_target)

file(GLOB toolchains "*.toolchain")
foreach(toolchain ${toolchains})
  add_target(${toolchain})
endforeach()

This should provide a platform that can be adjusted to your specific needs and scale well with the project. 这应该提供一个可以根据您的特定需求进行调整并随项目进行适当扩展的平台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM