Skip to content

Commit 981c48d

Browse files
committed
[feature] msvc-static
1 parent 153bdbe commit 981c48d

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

docs/examples/msvc-static.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# Automatically generated from tests/msvc-static/cmake.toml - DO NOT EDIT
3+
layout: default
4+
title: msvc static
5+
permalink: /examples/msvc-static
6+
parent: Examples
7+
nav_order: 8
8+
---
9+
10+
# msvc static
11+
12+
A msvc-static `cmake.toml` project:
13+
14+
```toml
15+
[project]
16+
name = "msvc-static"
17+
description = "msvc static"
18+
19+
[target.basic]
20+
type = "executable"
21+
sources = ["src/msvc-static.cpp"]
22+
msvc-static = true
23+
```
24+
25+
26+
27+
<sup><sub>This page was automatically generated from [tests/msvc-static/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/msvc-static/cmake.toml).</sub></sup>

include/project_parser.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ struct Target {
103103
Condition<std::string> cmake_after;
104104
ConditionVector include_before;
105105
ConditionVector include_after;
106+
107+
bool allow_msvc_static = false;
106108
};
107109

108110
struct Template {

src/cmake_generator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,10 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
10261026
gen.conditional_cmake(tmplate->outline.cmake_after);
10271027
}
10281028

1029+
if (target.allow_msvc_static && !target.name.empty()) {
1030+
cmd("set_property")("TARGET", target.name, "PROPERTY", "MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
1031+
}
1032+
10291033
cmd("unset")("CMKR_TARGET");
10301034
cmd("unset")("CMKR_SOURCES");
10311035
}

src/project_parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
514514
t.optional("precompile-headers", target.precompile_headers);
515515
t.optional("private-precompile-headers", target.private_precompile_headers);
516516

517+
t.optional("msvc-static", target.allow_msvc_static);
518+
517519
if (!target.headers.empty()) {
518520
auto &sources = target.sources.nth(0).value();
519521
const auto &headers = target.headers.nth(0)->second;

tests/CMakeLists.txt

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

tests/msvc-static/cmake.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# A msvc-static `cmake.toml` project:
2+
3+
[project]
4+
name = "msvc-static"
5+
description = "msvc static"
6+
7+
[target.basic]
8+
type = "executable"
9+
sources = ["src/msvc-static.cpp"]
10+
msvc-static = true
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <cstdio>
2+
3+
int main() {
4+
puts("Hello from cmkr(msvc-static)!");
5+
}

0 commit comments

Comments
 (0)