简体   繁体   English

如何正确配置跨平台的Delphi XE2项目?

[英]How to properly configure a cross-platform Delphi XE2 project?

Right now I have 2 platforms (Mac and Win32) and 2 configs (Debug ans Release). 现在我有2个平台(Mac和Win32)和2个配置(Debug ans Release)。 Whole thing is under SVN. 整件事都在SVN下。

Here is layout for build output: 这是构建输出的布局:

.\App\$(Platform)\$(Config)

The code is split into few folders and located here: 代码分为几个文件夹,位于此处:

.\Code\MyProject.dpr
.\Code\Common\
.\Code\Forms\
.\Code\Source\

Common data files are here: 常见的数据文件在这里:

.\Data\ custom data files (dlls, textures, models, etc.)

This scheme has certain flaws though, which I need to resolve, but I don't know how to make it better. 这个方案有一定的缺陷,我需要解决,但我不知道如何让它变得更好。 I want to have only one set of data files in SVN under Data folder, but I need to have it copied to .\\App\\$(Platform)\\$(Config) paths automatically on build (note, certain data files are common for both platforms, but some are not). 我想在数据文件夹下的SVN中只有一组数据文件,但我需要在构建时自动将其复制到.\\App\\$(Platform)\\$(Config)路径(注意,某些数据文件是常见的两个平台,但有些不是)。 Is there a way to setup build process to copy the files, like it does with Deployment and PAServer? 有没有办法设置构建过程来复制文件,就像部署和PAServer一样? Alternatively I could setup paths to Data files as ..\\..\\Data , but that looks weird to me. 或者,我可以将数据文件的路径设置为..\\..\\Data ,但这对我来说很奇怪。

Maybe there are some other options I'm not aware of, or project layout could be changed completely? 也许还有其他一些我不知道的选项,或者项目布局可以完全改变? How would you setup the project structure and build for cross-platform compiling? 您将如何设置项目结构并构建跨平台编译?

Use the Post Build actions. 使用Post Build操作。

From Project Options | 来自项目选项| Build Events | 构建事件| Post Build Events | 发布活动| Commands 命令

如何设置

Further reading at 进一步阅读

  1. Creating Build Events 创建构建事件

  2. Pre and Post-Build Automation in Delphi Delphi中的预建和自建后自动化

Ok, this is an old post, but this is what I do in Delphi (and similarly in Visual Studio) to get around this problem of having the different platform/config output executables in different folders, but a common set of data. 好吧,这是一个老帖子,但这是我在Delphi中做的(并且类似地在Visual Studio中)来解决在不同文件夹中具有不同平台/配置输出可执行文件但是一组通用数据的问题。 I have a function to strip off the "sub" folder parts, then my app can always access the common data in the root of these folders (in your case .\\App). 我有一个功能来剥离“子”文件夹部分,然后我的应用程序可以始终访问这些文件夹的根目录中的公共数据(在您的情况下。\\ App)。 Of course you can add further platforms and configs to the function ProjectPath as required: 当然,您可以根据需要向ProjectPath添加更多平台和配置:

uses System.StrUtils;
...
function ProjectPath : string;
// Removes sub-folders created by the Delphi IDE, so the executable can refer to the source folder,
// rather than to where the executable is.
// Excludes trailiong path delimiter
begin
  Result := ExtractFilePath (Application.ExeName);
  Result := System.StrUtils.ReplaceText (Result, '\Win32'  , '');    // ReplaceText is case insensitive
  Result := System.StrUtils.ReplaceText (Result, '\Win64'  , '');
  Result := System.StrUtils.ReplaceText (Result, '\Debug'  , '');
  Result := System.StrUtils.ReplaceText (Result, '\Release', '');
  Result := ExcludeTrailingPathDelimiter (Result);
end;
...
ConnectionString := 'Database=' + ProjectPath +'\DATAFILE.DAT;etc.';

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

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