blob: 8279694298436080b64b18eb24e59d60b08b4d1c [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)
Cheng C Yang209ec562019-03-12 16:37:44 +080020option (DISABLE_PSU "Disable installing PSU sensor" OFF)
James Feist63abdd42019-03-01 13:43:44 -080021
James Feist6714a252018-09-10 15:26:18 -070022include ("cmake/HunterGate.cmake")
23
24huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1
25 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
26
27project (sensors CXX)
28
James Feist63abdd42019-03-01 13:43:44 -080029set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp)
30
31set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp)
32
33set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
34
James Feist6714a252018-09-10 15:26:18 -070035set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp
36 src/Thresholds.cpp)
37
38set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp
39 src/Thresholds.cpp)
40
James Feist63abdd42019-03-01 13:43:44 -080041set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp)
James Feistbc896df2018-11-26 16:28:17 -080042
James Feist6ef20402019-01-07 16:45:08 -080043set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
44
Cheng C Yang916360b2019-05-07 18:47:16 +080045set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp
Cheng C Yang58b2b532019-05-31 00:19:45 +080046 src/PwmSensor.cpp src/PSUEvent.cpp)
Cheng C Yang209ec562019-03-12 16:37:44 +080047
James Feist6714a252018-09-10 15:26:18 -070048set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
49set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
50
James Feist582be092018-11-27 10:54:59 -080051if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -070052 option (ENABLE_TEST "Enable Google Test" OFF)
53 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto)
54
55 externalproject_add (
56 Boost URL
57 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
58 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
59 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
60 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
61 INSTALL_COMMAND ""
62 )
63 include_directories (${CMAKE_BINARY_DIR}/boost-src)
64 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
65
66 # requires apt install autoconf-archive and autoconf
67 externalproject_add (sdbusplus-project PREFIX
68 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
69 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
70 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
71 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
72 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
73 && ./bootstrap.sh && ./configure --enable-transaction
74 && make -j libsdbusplus.la INSTALL_COMMAND ""
75 LOG_DOWNLOAD ON)
76 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
77 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
78
79 externalproject_add (nlohmann-json PREFIX
80 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
81 GIT_REPOSITORY https://github.com/nlohmann/json.git
82 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
83 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
84 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
85 "" LOG_DOWNLOAD ON)
86 include_directories (${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
87 if (ENABLE_TEST)
88 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
89 hunter_add_package (GTest)
90
91 find_package (GTest CONFIG REQUIRED)
92
93 enable_testing ()
94
95 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
96 add_test (NAME test_fansensor COMMAND runTachTests)
97 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
98 ${DBUS_LIBRARIES} stdc++fs)
99 add_dependencies (runTachTests nlohmann-json)
100
101 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
102 ${HWMON_TEMP_SRC_FILES})
103 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
104 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
105 pthread ${DBUS_LIBRARIES} stdc++fs)
106 add_dependencies (runHwmonTempTests nlohmann-json)
107 endif ()
108
109endif ()
110
111add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
112add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
113add_definitions (-DBOOST_ALL_NO_LIB)
114add_definitions (-DBOOST_NO_RTTI)
115add_definitions (-DBOOST_NO_TYPEID)
116add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
117
118link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
119
120include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
121
James Feist63abdd42019-03-01 13:43:44 -0800122add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
123add_dependencies (adcsensor sdbusplus-project)
124target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
125
126add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
127add_dependencies (cpusensor sdbusplus-project)
128target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
James Feist58295ad2019-05-30 15:01:41 -0700129target_link_libraries (cpusensor gpiodcxx)
James Feist63abdd42019-03-01 13:43:44 -0800130
131add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
132 ${EXIT_AIR_SRC_FILES})
133add_dependencies (exitairtempsensor sdbusplus-project)
134target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
135
James Feist6714a252018-09-10 15:26:18 -0700136add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800137add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700138target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
139
140add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800141add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700142target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
143
Qiang XUe28d1fa2019-02-27 13:50:56 +0800144add_executable (intrusionsensor src/IntrusionSensorMain.cpp
145 ${INTRUSION_SRC_FILES})
146add_dependencies (intrusionsensor sdbusplus-project)
147target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
148target_link_libraries (intrusionsensor i2c)
149
James Feist63abdd42019-03-01 13:43:44 -0800150add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700151add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800152target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
153
Cheng C Yang209ec562019-03-12 16:37:44 +0800154add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700155add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800156target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
157
James Feist582be092018-11-27 10:54:59 -0800158if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700159 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
160 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800161 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800162 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
163 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800164 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800165 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700166 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700167endif ()
168
James Feist63abdd42019-03-01 13:43:44 -0800169set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
170set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800171
James Feist63abdd42019-03-01 13:43:44 -0800172if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700173 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800174 install (FILES
175 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
176 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
177endif ()
178
179if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700180 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800181 install (FILES
182 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
183 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
184endif ()
185
186if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700187 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800188 install (
189 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
190 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
191 )
192endif ()
193
194if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700195 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800196 install (FILES
197 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
198 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
199endif ()
200
201if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700202 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800203 install (
204 FILES
205 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
206 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
207 )
208endif ()
209
210if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700211 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800212 install (
213 FILES
214 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
215 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
216 )
217endif ()
218
219if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700220 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800221 install (FILES
222 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
223 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
224endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800225
226if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700227 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800228 install (FILES
229 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
230 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800231endif ()