Skip to content

Commit b0304d7

Browse files
committed
Perform build in storage's tmp dir. Add nice project labels for cppan targets.
1 parent 2b33c7f commit b0304d7

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

src/common/settings.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ void Settings::load(const yaml &root, const SettingsType type)
9191
}
9292
};
9393

94-
auto get_build_dir = [this](const path &p, SettingsType type)
94+
auto get_build_dir = [this](const path &p, SettingsType type, const auto &dirs)
9595
{
9696
switch (type)
9797
{
9898
case SettingsType::Local:
9999
return fs::current_path();
100100
case SettingsType::User:
101-
return directories.storage_dir_tmp;
102101
case SettingsType::System:
103-
return temp_directory_path() / "build";
102+
return dirs.storage_dir_tmp / "build";
104103
default:
105104
return p;
106105
}
@@ -111,7 +110,7 @@ void Settings::load(const yaml &root, const SettingsType type)
111110
auto sd = get_storage_dir(storage_dir_type);
112111
dirs.set_storage_dir(sd);
113112
dirs.build_dir_type = build_dir_type;
114-
dirs.set_build_dir(get_build_dir(build_dir, build_dir_type));
113+
dirs.set_build_dir(get_build_dir(build_dir, build_dir_type, dirs));
115114
directories.update(dirs, type);
116115
}
117116

src/printers/cmake.cpp

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void set_target_properties(Context &ctx, const String &name, const String &prope
220220

221221
void set_target_properties(Context &ctx, const String &property, const String &value)
222222
{
223-
ctx.addLine("set_target_properties(${this} PROPERTIES " + property + " " + value + ")");
223+
set_target_properties(ctx, "${this}", property, value);
224224
}
225225

226226
void declare_dummy_target(Context &ctx, const String &name)
@@ -273,6 +273,16 @@ String prepare_include_directory(const String &i)
273273
return "${SDIR}/" + i;
274274
};
275275

