blob: 645a1a883f32e8741cab76dce067f6e2a1e6107c [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)
40option (DISBALE_CPU "Disable installing CPU sensor" OFF)
41option (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
105 && ./bootstrap.sh && ./configure --enable-transaction
106 && make -j libsdbusplus.la INSTALL_COMMAND ""
107 LOG_DOWNLOAD ON)
James Feistb6c0b912019-07-09 12:21:44 -0700108 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
James Feist6714a252018-09-10 15:26:18 -0700109 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
110
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)
184
James Feist63abdd42019-03-01 13:43:44 -0800185add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700186add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800187target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
188
Yuan Li445efe32019-06-14 22:58:32 +0800189add_executable (mcutempsensor src/MCUTempSensor.cpp ${MCUTEMP_SRC_FILES})
190add_dependencies (mcutempsensor sdbusplus-project)
191target_link_libraries (mcutempsensor ${SENSOR_LINK_LIBS})
192target_link_libraries (mcutempsensor i2c)
193
Cheng C Yang209ec562019-03-12 16:37:44 +0800194add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700195add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800196target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
197
Nikhil Potadeb669b6b2019-03-13 10:52:21 -0700198if (NOT DISABLE_NVME)
199 add_executable (nvmesensor ${NVME_SRC_FILES})
200 add_dependencies (nvmesensor sdbusplus-project)
201 target_link_libraries (nvmesensor liblibmctp.a i2c ${SENSOR_LINK_LIBS})
202endif()
203
James Feist582be092018-11-27 10:54:59 -0800204if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700205 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
206 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800207 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800208 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
209 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800210 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800211 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Yuan Li445efe32019-06-14 22:58:32 +0800212 add_dependencies (mcutempsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700213 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700214endif ()
215
James Feist63abdd42019-03-01 13:43:44 -0800216set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
217set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800218
James Feist63abdd42019-03-01 13:43:44 -0800219if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700220 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800221 install (FILES
222 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
223 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
224endif ()
225
226if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700227 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800228 install (FILES
229 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
230 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
231endif ()
232
233if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700234 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800235 install (
236 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
237 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
238 )
239endif ()
240
241if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700242 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800243 install (FILES
244 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
245 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
246endif ()
247
248if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700249 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800250 install (
251 FILES
252 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
253 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
254 )
255endif ()
256
257if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700258 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800259 install (
260 FILES
261 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
262 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
263 )
264endif ()
265
266if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700267 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800268 install (FILES
269 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
270 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
271endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800272
Yuan Li445efe32019-06-14 22:58:32 +0800273if (NOT DISABLE_MCUTEMP)
274 install (TARGETS mcutempsensor DESTINATION bin)
James Feistb6c0b912019-07-09 12:21:44 -0700275 install (
276 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.mcutempsensor.service
277 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
278 )
Yuan Li445efe32019-06-14 22:58:32 +0800279endif ()
280
Cheng C Yang209ec562019-03-12 16:37:44 +0800281if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700282 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800283 install (FILES
284 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
285 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800286endif ()
Nikhil Potadeb669b6b2019-03-13 10:52:21 -0700287
288if (NOT DISABLE_NVME)
289 install (TARGETS nvmesensor DESTINATION bin)
290 install (FILES
291 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.nvmesensor.service
292 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
293endif ()