Skip to content

Commit

Permalink
Merge pull request #149 from build-cpp/relative-libs
Browse files Browse the repository at this point in the history
Improve relative path functionality for link-libraries
  • Loading branch information
mrexodia authored Sep 6, 2024
2 parents b0a1d79 + 50615e0 commit 87d9013
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- name: clang-format
id: clang-format
uses: DoozyX/clang-format-lint-action@c3b2c943e924028b93a707a5b1b017976ab8d50c # v0.15
uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 # v0.18.2
with:
exclude: './third_party'
extensions: 'c,h,cpp,hpp'
Expand Down
18 changes: 7 additions & 11 deletions src/project_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}/");
}
}
};
Expand Down

0 comments on commit 87d9013

Please sign in to comment.