Skip to content

Commit 1d1ea3f

Browse files
committed
Fix path generation on Windows
1 parent 16e68d7 commit 1d1ea3f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Regenerate CMakeLists.txt file when necessary
44
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
5+
56
if(CMKR_INCLUDE_RESULT)
67
cmkr()
78
endif()
@@ -14,7 +15,7 @@ set(example_PROJECT_VERSION 0.1.0)
1415
project(example VERSION ${example_PROJECT_VERSION})
1516

1617
set(EXAMPLE_SOURCES
17-
"src/example.cpp"
18+
src/example.cpp
1819
)
1920

2021
add_executable(example ${EXAMPLE_SOURCES})

src/gen.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ std::string format(const char *fmt, Args... args) {
3838
return temp;
3939
}
4040

41-
std::vector<fs::path> expand_path(const fs::path &p) {
42-
std::vector<fs::path> temp;
41+
static std::vector<std::string> expand_cmake_path(const fs::path &p) {
42+
std::vector<std::string> temp;
4343
if (p.filename().stem().string() == "*") {
4444
auto ext = p.extension();
4545
for (const auto &f : fs::directory_iterator(p.parent_path())) {
4646
if (f.path().extension() == ext) {
47-
temp.push_back(f.path());
47+
temp.push_back(f.path().string());
4848
}
4949
}
5050
} else {
51-
temp.push_back(p);
51+
temp.push_back(p.string());
52+
}
53+
// Normalize all paths to work with CMake (it needs a / on Windows as well)
54+
for(auto& path : temp) {
55+
std::replace(path.begin(), path.end(), '\\', '/');
5256
}
5357
return temp;
5458
}
@@ -263,7 +267,7 @@ int generate_cmake(const char *path) {
263267
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
264268
for (const auto &src : bin.sources) {
265269
auto path = fs::path(src);
266-
auto expanded = detail::expand_path(path);
270+
auto expanded = detail::expand_cmake_path(path);
267271
for (const auto &f : expanded) {
268272
ss << "\t" << f << "\n";
269273
}
@@ -357,7 +361,7 @@ int generate_cmake(const char *path) {
357361
if (!inst.files.empty()) {
358362
ss << "\tFILES ";
359363
for (const auto &file : inst.files) {
360-
auto path = detail::expand_path(fs::path(file));
364+
auto path = detail::expand_cmake_path(fs::path(file));
361365
for (const auto &f : path)
362366
ss << f << " ";
363367
}

0 commit comments

Comments
 (0)