diff --git a/include/gen.h b/include/gen.h index 0e808af..a2c99c0 100644 --- a/include/gen.h +++ b/include/gen.h @@ -6,7 +6,7 @@ namespace gen { int generate_project(const char *typ); -int generate_cmake(const char *path); +int generate_cmake(const char *path, bool root = true); } // namespace gen } // namespace cmkr diff --git a/src/cmkrlib/gen.cpp b/src/cmkrlib/gen.cpp index 0cfdb56..78f5fec 100644 --- a/src/cmkrlib/gen.cpp +++ b/src/cmkrlib/gen.cpp @@ -205,7 +205,7 @@ struct Command { } }; -int generate_cmake(const char *path) { +int generate_cmake(const char *path, bool root) { if (fs::exists(fs::path(path) / "cmake.toml")) { cmake::CMake cmake(path, false); std::stringstream ss; @@ -243,16 +243,18 @@ int generate_cmake(const char *path) { } // TODO: make this a setting in the toml? - comment("Regenerate CMakeLists.txt file when necessary"); - cmd("include")("cmkr.cmake", "OPTIONAL", "RESULT_VARIABLE", "CMKR_INCLUDE_RESULT").endl(); + if(root) { + comment("Regenerate CMakeLists.txt file when necessary"); + cmd("include")("cmkr.cmake", "OPTIONAL", "RESULT_VARIABLE", "CMKR_INCLUDE_RESULT").endl(); - cmd("if")("CMKR_INCLUDE_RESULT"); - cmd("cmkr")(); - cmd("endif")().endl(); + cmd("if")("CMKR_INCLUDE_RESULT"); + cmd("cmkr")(); + cmd("endif")().endl(); - cmd("cmake_minimum_required")("VERSION", cmake.cmake_version).endl(); + cmd("cmake_minimum_required")("VERSION", cmake.cmake_version).endl(); - cmd("set_property")("GLOBAL", "PROPERTY", "USE_FOLDERS", "ON").endl(); + cmd("set_property")("GLOBAL", "PROPERTY", "USE_FOLDERS", "ON").endl(); + } // TODO: remove support and replace with global compile-features if (!cmake.cppflags.empty()) { @@ -540,7 +542,7 @@ int generate_cmake(const char *path) { for (const auto &sub : cmake.subdirs) { if (fs::exists(fs::path(sub) / "cmake.toml")) - generate_cmake(sub.c_str()); + generate_cmake(sub.c_str(), false); } } else { throw std::runtime_error("No cmake.toml found!");