blob: 1d5769142837a6463b58fdc7a534f01e3b0d8398 [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})
129
130add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
131 ${EXIT_AIR_SRC_FILES})
132add_dependencies (exitairtempsensor sdbusplus-project)
133target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
134
James Feist6714a252018-09-10 15:26:18 -0700135add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800136add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700137target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
138
139add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800140add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700141target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
142
Qiang XUe28d1fa2019-02-27 13:50:56 +0800143add_executable (intrusionsensor src/IntrusionSensorMain.cpp
144 ${INTRUSION_SRC_FILES})
145add_dependencies (intrusionsensor sdbusplus-project)
146target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
147target_link_libraries (intrusionsensor i2c)
148
James Feist63abdd42019-03-01 13:43:44 -0800149add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700150add_dependencies (ipmbsensor sdbusplus-project)
James Feist63abdd42019-03-01 13:43:44 -0800151target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
152
Cheng C Yang209ec562019-03-12 16:37:44 +0800153add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
James Feistebce7df2019-04-23 16:19:11 -0700154add_dependencies (psusensor sdbusplus-project)
Cheng C Yang209ec562019-03-12 16:37:44 +0800155target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
156
James Feist582be092018-11-27 10:54:59 -0800157if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700158 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
159 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800160 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800161 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
162 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800163 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800164 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
James Feistebce7df2019-04-23 16:19:11 -0700165 add_dependencies (psusensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700166endif ()
167
James Feist63abdd42019-03-01 13:43:44 -0800168set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
169set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800170
James Feist63abdd42019-03-01 13:43:44 -0800171if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700172 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800173 install (FILES
174 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
175 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
176endif ()
177
178if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700179 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800180 install (FILES
181 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
182 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
183endif ()
184
185if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700186 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800187 install (
188 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
189 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
190 )
191endif ()
192
193if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700194 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800195 install (FILES
196 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
197 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
198endif ()
199
200if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700201 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800202 install (
203 FILES
204 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
205 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
206 )
207endif ()
208
209if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700210 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800211 install (
212 FILES
213 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
214 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
215 )
216endif ()
217
218if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700219 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800220 install (FILES
221 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
222 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
223endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800224
225if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700226 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang93dc2c82019-04-12 11:45:31 +0800227 install (FILES
228 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.psusensor.service
229 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
Cheng C Yang209ec562019-03-12 16:37:44 +0800230endif ()