MinGW#
Lowlevel MinGW Tests
Executable#
1// MINGW specialized Toolchain
2Toolchain_mingw mingw;
3
4// MINGW specialized targets
5// Creates `Simple.exe`
6ExecutableTarget_mingw exetarget("Simple", mingw, "");
7exetarget.GlobSources("src");
8exetarget.AddIncludeDir("include", true);
9exetarget.Build();
10
11// Build
12tf::Executor executor;
13executor.run(exetarget.GetTaskflow());
14executor.wait_for_all();
StaticLib#
1// MINGW specialized Toolchain
2Toolchain_mingw mingw;
3
4// MINGW specialized targets
5// Creates `librandom.lib`
6StaticTarget_mingw statictarget("librandom", mingw, "");
7statictarget.AddSource("src/random.cpp");
8statictarget.AddIncludeDir("include", true);
9statictarget.Build();
10
11// MINGW specialized targets
12// Creates `Simple.exe`
13ExecutableTarget_mingw exetarget("Simple", mingw, "");
14exetarget.AddSource("src/main.cpp");
15exetarget.AddIncludeDir("include", true);
16exetarget.AddLibDep(statictarget);
17exetarget.Build();
18
19// Build
20tf::Executor executor;
21tf::Taskflow taskflow;
22
23// Setup your dependencies explicitly
24// Here statictarget needs to be built before exetarget
25auto statictargetTask = taskflow.composed_of(statictarget.GetTaskflow());
26auto exetargetTask = taskflow.composed_of(exetarget.GetTaskflow());
27exetargetTask.succeed(statictargetTask);
28
29executor.run(taskflow);
30executor.wait_for_all();
DynamicLib#
1// MINGW specialized Toolchain
2Toolchain_mingw mingw;
3
4// MINGW specialized targets
5// Creates `librandom.lib` and `librandom.lib.dll`
6DynamicTarget_mingw dynamictarget("librandom", mingw, "");
7dynamictarget.AddSource("src/random.cpp");
8dynamictarget.AddIncludeDir("include", true);
9dynamictarget.Build();
10
11// MINGW specialized target
12// Creates `Simple.exe` which uses the above dynamic library
13ExecutableTarget_mingw exetarget("Simple", mingw, "");
14exetarget.AddSource("src/main.cpp");
15exetarget.AddIncludeDir("include", true);
16exetarget.AddLibDep(dynamictarget);
17exetarget.Build();
18
19// Build
20tf::Executor executor;
21tf::Taskflow taskflow;
22
23// Setup your dependencies explicitly
24// Here dynamictarget needs to be built before exetarget
25auto dynamictargetTask = taskflow.composed_of(dynamictarget.GetTaskflow());
26auto exetargetTask = taskflow.composed_of(exetarget.GetTaskflow());
27exetargetTask.succeed(dynamictargetTask);
28
29executor.run(taskflow);
30executor.wait_for_all();
31
32// Now that both your targets are built, copy the dynamictarget DLL to the exetarget location
33// This is required for your exetarget to run properly
34if (exetarget.IsBuilt()) {
35 fs::path copy_to_path =
36 exetarget.GetTargetBuildDir() / dynamictarget.GetTargetPath().filename();
37 fs::remove_all(copy_to_path);
38 fs::copy(dynamictarget.GetTargetPath(), copy_to_path);
39}
Note
Our ExecutableTarget_mingw
depends on DynamicTarget_mingw
and requires the librandom.dll
file to be present in the same folder location as the executable when running.
PrecompileHeader#
1int main() {
2 Toolchain_mingw mingw;
3
4 ExecutableTarget_mingw g_cppflags("cppflags", mingw, "files");
5 cppflags_build_cb(g_cppflags);
6
7 ExecutableTarget_mingw g_cflags("cflags", mingw, "files");
8 cflags_build_cb(g_cflags);
9
10 tf::Executor executor;
11 tf::Taskflow taskflow;
12
13 taskflow.composed_of(g_cppflags.GetTaskflow());
14 taskflow.composed_of(g_cflags.GetTaskflow());
15 executor.run(taskflow);
16 executor.wait_for_all();
17}
18
19static void cppflags_build_cb(BaseTarget &cppflags) {
20 cppflags.AddSource("main.cpp", "src");
21 cppflags.AddSource("random.cpp", "src");
22 cppflags.AddIncludeDir("include", true);
23
24 cppflags.AddPch("pch/pch_cpp.h");
25 cppflags.AddPch("pch/pch_c.h");
26 cppflags.AddIncludeDir("pch", true);
27
28 cppflags.AddPreprocessorFlag("-DRANDOM=1");
29 cppflags.AddCppCompileFlag("-Wall");
30 cppflags.AddCppCompileFlag("-Werror");
31 cppflags.AddLinkFlag("-lm");
32
33 cppflags.Build();
34}
35
36static void cflags_build_cb(BaseTarget &cflags) {
37 cflags.AddSource("main.c", "src");
38
39 cflags.AddPch("pch/pch_c.h");
40 cflags.AddIncludeDir("pch", false);
41 cflags.AddHeader("pch/pch_c.h");
42
43 cflags.AddPreprocessorFlag("-DRANDOM=1");
44 cflags.AddCCompileFlag("-Wall");
45 cflags.AddCCompileFlag("-Werror");
46 cflags.AddLinkFlag("-lm");
47
48 cflags.Build();
49}