blob: 2cc888b42c6362864b085427d3d5a672e0eb2b03 [file] [log] [blame]
Cheng C Yangeecaf822019-12-19 00:34:23 +08001cmake_minimum_required (VERSION 3.2 FATAL_ERROR)
2include (ExternalProject)
Jason M. Billsd23b84a2021-05-07 09:24:44 -07003set (CMAKE_CXX_STANDARD 20)
Cheng C Yangeecaf822019-12-19 00:34:23 +08004set (CMAKE_CXX_STANDARD_REQUIRED ON)
5set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
6set (DBUS_OBJECT_NAME "xyz/openbmc_project/Smbios/MDR_V2")
7set (DBUS_INTF_NAME "xyz.openbmc_project.Smbios.MDR_V2")
8
Zhikui Ren77455892020-11-19 12:29:44 -08009# disable now to wa boost bug chriskohlhoff/asio#533
10# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
Cheng C Yangeecaf822019-12-19 00:34:23 +080011
Cheng C Yangeecaf822019-12-19 00:34:23 +080012include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
13link_directories (${DBUSINTERFACE_LIBRARIES})
14
15find_package (PkgConfig REQUIRED)
Jonathan Doman94c94bf2020-10-05 23:25:45 -070016
Cheng C Yangeecaf822019-12-19 00:34:23 +080017pkg_check_modules (SYSTEMD libsystemd REQUIRED)
18include_directories (${SYSTEMD_INCLUDE_DIRS})
19link_directories (${SYSTEMD_LIBRARY_DIRS})
20
21# import sdbusplus
Cheng C Yangeecaf822019-12-19 00:34:23 +080022pkg_check_modules (SDBUSPLUSPLUS sdbusplus REQUIRED)
23include_directories (${SDBUSPLUSPLUS_INCLUDE_DIRS})
24link_directories (${SDBUSPLUSPLUS_LIBRARY_DIRS})
Jonathan Doman94c94bf2020-10-05 23:25:45 -070025find_program (SDBUSPLUSPLUS sdbus++)
Cheng C Yangeecaf822019-12-19 00:34:23 +080026
27# phosphor-dbus-interfaces
Cheng C Yangeecaf822019-12-19 00:34:23 +080028pkg_check_modules (DBUSINTERFACE phosphor-dbus-interfaces REQUIRED)
29include_directories (${DBUSINTERFACE_INCLUDE_DIRS})
30link_directories (${DBUSINTERFACE_LIBRARY_DIRS})
31
Zhikui Ren18a5ab92020-09-01 21:35:20 -070032# boost
33include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
34set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
35add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
36add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
37add_definitions (-DBOOST_ALL_NO_LIB)
38add_definitions (-DBOOST_NO_RTTI)
39add_definitions (-DBOOST_NO_TYPEID)
40add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
41
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080042set (SRC_FILES src/mdrv2.cpp src/mdrv2_main.cpp src/cpu.cpp src/dimm.cpp
Jie Yang08e4a6d2021-08-23 13:07:41 -070043 src/system.cpp src/pcieslot.cpp)
Cheng C Yangeecaf822019-12-19 00:34:23 +080044
45include_directories (${CMAKE_CURRENT_BINARY_DIR})
46
Cheng C Yangeecaf822019-12-19 00:34:23 +080047add_executable (smbiosmdrv2app ${SRC_FILES})
48target_link_libraries (smbiosmdrv2app ${SYSTEMD_LIBRARIES})
49target_link_libraries (smbiosmdrv2app ${DBUSINTERFACE_LIBRARIES})
50target_link_libraries (smbiosmdrv2app ${SDBUSPLUSPLUS_LIBRARIES})
51target_link_libraries (smbiosmdrv2app phosphor_logging)
52
Zhikui Ren18a5ab92020-09-01 21:35:20 -070053option (DIMM_DBUS "Expose DIMM D-Bus Interface" ON)
54
55if (DIMM_DBUS)
56 target_compile_definitions (smbiosmdrv2app PRIVATE DIMM_DBUS)
57endif ()
58
Kuiying Wang3f244c02020-09-04 10:26:31 +080059install (TARGETS smbiosmdrv2app DESTINATION bin)
Zhikui Ren18a5ab92020-09-01 21:35:20 -070060
Jie Yang6e3e9c22021-07-22 18:41:44 -070061install (FILES ${PROJECT_SOURCE_DIR}/service_files/smbios-mdrv2.service
62 DESTINATION /lib/systemd/system/)
Zhikui Ren18a5ab92020-09-01 21:35:20 -070063
Jie Yang6e3e9c22021-07-22 18:41:44 -070064option (CPU_INFO "Add Cpuinfo Service" ON)
65
66option (YOCTO "Enable Building in Yocto" OFF)
67
68if (CPU_INFO)
69 add_executable (cpuinfoapp src/cpuinfo_main.cpp src/speed_select.cpp
Jonathan Doman16a2ced2021-11-01 11:13:22 -070070 src/sst_mailbox.cpp
Jie Yang6e3e9c22021-07-22 18:41:44 -070071 src/cpuinfo_utils.cpp)
72 target_link_libraries (cpuinfoapp ${SYSTEMD_LIBRARIES})
73 target_link_libraries (cpuinfoapp ${DBUSINTERFACE_LIBRARIES})
74 target_link_libraries (cpuinfoapp ${SDBUSPLUSPLUS_LIBRARIES})
75 target_link_libraries (cpuinfoapp phosphor_logging)
76 target_link_libraries (cpuinfoapp i2c)
77 target_link_libraries (cpuinfoapp peci)
78
79 if (NOT YOCTO)
80 add_dependencies (cpuinfoapp libpeci)
81 externalproject_add (libpeci PREFIX ${CMAKE_BINARY_DIR}/libpeci
82 GIT_REPOSITORY https://github.com/openbmc/libpeci.git
Jonathan Doman631388e2021-11-04 10:48:35 -070083 GIT_TAG 6a00e9aa72f75d66eb8b9572c7fd3894f91c6bba
Jie Yang6e3e9c22021-07-22 18:41:44 -070084 INSTALL_COMMAND "")
85
86 externalproject_get_property (libpeci SOURCE_DIR)
87 include_directories (${SOURCE_DIR})
88
89 externalproject_get_property (libpeci BINARY_DIR)
90 add_library (peci SHARED IMPORTED)
91 set_target_properties (peci
92 PROPERTIES IMPORTED_LOCATION ${BINARY_DIR}/libpeci.so)
93 endif ()
94
95 install (TARGETS cpuinfoapp
96 RUNTIME DESTINATION bin
97 LIBRARY DESTINATION lib
98 ARCHIVE DESTINATION lib/static)
99
100 install (FILES
101 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.cpuinfo.service
102 DESTINATION /lib/systemd/system/)
103endif()
Jie Yangfbe1b682021-02-19 04:54:55 -0800104
105option (IPMI_BLOB "Add IPMI Blobs" ON)
106
107if (IPMI_BLOB)
108 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/smbios-ipmi-blobs)
109 add_library (smbiosstore SHARED src/smbios-ipmi-blobs/handler.cpp
110 src/smbios-ipmi-blobs/main.cpp)
111 set_target_properties (smbiosstore PROPERTIES VERSION "0.0.0")
112 set_target_properties (smbiosstore PROPERTIES SOVERSION "0")
113 target_link_libraries (smbiosstore sdbusplus)
114 target_link_libraries (smbiosstore phosphor_logging)
Jie Yang6e3e9c22021-07-22 18:41:44 -0700115 install (TARGETS smbiosstore DESTINATION /usr/lib/ipmid-providers)
Jie Yangfbe1b682021-02-19 04:54:55 -0800116
117 if (NOT YOCTO)
118 add_dependencies (smbiosstore phosphor-host-ipmid phosphor-ipmi-blobs)
119
120 file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/prefix)
121 externalproject_add (
Jonathan Doman63089f72022-06-16 17:06:18 -0700122 phosphor-host-ipmid
123 PREFIX ${CMAKE_BINARY_DIR}/phosphor-host-ipmid
Jie Yangfbe1b682021-02-19 04:54:55 -0800124 GIT_REPOSITORY https://github.com/openbmc/phosphor-host-ipmid
125 SOURCE_DIR ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src
Jonathan Doman63089f72022-06-16 17:06:18 -0700126 CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src
127 && meson --prefix=${CMAKE_BINARY_DIR}/prefix build-ext
128 BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src
129 && ninja -C build-ext
130 INSTALL_COMMAND cd ${CMAKE_BINARY_DIR}/phosphor-host-ipmid-src
131 && ninja -C build-ext install
132 LOG_DOWNLOAD ON)
Jie Yangfbe1b682021-02-19 04:54:55 -0800133 include_directories (${CMAKE_BINARY_DIR}/prefix/include)
134 link_directories (${CMAKE_BINARY_DIR}/prefix/lib)
135
136 externalproject_add (
137 phosphor-ipmi-blobs PREFIX ${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs
138 GIT_REPOSITORY https://github.com/openbmc/phosphor-ipmi-blobs
139 SOURCE_DIR ${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs-src
140 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "")
141 include_directories (${CMAKE_BINARY_DIR}/phosphor-ipmi-blobs-src)
142
143 # unit tests
144 set (BLOB_TEST_SRC src/smbios-ipmi-blobs/test)
145
146 find_package (GTest REQUIRED)
147
148 enable_testing ()
149
150 add_executable (runBlobBasic ${BLOB_TEST_SRC}/handler_unittest.cpp)
151 add_test (NAME test_blobbasic COMMAND runBlobBasic)
152 target_link_libraries (runBlobBasic smbiosstore ${GTEST_BOTH_LIBRARIES})
153
154 add_executable (runBlobOpen ${BLOB_TEST_SRC}/handler_open_unittest.cpp)
155 add_test (NAME test_blobopen COMMAND runBlobOpen)
156 target_link_libraries (runBlobOpen smbiosstore ${GTEST_BOTH_LIBRARIES})
157
158 add_executable (runBlobReadWrite
159 ${BLOB_TEST_SRC}/handler_readwrite_unittest.cpp)
160 add_test (NAME test_blobreadwrite COMMAND runBlobReadWrite)
161 target_link_libraries (runBlobReadWrite
162 smbiosstore -lgmock -lgmock_main ${GTEST_BOTH_LIBRARIES})
163
164 add_executable (runBlobStatClose
165 ${BLOB_TEST_SRC}/handler_statclose_unittest.cpp)
166 add_test (NAME test_blobStatClose COMMAND runBlobStatClose)
167 target_link_libraries (runBlobStatClose smbiosstore
168 ${GTEST_BOTH_LIBRARIES})
169 endif ()
170endif ()