1project(
2    'openpower-proc-control',
3    'cpp',
4    default_options: [
5        'warning_level=3',
6        'werror=true',
7        'cpp_std=c++20',
8        'buildtype=debugoptimized',
9        'b_ndebug=if-release',
10    ],
11    license: 'Apache-2.0',
12    version: '1.0',
13    meson_version: '>=0.57.0',
14)
15add_project_arguments('-Wno-psabi', language: 'cpp')
16
17if get_option('cpp_std') != 'c++20'
18    error('This project requires c++20')
19endif
20
21if(get_option('buildtype') == 'minsize')
22    add_project_arguments('-DNDEBUG', language : 'cpp')
23endif
24
25cxx = meson.get_compiler('cpp')
26
27extra_sources = []
28extra_dependencies = []
29extra_unit_files = []
30
31# Configuration header file(config.h) generation
32conf_data = configuration_data()
33
34conf_data.set_quoted('DEVTREE_EXPORT_FILTER_FILE', get_option('DEVTREE_EXPORT_FILTER_FILE'),
35                      description : 'Path to the phal devtree export filter file'
36                    )
37
38conf_data.set_quoted('DEVTREE_EXP_FILE', get_option('DEVTREE_EXP_FILE'),
39                      description : 'Path to the devtree export copy file'
40                    )
41
42configure_file(configuration : conf_data,
43               output : 'config.h'
44              )
45
46unit_subs = configuration_data()
47unit_subs.set('bindir', join_paths(get_option('prefix'), get_option('bindir')))
48unit_subs.set('ENABLE_PHAL_TRUE', '#')
49
50if get_option('phal').enabled() and get_option('p9').enabled()
51    error('phal and p9 cannot be selected at the same time')
52endif
53
54build_p9 = not get_option('p9').disabled()
55build_openfsi = not get_option('openfsi').disabled()
56build_phal = get_option('phal').enabled()
57
58if get_option('phal').enabled() and not get_option('p9').disabled()
59    build_p9 = false
60endif
61
62summary('building p9', build_p9)
63summary('building openfsi', build_openfsi)
64summary('building phal', build_phal)
65
66if build_p9
67    extra_sources += [
68        'procedures/p9/cleanup_pcie.cpp',
69        'procedures/p9/set_sync_fsi_clock_mode.cpp',
70        'procedures/p9/start_host.cpp',
71        'procedures/p9/start_host_mpreboot.cpp',
72    ]
73endif
74if build_openfsi
75    extra_sources += [
76        'procedures/openfsi/scan.cpp',
77    ]
78endif
79if build_phal
80    extra_sources += [
81        'procedures/phal/start_host.cpp',
82        'procedures/phal/set_SPI_mux.cpp',
83        'procedures/phal/proc_pre_poweroff.cpp',
84        'procedures/phal/check_host_running.cpp',
85        'procedures/phal/import_devtree.cpp',
86        'extensions/phal/common_utils.cpp',
87        'extensions/phal/pdbg_utils.cpp',
88        'extensions/phal/create_pel.cpp',
89        'extensions/phal/phal_error.cpp',
90    ]
91    extra_dependencies += [
92        dependency('libdt-api'),
93        cxx.find_library('ekb'),
94        cxx.find_library('ipl'),
95        cxx.find_library('phal'),
96    ]
97    extra_unit_files = [
98        'service_files/set-spi-mux.service',
99        'service_files/phal-reinit-devtree.service',
100        'service_files/proc-pre-poweroff@.service',
101        'service_files/op-reset-host-check@.service',
102        'service_files/op-reset-host-clear.service',
103        'service_files/phal-import-devtree@.service',
104        'service_files/phal-export-devtree@.service',
105    ]
106    unit_subs.set('ENABLE_PHAL_TRUE', '')
107endif
108
109executable(
110    'openpower-proc-control',
111    [
112        'cfam_access.cpp',
113        'ext_interface.cpp',
114        'filedescriptor.cpp',
115        'proc_control.cpp',
116        'targeting.cpp',
117        'procedures/common/cfam_overrides.cpp',
118        'procedures/common/cfam_reset.cpp',
119        'procedures/common/enter_mpreboot.cpp',
120        'procedures/common/collect_sbe_hb_data.cpp',
121        'util.cpp',
122    ] + extra_sources,
123    dependencies: [
124        dependency('libgpiodcxx'),
125        cxx.find_library('pdbg'),
126        dependency('phosphor-dbus-interfaces'),
127        dependency('phosphor-logging'),
128        dependency('sdbusplus'),
129        dependency('threads'),
130        dependency('fmt'),
131    ] + extra_dependencies,
132    install: true
133)
134
135executable(
136    'openpower-proc-nmi',
137    [
138        'nmi_main.cpp',
139        'nmi_interface.cpp',
140    ],
141    dependencies: [
142        cxx.find_library('pdbg'),
143        dependency('phosphor-dbus-interfaces'),
144        dependency('phosphor-logging'),
145        dependency('sdbusplus'),
146   ],
147   install: true
148)
149
150if build_phal
151    executable(
152        'phal-export-devtree',
153        [
154            'extensions/phal/devtree_export.cpp',
155            'extensions/phal/fw_update_watch.cpp',
156            'extensions/phal/pdbg_utils.cpp',
157            'extensions/phal/create_pel.cpp',
158            'util.cpp',
159        ],
160        dependencies: [
161            dependency('phosphor-logging'),
162            dependency('sdbusplus'),
163            dependency('sdeventplus'),
164            dependency('fmt'),
165            dependency('phosphor-dbus-interfaces'),
166            cxx.find_library('pdbg'),
167       ],
168       install: true
169   )
170endif
171
172unit_files = [
173    'service_files/pcie-poweroff@.service',
174    'service_files/xyz.openbmc_project.Control.Host.NMI.service',
175    'service_files/op-stop-instructions@.service',
176    'service_files/op-cfam-reset.service',
177    'service_files/op-continue-mpreboot@.service',
178    'service_files/op-enter-mpreboot@.service',
179] + extra_unit_files
180
181systemd_system_unit_dir = dependency('systemd').get_pkgconfig_variable(
182    'systemdsystemunitdir',
183    define_variable: ['prefix', get_option('prefix')])
184foreach u : unit_files
185    configure_file(
186        configuration: unit_subs,
187        input: u + '.in',
188        install: true,
189        install_dir: systemd_system_unit_dir,
190        output: '@BASENAME@'
191    )
192endforeach
193
194if not get_option('tests').disabled()
195    test(
196        'utest',
197        executable(
198            'utest',
199            'test/utest.cpp',
200            'targeting.cpp',
201            'filedescriptor.cpp',
202            dependencies: [
203                dependency('gtest', main: true),
204                dependency('phosphor-logging'),
205            ],
206            implicit_include_directories: false,
207            include_directories: '.',
208        )
209    )
210endif
211