Merge pull request #3 from mrexodia/fix-windows

Fix path generation on Windows
self-hosting
Mohammed Alyousef 4 years ago committed by GitHub
commit 369ef8f68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -38,17 +38,21 @@ std::string format(const char *fmt, Args... args) {
return temp; return temp;
} }
std::vector<fs::path> expand_path(const fs::path &p) { static std::vector<std::string> expand_cmake_path(const fs::path &p) {
std::vector<fs::path> temp; std::vector<std::string> temp;
if (p.filename().stem().string() == "*") { if (p.filename().stem().string() == "*") {
auto ext = p.extension(); auto ext = p.extension();
for (const auto &f : fs::directory_iterator(p.parent_path())) { for (const auto &f : fs::directory_iterator(p.parent_path())) {
if (f.path().extension() == ext) { if (f.path().extension() == ext) {
temp.push_back(f.path()); temp.push_back(f.path().string());
} }
} }
} else { } 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; return temp;
} }
@ -263,7 +267,7 @@ int generate_cmake(const char *path) {
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n"; ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
for (const auto &src : bin.sources) { for (const auto &src : bin.sources) {
auto path = fs::path(src); auto path = fs::path(src);
auto expanded = detail::expand_path(path); auto expanded = detail::expand_cmake_path(path);
for (const auto &f : expanded) { for (const auto &f : expanded) {
ss << "\t" << f << "\n"; ss << "\t" << f << "\n";
} }
@ -357,7 +361,7 @@ int generate_cmake(const char *path) {
if (!inst.files.empty()) { if (!inst.files.empty()) {
ss << "\tFILES "; ss << "\tFILES ";
for (const auto &file : inst.files) { 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) for (const auto &f : path)
ss << f << " "; ss << f << " ";
} }

Loading…
Cancel
Save