Skip to content

Commit a60c83b

Browse files
committed
Add default APIs.
1 parent 5804c3e commit a60c83b

7 files changed

Lines changed: 30 additions & 12 deletions

File tree

src/client/build.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ int build_packages(const String &name, const PackagesSet &pkgs, const path &sett
3737
int build_packages(const String &name, const PackagesSet &pkgs);
3838
int build_packages(const Config &c, const String &name);
3939

40-
String get_full_config_name(const path &bin_dir)
41-
{
42-
return read_file(bin_dir / CPPAN_CONFIG_FILENAME);
43-
}
44-
4540
String test_run()
4641
{
4742
// do a test build to extract config string
@@ -81,7 +76,7 @@ String test_run()
8176
throw std::runtime_error("There are errors during test run");
8277

8378
// read cfg
84-
auto c = get_full_config_name(bin_dir);
79+
auto c = read_file(bin_dir / CPPAN_CONFIG_FILENAME);
8580
if (c.empty())
8681
throw std::logic_error("Test config is empty");
8782

@@ -186,9 +181,6 @@ int build_packages(const Config &c, const String &name)
186181
auto printer = Printer::create(ls.printerType);
187182
printer->prepare_build(bs);
188183

189-
if (fs::exists(bs.binary_directory))
190-
bs.config_fullname = get_full_config_name(bs.binary_directory);
191-
192184
auto ret = printer->generate(bs);
193185
if (ret || ls.generate_only)
194186
return ret;

src/common/project.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ void Project::load(const yaml &root)
674674
YAML_EXTRACT_AUTO(rc_enabled);
675675
//YAML_EXTRACT_AUTO(disabled);
676676
YAML_EXTRACT_AUTO(skip_on_server);
677+
YAML_EXTRACT_AUTO(skip_default_api);
678+
YAML_EXTRACT_AUTO(default_api_start);
677679
YAML_EXTRACT_AUTO(build_dependencies_with_same_config);
678680

679681
api_name = get_sequence_set<String>(root, "api_name");
@@ -1293,6 +1295,8 @@ yaml Project::save() const
12931295
ADD_IF_NOT_VAL_TRIPLE(rc_enabled);
12941296
//ADD_IF_VAL_TRIPLE(disabled);
12951297
ADD_IF_VAL_TRIPLE(skip_on_server);
1298+
ADD_IF_VAL_TRIPLE(skip_default_api);
1299+
ADD_IF_NOT_EMPTY(default_api_start);
12961300
ADD_IF_VAL_TRIPLE(build_dependencies_with_same_config);
12971301

12981302
ADD_SET(api_name, api_name);

src/common/project.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ struct Project
239239
bool rc_enabled = true;
240240
//bool disabled = false;
241241
bool skip_on_server = false;
242+
bool skip_default_api = false;
243+
String default_api_start;
242244

243245
StringSet api_name;
244246
String output_name; // file name

src/common/project_path.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class ProjectPath
8989
return path_elements.empty();
9090
}
9191

92+
auto front() const
93+
{
94+
return path_elements.front();
95+
}
96+
9297
auto back() const
9398
{
9499
return path_elements.back();

src/common/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct BuildSettings
4343
path binary_directory;
4444
String source_directory_hash;
4545
String config;
46-
String config_fullname;
46+
mutable String config_fullname;
4747

4848
void set_build_dirs(const String &name);
4949
void append_build_dirs(const path &p);

src/common/yaml.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ String dump_yaml_config(const yaml &root)
179179
"build_dependencies_with_same_config",
180180
"disabled",
181181
"skip_on_server",
182+
"skip_default_api",
183+
"default_api_start",
182184

183185
"api_name",
184186

src/printers/cmake.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ int CMakePrinter::generate(const BuildSettings &bs) const
12851285
c.buf_size = 256; // for frequent flushes
12861286
auto ret = run_command(s, c);
12871287

1288+
if (fs::exists(bs.binary_directory / CPPAN_CONFIG_FILENAME))
1289+
bs.config_fullname = read_file(bs.binary_directory / CPPAN_CONFIG_FILENAME);
1290+
12881291
if (bs.allow_links)
12891292
{
12901293
if (!s.silent || s.is_custom_build_dir())
@@ -2108,7 +2111,9 @@ endif()
21082111
ctx.increaseIndent("target_compile_definitions (${this}");
21092112
if (!d.flags[pfHeaderOnly])
21102113
{
2111-
ctx.addLine("PRIVATE ${LIBRARY_API}"s + (d.flags[pfExecutable] ? "" : "=${CPPAN_EXPORT}"));
2114+
// ?
2115+
//ctx.addLine("PRIVATE ${LIBRARY_API}"s + (d.flags[pfExecutable] ? "" : "=${CPPAN_EXPORT}"));
2116+
ctx.addLine("PRIVATE ${LIBRARY_API}=${CPPAN_EXPORT}");
21122117
if (!d.flags[pfExecutable])
21132118
ctx.addLine("INTERFACE ${LIBRARY_API}=${CPPAN_IMPORT}");
21142119
}
@@ -2301,7 +2306,15 @@ endif()
23012306
// CPPAN_CONFIG is private for a package!
23022307
ctx.addLine("PRIVATE CPPAN_CONFIG=\"${config}\"");
23032308
}
2304-
for (auto &a : p.api_name)
2309+
auto api_names = p.api_name;
2310+
if (!p.skip_default_api)
2311+
{
2312+
auto pp = p.pkg.ppath;
2313+
while (!pp.empty() && pp.front() != p.default_api_start)
2314+
pp = pp.slice(1);
2315+
api_names.insert(boost::to_upper_copy(!pp.empty() ? pp.toString("_") : p.pkg.ppath.back()) + "_API");
2316+
}
2317+
for (auto &a : api_names)
23052318
ctx.addLine(visibility + " " + a + "=${LIBRARY_API}");
23062319
ctx.decreaseIndent(")");
23072320
ctx.addLine();

0 commit comments

Comments
 (0)