Fix path generation on Windows

toml-checker
Duncan Ogilvie 4 years ago
parent 16e68d7542
commit 1d1ea3fdfd

@ -2,6 +2,7 @@
# Regenerate CMakeLists.txt file when necessary
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
if(CMKR_INCLUDE_RESULT)
cmkr()
endif()
@ -14,7 +15,7 @@ set(example_PROJECT_VERSION 0.1.0)
project(example VERSION ${example_PROJECT_VERSION})
set(EXAMPLE_SOURCES
"src/example.cpp"
src/example.cpp
)
add_executable(example ${EXAMPLE_SOURCES})

@ -38,17 +38,21 @@ std::string format(const char *fmt, Args... args) {
return temp;
}
std::vector<fs::path> expand_path(const fs::path &p) {
std::vector<fs::path> temp;
static std::vector<std::string> expand_cmake_path(const fs::path &p) {
std::vector<std::string> temp;
if (p.filename().stem().string() == "*") {
auto ext = p.extension();
for (const auto &f : fs::directory_iterator(p.parent_path())) {
if (f.path().extension() == ext) {
temp.push_back(f.path());
temp.push_back(f.path().string());
}
}
} else {
temp.push_back(p);
temp.push_back(p.string());
}
// Normalize all paths to work with CMake (it needs a / on Windows as well)
for(auto& path : temp) {
std::replace(path.begin(), path.end(), '\\', '/');
}
return temp;
}
@ -263,7 +267,7 @@ int generate_cmake(const char *path) {
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
for (const auto &src : bin.sources) {
auto path = fs::path(src);
auto expanded = detail::expand_path(path);
auto expanded = detail::expand_cmake_path(path);
for (const auto &f : expanded) {
ss << "\t" << f << "\n";
}
@ -357,7 +361,7 @@ int generate_cmake(const char *path) {
if (!inst.files.empty()) {
ss << "\tFILES ";
for (const auto &file : inst.files) {
auto path = detail::expand_path(fs::path(file));
auto path = detail::expand_cmake_path(fs::path(file));
for (const auto &f : path)
ss << f << " ";
}

Loading…
Cancel
Save