Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.2 FATAL_ERROR) |
| 2 | include (ExternalProject) |
Jason M. Bills | d23b84a | 2021-05-07 09:24:44 -0700 | [diff] [blame] | 3 | set (CMAKE_CXX_STANDARD 20) |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 4 | set (CMAKE_CXX_STANDARD_REQUIRED ON) |
| 5 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 6 | set (DBUS_OBJECT_NAME "xyz/openbmc_project/Smbios/MDR_V2") |
| 7 | set (DBUS_INTF_NAME "xyz.openbmc_project.Smbios.MDR_V2") |
| 8 | |
Zhikui Ren | 7745589 | 2020-11-19 12:29:44 -0800 | [diff] [blame] | 9 | # disable now to wa boost bug chriskohlhoff/asio#533 |
| 10 | # set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 11 | |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 12 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 13 | link_directories (${DBUSINTERFACE_LIBRARIES}) |
| 14 | |
| 15 | find_package (PkgConfig REQUIRED) |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 16 | |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 17 | pkg_check_modules (SYSTEMD libsystemd REQUIRED) |
| 18 | include_directories (${SYSTEMD_INCLUDE_DIRS}) |
| 19 | link_directories (${SYSTEMD_LIBRARY_DIRS}) |
| 20 | |
| 21 | # import sdbusplus |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 22 | pkg_check_modules (SDBUSPLUSPLUS sdbusplus REQUIRED) |
| 23 | include_directories (${SDBUSPLUSPLUS_INCLUDE_DIRS}) |
| 24 | link_directories (${SDBUSPLUSPLUS_LIBRARY_DIRS}) |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 25 | find_program (SDBUSPLUSPLUS sdbus++) |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 26 | |
| 27 | # phosphor-dbus-interfaces |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 28 | pkg_check_modules (DBUSINTERFACE phosphor-dbus-interfaces REQUIRED) |
| 29 | include_directories (${DBUSINTERFACE_INCLUDE_DIRS}) |
| 30 | link_directories (${DBUSINTERFACE_LIBRARY_DIRS}) |
| 31 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 32 | # boost |
| 33 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src) |
| 34 | set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH}) |
| 35 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 36 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 37 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 38 | add_definitions (-DBOOST_NO_RTTI) |
| 39 | add_definitions (-DBOOST_NO_TYPEID) |
| 40 | add_definitions (-DBOOST_ASIO_DISABLE_THREADS) |
| 41 | |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 42 | set (SRC_FILES src/mdrv2.cpp src/mdrv2_main.cpp src/cpu.cpp src/dimm.cpp |
Jie Yang | 08e4a6d | 2021-08-23 13:07:41 -0700 | [diff] [blame] | 43 | src/system.cpp src/pcieslot.cpp) |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 44 | |
| 45 | include_directories (${CMAKE_CURRENT_BINARY_DIR}) |
| 46 | |
Cheng C Yang | eecaf82 | 2019-12-19 00:34:23 +0800 | [diff] [blame] | 47 | add_executable (smbiosmdrv2app ${SRC_FILES}) |
| 48 | target_link_libraries (smbiosmdrv2app ${SYSTEMD_LIBRARIES}) |
| 49 | target_link_libraries (smbiosmdrv2app ${DBUSINTERFACE_LIBRARIES}) |
| 50 | target_link_libraries (smbiosmdrv2app ${SDBUSPLUSPLUS_LIBRARIES}) |
| 51 | target_link_libraries (smbiosmdrv2app phosphor_logging) |
| 52 | |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 53 | option (DIMM_DBUS "Expose DIMM D-Bus Interface" ON) |
| 54 | |
| 55 | if (DIMM_DBUS) |
| 56 | target_compile_definitions (smbiosmdrv2app PRIVATE DIMM_DBUS) |
| 57 | endif () |
| 58 | |
Hieu Huynh | 075f900 | 2023-06-08 08:32:53 +0000 | [diff] [blame] | 59 | if (NOT DEFINED SYSTEMD_SYSTEM_UNIT_DIR) |
| 60 | pkg_get_variable(SYSTEMD_SYSTEM_UNIT_DIR systemd systemdsystemunitdir) |
| 61 | endif() |
| 62 | |
Kuiying Wang | 3f244c0 | 2020-09-04 10:26:31 +0800 | [diff] [blame] | 63 | install (TARGETS smbiosmdrv2app DESTINATION bin) |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 64 | |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 65 | install (FILES ${PROJECT_SOURCE_DIR}/service_files/smbios-mdrv2.service |
Hieu Huynh | 075f900 | 2023-06-08 08:32:53 +0000 | [diff] [blame] | 66 | DESTINATION "${SYSTEMD_SYSTEM_UNIT_DIR}") |
Zhikui Ren | 18a5ab9 | 2020-09-01 21:35:20 -0700 | [diff] [blame] | 67 | |
John Edward Broadbent | efd4154 | 2022-12-13 16:39:18 -0800 | [diff] [blame] | 68 | option (DIMM_ONLY_LOCATOR "Only use the DIMM number, and not the bank" OFF) |
| 69 | |
| 70 | if (DIMM_ONLY_LOCATOR) |
| 71 | target_compile_definitions (smbiosmdrv2app PRIVATE DIMM_ONLY_LOCATOR) |
| 72 | endif () |
| 73 | |
| 74 | |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 75 | option (CPU_INFO "Add Cpuinfo Service" ON) |
| 76 | |
| 77 | option (YOCTO "Enable Building in Yocto" OFF) |
| 78 | |
| 79 | if (CPU_INFO) |
| 80 | add_executable (cpuinfoapp src/cpuinfo_main.cpp src/speed_select.cpp |
Jonathan Doman | 16a2ced | 2021-11-01 11:13:22 -0700 | [diff] [blame] | 81 | src/sst_mailbox.cpp |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 82 | src/cpuinfo_utils.cpp) |
| 83 | target_link_libraries (cpuinfoapp ${SYSTEMD_LIBRARIES}) |
| 84 | target_link_libraries (cpuinfoapp ${DBUSINTERFACE_LIBRARIES}) |
| 85 | target_link_libraries (cpuinfoapp ${SDBUSPLUSPLUS_LIBRARIES}) |
| 86 | target_link_libraries (cpuinfoapp phosphor_logging) |
| 87 | target_link_libraries (cpuinfoapp i2c) |
| 88 | target_link_libraries (cpuinfoapp peci) |
| 89 | |
| 90 | if (NOT YOCTO) |
| 91 | add_dependencies (cpuinfoapp libpeci) |
| 92 | externalproject_add (libpeci PREFIX ${CMAKE_BINARY_DIR}/libpeci |
| 93 | GIT_REPOSITORY https://github.com/openbmc/libpeci.git |
Saitwal, Meghan | 226357e | 2023-07-20 15:28:39 +0000 | [diff] [blame] | 94 | GIT_TAG b33f593d97cd814e73473376945d8bed27daeb37 |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 95 | INSTALL_COMMAND "") |
| 96 | |
| 97 | externalproject_get_property (libpeci SOURCE_DIR) |
| 98 | include_directories (${SOURCE_DIR}) |
| 99 | |
| 100 | externalproject_get_property (libpeci BINARY_DIR) |
| 101 | add_library (peci SHARED IMPORTED) |
| 102 | set_target_properties (peci |
| 103 | PROPERTIES IMPORTED_LOCATION ${BINARY_DIR}/libpeci.so) |
| 104 | endif () |
| 105 | |
| 106 | install (TARGETS cpuinfoapp |
| 107 | RUNTIME DESTINATION bin |
| 108 | LIBRARY DESTINATION lib |
| 109 | ARCHIVE DESTINATION lib/static) |
| 110 | |
| 111 | install (FILES |
| 112 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.cpuinfo.service |
Hieu Huynh | 075f900 | 2023-06-08 08:32:53 +0000 | [diff] [blame] | 113 | DESTINATION "${SYSTEMD_SYSTEM_UNIT_DIR}") |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 114 | endif() |
Jie Yang | fbe1b68 | 2021-02-19 04:54:55 -0800 | [diff] [blame] | 115 | |
| 116 | option (IPMI_BLOB "Add IPMI Blobs" ON) |
| 117 | |
| 118 | if (IPMI_BLOB) |
| 119 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/smbios-ipmi-blobs) |
| 120 | add_library (smbiosstore SHARED src/smbios-ipmi-blobs/handler.cpp |
| 121 | src/smbios-ipmi-blobs/main.cpp) |
| 122 | set_target_properties (smbiosstore PROPERTIES VERSION "0.0.0") |
| 123 | set_target_properties (smbiosstore PROPERTIES SOVERSION "0") |
| 124 | target_link_libraries (smbiosstore sdbusplus) |
| 125 | target_link_libraries (smbiosstore phosphor_logging) |
Jie Yang | 6e3e9c2 | 2021-07-22 18:41:44 -0700 | [diff] [blame] | 126 | install (TARGETS smbiosstore DESTINATION /usr/lib/ipmid-providers) |
Jie Yang | fbe1b68 | 2021-02-19 04:54:55 -0800 | [diff] [blame] | 127 | |
| 128 | if (NOT YOCTO) |
| 129 | add_dependencies (smbiosstore phosphor-host-ipmid phosphor-ipmi-blobs) |
| 130 | |
| 131 | file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/prefix) |
| 132 | externalproject_add ( |
Jonathan Doman | 63089f7 | 2022-06-16 17:06:18 -0700 | [diff] [blame] | 133 | phosphor-host-ipmid |
| 134 | PREFIX ${CMAKE_BINARY_DIR}/phosphor-host-ipmid |
Jie Yang | fbe1b68 | 2021-02-19 04:54:55 -0800 | [diff] [blame] | 135 | GIT_REPOSITORY https://github.com/openbmc/phosphor-host-ipmid |
| 136 | SOURCE_DIR ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src |
Jonathan Doman | 63089f7 | 2022-06-16 17:06:18 -0700 | [diff] [blame] | 137 | CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src |
| 138 | && meson --prefix=${CMAKE_BINARY_DIR}/prefix build-ext |
| 139 | BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src |
| 140 | && ninja -C build-ext |
| 141 | INSTALL_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src |
| 142 | && ninja -C build-ext install |
| 143 | LOG_DOWNLOAD ON) |
Jie Yang | fbe1b68 | 2021-02-19 04:54:55 -0800 | [diff] [blame] | 144 | include_directories (${CMAKE_BINARY_DIR}/prefix/include) |
| 145 | link_directories (${CMAKE_BINARY_DIR}/prefix/lib) |
| 146 | |
| 147 | externalproject_add ( |
| 148 | phosphor-ipmi-blobs PREFIX ${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs |
| 149 | GIT_REPOSITORY https://github.com/openbmc/phosphor-ipmi-blobs |
| 150 | SOURCE_DIR ${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs-src |
| 151 | CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "") |
| 152 | include_directories (${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs-src) |
| 153 | |
| 154 | # unit tests |
| 155 | set (BLOB_TEST_SRC src/smbios-ipmi-blobs/test) |
| 156 | |
| 157 | find_package (GTest REQUIRED) |
| 158 | |
| 159 | enable_testing () |
| 160 | |
| 161 | add_executable (runBlobBasic ${BLOB_TEST_SRC}/handler_unittest.cpp) |
| 162 | add_test (NAME test_blobbasic COMMAND runBlobBasic) |
| 163 | target_link_libraries (runBlobBasic smbiosstore ${GTEST_BOTH_LIBRARIES}) |
| 164 | |
| 165 | add_executable (runBlobOpen ${BLOB_TEST_SRC}/handler_open_unittest.cpp) |
| 166 | add_test (NAME test_blobopen COMMAND runBlobOpen) |
| 167 | target_link_libraries (runBlobOpen smbiosstore ${GTEST_BOTH_LIBRARIES}) |
| 168 | |
| 169 | add_executable (runBlobReadWrite |
| 170 | ${BLOB_TEST_SRC}/handler_readwrite_unittest.cpp) |
| 171 | add_test (NAME test_blobreadwrite COMMAND runBlobReadWrite) |
| 172 | target_link_libraries (runBlobReadWrite |
| 173 | smbiosstore -lgmock -lgmock_main ${GTEST_BOTH_LIBRARIES}) |
| 174 | |
| 175 | add_executable (runBlobStatClose |
| 176 | ${BLOB_TEST_SRC}/handler_statclose_unittest.cpp) |
| 177 | add_test (NAME test_blobStatClose COMMAND runBlobStatClose) |
| 178 | target_link_libraries (runBlobStatClose smbiosstore |
| 179 | ${GTEST_BOTH_LIBRARIES}) |
| 180 | endif () |
| 181 | endif () |