Skip to content

Commit 904114e

Browse files
committed
Fix install rule for executable projects
The type_not and if_not template queries were also introduced for this, because the fix was less verbose this way.
1 parent ac034ba commit 904114e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

cmake-init/cmake_init.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,20 @@ def write_file(path, d, overwrite, zip_path):
198198

199199
def replacer(match):
200200
query = match.group(1)
201+
expected = True
202+
if query.endswith("_not"):
203+
query = query[:-4]
204+
expected = False
201205
if query == "type":
202206
mapping = {"exe": "e", "header": "h", "shared": "s"}
203-
if mapping[match.group(2)] == d["type_id"]:
207+
actual = mapping[match.group(2)] == d["type_id"]
208+
if actual == expected:
204209
return match.group(3)
205-
elif query == "if" and d[match.group(2)] is True:
210+
elif query == "if" and d[match.group(2)] == expected:
206211
return match.group(3)
207212
return ""
208213

209-
regex = re.compile("{(type|if) ([^}]+)}(.+?){end}", re.DOTALL)
214+
regex = re.compile("{((?:type|if)(?:_not)?) ([^}]+)}(.+?){end}", re.DOTALL)
210215
contents = regex.sub(replacer, zip_path.read_text(encoding="UTF-8"))
211216
with open(path, "w", encoding="UTF-8", newline="\n") as f:
212217
f.write(contents % d)

cmake-init/templates/common/cmake/install-rules.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ install(
2626
){end}
2727

2828
install(
29-
TARGETS %(name)s_%(name)s
29+
TARGETS %(name)s_{type_not exe}%(name)s{end}{type exe}exe{end}
3030
EXPORT %(name)sTargets{type exe}
3131
RUNTIME COMPONENT %(name)s_Runtime{end}{type shared}
3232
RUNTIME #

0 commit comments

Comments
 (0)