2020-05-03 03:46:58 -04:00
|
|
|
#include "pch.h"
|
|
|
|
|
#include "tools.h"
|
|
|
|
|
|
|
|
|
|
namespace mob
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
cmake::cmake()
|
|
|
|
|
: basic_process_runner("cmake"), gen_(jom), arch_(arch::def)
|
|
|
|
|
{
|
|
|
|
|
process_
|
2020-05-17 12:47:44 -04:00
|
|
|
.binary(binary());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::path cmake::binary()
|
|
|
|
|
{
|
2020-05-17 15:50:15 -04:00
|
|
|
return conf::tool_by_name("cmake");
|
2020-05-17 12:47:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cmake::clean(const context& cx, const fs::path& root)
|
|
|
|
|
{
|
|
|
|
|
cx.trace(context::rebuild, "deleting all generator directories");
|
|
|
|
|
|
|
|
|
|
for (auto&& [k, g] : all_generators())
|
|
|
|
|
{
|
|
|
|
|
op::delete_directory(cx,
|
|
|
|
|
root / g.output_dir(arch::x86), op::optional);
|
|
|
|
|
|
|
|
|
|
op::delete_directory(cx,
|
|
|
|
|
root / g.output_dir(arch::x64), op::optional);
|
|
|
|
|
}
|
2020-05-03 03:46:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmake& cmake::generator(generators g)
|
|
|
|
|
{
|
|
|
|
|
gen_ = g;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
cmake& cmake::generator(const std::string& g)
|
|
|
|
|
{
|
|
|
|
|
genstring_ = g;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 03:46:58 -04:00
|
|
|
cmake& cmake::root(const fs::path& p)
|
|
|
|
|
{
|
|
|
|
|
root_ = p;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
cmake& cmake::output(const fs::path& p)
|
|
|
|
|
{
|
|
|
|
|
output_ = p;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 03:46:58 -04:00
|
|
|
cmake& cmake::prefix(const fs::path& s)
|
|
|
|
|
{
|
|
|
|
|
prefix_ = s;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:29:38 -04:00
|
|
|
cmake& cmake::def(const std::string& name, const std::string& value)
|
2020-05-03 03:46:58 -04:00
|
|
|
{
|
2020-05-06 12:29:38 -04:00
|
|
|
process_.arg("-D" + name + "=" + value + "");
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmake& cmake::def(const std::string& name, const fs::path& p)
|
|
|
|
|
{
|
2020-05-12 12:00:02 -04:00
|
|
|
def(name, path_to_utf8(p));
|
2020-05-06 12:29:38 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmake& cmake::def(const std::string& name, const char* s)
|
|
|
|
|
{
|
|
|
|
|
def(name, std::string(s));
|
2020-05-03 03:46:58 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmake& cmake::architecture(arch a)
|
|
|
|
|
{
|
|
|
|
|
arch_ = a;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
cmake& cmake::cmd(const std::string& s)
|
|
|
|
|
{
|
|
|
|
|
cmd_ = s;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 03:46:58 -04:00
|
|
|
fs::path cmake::result() const
|
|
|
|
|
{
|
|
|
|
|
return output_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cmake::do_run()
|
|
|
|
|
{
|
2020-05-06 12:29:38 -04:00
|
|
|
if (root_.empty())
|
2020-05-17 21:23:43 -04:00
|
|
|
cx().bail_out(context::generic, "cmake output path is empty");
|
2020-05-06 12:29:38 -04:00
|
|
|
|
2020-05-04 05:38:23 -04:00
|
|
|
const auto& g = get_generator(gen_);
|
2020-05-17 19:21:26 -04:00
|
|
|
|
|
|
|
|
if (output_.empty())
|
|
|
|
|
output_ = root_ / (g.output_dir(arch_));
|
2020-05-03 03:46:58 -04:00
|
|
|
|
|
|
|
|
process_
|
2020-05-12 14:33:46 -04:00
|
|
|
.stdout_encoding(encodings::utf8)
|
|
|
|
|
.stderr_encoding(encodings::utf8)
|
2020-05-03 03:46:58 -04:00
|
|
|
.arg("-DCMAKE_BUILD_TYPE=Release")
|
2020-05-04 01:24:47 -04:00
|
|
|
.arg("-DCMAKE_INSTALL_MESSAGE=NEVER", process::log_quiet)
|
|
|
|
|
.arg("--log-level", "WARNING", process::log_quiet)
|
2020-05-17 19:21:26 -04:00
|
|
|
.arg("--no-warn-unused-cli");
|
|
|
|
|
|
|
|
|
|
if (genstring_.empty())
|
|
|
|
|
{
|
|
|
|
|
process_
|
|
|
|
|
.arg("-G", "\"" + g.name + "\"")
|
|
|
|
|
.arg(g.get_arch(arch_));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
process_
|
|
|
|
|
.arg("-G", "\"" + genstring_ + "\"");
|
|
|
|
|
}
|
2020-05-03 03:46:58 -04:00
|
|
|
|
|
|
|
|
if (!prefix_.empty())
|
|
|
|
|
process_.arg("-DCMAKE_INSTALL_PREFIX=", prefix_, process::nospace);
|
|
|
|
|
|
2020-05-17 19:21:26 -04:00
|
|
|
if (cmd_.empty())
|
|
|
|
|
process_.arg("..");
|
|
|
|
|
else
|
|
|
|
|
process_.arg(cmd_);
|
|
|
|
|
|
2020-05-03 03:46:58 -04:00
|
|
|
process_
|
2020-05-13 11:51:48 -04:00
|
|
|
.env(env::vs(arch_)
|
|
|
|
|
.set("CXXFLAGS", "/wd4566"))
|
2020-05-03 03:46:58 -04:00
|
|
|
.cwd(output_);
|
|
|
|
|
|
|
|
|
|
execute_and_join();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 05:38:23 -04:00
|
|
|
const std::map<cmake::generators, cmake::gen_info>& cmake::all_generators()
|
2020-05-03 03:46:58 -04:00
|
|
|
{
|
|
|
|
|
static const std::map<generators, gen_info> map =
|
|
|
|
|
{
|
|
|
|
|
{ generators::jom, {"build", "NMake Makefiles JOM", "", "" }},
|
|
|
|
|
|
|
|
|
|
{ generators::vs, {
|
|
|
|
|
"vsbuild",
|
2020-05-17 12:47:44 -04:00
|
|
|
"Visual Studio " + vs::version() + " " + vs::year(),
|
2020-05-03 03:46:58 -04:00
|
|
|
"Win32",
|
|
|
|
|
"x64"
|
2020-05-17 19:21:26 -04:00
|
|
|
}}
|
2020-05-03 03:46:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 05:38:23 -04:00
|
|
|
const cmake::gen_info& cmake::get_generator(generators g)
|
2020-05-03 03:46:58 -04:00
|
|
|
{
|
|
|
|
|
const auto& map = all_generators();
|
|
|
|
|
|
2020-05-04 05:38:23 -04:00
|
|
|
auto itor = map.find(g);
|
2020-05-03 03:46:58 -04:00
|
|
|
if (itor == map.end())
|
|
|
|
|
bail_out("unknown generator");
|
|
|
|
|
|
|
|
|
|
return itor->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string cmake::gen_info::get_arch(arch a) const
|
|
|
|
|
{
|
|
|
|
|
switch (a)
|
|
|
|
|
{
|
|
|
|
|
case arch::x86:
|
|
|
|
|
{
|
|
|
|
|
if (x86.empty())
|
|
|
|
|
return {};
|
|
|
|
|
else
|
|
|
|
|
return "-A " + x86;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case arch::x64:
|
|
|
|
|
{
|
|
|
|
|
if (x64.empty())
|
|
|
|
|
return {};
|
|
|
|
|
else
|
2020-05-06 12:29:38 -04:00
|
|
|
return "-A " + x64;
|
2020-05-03 03:46:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case arch::dont_care:
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
bail_out("gen_info::get_arch(): bad arch");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string cmake::gen_info::output_dir(arch a) const
|
|
|
|
|
{
|
|
|
|
|
switch (a)
|
|
|
|
|
{
|
|
|
|
|
case arch::x86:
|
|
|
|
|
return (dir + "_32");
|
|
|
|
|
|
|
|
|
|
case arch::x64:
|
|
|
|
|
case arch::dont_care:
|
|
|
|
|
return dir;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
bail_out("gen_info::get_arch(): bad arch");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|