Skip to content

Commit

Permalink
chore: 依赖 dll 移到 third_party 文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Mar 10, 2024
1 parent a6cc7fa commit 06ca4e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
28 changes: 19 additions & 9 deletions src/Common.Post.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,25 @@
</Link>
</ItemDefinitionGroup>

<!--TensorRT -->
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\include;S:\TensorRT-8.6.1.6\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\lib\x64;S:\TensorRT-8.6.1.6\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<!--TensorRT -->
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\include;S:\TensorRT-8.6.1.6\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\lib\x64;S:\TensorRT-8.6.1.6\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>

<Target Name="FixDllPath" BeforeTargets="PrepareForBuild">
<ItemGroup>
<DirectMLContent Include="@(Content)" Condition="'%(Filename)' == '$(Microsoft_AI_DirectML_Library_Basename)' or '%(Filename)' == '$(Microsoft_AI_DirectML_Debug_Layer_Basename)'" />
<Content Remove="@(DirectMLContent)" />
<Content Include="@(DirectMLContent)">
<TargetPath>third_party\%(FileName)%(Extension)</TargetPath>
</Content>
</ItemGroup>
</Target>

<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
Expand Down
1 change: 1 addition & 0 deletions src/Magpie.App/Magpie.App.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<SubSystem>Console</SubSystem>
<AdditionalDependencies>kernel32.lib;ole32.lib;oleaut32.lib;user32.lib;gdi32.lib;$(OutDir).\Magpie.Core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>Magpie.App.def</ModuleDefinitionFile>
<DelayLoadDLLs>d3d12.dll;cudart64_12.dll;onnxruntime.dll;DirectML.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
19 changes: 13 additions & 6 deletions src/Magpie/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
#include "StrUtils.h"

// 将当前目录设为程序所在目录
static void SetCurDir() noexcept {
wchar_t curDir[MAX_PATH] = { 0 };
GetModuleFileName(NULL, curDir, MAX_PATH);
static std::wstring SetCurDir() noexcept {
std::wstring curDir(MAX_PATH, L'\0');
curDir.resize(GetModuleFileName(NULL, curDir.data(), MAX_PATH));

for (int i = (int)StrUtils::StrLen(curDir) - 1; i >= 0; --i) {
int i = (int)curDir.size() - 1;
for (; i >= 0; --i) {
if (curDir[i] == L'\\' || curDir[i] == L'/') {
break;
} else {
curDir[i] = L'\0';
}
}
curDir.resize(i);

SetCurrentDirectory(curDir);
SetCurrentDirectory(curDir.c_str());
return curDir;
}

int APIENTRY wWinMain(
Expand All @@ -51,7 +54,11 @@ int APIENTRY wWinMain(
// 见 https://kennykerr.ca/2018/03/24/cppwinrt-hosting-the-windows-runtime/
winrt::init_apartment(winrt::apartment_type::single_threaded);

SetCurDir();
std::wstring curDir = SetCurDir();

SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
curDir += L"\\third_party";
AddDllDirectory(curDir.c_str());

auto& app = Magpie::XamlApp::Get();
if (!app.Initialize(hInstance, lpCmdLine)) {
Expand Down

0 comments on commit 06ca4e0

Please sign in to comment.