276+
void print_sdir_bdir(Context &ctx, const Package &d)
277+
{
278+
if (d.flags[pfLocalProject])
279+
ctx.addLine("set(SDIR " + normalize_path(rd[d].config->getDefaultProject().root_directory) + ")");
280+
else
281+
ctx.addLine("set(SDIR ${CMAKE_CURRENT_SOURCE_DIR})");
282+
ctx.addLine("set(BDIR ${CMAKE_CURRENT_BINARY_DIR})");
283+
ctx.emptyLines();
284+
}
285+
276286
String get_binary_path(const Package &d, const String &prefix)
277287
{
278288
return prefix + "/cppan/" + d.getHashShort();
@@ -474,9 +484,13 @@ void print_build_dependencies(Context &ctx, const Package &d, const String &targ
474484
}
475485
local.emptyLines();
476486

487+
bool deps = false;
477488
String build_deps_tgt = "${this}";
478489
if (d.empty() && target.find("-b") != target.npos)
490+
{
479491
build_deps_tgt += "-d"; // deps
492+
deps = true;
493+
}
480494
else
481495
build_deps_tgt += "-b-d";
482496

@@ -539,6 +553,10 @@ void print_build_dependencies(Context &ctx, const Package &d, const String &targ
539553
local.addLine(")");
540554
local.addLine("add_dependencies(${this} " + build_deps_tgt + ")");
541555
print_solution_folder(local, build_deps_tgt, service_folder);
556+
if (deps)
557+
set_target_properties(local, build_deps_tgt, "PROJECT_LABEL", "dependencies");
558+
else
559+
set_target_properties(local, build_deps_tgt, "PROJECT_LABEL", (d.flags[pfLocalProject] ? d.ppath.back() : d.target_name) + "-build-dependencies");
542560
local.addLine();
543561

544562
if (has_build_deps)
@@ -1137,12 +1155,7 @@ void CMakePrinter::print_src_config_file(const path &fn) const
11371155
ctx.addLine("set(EXECUTABLE " + String(d.flags[pfExecutable] ? "1" : "0") + ")");
11381156
ctx.addLine();
11391157

1140-
if (d.flags[pfLocalProject])
1141-
ctx.addLine("set(SDIR " + normalize_path(p.root_directory) + ")");
1142-
else
1143-
ctx.addLine("set(SDIR ${CMAKE_CURRENT_SOURCE_DIR})");
1144-
ctx.addLine("set(BDIR ${CMAKE_CURRENT_BINARY_DIR})");
1145-
ctx.addLine();
1158+
print_sdir_bdir(ctx, d);
11461159

11471160
ctx.addLine("set(LIBRARY_API " + library_api(d) + ")");
11481161
ctx.addLine();
@@ -1329,10 +1342,7 @@ endif()
13291342
if (!d.flags[pfHeaderOnly])
13301343
{
13311344
set_target_properties(ctx, "OUTPUT_NAME", d.target_name);
1332-
if (d.flags[pfLocalProject])
1333-
set_target_properties(ctx, "PROJECT_LABEL", d.ppath.back());
1334-
else
1335-
set_target_properties(ctx, "PROJECT_LABEL", d.target_name);
1345+
set_target_properties(ctx, "PROJECT_LABEL", d.flags[pfLocalProject] ? d.ppath.back() : d.target_name);
13361346
ctx.emptyLines();
13371347
}
13381348
}
@@ -1681,9 +1691,9 @@ target_compile_options(${this}
16811691
)
16821692
endif()
16831693
1684-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
1694+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
16851695
target_compile_options(${this}
1686-
PRIVATE -Wmacro-redefined
1696+
PRIVATE -Wno-macro-redefined
16871697
)
16881698
endif()
16891699
)");
@@ -1893,9 +1903,7 @@ void CMakePrinter::print_src_actions_file(const path &fn) const
18931903
ctx.addLine("set(CMAKE_CURRENT_BINARY_DIR_OLD ${CMAKE_CURRENT_BINARY_DIR})");
18941904
ctx.addLine("set(CMAKE_CURRENT_BINARY_DIR \"" + normalize_path(get_binary_path(d)) + "\")");
18951905
ctx.addLine();
1896-
ctx.addLine("set(SDIR ${CMAKE_CURRENT_SOURCE_DIR})");
1897-
ctx.addLine("set(BDIR ${CMAKE_CURRENT_BINARY_DIR})");
1898-
ctx.addLine();
1906+
print_sdir_bdir(ctx, d);
18991907
ctx.addLine("set(LIBRARY_API " + library_api(d) + ")");
19001908
ctx.addLine();
19011909
print_bs_insertion(ctx, p, "pre sources", &BuildSystemConfigInsertions::pre_sources);
@@ -2315,17 +2323,19 @@ void CMakePrinter::print_meta_config_file(const path &fn) const
23152323
// re-run cppan when root cppan.yml is changed
23162324
if (settings.add_run_cppan_target)
23172325
{
2326+
print_sdir_bdir(ctx, d);
2327+
23182328
config_section_title(ctx, "cppan regenerator");
23192329
ctx.addLine(R"(set(file ${CMAKE_CURRENT_BINARY_DIR}/run-cppan.txt)
23202330
add_custom_command(OUTPUT ${file}
23212331
COMMAND ${CPPAN_COMMAND} -d ${PROJECT_SOURCE_DIR}
23222332
COMMAND ${CMAKE_COMMAND} -E echo "" > ${file}
2323-
DEPENDS ${PROJECT_SOURCE_DIR}/cppan.yml
2333+
DEPENDS ${SDIR}/cppan.yml
23242334
)
23252335
add_custom_target(run-cppan
23262336
DEPENDS ${file}
23272337
SOURCES
2328-
${PROJECT_SOURCE_DIR}/cppan.yml
2338+
${SDIR}/cppan.yml
23292339
\")" + normalize_path(directories.get_static_files_dir() / cmake_functions_filename) + R"(\"
23302340
${PROJECT_SOURCE_DIR}/cppan/)" + cmake_helpers_filename + R"(
23312341
)
@@ -2614,7 +2624,11 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON))");
26142624
if (d.empty())
26152625
{
26162626
declare_dummy_target(ctx, cppan_dummy_build_target);
2627+
set_target_properties(ctx, cppan_dummy_target(cppan_dummy_build_target), "PROJECT_LABEL", "build-dependencies");
2628+
26172629
declare_dummy_target(ctx, cppan_dummy_copy_target);
2630+
set_target_properties(ctx, cppan_dummy_target(cppan_dummy_copy_target), "PROJECT_LABEL", "copy-dependencies");
2631+
26182632
ctx.addLine("add_dependencies(" + cppan_dummy_target(cppan_dummy_copy_target) + " " + cppan_dummy_target(cppan_dummy_build_target) + ")");
26192633
}
26202634

@@ -2713,14 +2727,23 @@ void CMakePrinter::parallel_vars_check(const ParallelCheckOptions &o) const
27132727
if (!o.toolchain.empty())
27142728
args.push_back("-DCMAKE_TOOLCHAIN_FILE=" + o.toolchain);
27152729

2730+
//
2731+
command::Result ret;
27162732
auto print = [](const String &s)
27172733
{
27182734
LOG_INFO(logger, s);
27192735
};
27202736
command::Options o;
27212737
o.out.action = print;
27222738
o.err.action = print;
2723-
auto ret = command::execute_and_capture(args, o);
2739+
2740+
#ifndef _WIN32
2741+
// hide output for *nix as it very fast there
2742+
if (N >= 4)
2743+
ret = command::execute(args);
2744+
else
2745+
#endif
2746+
ret = command::execute_and_capture(args, o);
27242747

27252748
// do not fail (throw), try to read already found variables
27262749
if (ret.rc)

0 commit comments

Comments
 (0)