Skip to content

Commit cb55a3c

Browse files
committed
fix(build): correct misleading CMake error detection and improve project root handling
2 parents 576e64e + 8127bad commit cb55a3c

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

src/commands/BuildCommand.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,18 +792,30 @@ namespace vix::commands::BuildCommand
792792
{
793793
fs::path base = cwd;
794794
if (!opt.dir.empty())
795-
base = fs::path(opt.dir);
795+
base = fs::absolute(fs::path(opt.dir));
796796

797+
fs::path projectDir;
797798
const auto root = util::find_project_root(base);
798-
if (!root)
799+
800+
if (root)
801+
{
802+
projectDir = *root;
803+
}
804+
else if (util::file_exists(base / "CMakeLists.txt"))
805+
{
806+
projectDir = base;
807+
}
808+
else
809+
{
799810
return std::nullopt;
811+
}
800812

801813
const auto presetOpt = resolve_preset(opt.preset);
802814
if (!presetOpt)
803815
return std::nullopt;
804816

805817
process::Plan plan;
806-
plan.projectDir = *root;
818+
plan.projectDir = fs::absolute(projectDir);
807819
plan.preset = *presetOpt;
808820

809821
plan.launcher = detect_launcher(opt);
@@ -824,8 +836,10 @@ namespace vix::commands::BuildCommand
824836

825837
std::string toolchainContent;
826838
if (!opt.targetTriple.empty())
839+
{
827840
toolchainContent =
828841
build::toolchain_contents_for_triple(opt.targetTriple, opt.sysroot);
842+
}
829843

830844
plan.cmakeVars = build_cmake_vars(
831845
plan.preset,

src/errors/build/CMakeBuildErrors.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,37 @@ namespace vix::cli::errors::build
201201

202202
bool handleMissingCMakeLists(std::string_view log)
203203
{
204-
if (!contains(log, "CMakeLists.txt") ||
205-
(!contains(log, "does not exist") &&
206-
!contains(log, "not found") &&
207-
!contains(log, "Cannot find")))
204+
const bool missingSourceDirCMakeLists =
205+
contains(log, "The source directory") &&
206+
contains(log, "does not appear to contain CMakeLists.txt");
207+
208+
const bool missingExplicitCMakeLists =
209+
contains(log, "CMake Error: The source directory") &&
210+
contains(log, "CMakeLists.txt");
211+
212+
const bool missingPathCMakeLists =
213+
contains(log, "Source directory") &&
214+
contains(log, "does not exist") &&
215+
contains(log, "CMakeLists.txt");
216+
217+
if (!missingSourceDirCMakeLists &&
218+
!missingExplicitCMakeLists &&
219+
!missingPathCMakeLists)
208220
{
209221
return false;
210222
}
211223

212224
const std::string path = extract(
213225
log,
214-
std::regex(R"re(source directory\s+"([^"]+)")re"));
226+
std::regex(R"re((?:The source directory|Source directory)\s+"([^"]+)")re"));
215227

216228
error("CMake configure failed: CMakeLists.txt not found.");
217-
printField("directory: ", path);
218-
hint("Make sure you are running cmake from the correct directory.");
219-
hint("Expected a CMakeLists.txt at the root of the project.");
229+
230+
if (!path.empty())
231+
printField("directory: ", path);
232+
233+
hint("Check the source directory passed to CMake.");
234+
hint("Run with --verbose to inspect the full configure command.");
220235
return true;
221236
}
222237

0 commit comments

Comments
 (0)