Skip to content

Commit 523f5f4

Browse files
authored
Merge pull request #150 from build-cpp/msvc-runtime-root
Only emit `MSVC_RUNTIME_LIBRARY` in the root project
2 parents 87d9013 + 510cf71 commit 523f5f4

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/cmake_generator.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
731731
if (is_root_project) {
732732
cmd("cmake_minimum_required")("VERSION", project.cmake_version).endl();
733733

734-
// clang-format on
735734
if (!project.allow_in_tree) {
736735
// clang-format off
737736
cmd("if")("CMAKE_SOURCE_DIR", "STREQUAL", "CMAKE_BINARY_DIR");
@@ -740,6 +739,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
740739
// clang-format on
741740
}
742741

742+
if (project.project_msvc_runtime != parser::msvc_last) {
743+
comment("Enable support for MSVC_RUNTIME_LIBRARY");
744+
cmd("cmake_policy")("SET", "CMP0091", "NEW").endl();
745+
}
746+
743747
cmd("set")("CMKR_ROOT_PROJECT", "OFF");
744748
// clang-format off
745749
cmd("if")("CMAKE_CURRENT_SOURCE_DIR", "STREQUAL", "CMAKE_SOURCE_DIR");
@@ -758,15 +762,9 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
758762

759763
comment("Create a configure-time dependency on cmake.toml to improve IDE support");
760764
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
761-
cmd("endif")().endl();
762-
// clang-format on
763-
764-
if (project.project_msvc_runtime != parser::msvc_last) {
765-
comment("Enable support for MSVC_RUNTIME_LIBRARY");
766-
cmd("cmake_policy")("SET", "CMP0091", "NEW");
767765

768-
// clang-format off
769-
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
766+
if (project.project_msvc_runtime != parser::msvc_last) {
767+
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
770768
switch (project.project_msvc_runtime) {
771769
case parser::msvc_dynamic:
772770
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
@@ -777,9 +775,10 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
777775
default:
778776
break;
779777
}
780-
cmd("endif")().endl();
781-
// clang-format on
782-
}
778+
cmd("endif")().endl();
779+
}
780+
cmd("endif")().endl();
781+
// clang-format on
783782

784783
fs::path cmkr_include(project.cmkr_include);
785784
if (!project.cmkr_include.empty() && !fs::exists(cmkr_include) && cmkr_include.is_relative()) {

0 commit comments

Comments
 (0)