Skip to content

Commit 87d9013

Browse files
authored
Merge pull request #149 from build-cpp/relative-libs
Improve relative path functionality for link-libraries
2 parents b0a1d79 + 50615e0 commit 87d9013

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- name: clang-format
1616
id: clang-format
17-
uses: DoozyX/clang-format-lint-action@c3b2c943e924028b93a707a5b1b017976ab8d50c # v0.15
17+
uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 # v0.18.2
1818
with:
1919
exclude: './third_party'
2020
extensions: 'c,h,cpp,hpp'

src/project_parser.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -657,20 +657,16 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
657657
continue;
658658
}
659659

660-
// Skip paths that don't contain backwards or forwards slashes
661-
if (library_path.find_first_of(R"(\/)") == std::string::npos) {
662-
continue;
663-
}
664-
665-
// Check if the new file path exists, otherwise emit an error
666-
const auto expected_library_file_path = fs::path{path} / library_path;
667-
if (!fs::exists(expected_library_file_path)) {
660+
if (fs::exists(fs::path(path) / library_path)) {
661+
// If the file path is relative, prepend ${CMAKE_CURRENT_SOURCE_DIR}
662+
library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
663+
} else if (library_path.find_first_of(R"(\/)") != std::string::npos) {
664+
// Error if the path contains a directory separator and the file doesn't exist
668665
throw std::runtime_error("Attempted to link against a library file that doesn't exist for target \"" + name + "\" in \"" +
669666
key + "\": " + library_path);
667+
} else {
668+
// NOTE: We cannot check if system libraries exist, so we leave them as-is
670669
}
671-
672-
// Prepend ${CMAKE_CURRENT_SOURCE_DIR} to the path
673-
library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
674670
}
675671
}
676672
};

0 commit comments

Comments
 (0)