xref: /openbmc/phosphor-power/meson.build (revision 516e22fe84f77c2d029b028785dfd1e5633267b5)
139b370a5SBrad Bishopproject(
2690e7804SGeorge Liu    'phosphor-power',
339b370a5SBrad Bishop    'cpp',
439b370a5SBrad Bishop    default_options: [
539b370a5SBrad Bishop        'warning_level=3',
639b370a5SBrad Bishop        'werror=true',
75d79d36aSPatrick Williams        'cpp_std=c++23',
881d6cde4SBrandon Wyman        'buildtype=debugoptimized',
9*516e22feSPatrick Williams        'prefix=/usr',
1039b370a5SBrad Bishop    ],
1139b370a5SBrad Bishop    license: 'Apache-2.0',
1239b370a5SBrad Bishop    version: '1.0',
135d79d36aSPatrick Williams    meson_version: '>=1.1.1',
1439b370a5SBrad Bishop)
1539b370a5SBrad Bishop
16888bebdeSPatrick Williamscxx = meson.get_compiler('cpp')
17888bebdeSPatrick Williams
18b59b1fa2SJayanth Othayoth# Check if the compiler is Clang
19b59b1fa2SJayanth Othayothif meson.get_compiler('cpp').get_id() == 'clang'
20b59b1fa2SJayanth Othayoth    add_global_arguments('-Wno-defaulted-function-deleted', language: 'cpp')
21b59b1fa2SJayanth Othayothendif
22b59b1fa2SJayanth Othayoth
2339b370a5SBrad Bishopbuild_tests = get_option('tests')
2439b370a5SBrad Bishop
255c6a693eSPatrick Williamsif get_option('oe-sdk').allowed()
26dc8e9312SBrandon Wyman    # Setup OE SYSROOT
27*516e22feSPatrick Williams    OECORE_TARGET_SYSROOT = run_command(
28*516e22feSPatrick Williams        'sh',
29*516e22feSPatrick Williams        '-c',
30*516e22feSPatrick Williams        'echo $OECORE_TARGET_SYSROOT',
31*516e22feSPatrick Williams    ).stdout().strip()
32dc8e9312SBrandon Wyman    if OECORE_TARGET_SYSROOT == ''
33dc8e9312SBrandon Wyman        error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
34dc8e9312SBrandon Wyman    endif
35dc8e9312SBrandon Wyman    message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
36*516e22feSPatrick Williams    rpath = ':'.join(
37*516e22feSPatrick Williams        [OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'],
38*516e22feSPatrick Williams    )
39*516e22feSPatrick Williams    ld_so = run_command(
40*516e22feSPatrick Williams        'sh',
41*516e22feSPatrick Williams        '-c',
42*516e22feSPatrick Williams        'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1',
43*516e22feSPatrick Williams    ).stdout().strip()
44dc8e9312SBrandon Wyman    dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
45dc8e9312SBrandon Wymanelse
46dc8e9312SBrandon Wyman    dynamic_linker = []
47dc8e9312SBrandon Wymanendif
48dc8e9312SBrandon Wyman
49dc8e9312SBrandon Wyman
50220c246aSMatt Spinlergmock = dependency('gmock', disabler: true, required: false)
51220c246aSMatt Spinlergtest = dependency('gtest', main: true, disabler: true, required: false)
525c6a693eSPatrick Williamsif (not gtest.found() or not gmock.found()) and build_tests.allowed()
53220c246aSMatt Spinler    gtest_opts = import('cmake').subproject_options()
54*516e22feSPatrick Williams    gtest_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'})
55*516e22feSPatrick Williams    gtest_proj = import('cmake').subproject(
56*516e22feSPatrick Williams        'googletest',
57220c246aSMatt Spinler        options: gtest_opts,
58*516e22feSPatrick Williams        required: false,
59*516e22feSPatrick Williams    )
60220c246aSMatt Spinler    if gtest_proj.found()
61220c246aSMatt Spinler        gtest = declare_dependency(
62220c246aSMatt Spinler            dependencies: [
63220c246aSMatt Spinler                dependency('threads'),
64220c246aSMatt Spinler                gtest_proj.dependency('gtest'),
65220c246aSMatt Spinler                gtest_proj.dependency('gtest_main'),
66*516e22feSPatrick Williams            ],
67220c246aSMatt Spinler        )
68220c246aSMatt Spinler        gmock = gtest_proj.dependency('gmock')
69220c246aSMatt Spinler    else
70220c246aSMatt Spinler        assert(false, 'Googletest is required if tests are enabled')
71220c246aSMatt Spinler    endif
72220c246aSMatt Spinlerendif
73220c246aSMatt Spinler
74220c246aSMatt Spinler
75220c246aSMatt Spinler
7639b370a5SBrad Bishopphosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
7739b370a5SBrad Bishopphosphor_logging = dependency('phosphor-logging')
7843082e70SLei YUprog_python = import('python').find_installation('python3')
7939b370a5SBrad Bishopsdbusplus = dependency('sdbusplus')
8039b370a5SBrad Bishopsdbuspp = find_program('sdbus++')
8139b370a5SBrad Bishopsdeventplus = dependency('sdeventplus')
82e83604beSCheng C Yangpthread = dependency('threads')
837cbc5536SMatthew Barthstdplus = dependency('stdplus')
8489283d10SAndrew Geisslerboost = dependency('boost')
85*516e22feSPatrick Williamslibgpiodcxx = dependency('libgpiodcxx', default_options: ['bindings=cxx'])
86888bebdeSPatrick Williams
87d694d8fcSPatrick Williamsnlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
88888bebdeSPatrick Williams
89888bebdeSPatrick Williamsif cxx.has_header('CLI/CLI.hpp')
90888bebdeSPatrick Williams    cli11_dep = declare_dependency()
91888bebdeSPatrick Williamselse
92888bebdeSPatrick Williams    cli11_dep = dependency('CLI11')
93888bebdeSPatrick Williamsendif
9439b370a5SBrad Bishop
95bd3bd824SLei YUsystemd = dependency('systemd')
96df2f4cb8SPatrick Williamslibsystemd_dep = dependency('libsystemd')
9795f6aab2SPatrick Williamsservicedir = systemd.get_variable('systemdsystemunitdir')
98bd3bd824SLei YU
99bd3bd824SLei YUservices = [
1001c40f1c1SBrad Bishop    ['supply-monitor', 'power-supply-monitor@.service'],
1011c40f1c1SBrad Bishop    ['sequencer-monitor', 'pseq-monitor-pgood.service'],
1021c40f1c1SBrad Bishop    ['sequencer-monitor', 'pseq-monitor.service'],
1031c40f1c1SBrad Bishop    ['supply-monitor-ng', 'phosphor-psu-monitor.service'],
1041c40f1c1SBrad Bishop    ['regulators', 'phosphor-regulators.service'],
1051c40f1c1SBrad Bishop    ['regulators', 'phosphor-regulators-config.service'],
1061c40f1c1SBrad Bishop    ['regulators', 'phosphor-regulators-monitor-enable.service'],
1071c40f1c1SBrad Bishop    ['regulators', 'phosphor-regulators-monitor-disable.service'],
1085f99bc02SJim Wright    ['power-control', 'phosphor-power-control.service'],
109bd3bd824SLei YU]
110bd3bd824SLei YU
1116f499e68SGeorge Liufs = import('fs')
112bd3bd824SLei YUforeach service : services
1131c40f1c1SBrad Bishop    if get_option(service[0])
114*516e22feSPatrick Williams        fs.copyfile(
115*516e22feSPatrick Williams            'services/' + service[1],
1166f499e68SGeorge Liu            install: true,
117*516e22feSPatrick Williams            install_dir: servicedir,
118*516e22feSPatrick Williams        )
1191c40f1c1SBrad Bishop    endif
120bd3bd824SLei YUendforeach
121bd3bd824SLei YU
12240247cceSAndy YF Wang# Get the power sequencer class name
12340247cceSAndy YF Wangsequencer = get_option('power_sequencer')
12440247cceSAndy YF Wangif sequencer == 'ucd90160'
12540247cceSAndy YF Wang    sequencer_class = 'UCD90160'
12640247cceSAndy YF Wangelif sequencer == 'mihawk-cpld'
12740247cceSAndy YF Wang    sequencer_class = 'MihawkCPLD'
12840247cceSAndy YF Wangelse
12940247cceSAndy YF Wang    # power sequencer is incorrect
13040247cceSAndy YF Wang    error('power sequencer is incorrect')
13140247cceSAndy YF Wangendif
13240247cceSAndy YF Wang
13339b370a5SBrad Bishopconf = configuration_data()
13439b370a5SBrad Bishopconf.set_quoted(
135*516e22feSPatrick Williams    'INPUT_HISTORY_BUSNAME_ROOT',
136*516e22feSPatrick Williams    get_option('input-history-busname-root'),
137*516e22feSPatrick Williams)
13839b370a5SBrad Bishopconf.set_quoted(
139*516e22feSPatrick Williams    'INPUT_HISTORY_SENSOR_ROOT',
140*516e22feSPatrick Williams    get_option('input-history-sensor-root'),
141*516e22feSPatrick Williams)
142*516e22feSPatrick Williamsconf.set_quoted('INPUT_HISTORY_SYNC_GPIO', get_option('input-history-sync-gpio'))
143*516e22feSPatrick Williamsconf.set_quoted('PSU_JSON_PATH', '/usr/share/phosphor-power/psu.json')
144*516e22feSPatrick Williamsconf.set('SEQUENCER', sequencer_class)
145*516e22feSPatrick Williamsconf.set10('DEVICE_ACCESS', get_option('device-access'))
1461d7a7df8SBrandon Wymanconf.set10('IBM_VPD', get_option('ibm-vpd'))
14739b370a5SBrad Bishop
14839b370a5SBrad Bishopconfigure_file(output: 'config.h', configuration: conf)
14939b370a5SBrad Bishop
15039b370a5SBrad Bishop# Ensure the generated header here winds up in the correct path in the build
15139b370a5SBrad Bishop# tree such that it actually get used and doesn't get found in the sysroot
15239b370a5SBrad Bishop# somewhere.  Meson doesn't allow path elements (rightfully so) when specifying
15339b370a5SBrad Bishop# the output filename of a target definition so the target must be defined in
15439b370a5SBrad Bishop# the directory where the artifacts need to be placed.  Do that now, because
15539b370a5SBrad Bishop# the generated source (cpp) is needed to define the library target.
15639b370a5SBrad Bishopsubdir('org/open_power/Witherspoon/Fault')
15739b370a5SBrad Bishop
15839b370a5SBrad Bishoplibpower = static_library(
15939b370a5SBrad Bishop    'power',
16039b370a5SBrad Bishop    error_cpp,
16139b370a5SBrad Bishop    error_hpp,
1623cc348ceSShawn McCarney    'compatible_system_types_finder.cpp',
16398f42947SShawn McCarney    'dbus_interfaces_finder.cpp',
16439b370a5SBrad Bishop    'gpio.cpp',
16539b370a5SBrad Bishop    'pmbus.cpp',
1665f51444dSShawn McCarney    'temporary_file.cpp',
167de5434d8SShawn McCarney    'temporary_subdirectory.cpp',
16839b370a5SBrad Bishop    'utility.cpp',
16939b370a5SBrad Bishop    dependencies: [
170888bebdeSPatrick Williams        nlohmann_json_dep,
17139b370a5SBrad Bishop        phosphor_dbus_interfaces,
17239b370a5SBrad Bishop        phosphor_logging,
17339b370a5SBrad Bishop        sdbusplus,
17439b370a5SBrad Bishop        sdeventplus,
17539b370a5SBrad Bishop    ],
17639b370a5SBrad Bishop)
17739b370a5SBrad Bishop
1787c2fbbb6SLei YUlibpower_inc = include_directories('.')
1797c2fbbb6SLei YU
1804c94bc7cSShawn McCarney# Build the tools/i2c sub-directory first.  Other sub-directories depend on
1814c94bc7cSShawn McCarney# Meson variables defined there.
1824c94bc7cSShawn McCarneysubdir('tools/i2c')
1834c94bc7cSShawn McCarney
1841c40f1c1SBrad Bishopif get_option('regulators')
185a2461b34SShawn McCarney    subdir('phosphor-regulators')
1861c40f1c1SBrad Bishopendif
1871c40f1c1SBrad Bishopif get_option('sequencer-monitor')
18839b370a5SBrad Bishop    subdir('power-sequencer')
1891c40f1c1SBrad Bishopendif
1905f99bc02SJim Wrightif get_option('power-control')
1911553cd9aSJim Wright    subdir('phosphor-power-sequencer')
1921553cd9aSJim Wrightendif
1931c40f1c1SBrad Bishopif get_option('supply-monitor')
19439b370a5SBrad Bishop    subdir('power-supply')
1951c40f1c1SBrad Bishopendif
1961c40f1c1SBrad Bishopif get_option('supply-monitor-ng')
1972ad76bd3SBrandon Wyman    subdir('phosphor-power-supply')
1981c40f1c1SBrad Bishopendif
1991c40f1c1SBrad Bishopif get_option('utils')
2000bf1b782SLei YU    subdir('tools/power-utils')
2011c40f1c1SBrad Bishopendif
2025c6a693eSPatrick Williamsif get_option('tests').allowed()
20339b370a5SBrad Bishop    subdir('test')
204ff481438SShawn McCarneyendif
2051c40f1c1SBrad Bishopif get_option('cold-redundancy')
206e83604beSCheng C Yang    subdir('cold-redundancy')
2071c40f1c1SBrad Bishopendif
208