blob: 2715c4e61d722cc831618781448389eff2b86f0f [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001cmake_minimum_required (VERSION 2.8.10 FATAL_ERROR)
2set (BUILD_SHARED_LIBRARIES OFF)
3include (ExternalProject)
James Feist7bc2bab2018-10-26 14:09:45 -07004set (CMAKE_CXX_STANDARD 17)
James Feist6714a252018-09-10 15:26:18 -07005set (CMAKE_CXX_STANDARD_REQUIRED ON)
James Feistb6c0b912019-07-09 12:21:44 -07006set (
7 CMAKE_CXX_FLAGS
8 "${CMAKE_CXX_FLAGS} -lstdc++fs \
9 -Werror \
10 -Wall \
11 -Wextra \
12 -Wnon-virtual-dtor \
13 -Wold-style-cast \
14 -Wcast-align \
15 -Wunused \
16 -Woverloaded-virtual \
17 -Wpedantic \
18 -Wmisleading-indentation \
19 -Wduplicated-cond \
20 -Wduplicated-branches \
21 -Wlogical-op \
22 -Wnull-dereference \
23 -Wuseless-cast \
24 -Wdouble-promotion \
25 -Wformat=2 \
26 -Wno-sign-compare \
27 -Wno-reorder \
28"
29)
30# todo: get rid of nos, add the below:
31# -Wshadow \
32# -Wconversion \
James Feiste6c34d02018-11-30 14:23:54 -080033
James Feist6714a252018-09-10 15:26:18 -070034set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
35
James Feist582be092018-11-27 10:54:59 -080036option (YOCTO "Enable Building in Yocto" OFF)
James Feist6714a252018-09-10 15:26:18 -070037option (HUNTER_ENABLED "Enable hunter package pulling" OFF)
James Feist63abdd42019-03-01 13:43:44 -080038
39option (DISABLE_ADC "Disable installing ADC sensor" OFF)
Zbigniew Kurzynskia2cec8c2020-04-03 15:07:20 +020040option (DISABLE_CPU "Disable installing CPU sensor" OFF)
James Feist63abdd42019-03-01 13:43:44 -080041option (DISABLE_EXIT_AIR "Disable installing Exit Air Temp sensor" OFF)
42option (DISABLE_FAN "Disable installing fan sensor" OFF)
43option (DISABLE_HWMON_TEMP "Disable installing hwmon temp sensor" OFF)
44option (DISABLE_INTRUSION "Disable installing intrusion sensor" OFF)
45option (DISABLE_IPMB "Disable installing IPMB sensor" OFF)
Yuan Li445efe32019-06-14 22:58:32 +080046option (DISABLE_MCUTEMP "Disable installing MCU temperature sensor" OFF)
Cheng C Yang209ec562019-03-12 16:37:44 +080047option (DISABLE_PSU "Disable installing PSU sensor" OFF)
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070048option (DISABLE_NVME "Disable installing NVME sensor" ON)
James Feist63abdd42019-03-01 13:43:44 -080049
James Feist6714a252018-09-10 15:26:18 -070050include ("cmake/HunterGate.cmake")
51
52huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1
53 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
54
55project (sensors CXX)
56
James Feist63abdd42019-03-01 13:43:44 -080057set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp)
58
59set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp)
60
61set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
62
James Feist6714a252018-09-10 15:26:18 -070063set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp
64 src/Thresholds.cpp)
65
66set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp
67 src/Thresholds.cpp)
68
James Feist63abdd42019-03-01 13:43:44 -080069set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp)
James Feistbc896df2018-11-26 16:28:17 -080070
James Feist6ef20402019-01-07 16:45:08 -080071set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
72
Yuan Li445efe32019-06-14 22:58:32 +080073set (MCUTEMP_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
74
Cheng C Yang916360b2019-05-07 18:47:16 +080075set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp
Cheng C Yang58b2b532019-05-31 00:19:45 +080076 src/PwmSensor.cpp src/PSUEvent.cpp)
Cheng C Yang209ec562019-03-12 16:37:44 +080077
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070078set (NVME_SRC_FILES src/Utils.cpp src/NVMeSensorMain.cpp src/NVMeSensor.cpp src/Thresholds.cpp)
79
James Feist6714a252018-09-10 15:26:18 -070080set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
81set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
82
James Feist582be092018-11-27 10:54:59 -080083if (NOT YOCTO)
Nikhil Potadeb669b6b2019-03-13 10:52:21 -070084 set (DISABLE_NVME ON) # todo allow this to build out of tree
James Feist6714a252018-09-10 15:26:18 -070085 option (ENABLE_TEST "Enable Google Test" OFF)
James Feist6714a252018-09-10 15:26:18 -070086
87 externalproject_add (
88 Boost URL
89 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
90 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
91 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
92 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
93 INSTALL_COMMAND ""
94 )
James Feistb6c0b912019-07-09 12:21:44 -070095 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
James Feist6714a252018-09-10 15:26:18 -070096 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
97
98 # requires apt install autoconf-archive and autoconf
99 externalproject_add (sdbusplus-project PREFIX
100 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
101 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
102 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
103 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
104 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
Patrick Williams41061e22020-06-01 07:41:13 -0500105 && meson build -Ddefault_library=static && ninja -C
106 build libsdbusplus.a INSTALL_COMMAND ""
James Feist6714a252018-09-10 15:26:18 -0700107 LOG_DOWNLOAD ON)
James Feistb6c0b912019-07-09 12:21:44 -0700108 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
Patrick Williams41061e22020-06-01 07:41:13 -0500109 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/build)
James Feist6714a252018-09-10 15:26:18 -0700110
111 externalproject_add (nlohmann-json PREFIX
112 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
113 GIT_REPOSITORY https://github.com/nlohmann/json.git
114 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
115 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
116 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
117 "" LOG_DOWNLOAD ON)
James Feistb6c0b912019-07-09 12:21:44 -0700118 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
Nikhil Potadeb669b6b2019-03-13 10:52:21 -0700119
James Feist6714a252018-09-10 15:26:18 -0700120 if (ENABLE_TEST)
121 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
122 hunter_add_package (GTest)
123
124 find_package (GTest CONFIG REQUIRED)
125
126 enable_testing ()
127
128 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
129 add_test (NAME test_fansensor COMMAND runTachTests)
130 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
131 ${DBUS_LIBRARIES} stdc++fs)
132 add_dependencies (runTachTests nlohmann-json)
133
134 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
135 ${HWMON_TEMP_SRC_FILES})
136 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
137 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
138 pthread ${DBUS_LIBRARIES} stdc++fs)
139 add_dependencies (runHwmonTempTests nlohmann-json)
140 endif ()
141
142endif ()
143
144add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
145add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
146add_definitions (-DBOOST_ALL_NO_LIB)
147add_definitions (-DBOOST_NO_RTTI)
148add_definitions (-DBOOST_NO_TYPEID)
149add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
150
151link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
152
153include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
154
James Feist63abdd42019-03-01 13:43:44 -0800155add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
156add_dependencies (adcsensor sdbusplus-project)
157target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
Jae Hyun Yoo12bbae02019-07-22 17:24:09 -0700158target_link_libraries (adcsensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800159
160add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
161add_dependencies (cpusensor sdbusplus-project)
162target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
James Feist58295ad2019-05-30 15:01:41 -0700163target_link_libraries (cpusensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800164
165add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
166 ${EXIT_AIR_SRC_FILES})
167add_dependencies (exitairtempsensor sdbusplus-project)
168target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
169
James Feist6714a252018-09-10 15:26:18 -0700170add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800171add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700172target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
Zhikui Ren347dd4e2019-12-12 13:39:50 -0800173target_link_libraries (fansensor gpiodcxx)
James Feist6714a252018-09-10 15:26:18 -0700174
175add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800176add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700177target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
178
Qiang XUe28d1fa2019-02-27 13:50:56 +0800179add_executable (intrusionsensor src/IntrusionSensorMain.cpp
180 ${INTRUSION_SRC_FILES})
181add_dependencies (intrusionsensor sdbusplus-project)
182target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
183target_link_libraries (intrusionsensor i2c)
ZhikuiRenba8a8bf2020-01-09 15:55:43 -0800184target_link_libraries (intrusionsensor gpiodcxx)
Qiang XUe28d1fa2019-02-27 13:50:56 +0800185
James Feist63abdd42019-03-01 13:43:44 -0800186add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700187add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800188target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
189
Yuan Li445efe32019-06-14 22:58:32 +0800190add_executable (mcutempsensor src/MCUTempSensor.cpp ${MCUTEMP_SRC_FILES})
191add_dependencies (mcutempsensor sdbusplus-project)
192target_link_libraries (mcutempsensor ${SENSOR_LINK_LIBS})
193target_link_libraries (mcutempsensor i2c)
194
Cheng C Yang209ec562019-03-12 16:37:44 +0800195add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700196add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800197target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
198
Nikhil Potadeb669b6b2019-03-13 10:52:21 -0700199if (NOT DISABLE_NVME)
200 add_executable (nvmesensor ${NVME_SRC_FILES})
201 add_dependencies (nvmesensor sdbusplus-project)
202 target_link_libraries (nvmesensor liblibmctp.a i2c ${SENSOR_LINK_LIBS})
203endif()
204
James Feist582be092018-11-27 10:54:59 -0800205if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700206 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
207 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800208 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800209 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
210 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800211 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800212 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Yuan Li445efe32019-06-14 22:58:32 +0800213 add_dependencies (mcutempsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700214 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700215endif ()
216
James Feist63abdd42019-03-01 13:43:44 -0800217set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
218set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800219
James Feist63abdd42019-03-01 13:43:44 -0800220if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700221 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800222 install (FILES
223 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
224 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
225endif ()
226
227if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700228 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800229 install (FILES
230 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
231 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
232endif ()
233
234if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700235 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800236 install (
237 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
238 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
239 )
240endif ()
241
242if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700243 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800244 install (FILES
245 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
246 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
247endif ()
248
249if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700250 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800251 install (
252 FILES
253 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
254 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
255 )
256endif ()
257
258if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700259 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800260 install (
261 FILES
262 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
263 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
264 )
265endif ()
266
267if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700268 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800269 install (FILES
270 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
271 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
272endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800273
Yuan Li445efe32019-06-14 22:58:32 +0800274if (NOT DISABLE_MCUTEMP)
275 install (TARGETS mcutempsensor DESTINATION bin)
James Feistb6c0b912019-07-09 12:21:44 -0700276 install (
277 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.mcutempsensor.service
278 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
279 )
Yuan Li445efe32019-06-14 22:58:32 +0800280endif ()
281
Cheng C Yang209ec562019-03-12 16:37:44 +0800282if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700283 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800284 install (FILES
285 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
286 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800287endif ()
Nikhil Potadeb669b6b2019-03-13 10:52:21 -0700288
289if (NOT DISABLE_NVME)
290 install (TARGETS nvmesensor DESTINATION bin)
291 install (FILES
292 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.nvmesensor.service
293 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
294endif ()