| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2019 The Meson development team |
| 3 |
# Copyright © 2023-2025 Intel Corporation |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
from mesonbuild.templates.sampleimpl import ClassImpl |
| 8 |
|
| 9 |
|
| 10 |
hello_cs_template = '''using System; |
| 11 |
|
| 12 |
public class {class_name} {{ |
| 13 |
const String PROJECT_NAME = "{project_name}"; |
| 14 |
|
| 15 |
static int Main(String[] args) {{ |
| 16 |
if (args.Length > 0) {{ |
| 17 |
System.Console.WriteLine(String.Format("{project_name} takes no arguments..")); |
| 18 |
return 1; |
| 19 |
}} |
| 20 |
Console.WriteLine(String.Format("This is project {{0}}.", PROJECT_NAME)); |
| 21 |
return 0; |
| 22 |
}} |
| 23 |
}} |
| 24 |
|
| 25 |
''' |
| 26 |
|
| 27 |
hello_cs_meson_template = '''project( |
| 28 |
'{project_name}', |
| 29 |
'cs', |
| 30 |
version : '{version}', |
| 31 |
meson_version : '>= {meson_version}', |
| 32 |
default_options : ['warning_level=3'], |
| 33 |
) |
| 34 |
|
| 35 |
dependencies = [{dependencies} |
| 36 |
] |
| 37 |
|
| 38 |
sources = [{source_files} |
| 39 |
] |
| 40 |
|
| 41 |
exe = executable( |
| 42 |
'{exe_name}', |
| 43 |
sources, |
| 44 |
install : true, |
| 45 |
dependencies : dependencies, |
| 46 |
) |
| 47 |
|
| 48 |
test('basic', exe) |
| 49 |
''' |
| 50 |
|
| 51 |
lib_cs_template = ''' |
| 52 |
public class {class_name} {{ |
| 53 |
private const int number = 6; |
| 54 |
|
| 55 |
public int get_number() {{ |
| 56 |
return number; |
| 57 |
}} |
| 58 |
}} |
| 59 |
|
| 60 |
''' |
| 61 |
|
| 62 |
lib_cs_test_template = '''using System; |
| 63 |
|
| 64 |
public class {class_test} {{ |
| 65 |
static int Main(String[] args) {{ |
| 66 |
if (args.Length > 0) {{ |
| 67 |
System.Console.WriteLine("{project_name} takes no arguments.."); |
| 68 |
return 1; |
| 69 |
}} |
| 70 |
{class_name} c = new {class_name}(); |
| 71 |
Boolean result = true; |
| 72 |
return result.CompareTo(c.get_number() != 6); |
| 73 |
}} |
| 74 |
}} |
| 75 |
|
| 76 |
''' |
| 77 |
|
| 78 |
lib_cs_meson_template = '''project( |
| 79 |
'{project_name}', |
| 80 |
'cs', |
| 81 |
version : '{version}', |
| 82 |
meson_version : '>= {meson_version}', |
| 83 |
default_options : ['warning_level=3'], |
| 84 |
) |
| 85 |
|
| 86 |
dependencies = [{dependencies} |
| 87 |
] |
| 88 |
|
| 89 |
sources = [{source_files} |
| 90 |
] |
| 91 |
|
| 92 |
stlib = shared_library( |
| 93 |
'{lib_name}', |
| 94 |
sources, |
| 95 |
dependencies : dependencies, |
| 96 |
install : true, |
| 97 |
) |
| 98 |
|
| 99 |
test_exe = executable( |
| 100 |
'{test_exe_name}', |
| 101 |
'{test_source_file}', |
| 102 |
dependencies : dependencies, |
| 103 |
link_with : stlib, |
| 104 |
) |
| 105 |
test('{test_name}', test_exe) |
| 106 |
|
| 107 |
# Make this library usable as a Meson subproject. |
| 108 |
{ltoken}_dep = declare_dependency( |
| 109 |
include_directories : include_directories('.'), |
| 110 |
dependencies : dependencies, |
| 111 |
link_with : stlib, |
| 112 |
) |
| 113 |
meson.override_dependency('{project_name}', {ltoken}_dep) |
| 114 |
|
| 115 |
''' |
| 116 |
|
| 117 |
|
| 118 |
class CSharpProject(ClassImpl): |
| 119 |
|
| 120 |
source_ext = 'cs' |
| 121 |
exe_template = hello_cs_template |
| 122 |
exe_meson_template = hello_cs_meson_template |
| 123 |
lib_template = lib_cs_template |
| 124 |
lib_test_template = lib_cs_test_template |
| 125 |
lib_meson_template = lib_cs_meson_template |