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