通过使用特定于平台的项目文件或使用项目生成器来构建自动化?

发布于 2024-08-16 11:07:00 字数 547 浏览 11 评论 0原文

有一些构建系统能够生成特定于平台的项目文件,例如 Visual Studio slnvcprojvcxproj 文件或 XCode< OS X 下的 /code> xcodeproj 项目。

其中之一是 CMake,但我发现对此的支持非常有限,有缺陷,而且很难用较新的版本(如 VS)保持更新2010)。

此外,至少 CMake 缺少对 Visual Studio 属性页的支持,这使得管理和更改项目范围的配置变得更加困难 - 例如为所有项目启用/禁用代码分析。

解决上述问题的方法是为每个平台手动创建项目文件 - 在我的例子中只有两个,但即使有更多,数量也不应该太大。

将特定于平台的构建命令调用到通用构建自动化脚本中非常容易。例如,我使用 waf (Python) 在几个项目上自动执行此操作,而不使用其自己的构建部分。

我想看看您会选择什么:尝试修复/维护项目生成器或保留单独的项目文件?

There are some build systems that are able to generate platform specific project files like Visual Studio sln,vcproj,vcxproj files or XCode xcodeproj projects under OS X.

One of them is CMake but I found out that the support for this is quite limited, buggy and that is very hard to keep it updated with newer versions (like VS 2010).

Also, at least CMake, is missing support for property pages for Visual Studio and this makes harder to manage and change project wide configurations - like enabling/disabling Code Analysis for all projects.

An workaround to the above issue is to manually create project files for each platform - in my case there are only two, but even with more the number should not be so big.

It is quite easy to call the platform specific build commands into a generic build automation script. For example I used waf (Python) for automating this on few projects without using its own build part.

I would like to see what you would choose between: trying to repair/maintain project generators or keeping separated project files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我ぃ本無心為│何有愛 2024-08-23 11:07:00

这就是我们所做的,它可能不是最好的方法,但它对我们来说确实很好,我们发现维护起来并不太难,也许你会觉得它很有趣。

我们的主要平台是windows,几乎所有的开发都是在VS IDE中完成的。对于其他平台(目前只有一些 Linux 版本),我们专门使用 CMake。基本上我们选择了“尝试修复/维护项目生成器”方式,但以 Visual Studio 项目文件作为起点。

  • 我们使用 Visual Studio 项目文件作为项目中所有文件的容器
  • 所有构建选项都在属性表中设置,每个项目都有一个标准集,最终还有一些额外的表来拉入某些库等,
  • 我们有一些简单的脚本,允许批量添加/删除属性表,
  • 所有属性表都有一个 cmake 对应项;两者都保存在同一目录中,如果我们更新其中一个,我们也会始终更新对应的目录。这不是通过脚本完成的,我承认这是“复杂”的部分:尽管我们确实非常重视宏,但总有一些选项在一个平台上可用,而在另一个平台上则不然。
  • 我们有一个将 vcproj 文件转换为 cmake 文件的脚本,它基本上创建了一个 cmake 文件,其中包括相应的 cmake 属性表,并包含 vcproj 具有的所有源文件。
  • 最后但并非最不重要的一点是,我编写了一个可以在我们使用的所有平台上运行的构建服务器。它使用 msbuild 或 cmake 进行构建,这是保持该系统正常运行的关键:我们所做的每个更改都会在至少两台机器上触发构建+测试,因此我们立即知道一切是否仍然正常。

我们最近开始使用VS2010,迁移只花了大约一天的时间:首先我们让VS转换我们所有的项目和属性表,然后我们对脚本进行一些调整以处理新的xml文件格式。

编辑

抱歉,我无法发布脚本、公司政策,希望您理解。
不过,一点伪代码没有问题。在 VS2008 项目文件中添加/删除属性表如下:

foreach proj in projectfiles //list of vcproj files
  foreach config in configuration //configurations eg 'Debug|Win32, Debug|x64'
    f = OpenFile( proj );
      //find start of Configuration element, then get what's after InheritedPropertySheets=
    propsheets = GetPropSheetsForConfig( f, config );
    propsheets = DoAction( action, args, propsheets ); //action is add/remove/.. with argument args
    SetPropSheetsForConfig( f, propsheets );

对于 CMakeLists 文件,这几乎是相同的,除了脚本在“include(..)”行上工作。

从 vcproj 转换为 CMakeLists:

f = OpenFile( proj );
projname = GetProjectName( f );
sources = GetSourceFiles( f ); //all File/RelativePath elements under Filter 'Source Files'
sources = CheckFilter( sources ); //apply rules to include/exclude platform specific files
propsheets[] = GetPropSheetsForConfig( f, configs[] );

fout = CreateCMakeFromProj( proj ); //CMakeLists.txt in corresponding directory
WriteCMakeHeader( fout, projname );
WriteCMakeSources( sources );
WriteCMakeIncludes( configs[], propsheets[] ); //write includes, conditional on CMAKE_BUILD_TYPE

