Skip to content

Commit ecd210d

Browse files
authored
More flexibility to build Debug components (#136)
* Build components in all variant for boost to avoid issue with USVFS. * Build googletest in both Debug and Release. * Allow build configurations other than RelWithDebInfo.
1 parent d1965ac commit ecd210d

File tree

20 files changed

+423
-193
lines changed

20 files changed

+423
-193
lines changed

mob.ini

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ super = cmake_common modorganizer* githubpp
2222
plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_*
2323

2424
[task]
25-
enabled = true
26-
mo_org = ModOrganizer2
27-
mo_branch = master
28-
mo_fallback =
29-
no_pull = false
30-
ignore_ts = false
31-
revert_ts = false
25+
enabled = true
26+
mo_org = ModOrganizer2
27+
mo_branch = master
28+
mo_fallback =
29+
no_pull = false
30+
ignore_ts = false
31+
revert_ts = false
32+
configuration = RelWithDebInfo
3233

3334
git_url_prefix = https://github.com/
3435
git_shallow = true
@@ -118,7 +119,6 @@ zlib = v1.3.1
118119
libbsarch = 0.0.9
119120
usvfs = master
120121
explorerpp = 1.4.0
121-
122122
ss_paper_lad_6788 = 7.2
123123
ss_paper_automata_6788 = 3.2
124124
ss_paper_mono_6788 = 3.2
@@ -129,6 +129,11 @@ ss_starfield_trosski = V1.11
129129
ss_fallout3_trosski = v1.11
130130
ss_fallout4_trosski = v1.11
131131

132+
[build-types]
133+
libbsarch = release
134+
pyqt = release
135+
python = release
136+
132137
[paths]
133138
third_party =
134139
prefix =

readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ aqt install-qt --outputdir "C:\Qt" windows desktop 6.7.0 win64_msvc2019_64 -m qt
6868
- Optional:
6969
- Qt Source Files
7070
- Qt Debug Files
71-
71+
7272
### Visual Studio
7373
- Install Visual Studio 2022 ([Installer](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false))
7474
- Desktop development with C++
@@ -141,9 +141,10 @@ Inside the INI file are `[sections]` and `key = value` pairs. The `[task]` secti
141141
### `[task]`
142142
Options for individual tasks. Can be `[task_name:task]`, where `task_name` is the name of a task (see `mob list`) , `super` for all MO tasks or a glob like `installer_*`.
143143

144-
| Option | Type | Description |
145-
| --- | --- | --- |
146-
| `enabled` | bool | Whether this task is enabled. Disabled tasks are never built. When specifying task names with `mob build task1 task2...`, all tasks except those given are turned off. |
144+
| Option | Type | Description |
145+
| --- | --- | --- |
146+
| `enabled` | bool | Whether this task is enabled. Disabled tasks are never built. When specifying task names with `mob build task1 task2...`, all tasks except those given are turned off. |
147+
| `configuration` | enum | Which configuration to build, should be one of Debug, Release or RelWithDebInfo with RelWithDebInfo being the default.|
147148

148149
#### Common git options
149150
Unless otherwise stated, applies to any task that is a git repo.

src/core/conf.cpp

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ namespace mob::details {
1414
using key_value_map = std::map<std::string, std::string, std::less<>>;
1515
using section_map = std::map<std::string, key_value_map, std::less<>>;
1616

17+
static std::unordered_map<mob::config, std::string_view> s_configuration_values{
18+
{mob::config::release, "Release"},
19+
{mob::config::debug, "Debug"},
20+
{mob::config::relwithdebinfo, "RelWithDebInfo"}};
21+
1722
// holds all the options not related to tasks (global, tools, paths, etc.)
1823
static section_map g_conf;
1924

@@ -27,6 +32,18 @@ namespace mob::details {
2732
static int g_file_log_level = 5;
2833
static bool g_dry = false;
2934

35+
// check if the two given string are equals case-insensitive
36+
//
37+
bool case_insensitive_equals(std::string_view lhs, std::string_view rhs)
38+
{
39+
// _strcmpi does not have a n-overload, and since string_view is not
40+
// necessarily null-terminated, _strmcpi cannot be safely used
41+
return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs),
42+
std::end(rhs), [](auto&& c1, auto&& c2) {
43+
return ::tolower(c1) == ::tolower(c2);
44+
});
45+
}
46+
3047
bool bool_from_string(std::string_view s)
3148
{
3249
return (s == "true" || s == "yes" || s == "1");
@@ -85,6 +102,17 @@ namespace mob::details {
85102
kitor->second = value;
86103
}
87104

105+
config string_to_config(std::string_view value)
106+
{
107+
for (const auto& [c, v] : s_configuration_values) {
108+
if (case_insensitive_equals(value, v)) {
109+
return c;
110+
}
111+
}
112+
113+
gcx().bail_out(context::conf, "invalid configuration '{}'", value);
114+
}
115+
88116
// sets the given option, adds it if it doesn't exist; used when setting options
89117
// from the master ini
90118
//
@@ -184,6 +212,28 @@ namespace mob::details {
184212
g_tasks[task_name][key] = std::move(value);
185213
}
186214

215+
// read a CMake constant from the configuration
216+
//
217+
template <typename T>
218+
T parse_cmake_value(std::string_view section, std::string_view key,
219+
std::string_view value,
220+
std::unordered_map<T, std::string_view> const& values)
221+
{
222+
for (const auto& [value_c, value_s] : values) {
223+
if (case_insensitive_equals(value_s, value)) {
224+
return value_c;
225+
}
226+
}
227+
228+
// build a string containing allowed value for logging
229+
std::vector<std::string_view> values_s;
230+
for (const auto& [value_c, value_s] : values) {
231+
values_s.push_back(value_s);
232+
}
233+
gcx().bail_out(context::conf, "bad value '{}' for {}/{} (expected one of {})",
234+
value, section, key, join(values_s, ", ", std::string{}));
235+
}
236+
187237
} // namespace mob::details
188238

189239
namespace mob {
@@ -644,6 +694,11 @@ namespace mob {
644694
return {};
645695
}
646696

697+
conf_build_types conf::build_types()
698+
{
699+
return {};
700+
}
701+
647702
conf_paths conf::path()
648703
{
649704
return {};
@@ -666,57 +721,52 @@ namespace mob {
666721
return details::g_dry;
667722
}
668723

669-
conf_task::conf_task(std::vector<std::string> names) : names_(std::move(names)) {}
724+
// use appropriate case for the below constants since we will be using them in
725+
// to_string, although most of cmake and msbuild is case-insensitive so it will
726+
// not matter much in the end
670727

671-
std::string conf_task::get(std::string_view key) const
728+
static std::unordered_map<conf_cmake::constant, std::string_view> constant_values{
729+
{conf_cmake::always, "ALWAYS"},
730+
{conf_cmake::lazy, "LAZY"},
731+
{conf_cmake::never, "NEVER"}};
732+
733+
std::string conf_cmake::to_string(constant c)
672734
{
673-
return details::get_string_for_task(names_, key);
735+
return std::string{constant_values.at(c)};
674736
}
675737

676-
bool conf_task::get_bool(std::string_view key) const
738+
conf_cmake::conf_cmake() : conf_section("cmake") {}
739+
740+
conf_cmake::constant conf_cmake::install_message() const
677741
{
678-
return details::get_bool_for_task(names_, key);
742+
return details::parse_cmake_value(
743+
name(), "install_message", details::get_string(name(), "install_message"),
744+
constant_values);
679745
}
680746

681-
bool conf_cmake::cmake_constant::is_equivalent(std::string_view other) const
747+
std::string conf_cmake::host() const
682748
{
683-
// _strcmpi does not have a n-overload, and since string_view is not
684-
// necessarily null-terminated, _strmcpi cannot be safely used
685-
return std::equal(std::begin(value_), std::end(value_), std::begin(other),
686-
std::end(other), [](auto&& c1, auto&& c2) {
687-
return ::tolower(c1) == ::tolower(c2);
688-
});
749+
return details::get_string(name(), "host");
689750
}
690751

691-
conf_cmake::conf_cmake() : conf_section("cmake") {}
692-
693-
const conf_cmake::cmake_constant conf_cmake::ALWAYS{"always"};
694-
const conf_cmake::cmake_constant conf_cmake::LAZY{"lazy"};
695-
const conf_cmake::cmake_constant conf_cmake::NEVER{"never"};
752+
conf_task::conf_task(std::vector<std::string> names) : names_(std::move(names)) {}
696753

697-
conf_cmake::cmake_constant conf_cmake::install_message() const
754+
std::string conf_task::get(std::string_view key) const
698755
{
699-
return read_cmake_constant("install_message", {ALWAYS, LAZY, NEVER});
756+
return details::get_string_for_task(names_, key);
700757
}
701758

702-
std::string conf_cmake::host() const
759+
bool conf_task::get_bool(std::string_view key) const
703760
{
704-
return details::get_string(name(), "host");
761+
return details::get_bool_for_task(names_, key);
705762
}
706763

707-
conf_cmake::cmake_constant
708-
conf_cmake::read_cmake_constant(std::string_view key,
709-
std::vector<cmake_constant> const& allowed) const
764+
mob::config conf_task::configuration() const
710765
{
711-
const auto value = details::get_string(name(), key);
712-
for (const auto& constant : allowed) {
713-
if (constant.is_equivalent(value)) {
714-
return constant;
715-
}
716-
}
717-
718-
gcx().bail_out(context::conf, "bad value '{}' for {}/{} (expected one of {})",
719-
value, name(), key, join(allowed, ", ", std::string{}));
766+
return details::parse_cmake_value(
767+
names_[0], "configuration",
768+
details::get_string_for_task(names_, "configuration"),
769+
details::s_configuration_values);
720770
}
721771

722772
conf_tools::conf_tools() : conf_section("tools") {}
@@ -725,6 +775,8 @@ namespace mob {
725775

726776
conf_versions::conf_versions() : conf_section("versions") {}
727777

778+
conf_build_types::conf_build_types() : conf_section("build-types") {}
779+
728780
conf_prebuilt::conf_prebuilt() : conf_section("prebuilt") {}
729781

730782
conf_paths::conf_paths() : conf_section("paths") {}

0 commit comments

Comments
 (0)