From 42ed3048b32f886edb80e105cc5c3c9959cb1041 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 6 Sep 2024 13:50:43 +0200 Subject: [PATCH] Improve relative path functionality for link-libraries --- src/project_parser.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/project_parser.cpp b/src/project_parser.cpp index c51a316..b1ceea6 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -657,20 +657,16 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p continue; } - // Skip paths that don't contain backwards or forwards slashes - if (library_path.find_first_of(R"(\/)") == std::string::npos) { - continue; - } - - // Check if the new file path exists, otherwise emit an error - const auto expected_library_file_path = fs::path{path} / library_path; - if (!fs::exists(expected_library_file_path)) { + if (fs::exists(fs::path(path) / library_path)) { + // If the file path is relative, prepend ${CMAKE_CURRENT_SOURCE_DIR} + library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/"); + } else if (library_path.find_first_of(R"(\/)") != std::string::npos) { + // Error if the path contains a directory separator and the file doesn't exist throw std::runtime_error("Attempted to link against a library file that doesn't exist for target \"" + name + "\" in \"" + key + "\": " + library_path); + } else { + // NOTE: We cannot check if system libraries exist, so we leave them as-is } - - // Prepend ${CMAKE_CURRENT_SOURCE_DIR} to the path - library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/"); } } };