blob: 564fce241a54fe040e67ef57f3c77e009d419da5 [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})
154
155add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
156add_dependencies (cpusensor sdbusplus-project)
157target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
James Feist58295ad2019-05-30 15:01:41 -0700158target_link_libraries (cpusensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800159
160add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
161 ${EXIT_AIR_SRC_FILES})
162add_dependencies (exitairtempsensor sdbusplus-project)
163target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
164
James Feist6714a252018-09-10 15:26:18 -0700165add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800166add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700167target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
168
169add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800170add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700171target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
172
Qiang XUe28d1fa2019-02-27 13:50:56 +0800173add_executable (intrusionsensor src/IntrusionSensorMain.cpp
174 ${INTRUSION_SRC_FILES})
175add_dependencies (intrusionsensor sdbusplus-project)
176target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
177target_link_libraries (intrusionsensor i2c)
178
James Feist63abdd42019-03-01 13:43:44 -0800179add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700180add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800181target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
182
Yuan Li445efe32019-06-14 22:58:32 +0800183add_executable (mcutempsensor src/MCUTempSensor.cpp ${MCUTEMP_SRC_FILES})
184add_dependencies (mcutempsensor sdbusplus-project)
185target_link_libraries (mcutempsensor ${SENSOR_LINK_LIBS})
186target_link_libraries (mcutempsensor i2c)
187
Cheng C Yang209ec562019-03-12 16:37:44 +0800188add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700189add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800190target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
191
James Feist582be092018-11-27 10:54:59 -0800192if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700193 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
194 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800195 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800196 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
197 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800198 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800199 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Yuan Li445efe32019-06-14 22:58:32 +0800200 add_dependencies (mcutempsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700201 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700202endif ()
203
James Feist63abdd42019-03-01 13:43:44 -0800204set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
205set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800206
James Feist63abdd42019-03-01 13:43:44 -0800207if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700208 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800209 install (FILES
210 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
211 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
212endif ()
213
214if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700215 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800216 install (FILES
217 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
218 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
219endif ()
220
221if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700222 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800223 install (
224 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
225 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
226 )
227endif ()
228
229if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700230 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800231 install (FILES
232 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
233 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
234endif ()
235
236if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700237 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800238 install (
239 FILES
240 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
241 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
242 )
243endif ()
244
245if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700246 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800247 install (
248 FILES
249 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
250 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
251 )
252endif ()
253
254if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700255 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800256 install (FILES
257 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
258 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
259endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800260
Yuan Li445efe32019-06-14 22:58:32 +0800261if (NOT DISABLE_MCUTEMP)
262 install (TARGETS mcutempsensor DESTINATION bin)
James Feistb6c0b912019-07-09 12:21:44 -0700263 install (
264 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.mcutempsensor.service
265 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
266 )
Yuan Li445efe32019-06-14 22:58:32 +0800267endif ()
268
Cheng C Yang209ec562019-03-12 16:37:44 +0800269if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700270 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800271 install (FILES
272 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
273 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800274endif ()