blob: 60a608b9012c9c901b6e39d0103a4701166e7594 [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)
James Feist63abdd42019-03-01 13:43:44 -080048
James Feist6714a252018-09-10 15:26:18 -070049include ("cmake/HunterGate.cmake")
50
51huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1
52 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
53
54project (sensors CXX)
55
James Feist63abdd42019-03-01 13:43:44 -080056set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp)
57
58set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp)
59
60set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
61
James Feist6714a252018-09-10 15:26:18 -070062set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp
63 src/Thresholds.cpp)
64
65set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp
66 src/Thresholds.cpp)
67
James Feist63abdd42019-03-01 13:43:44 -080068set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp)
James Feistbc896df2018-11-26 16:28:17 -080069
James Feist6ef20402019-01-07 16:45:08 -080070set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
71
Yuan Li445efe32019-06-14 22:58:32 +080072set (MCUTEMP_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
73
Cheng C Yang916360b2019-05-07 18:47:16 +080074set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp
Cheng C Yang58b2b532019-05-31 00:19:45 +080075 src/PwmSensor.cpp src/PSUEvent.cpp)
Cheng C Yang209ec562019-03-12 16:37:44 +080076
James Feist6714a252018-09-10 15:26:18 -070077set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
78set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
79
James Feist582be092018-11-27 10:54:59 -080080if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -070081 option (ENABLE_TEST "Enable Google Test" OFF)
James Feistb6c0b912019-07-09 12:21:44 -070082 include_directories (SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto)
James Feist6714a252018-09-10 15:26:18 -070083
84 externalproject_add (
85 Boost URL
86 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
87 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
88 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
89 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
90 INSTALL_COMMAND ""
91 )
James Feistb6c0b912019-07-09 12:21:44 -070092 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
James Feist6714a252018-09-10 15:26:18 -070093 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
94
95 # requires apt install autoconf-archive and autoconf
96 externalproject_add (sdbusplus-project PREFIX
97 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
98 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
99 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
100 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
101 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
102 && ./bootstrap.sh && ./configure --enable-transaction
103 && make -j libsdbusplus.la INSTALL_COMMAND ""
104 LOG_DOWNLOAD ON)
James Feistb6c0b912019-07-09 12:21:44 -0700105 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
James Feist6714a252018-09-10 15:26:18 -0700106 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
107
108 externalproject_add (nlohmann-json PREFIX
109 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
110 GIT_REPOSITORY https://github.com/nlohmann/json.git
111 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
112 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
113 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
114 "" LOG_DOWNLOAD ON)
James Feistb6c0b912019-07-09 12:21:44 -0700115 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
James Feist6714a252018-09-10 15:26:18 -0700116 if (ENABLE_TEST)
117 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
118 hunter_add_package (GTest)
119
120 find_package (GTest CONFIG REQUIRED)
121
122 enable_testing ()
123
124 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
125 add_test (NAME test_fansensor COMMAND runTachTests)
126 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
127 ${DBUS_LIBRARIES} stdc++fs)
128 add_dependencies (runTachTests nlohmann-json)
129
130 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
131 ${HWMON_TEMP_SRC_FILES})
132 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
133 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
134 pthread ${DBUS_LIBRARIES} stdc++fs)
135 add_dependencies (runHwmonTempTests nlohmann-json)
136 endif ()
137
138endif ()
139
140add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
141add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
142add_definitions (-DBOOST_ALL_NO_LIB)
143add_definitions (-DBOOST_NO_RTTI)
144add_definitions (-DBOOST_NO_TYPEID)
145add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
146
147link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
148
149include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
150
James Feist63abdd42019-03-01 13:43:44 -0800151add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
152add_dependencies (adcsensor sdbusplus-project)
153target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
Jae Hyun Yoo12bbae02019-07-22 17:24:09 -0700154target_link_libraries (adcsensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800155
156add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
157add_dependencies (cpusensor sdbusplus-project)
158target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
James Feist58295ad2019-05-30 15:01:41 -0700159target_link_libraries (cpusensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800160
161add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
162 ${EXIT_AIR_SRC_FILES})
163add_dependencies (exitairtempsensor sdbusplus-project)
164target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
165
James Feist6714a252018-09-10 15:26:18 -0700166add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800167add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700168target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
169
170add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800171add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700172target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
173
Qiang XUe28d1fa2019-02-27 13:50:56 +0800174add_executable (intrusionsensor src/IntrusionSensorMain.cpp
175 ${INTRUSION_SRC_FILES})
176add_dependencies (intrusionsensor sdbusplus-project)
177target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
178target_link_libraries (intrusionsensor i2c)
179
James Feist63abdd42019-03-01 13:43:44 -0800180add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700181add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800182target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
183
Yuan Li445efe32019-06-14 22:58:32 +0800184add_executable (mcutempsensor src/MCUTempSensor.cpp ${MCUTEMP_SRC_FILES})
185add_dependencies (mcutempsensor sdbusplus-project)
186target_link_libraries (mcutempsensor ${SENSOR_LINK_LIBS})
187target_link_libraries (mcutempsensor i2c)
188
Cheng C Yang209ec562019-03-12 16:37:44 +0800189add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700190add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800191target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
192
James Feist582be092018-11-27 10:54:59 -0800193if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700194 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
195 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800196 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800197 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
198 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800199 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800200 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Yuan Li445efe32019-06-14 22:58:32 +0800201 add_dependencies (mcutempsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700202 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700203endif ()
204
James Feist63abdd42019-03-01 13:43:44 -0800205set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
206set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800207
James Feist63abdd42019-03-01 13:43:44 -0800208if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700209 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800210 install (FILES
211 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
212 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
213endif ()
214
215if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700216 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800217 install (FILES
218 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
219 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
220endif ()
221
222if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700223 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800224 install (
225 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
226 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
227 )
228endif ()
229
230if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700231 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800232 install (FILES
233 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
234 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
235endif ()
236
237if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700238 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800239 install (
240 FILES
241 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
242 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
243 )
244endif ()
245
246if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700247 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800248 install (
249 FILES
250 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
251 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
252 )
253endif ()
254
255if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700256 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800257 install (FILES
258 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
259 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
260endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800261
Yuan Li445efe32019-06-14 22:58:32 +0800262if (NOT DISABLE_MCUTEMP)
263 install (TARGETS mcutempsensor DESTINATION bin)
James Feistb6c0b912019-07-09 12:21:44 -0700264 install (
265 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.mcutempsensor.service
266 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
267 )
Yuan Li445efe32019-06-14 22:58:32 +0800268endif ()
269
Cheng C Yang209ec562019-03-12 16:37:44 +0800270if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700271 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800272 install (FILES
273 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
274 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800275endif ()