Skip to content

Commit 71bd238

Browse files
committed
fix(run): handle header-only deps correctly in auto-deps CMake generation
- stop linking all inferred dependency aliases blindly - detect compiled deps via presence of CMakeLists.txt - link only valid CMake targets using if(TARGET ...) - avoid linking header-only libraries (no CMake target) - fix runtime error: target_link_libraries(... gk::pdf) target not found this restores support for header-only packages while keeping compiled deps working correctly
1 parent 58c52f1 commit 71bd238

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,6 @@ namespace vix::commands::RunCommand::detail
511511

512512
auto lf = parse_link_flags(scriptFlags);
513513
const auto cf = parse_compile_flags(scriptFlags);
514-
const auto autoDepAliases = extract_dep_aliases_from_include_dirs(cf.includeDirs);
515-
516514
const fs::path lockPath = cppPath.parent_path() / "vix.lock";
517515
auto orderedDeps = load_ordered_packages_from_lock(lockPath);
518516

@@ -547,6 +545,19 @@ namespace vix::commands::RunCommand::detail
547545
cmakeDeps.emplace_back(pkgDir, pkgPath);
548546
}
549547

548+
std::vector<std::string> cmakeDepAliases;
549+
cmakeDepAliases.reserve(cmakeDeps.size());
550+
551+
for (const auto &[pkgDir, _pkgPath] : cmakeDeps)
552+
{
553+
cmakeDepAliases.push_back(dep_id_to_cmake_alias(dep_dir_to_id(pkgDir)));
554+
}
555+
556+
std::sort(cmakeDepAliases.begin(), cmakeDepAliases.end());
557+
cmakeDepAliases.erase(
558+
std::unique(cmakeDepAliases.begin(), cmakeDepAliases.end()),
559+
cmakeDepAliases.end());
560+
550561
auto rank_dep = [](const std::string &pkgDir) -> int
551562
{
552563
if (pkgDir == "softadastra.core")
@@ -598,12 +609,15 @@ namespace vix::commands::RunCommand::detail
598609
}
599610
}
600611

601-
if (!autoDepAliases.empty())
612+
if (!cmakeDepAliases.empty())
602613
{
603-
s += "target_link_libraries(" + exeName + " PRIVATE\n";
604-
for (const auto &alias : autoDepAliases)
605-
s += " " + alias + "\n";
606-
s += ")\n\n";
614+
for (const auto &alias : cmakeDepAliases)
615+
{
616+
s += "if (TARGET " + alias + ")\n";
617+
s += " target_link_libraries(" + exeName + " PRIVATE " + alias + ")\n";
618+
s += "endif()\n";
619+
}
620+
s += "\n";
607621
}
608622

609623
if (!cf.defines.empty())

0 commit comments

Comments
 (0)