构建服务器现在是相当先进的材料,但一开始它只是一个 TCP 侦听器:

  • 等待连接
  • 获取可选参数(属性表/操作)
  • 存储库的更新
  • 最终运行属性表的批处理脚本使用给定的参数
  • 启动命令行完全重建+测试,捕获文件
  • 解析文件中包含“错误”的行的输出,邮件结果

Here's what we do, it might not be the best way, but it works really good for us and we found that it's not too hard to maintain, maybe you find it interesting.

Our main platform is windows, nearly all development is done in the VS IDE. For the other platforms (only some linux flavors for now) we use CMake exclusively. Basically we chose the "trying to repair/maintain project generators" way, but with Visual Studio project files as a starting point.

  • we use visual studio project files as a container for all files in a project
  • all build options are set in property sheets, each project has a standard set and eventually some extra sheets to pull in certain libraries etc
  • we have some simple scripts that allow to add/remove property sheets in one batch
  • all property sheets have a cmake counterpart; both are kept in the same directory, and if we update one, we update the counterpart as well, always. This is not done with a script, and I admit this is the 'complicated' part: although we realy heavily on macros, there are always options that are available on one platform but ot on the other.
  • we have a script that converts vcproj files into cmake files, it basically creates a cmake file which includes the corresponding cmake property sheets and which contains all source files the vcproj has.
  • last but not least I wrote a build server that runs on all platforms we use. It builds using msbuild or cmake, and it is the key in keeping this system working: each change we make triggers a build+tests on at least two machines, so we know immedeatly if all is stil fine.

We recently started using VS2010, and the migration only took about a day: first we let VS convert all our projects and property sheets, then we made some adjustments to the scripts to handle the new xml file formats.

Edit

sorry but I cannot post the scripts, company policy, hope you understand.
A bit of pseudocode is no problem though. Adding/removing property sheets in VS2008 project files goes like this:

foreach proj in projectfiles //list of vcproj files
  foreach config in configuration //configurations eg 'Debug|Win32, Debug|x64'
    f = OpenFile( proj );
      //find start of Configuration element, then get what's after InheritedPropertySheets=
    propsheets = GetPropSheetsForConfig( f, config );
    propsheets = DoAction( action, args, propsheets ); //action is add/remove/.. with argument args
    SetPropSheetsForConfig( f, propsheets );

For the CMakeLists files this is pretty much the same, except the script works on the 'include(..)' lines.

Convertig from vcproj to CMakeLists:

f = OpenFile( proj );
projname = GetProjectName( f );
sources = GetSourceFiles( f ); //all File/RelativePath elements under Filter 'Source Files'
sources = CheckFilter( sources ); //apply rules to include/exclude platform specific files
propsheets[] = GetPropSheetsForConfig( f, configs[] );

fout = CreateCMakeFromProj( proj ); //CMakeLists.txt in corresponding directory
WriteCMakeHeader( fout, projname );
WriteCMakeSources( sources );
WriteCMakeIncludes( configs[], propsheets[] ); //write includes, conditional on CMAKE_BUILD_TYPE

The build server is quite advanced material now, but in the beginning it was just a TCP listener:

  • await connection
  • get optional arguments (property sheets/action)
  • update of the repository
  • eventually run the batch script for the property sheets with the given arguments
  • start command line full rebuild + tests, capture output in file
  • parse file for lines containing 'error', mail results
热血少△年 2024-08-23 11:07:00

我的所有项目都是跨平台的,我更喜欢解决方法。
使用 Scons 维护跨平台项目几乎不需要任何工作。一个良好定义的环境适用于大多数项目,并为每个项目/子项目使用一个模板。您还可以完全控制构建过程,从而轻松使用领域特定语言、进行代码生成、管理源代码控制。

当你了解Python时,学习Scons非常简单,如果不了解Python,你就会发现两种伟大的技术,而不是一种;)

All my projects are cross platform, and my preference is the workaround.
With Scons maintaining a cross platform project is little or no work. One good defined environment will work for most project, and use a template for each project/subproject. You also have the benefit of complete control over the building process, allowing you to use domain specific languages, do code generation, manage source control, with ease.

Learning Scons is dead simple when you know python, without knowing python, you are disconvering two great technologies not one ;)

暖风昔人 2024-08-23 11:07:00

我们将 boost.build 用于我们的平台项目。它适用于 C++ 库项目。我们喜欢它,因为我们只需要维护一个脚本,并且它与 Boost.Test 集成得很好。

它确实有一个非常陡峭的学习曲线,而且文档也很差。但它在我们工作的两个平台 Windows 和 Linux 上运行良好。

We use boost.build for our platform projects. It works well for C++ library projects. We like it because we only need to maintain one script and it integrates with Boost.Test well.

It does have a very steep learning curve and the documentation is quite poor. But it does its work well on Windows and Linux, the two platforms that we work on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文