Skip to content

Commit ac882f9

Browse files
committed
Correctly copy deps for ninja generator.
1 parent b7db147 commit ac882f9

7 files changed

Lines changed: 93 additions & 10 deletions

File tree

src/common/package.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ Package extractFromString(const String &target)
149149
return p;
150150
}
151151

152+
Package extractFromStringAny(const String &target)
153+
{
154+
auto pos = target.rfind('-');
155+
156+
Package p;
157+
p.ppath = target.substr(0, pos);
158+
if (pos != target.npos)
159+
p.version = target.substr(pos + 1);
160+
p.createNames();
161+
return p;
162+
}
163+
152164
void cleanPackages(const String &s, int flags)
153165
{
154166
// on source flag remove all

src/common/package.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ using PackagesMap = std::unordered_map<Package, Package>;
7373
using PackagesSet = std::unordered_set<Package>;
7474

7575
Package extractFromString(const String &target);
76+
Package extractFromStringAny(const String &target);
7677

7778
struct CleanTarget
7879
{

src/common/project.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,9 @@ void Project::load(const yaml &root)
979979
{
980980
if (d.IsScalar())
981981
{
982-
dependency.ppath = this->relative_name_to_absolute(d.template as<String>());
982+
auto p = extractFromStringAny(d.template as<String>());
983+
dependency.ppath = this->relative_name_to_absolute(p.ppath.toString());
984+
dependency.version = p.version;
983985
}
984986
else if (d.IsMap())
985987
{

src/common/settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void Settings::load_main(const yaml &root, const SettingsType type)
147147

148148
YAML_EXTRACT_AUTO(disable_update_checks);
149149
YAML_EXTRACT_AUTO(max_download_threads);
150+
YAML_EXTRACT_AUTO(debug_generated_cmake_configs);
150151
YAML_EXTRACT(storage_dir, String);
151152
YAML_EXTRACT(build_dir, String);
152153
YAML_EXTRACT(cppan_dir, String);

src/common/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct Settings
7676
// do not check for new cppan version
7777
bool disable_update_checks = false;
7878
int max_download_threads = get_max_threads(8);
79+
bool debug_generated_cmake_configs = false;
7980

8081
// build settings
8182
String c_compiler;

src/inserts/CPPANConfig.cmake

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mark_as_advanced(CPPAN_EXECUTABLE)
88

99
########################################
1010

11-
set(CPPAN_DEPS_DIR ${CMAKE_BINARY_DIR}/.cppan/cmake CACHE STRING "Cppan local deps file.")
11+
set(CPPAN_DEPS_DIR ${CMAKE_BINARY_DIR}/.cppan/cmake CACHE STRING "Cppan local deps dir.")
1212
set(CPPAN_DEPS_FILE ${CPPAN_DEPS_DIR}/cppan.yml CACHE STRING "Cppan local deps file.")
1313

1414
file(WRITE ${CPPAN_DEPS_FILE} "dependencies:\n")
@@ -17,12 +17,10 @@ file(WRITE ${CPPAN_DEPS_FILE} "dependencies:\n")
1717
# FUNCTION cppan_add_dependency
1818
########################################
1919

20-
function(cppan_add_dependency d)
21-
if (${ARGC} EQUAL 1)
22-
file(APPEND ${CPPAN_DEPS_FILE} " - ${d}\n")
23-
else()
24-
file(APPEND ${CPPAN_DEPS_FILE} " - ${d}: ${ARGN}\n")
25-
endif()
20+
function(cppan_add_package)
21+
foreach(a ${ARGN})
22+
file(APPEND ${CPPAN_DEPS_FILE} " - ${a}\n")
23+
endforeach()
2624
endfunction()
2725

2826
########################################
@@ -40,7 +38,6 @@ function(cppan_execute)
4038
message(FATAL_ERROR "cppan: non-zero exit code - ${ret}")
4139
endif()
4240

43-
file(WRITE ${CPPAN_DEPS_FILE} "")
4441
add_subdirectory(${CPPAN_DEPS_DIR}/.cppan ${CPPAN_DEPS_DIR}/.cppan/cmake_bdir)
4542
endfunction()
4643

src/printers/cmake.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class ScopedDependencyCondition
129129

130130
String cmake_debug_message(const String &s)
131131
{
132+
if (!Settings::get_local_settings().debug_generated_cmake_configs)
133+
return "";
134+
132135
return cmake_debug_message_fun + "(\"" + s + "\")";
133136
}
134137

@@ -184,6 +187,9 @@ void file_header(CMakeContext &ctx, const Package &d, bool root)
184187
ctx.addLine("include(" + normalize_path(directories.get_static_files_dir() / cmake_header_filename) + ")");
185188
ctx.addLine();
186189

190+
if (!Settings::get_local_settings().debug_generated_cmake_configs)
191+
return;
192+
187193
// before header message
188194
if (!root)
189195
{
@@ -205,6 +211,9 @@ void file_header(CMakeContext &ctx, const Package &d, bool root)
205211

206212
void file_footer(CMakeContext &ctx, const Package &d)
207213
{
214+
if (!Settings::get_local_settings().debug_generated_cmake_configs)
215+
return;
216+
208217
config_section_title(ctx, "footer", true);
209218
ctx.addLine(cmake_debug_message("Leaving file: ${CMAKE_CURRENT_LIST_FILE}"));
210219
ctx.addLine();
@@ -775,6 +784,11 @@ void CMakePrinter::print_copy_dependencies(CMakeContext &ctx, const String &targ
775784
ctx.addLine("set(copy_content \"${copy_content} @setlocal\\n\")");
776785
ctx.endif();
777786

787+
// we're in helper, set this var to build target
788+
if (d.empty())
789+
ctx.addLine("set(this " + target + ")");
790+
ctx.emptyLines();
791+
778792
ctx.addLine("set(output_dir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})");
779793
ctx.if_("NOT output_dir");
780794
ctx.addLine("set(output_dir ${CMAKE_BINARY_DIR})");
@@ -914,6 +928,61 @@ add_custom_command(TARGET )" + target + R"( POST_BUILD
914928

915929
ctx.endif();
916930
ctx.addLine();
931+
932+
// like with build deps
933+
for (auto &dp : copy_deps)
934+
{
935+
auto &p = dp.second;
936+
937+
// local projects are always built inside solution
938+
if (p.flags[pfLocalProject])
939+
continue;
940+
941+
ScopedDependencyCondition sdc(ctx, p);
942+
ctx.addLine("get_target_property(imploc_" + p.variable_name + " " + p.target_name + " IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPER})");
943+
}
944+
ctx.emptyLines();
945+
946+
bool deps = false;
947+
String build_deps_tgt = "${this}";
948+
if (d.empty() && target.find("-c") != target.npos)
949+
{
950+
build_deps_tgt += "-d"; // deps
951+
deps = true;
952+
}
953+
else
954+
build_deps_tgt += "-c-d";
955+
956+
// do not use add_custom_command as it doesn't work
957+
// add custom target and add a dependency below
958+
// second way is to use add custom target + add custom command (POST?(PRE)_BUILD)
959+
ctx.addLine("set(bp)");
960+
//for (auto &dp : build_deps_all)
961+
for (auto &dp : copy_deps)
962+
{
963+
auto &p = dp.second;
964+
965+
// local projects are always built inside solution
966+
if (p.flags[pfLocalProject])
967+
continue;
968+
969+
ScopedDependencyCondition sdc(ctx, p, false);
970+
ctx.addLine("set(bp ${bp} ${imploc_" + p.variable_name + "})");
971+
}
972+
ctx.emptyLines();
973+
974+
ctx.increaseIndent("add_custom_target(" + build_deps_tgt);
975+
ctx.addLine("COMMAND ${file}");
976+
ctx.increaseIndent("BYPRODUCTS ${bp}");
977+
ctx.decreaseIndent(")", 2);
978+
ctx.addLine("add_dependencies(${this} " + build_deps_tgt + ")");
979+
print_solution_folder(ctx, build_deps_tgt, deps ? service_folder : service_deps_folder);
980+
//this causes long paths issue
981+
//if (deps)
982+
// set_target_properties(ctx, build_deps_tgt, "PROJECT_LABEL", "dependencies");
983+
//else
984+
// set_target_properties(ctx, build_deps_tgt, "PROJECT_LABEL", (d.flags[pfLocalProject] ? d.ppath.back() : d.target_name) + "-build-dependencies");
985+
ctx.addLine();
917986
}
918987

919988
void CMakePrinter::prepare_rebuild() const
@@ -2953,7 +3022,7 @@ endif()
29533022
\"${CMAKE_TOOLCHAIN_FILE}\"
29543023
)"s;
29553024
ctx.if_("CPPAN_COMMAND");
2956-
ctx.addLine("cppan_debug_message(\"" + cmd + "\")");
3025+
cmake_debug_message(cmd);
29573026
ctx.addLine("execute_process(" + cmd + " RESULT_VARIABLE ret)");
29583027
ctx.addLine("check_result_variable(${ret} \"" + cmd + "\")");
29593028
ctx.endif();

0 commit comments

Comments
 (0)