blob: af1a41c4e6530b783c1138e6d880427041b6ebd0 [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 Feist947cd412018-11-27 12:51:51 -08006set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs -Werror")
James Feiste6c34d02018-11-30 14:23:54 -08007
James Feist6714a252018-09-10 15:26:18 -07008set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
9
James Feist582be092018-11-27 10:54:59 -080010option (YOCTO "Enable Building in Yocto" OFF)
James Feist6714a252018-09-10 15:26:18 -070011option (HUNTER_ENABLED "Enable hunter package pulling" OFF)
James Feist63abdd42019-03-01 13:43:44 -080012
13option (DISABLE_ADC "Disable installing ADC sensor" OFF)
14option (DISBALE_CPU "Disable installing CPU sensor" OFF)
15option (DISABLE_EXIT_AIR "Disable installing Exit Air Temp sensor" OFF)
16option (DISABLE_FAN "Disable installing fan sensor" OFF)
17option (DISABLE_HWMON_TEMP "Disable installing hwmon temp sensor" OFF)
18option (DISABLE_INTRUSION "Disable installing intrusion sensor" OFF)
19option (DISABLE_IPMB "Disable installing IPMB sensor" OFF)
Yuan Li445efe32019-06-14 22:58:32 +080020option (DISABLE_MCUTEMP "Disable installing MCU temperature sensor" OFF)
Cheng C Yang209ec562019-03-12 16:37:44 +080021option (DISABLE_PSU "Disable installing PSU sensor" OFF)
James Feist63abdd42019-03-01 13:43:44 -080022
James Feist6714a252018-09-10 15:26:18 -070023include ("cmake/HunterGate.cmake")
24
25huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1
26 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
27
28project (sensors CXX)
29
James Feist63abdd42019-03-01 13:43:44 -080030set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp)
31
32set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp)
33
34set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
35
James Feist6714a252018-09-10 15:26:18 -070036set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp
37 src/Thresholds.cpp)
38
39set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp
40 src/Thresholds.cpp)
41
James Feist63abdd42019-03-01 13:43:44 -080042set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp)
James Feistbc896df2018-11-26 16:28:17 -080043
James Feist6ef20402019-01-07 16:45:08 -080044set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
45
Yuan Li445efe32019-06-14 22:58:32 +080046set (MCUTEMP_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
47
Cheng C Yang916360b2019-05-07 18:47:16 +080048set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp
Cheng C Yang58b2b532019-05-31 00:19:45 +080049 src/PwmSensor.cpp src/PSUEvent.cpp)
Cheng C Yang209ec562019-03-12 16:37:44 +080050
James Feist6714a252018-09-10 15:26:18 -070051set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
52set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
53
James Feist582be092018-11-27 10:54:59 -080054if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -070055 option (ENABLE_TEST "Enable Google Test" OFF)
56 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto)
57
58 externalproject_add (
59 Boost URL
60 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
61 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
62 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
63 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
64 INSTALL_COMMAND ""
65 )
66 include_directories (${CMAKE_BINARY_DIR}/boost-src)
67 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
68
69 # requires apt install autoconf-archive and autoconf
70 externalproject_add (sdbusplus-project PREFIX
71 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
72 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
73 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
74 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
75 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
76 && ./bootstrap.sh && ./configure --enable-transaction
77 && make -j libsdbusplus.la INSTALL_COMMAND ""
78 LOG_DOWNLOAD ON)
79 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
80 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
81
82 externalproject_add (nlohmann-json PREFIX
83 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
84 GIT_REPOSITORY https://github.com/nlohmann/json.git
85 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
86 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
87 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
88 "" LOG_DOWNLOAD ON)
89 include_directories (${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
90 if (ENABLE_TEST)
91 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
92 hunter_add_package (GTest)
93
94 find_package (GTest CONFIG REQUIRED)
95
96 enable_testing ()
97
98 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
99 add_test (NAME test_fansensor COMMAND runTachTests)
100 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
101 ${DBUS_LIBRARIES} stdc++fs)
102 add_dependencies (runTachTests nlohmann-json)
103
104 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
105 ${HWMON_TEMP_SRC_FILES})
106 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
107 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
108 pthread ${DBUS_LIBRARIES} stdc++fs)
109 add_dependencies (runHwmonTempTests nlohmann-json)
110 endif ()
111
112endif ()
113
114add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
115add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
116add_definitions (-DBOOST_ALL_NO_LIB)
117add_definitions (-DBOOST_NO_RTTI)
118add_definitions (-DBOOST_NO_TYPEID)
119add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
120
121link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
122
123include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
124
James Feist63abdd42019-03-01 13:43:44 -0800125add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
126add_dependencies (adcsensor sdbusplus-project)
127target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
128
129add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
130add_dependencies (cpusensor sdbusplus-project)
131target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
James Feist58295ad2019-05-30 15:01:41 -0700132target_link_libraries (cpusensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800133
134add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
135 ${EXIT_AIR_SRC_FILES})
136add_dependencies (exitairtempsensor sdbusplus-project)
137target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
138
James Feist6714a252018-09-10 15:26:18 -0700139add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800140add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700141target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
142
143add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800144add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700145target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
146
Qiang XUe28d1fa2019-02-27 13:50:56 +0800147add_executable (intrusionsensor src/IntrusionSensorMain.cpp
148 ${INTRUSION_SRC_FILES})
149add_dependencies (intrusionsensor sdbusplus-project)
150target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
151target_link_libraries (intrusionsensor i2c)
152
James Feist63abdd42019-03-01 13:43:44 -0800153add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700154add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800155target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
156
Yuan Li445efe32019-06-14 22:58:32 +0800157add_executable (mcutempsensor src/MCUTempSensor.cpp ${MCUTEMP_SRC_FILES})
158add_dependencies (mcutempsensor sdbusplus-project)
159target_link_libraries (mcutempsensor ${SENSOR_LINK_LIBS})
160target_link_libraries (mcutempsensor i2c)
161
Cheng C Yang209ec562019-03-12 16:37:44 +0800162add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700163add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800164target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
165
James Feist582be092018-11-27 10:54:59 -0800166if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700167 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
168 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800169 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800170 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
171 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800172 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800173 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Yuan Li445efe32019-06-14 22:58:32 +0800174 add_dependencies (mcutempsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700175 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700176endif ()
177
James Feist63abdd42019-03-01 13:43:44 -0800178set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
179set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800180
James Feist63abdd42019-03-01 13:43:44 -0800181if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700182 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800183 install (FILES
184 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
185 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
186endif ()
187
188if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700189 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800190 install (FILES
191 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
192 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
193endif ()
194
195if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700196 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800197 install (
198 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
199 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
200 )
201endif ()
202
203if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700204 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800205 install (FILES
206 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
207 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
208endif ()
209
210if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700211 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800212 install (
213 FILES
214 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
215 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
216 )
217endif ()
218
219if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700220 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800221 install (
222 FILES
223 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
224 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
225 )
226endif ()
227
228if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700229 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800230 install (FILES
231 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
232 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
233endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800234
Yuan Li445efe32019-06-14 22:58:32 +0800235if (NOT DISABLE_MCUTEMP)
236 install (TARGETS mcutempsensor DESTINATION bin)
237 install (FILES
238 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.mcutempsensor.service
239 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
240endif ()
241
Cheng C Yang209ec562019-03-12 16:37:44 +0800242if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700243 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800244 install (FILES
245 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
246 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800247endif ()