Skip to content

Commit eba5bf4

Browse files
authored
Build DirectXTex with mob. (#140)
1 parent a308e75 commit eba5bf4

File tree

5 files changed

+98
-1
lines changed

5 files changed

+98
-1
lines changed

mob.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ boost = 1.85.0
101101
boost_vs = 14.3
102102
fmt = 10.2.1
103103
gtest = main
104+
directxtex = main
104105
libloot = 0.22.4
105106
lz4 = v1.9.4
106107
nmm = 0.71.2

src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace mob {
3333
.add_task<libbsarch>()
3434
.add_task<libloot>()
3535
.add_task<openssl>()
36-
.add_task<bzip2>();
36+
.add_task<bzip2>()
37+
.add_task<directxtex>();
3738

3839
add_task<parallel_tasks>()
3940
.add_task<tasks::python>()

src/tasks/directxtex.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "pch.h"
2+
#include "tasks.h"
3+
4+
namespace mob::tasks {
5+
6+
namespace {
7+
8+
msbuild create_msbuild_tool(arch a, config config,
9+
msbuild::ops o = msbuild::build)
10+
{
11+
return std::move(msbuild(o).architecture(a).configuration(config).solution(
12+
directxtex::source_path() / "DirectXTex" /
13+
"DirectXTex_Desktop_2022.vcxproj"));
14+
}
15+
16+
} // namespace
17+
18+
directxtex::directxtex() : basic_task("directxtex") {}
19+
20+
std::string directxtex::version()
21+
{
22+
return conf().version().get("directxtex");
23+
}
24+
25+
bool directxtex::prebuilt()
26+
{
27+
return false;
28+
}
29+
30+
fs::path directxtex::source_path()
31+
{
32+
return conf().path().build() / "DirectXTex";
33+
}
34+
35+
void directxtex::do_clean(clean c)
36+
{
37+
if (is_set(c, clean::reclone)) {
38+
git_wrap::delete_directory(cx(), source_path());
39+
return;
40+
}
41+
42+
if (is_set(c, clean::rebuild)) {
43+
run_tool(create_msbuild_tool(arch::x64, config::release, msbuild::clean));
44+
run_tool(create_msbuild_tool(arch::x64, config::debug, msbuild::clean));
45+
}
46+
}
47+
48+
void directxtex::do_fetch()
49+
{
50+
run_tool(make_git()
51+
.url(make_git_url("microsoft", "DirectXTex"))
52+
.branch(version())
53+
.root(source_path()));
54+
}
55+
56+
void directxtex::do_build_and_install()
57+
{
58+
op::create_directories(cx(), directxtex::source_path() / "Include");
59+
op::create_directories(cx(), directxtex::source_path() / "Lib" / "Debug");
60+
op::create_directories(cx(), directxtex::source_path() / "Lib" / "Release");
61+
62+
// DO NOT run these in parallel because both generate files that are shared
63+
// between release and debug
64+
run_tool(create_msbuild_tool(arch::x64, config::release));
65+
run_tool(create_msbuild_tool(arch::x64, config::debug));
66+
67+
const auto binary_path =
68+
source_path() / "DirectXTex" / "Bin" / "Desktop_2022" / "x64";
69+
70+
for (const auto& header : {"DDS.h", "DirectXTex.h", "DirectXTex.inl "}) {
71+
op::copy_file_to_dir_if_better(cx(), source_path() / "DirectXTex" / header,
72+
source_path() / "Include");
73+
}
74+
op::copy_file_to_dir_if_better(cx(), binary_path / "Debug" / "DirectXTex.lib",
75+
source_path() / "Lib" / "Debug");
76+
op::copy_file_to_dir_if_better(cx(), binary_path / "Release" / "DirectXTex.lib",
77+
source_path() / "Lib" / "Release");
78+
}
79+
80+
} // namespace mob::tasks

src/tasks/modorganizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ namespace mob::tasks {
226226
gtest::build_path(arch::x64, c == config::debug ? config::debug
227227
: config::release))
228228
.def("OPENSSL_ROOT_DIR", openssl::source_path())
229+
.def("DIRECTXTEX_ROOT", directxtex::source_path())
229230
.root(root));
230231
}
231232

src/tasks/tasks.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ namespace mob::tasks {
7777
void do_fetch() override;
7878
};
7979

80+
class directxtex : public basic_task<directxtex> {
81+
public:
82+
directxtex();
83+
84+
static std::string version();
85+
static bool prebuilt();
86+
static fs::path source_path();
87+
88+
protected:
89+
void do_clean(clean c) override;
90+
void do_fetch() override;
91+
void do_build_and_install() override;
92+
};
93+
8094
class explorerpp : public basic_task<explorerpp> {
8195
public:
8296
explorerpp();

0 commit comments

Comments
 (0)