Skip to content

Commit 9590760

Browse files
committed
Do not allow in-tree builds per default
1 parent 4b300df commit 9590760

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/project_parser.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct Project {
126126
std::string build_dir = "build";
127127
std::string generator;
128128
std::string config;
129+
bool allow_in_tree = false;
129130
Condition<std::vector<std::string>> project_subdirs;
130131
std::vector<std::string> cppflags;
131132
std::vector<std::string> cflags;

src/cmake_generator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,14 @@ int generate_cmake(const char *path, bool root) {
464464
if (root) {
465465
cmd("cmake_minimum_required")("VERSION", project.cmake_version).endl();
466466

467+
if (!project.allow_in_tree) {
468+
// clang-format off
469+
cmd("if")("CMAKE_SOURCE_DIR", "STREQUAL", "CMAKE_BINARY_DIR");
470+
cmd("message")("FATAL_ERROR", "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build");
471+
cmd("endif")().endl();
472+
// clang-format on
473+
}
474+
467475
comment("Regenerate CMakeLists.txt automatically in the root project");
468476
cmd("set")("CMKR_ROOT_PROJECT", "OFF");
469477
// clang-format off

src/project_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Project::Project(const std::string &path, bool build) {
7979
get_optional(cmake, "generator", generator);
8080
get_optional(cmake, "config", config);
8181
get_optional(cmake, "arguments", gen_args);
82+
get_optional(cmake, "allow-in-tree", allow_in_tree);
8283
}
8384
} else {
8485
if (toml.contains("cmake")) {

0 commit comments

Comments
 (0)