Skip to content

Commit a2f3329

Browse files
authored
Merge pull request #144 from build-cpp/msvc-runtime-subproject
Do not set CMAKE_MSVC_RUNTIME_LIBRARY if it's already set
2 parents 714a666 + 674c976 commit a2f3329

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/cmake_generator.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -731,23 +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-
if (project.project_msvc_runtime != parser::msvc_last) {
735-
comment("Enable support for MSVC_RUNTIME_LIBRARY");
736-
cmd("cmake_policy")("SET", "CMP0091", "NEW");
737-
738-
switch (project.project_msvc_runtime) {
739-
case parser::msvc_dynamic:
740-
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
741-
break;
742-
case parser::msvc_static:
743-
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
744-
break;
745-
default:
746-
break;
747-
}
748-
endl();
749-
}
750-
751734
// clang-format on
752735
if (!project.allow_in_tree) {
753736
// clang-format off
@@ -778,6 +761,26 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
778761
cmd("endif")().endl();
779762
// clang-format on
780763

764+
if (project.project_msvc_runtime != parser::msvc_last) {
765+
comment("Enable support for MSVC_RUNTIME_LIBRARY");
766+
cmd("cmake_policy")("SET", "CMP0091", "NEW");
767+
768+
// clang-format off
769+
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
770+
switch (project.project_msvc_runtime) {
771+
case parser::msvc_dynamic:
772+
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
773+
break;
774+
case parser::msvc_static:
775+
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
776+
break;
777+
default:
778+
break;
779+
}
780+
cmd("endif")().endl();
781+
// clang-format on
782+
}
783+
781784
fs::path cmkr_include(project.cmkr_include);
782785
if (!project.cmkr_include.empty() && !fs::exists(cmkr_include) && cmkr_include.is_relative()) {
783786
create_file(cmkr_include, resources::cmkr);

0 commit comments

Comments
 (0)