Do not allow in-tree builds per default

toml-checker
Duncan Ogilvie 3 years ago
parent 4b300df8d5
commit 95907602b4

4
CMakeLists.txt generated

@ -3,6 +3,10 @@
cmake_minimum_required(VERSION 2.8...3.8)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build")
endif()
# Regenerate CMakeLists.txt automatically in the root project
set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

@ -126,6 +126,7 @@ struct Project {
std::string build_dir = "build";
std::string generator;
std::string config;
bool allow_in_tree = false;
Condition<std::vector<std::string>> project_subdirs;
std::vector<std::string> cppflags;
std::vector<std::string> cflags;

@ -464,6 +464,14 @@ int generate_cmake(const char *path, bool root) {
if (root) {
cmd("cmake_minimum_required")("VERSION", project.cmake_version).endl();
if (!project.allow_in_tree) {
// clang-format off
cmd("if")("CMAKE_SOURCE_DIR", "STREQUAL", "CMAKE_BINARY_DIR");
cmd("message")("FATAL_ERROR", "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build");
cmd("endif")().endl();
// clang-format on
}
comment("Regenerate CMakeLists.txt automatically in the root project");
cmd("set")("CMKR_ROOT_PROJECT", "OFF");
// clang-format off

@ -79,6 +79,7 @@ Project::Project(const std::string &path, bool build) {
get_optional(cmake, "generator", generator);
get_optional(cmake, "config", config);
get_optional(cmake, "arguments", gen_args);
get_optional(cmake, "allow-in-tree", allow_in_tree);
}
} else {
if (toml.contains("cmake")) {

Loading…
Cancel
Save