chore: 支持通过 props 和命令行参数更改编译选项

This commit is contained in:
Xu 2025-07-01 14:44:25 +08:00
commit d2f4c31599
12 changed files with 50 additions and 50 deletions

View file

@ -14,6 +14,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00AB63C3-0CD3-4944-B8E6-58C86138618D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
src\BuildOptions.props = src\BuildOptions.props
src\Common.Post.props = src\Common.Post.props
src\Common.Pre.props = src\Common.Pre.props
Directory.Build.props = Directory.Build.props

View file

@ -5,7 +5,7 @@ MagpieFX is based on DirectX 11 compute shader
//!VERSION 4
// Use the "USE" directive to declare the features being utilized. The following values can be combined:
// MulAdd: Enables the "MulAdd" function.
//!USE MulAdd, Dynamic
//!USE MulAdd
// Use the "CAPABILITY" directive to declare the capabilities supported by this effect. Whether they
// are enabled depends on user configuration. The following values can be combined:
// FP16: Declares support for FP16.

22
src/BuildOptions.props Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- 不要直接修改这些选项,应通过 BuildOptions.props.user 或命令行参数覆盖 -->
<PropertyGroup>
<CommitId></CommitId>
<MajorVersion></MajorVersion>
<MinorVersion></MinorVersion>
<PatchVersion></PatchVersion>
<VersionTag></VersionTag>
<!-- 窗口模式缩放时把用于调整窗口尺寸的辅助窗口标示出来 -->
<DebugBorder>false</DebugBorder>
<!-- 在性能分析器上显示调试信息 -->
<DebugInfoOnOverlay>false</DebugInfoOnOverlay>
<!--使用 composition swapchain 呈现-->
<UseCompSwapchain>false</UseCompSwapchain>
</PropertyGroup>
<!-- 用户自定义编译选项 -->
<Import Project="$(MSBuildThisFileDirectory)BuildOptions.props.user" Condition="Exists('$(MSBuildThisFileDirectory)BuildOptions.props.user')" />
</Project>

View file

@ -15,8 +15,11 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<PreprocessorDefinitions>_WINDOWS;WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;WINRT_NO_MODULE_LOCK;WIL_SUPPRESS_EXCEPTIONS;WIL_USE_STL=1;NOGDICAPMASKS;NOICONS;NOATOM;NOCLIPBOARD;NODRAWTEXT;NOMEMMGR;NOMETAFILE;NOMINMAX;NOOPENFILE;NOSCROLL;NOSERVICE;NOSOUND;NOTEXTMETRIC;NOCOMM;NOKANJI;NOHELP;NOPROFILER;NODEFERWINDOWPOS;NOMCX;NO_SHLWAPI_PATH;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(CommitId)'!=''">MAGPIE_COMMIT_ID=$(CommitId);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(MajorVersion)'!='' And '$(MinorVersion)'!='' And '$(PatchVersion)'!='' And '$(VersionTag)'!=''">MAGPIE_VERSION_MAJOR=$(MajorVersion);MAGPIE_VERSION_MINOR=$(MinorVersion);MAGPIE_VERSION_PATCH=$(PatchVersion);MAGPIE_VERSION_TAG=$(VersionTag);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(CommitId)'!=''">MP_COMMIT_ID=$(CommitId);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(MajorVersion)'!='' And '$(MinorVersion)'!='' And '$(PatchVersion)'!='' And '$(VersionTag)'!=''">MP_MAJOR_VERSION=$(MajorVersion);MP_MINOR_VERSION=$(MinorVersion);MP_PATCH_VERSION=$(PatchVersion);MP_VERSION_TAG=$(VersionTag);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(DebugBorder)'=='true'">MP_DEBUG_BORDER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(DebugInfoOnOverlay)'=='true'">MP_DEBUG_INFO_ON_OVERLAY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(UseCompSwapchain)'=='true'">MP_USE_COMPSWAPCHAIN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
@ -46,7 +49,7 @@
</ItemDefinitionGroup>
<!-- 所有项目共享的头文件 -->
<Import Project="$(SolutionDir)\src\Shared\Shared.vcxitems" Label="Shared" />
<Import Project="$(MSBuildThisFileDirectory)Shared\Shared.vcxitems" Label="Shared" />
<!-- Conan 依赖 -->
<Import Project="$(SolutionDir)obj\$(Platform)\$(Configuration)\_ConanDeps\$(MSBuildProjectName)\conandeps.props" Condition="Exists('$(SolutionDir)obj\$(Platform)\$(Configuration)\_ConanDeps\$(MSBuildProjectName)\conandeps.props')" />

View file

@ -24,4 +24,7 @@
<IsPackaged>$(Configuration.EndsWith('Packaged'))</IsPackaged>
<DefaultLanguage>en-US</DefaultLanguage>
</PropertyGroup>
<!-- 编译选项 -->
<Import Project="$(MSBuildThisFileDirectory)BuildOptions.props" />
</Project>

View file

