blob: 35152b1cb3af05d8e456c9d31fd75f243cfb65f7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import _common
import ymake
from ymake import macro, Unit
@macro
def CMAKE_EXPORTED_TARGET_NAME_FROM_PATH(unit: Unit, *args: tuple[str, ...]):
"""
@usage: CMAKE_EXPORTED_TARGET_NAME_FROM_PATH(ProjectRoot)
Sets cmake target name to the module path relative to ProjectRoot with '/' replaced by '-',
without changing the name of the output artefact (see CMAKE_EXPORTED_TARGET_NAME).
Use it to resolve target name conflicts between same-named modules when a project subtree
is exported to cmake. For example, a PROGRAM(app) module at proj/foo/bar/app
with CMAKE_EXPORTED_TARGET_NAME_FROM_PATH(proj) is exported as cmake target
foo-bar-app still building artefact named app.
The module must be located strictly inside ProjectRoot.
"""
if len(args) != 1:
ymake.report_configure_error(
'[[imp]]CMAKE_EXPORTED_TARGET_NAME_FROM_PATH[[rst]] expects exactly one argument: a project root path'
)
return
module_dir = _common.strip_roots(unit.path())
root = args[0].strip('/')
if not root or not module_dir.startswith(root + '/'):
ymake.report_configure_error(
"[[imp]]CMAKE_EXPORTED_TARGET_NAME_FROM_PATH[[rst]]: module '[[imp]]{}[[rst]]' is not strictly inside '[[unimp]]{}[[rst]]'".format(
module_dir, args[0]
)
)
return
unit.oncmake_exported_target_name([module_dir[len(root) + 1 :].replace('/', '-')])
|