@ -856,7 +856,7 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
return needRedraw;
}
#ifdef MP_DEBUG_OVERLAY
#ifdef MP_DEBUG_INFO_ON_OVERLAY
static std::string RectToStr(const RECT& rect) noexcept {
return fmt::format("{},{},{},{} ({}x{})",
rect.left, rect.top, rect.right, rect.bottom,
@ -995,7 +995,7 @@ bool OverlayDrawer::_DrawProfiler(const SmallVector<float>& effectTimings, uint3
showPasses = false;
}
#ifdef MP_DEBUG_OVERLAY
#ifdef MP_DEBUG_INFO_ON_OVERLAY
ImGui::Spacing();
if (ImGui::CollapsingHeader("调试信息", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::TextUnformatted(StrHelper::Concat("源矩形: ",

View file

@ -72,8 +72,8 @@ ScalingError ScalingWindow::Create(HWND hwndSrc, ScalingOptions options) noexcep
}
Logger::Get().Info(fmt::format("缩放开始\n\t程序版本: {}\n\tOS 版本: {}\n\t管理员: {}",
#ifdef MAGPIE_VERSION_TAG
STRING(MAGPIE_VERSION_TAG),
#ifdef MP_VERSION_TAG
STRING(MP_VERSION_TAG),
#else
"dev",
#endif

View file

@ -59,16 +59,16 @@ hstring AboutViewModel::Version() const noexcept {
ResourceLoader::GetForCurrentView(CommonSharedConstants::APP_RESOURCE_MAP_ID);
return hstring(StrHelper::Concat(
resourceLoader.GetString(L"About_Version_Version"),
#ifdef MAGPIE_VERSION_TAG
#ifdef MP_VERSION_TAG
L" ",
WIDEN(STRING(MAGPIE_VERSION_TAG)) + 1,
WIDEN(STRING(MP_VERSION_TAG)) + 1,
#else
L" dev",
#endif
#ifdef MAGPIE_COMMIT_ID
#ifdef MP_COMMIT_ID
L" | ",
resourceLoader.GetString(L"About_Version_CommitId"),
L" " WIDEN(STRING(MAGPIE_COMMIT_ID)),
L" " WIDEN(STRING(MP_COMMIT_ID)),
#endif
L" | "
#ifdef _M_X64
@ -104,7 +104,7 @@ void AboutViewModel::IsCheckForPreviewUpdates(bool value) {
bool AboutViewModel::IsCheckForUpdatesButtonEnabled() const noexcept {
// 只有发布版本能检查更新
#ifdef MAGPIE_VERSION_TAG
#ifdef MP_VERSION_TAG
return !IsCheckingForUpdates() && !IsDownloadingOrLater();
#else
return false;

View file

@ -26,8 +26,8 @@ using namespace Windows::Web::Http;
namespace Magpie {
static constexpr Version MAGPIE_VERSION(
#ifdef MAGPIE_VERSION_MAJOR
MAGPIE_VERSION_MAJOR, MAGPIE_VERSION_MINOR, MAGPIE_VERSION_PATCH
#ifdef MP_MAJOR_VERSION
MP_MAJOR_VERSION, MP_MINOR_VERSION, MP_PATCH_VERSION
#else
0, 0, 0
#endif
@ -37,7 +37,7 @@ static constexpr uint32_t MD5_HASH_LENGTH = 16;
void UpdateService::Initialize() noexcept {
// 只有发布版本能检查更新
#ifdef MAGPIE_VERSION_TAG
#ifdef MP_VERSION_TAG
AppSettings& settings = AppSettings::Get();
if (settings.IsAutoCheckForUpdates()) {
_StartTimer();

View file

@ -74,8 +74,8 @@ int APIENTRY wWinMain(
CommonSharedConstants::REGISTER_TOUCH_HELPER_LOG_PATH);
Logger::Get().Info(fmt::format("程序启动\n\t版本: {}\n\tOS 版本: {}\n\t管理员: {}",
#ifdef MAGPIE_VERSION_TAG
STRING(MAGPIE_VERSION_TAG),
#ifdef MP_VERSION_TAG
STRING(MP_VERSION_TAG),
#else
"dev",
#endif

View file

@ -52,14 +52,3 @@ static uint32_t Measure(const Fn& func) noexcept {
return (uint32_t)dura.count();
}
// 这些宏用于实验或调试
// 窗口模式缩放时把用于调整窗口尺寸的辅助窗口标示出来
// #define MP_DEBUG_BORDER
// 在性能分析器上显示调试信息
// #define MP_DEBUG_OVERLAY
// 使用 composition swapchain 呈现
// #define MP_USE_COMPSWAPCHAIN

View file

@ -1,23 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
@ -31,6 +13,7 @@
<PropertyGroup>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="..\Common.Pre.props" />
<PropertyGroup>
<ConfigurationType>Utility</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
@ -97,8 +80,7 @@ ConanFile = conanFiles.ToArray();
<ConanInstallArch Condition="'$(Platform)' == 'ARM64'">armv8</ConanInstallArch>
</PropertyGroup>
<!-- 批量处理 _OutOfDateConanFile 中的元素。从 ConanCenter 下载的包没有 pdb会引发链接警告。 -->
<!-- 我们希望自己编译依赖且使用缓存,但很遗憾 conan 不支持。 -->
<Exec Condition="'@(_OutOfDateConanFile)' != ''" Command="conan install &quot;%(_OutOfDateConanFile.FullPath)&quot; -pr:a=conanprofile.txt --output-folder $(IntDir)%(_OutOfDateConanFile.ProjectName) --build=missing -s build_type=$(Configuration) -s arch=$(ConanInstallArch) --update" />
<!-- 批量处理 _OutOfDateConanFile 中的元素 -->
<Exec Condition="'@(_OutOfDateConanFile)' != ''" Command="conan install &quot;%(_OutOfDateConanFile.FullPath)&quot; -pr:a=conanprofile.txt --output-folder $(IntDir)%(_OutOfDateConanFile.ProjectName) -s build_type=$(Configuration) -s arch=$(ConanInstallArch) --build=missing --no-remote --update -c tools.info.package_id:confs=['tools.build:cxxflags']" />
</Target>
</Project>