blob: dc88000478dd1255717c5ad8d1a251a0e36cdb75 [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 Yang209ec562019-03-12 16:37:44 +080045set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp)
46
James Feist6714a252018-09-10 15:26:18 -070047set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
48set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
49
James Feist582be092018-11-27 10:54:59 -080050if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -070051 option (ENABLE_TEST "Enable Google Test" OFF)
52 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto)
53
54 externalproject_add (
55 Boost URL
56 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
57 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
58 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
59 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
60 INSTALL_COMMAND ""
61 )
62 include_directories (${CMAKE_BINARY_DIR}/boost-src)
63 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
64
65 # requires apt install autoconf-archive and autoconf
66 externalproject_add (sdbusplus-project PREFIX
67 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
68 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
69 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
70 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
71 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
72 && ./bootstrap.sh && ./configure --enable-transaction
73 && make -j libsdbusplus.la INSTALL_COMMAND ""
74 LOG_DOWNLOAD ON)
75 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
76 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
77
78 externalproject_add (nlohmann-json PREFIX
79 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
80 GIT_REPOSITORY https://github.com/nlohmann/json.git
81 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
82 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
83 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
84 "" LOG_DOWNLOAD ON)
85 include_directories (${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
86 if (ENABLE_TEST)
87 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
88 hunter_add_package (GTest)
89
90 find_package (GTest CONFIG REQUIRED)
91
92 enable_testing ()
93
94 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
95 add_test (NAME test_fansensor COMMAND runTachTests)
96 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
97 ${DBUS_LIBRARIES} stdc++fs)
98 add_dependencies (runTachTests nlohmann-json)
99
100 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
101 ${HWMON_TEMP_SRC_FILES})
102 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
103 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
104 pthread ${DBUS_LIBRARIES} stdc++fs)
105 add_dependencies (runHwmonTempTests nlohmann-json)
106 endif ()
107
108endif ()
109
110add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
111add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
112add_definitions (-DBOOST_ALL_NO_LIB)
113add_definitions (-DBOOST_NO_RTTI)
114add_definitions (-DBOOST_NO_TYPEID)
115add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
116
117link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
118
119include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
120
James Feist63abdd42019-03-01 13:43:44 -0800121add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
122add_dependencies (adcsensor sdbusplus-project)
123target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
124
125add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
126add_dependencies (cpusensor sdbusplus-project)
127target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
128
129add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
130 ${EXIT_AIR_SRC_FILES})
131add_dependencies (exitairtempsensor sdbusplus-project)
132target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
133
James Feist6714a252018-09-10 15:26:18 -0700134add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800135add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700136target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
137
138add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800139add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700140target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
141
Qiang XUe28d1fa2019-02-27 13:50:56 +0800142add_executable (intrusionsensor src/IntrusionSensorMain.cpp
143 ${INTRUSION_SRC_FILES})
144add_dependencies (intrusionsensor sdbusplus-project)
145target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
146target_link_libraries (intrusionsensor i2c)
147
James Feist63abdd42019-03-01 13:43:44 -0800148add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES})
149add_dependencies (ipmbsensor sdbusplus)
150target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
151
Cheng C Yang209ec562019-03-12 16:37:44 +0800152add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES})
153add_dependencies (psusensor sdbusplus-project)
154target_link_libraries (psusensor ${SENSOR_LINK_LIBS})
155
James Feist582be092018-11-27 10:54:59 -0800156if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700157 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
158 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800159 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800160 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
161 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800162 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist63abdd42019-03-01 13:43:44 -0800163 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700164endif ()
165
James Feist63abdd42019-03-01 13:43:44 -0800166set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files)
167set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/)
James Feistbc896df2018-11-26 16:28:17 -0800168
James Feist63abdd42019-03-01 13:43:44 -0800169if (NOT DISABLE_ADC)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700170 install (TARGETS adcsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800171 install (FILES
172 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service
173 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
174endif ()
175
176if (NOT DISABLE_CPU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700177 install (TARGETS cpusensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800178 install (FILES
179 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service
180 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
181endif ()
182
183if (NOT DISABLE_EXIT_AIR)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700184 install (TARGETS exitairtempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800185 install (
186 FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service
187 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
188 )
189endif ()
190
191if (NOT DISABLE_FAN)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700192 install (TARGETS fansensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800193 install (FILES
194 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service
195 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
196endif ()
197
198if (NOT DISABLE_HWMON_TEMP)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700199 install (TARGETS hwmontempsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800200 install (
201 FILES
202 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service
203 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
204 )
205endif ()
206
207if (NOT DISABLE_INTRUSION)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700208 install (TARGETS intrusionsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800209 install (
210 FILES
211 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service
212 DESTINATION ${SERVICE_FILE_INSTALL_DIR}
213 )
214endif ()
215
216if (NOT DISABLE_IPMB)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700217 install (TARGETS ipmbsensor DESTINATION bin)
James Feist63abdd42019-03-01 13:43:44 -0800218 install (FILES
219 ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service
220 DESTINATION ${SERVICE_FILE_INSTALL_DIR})
221endif ()
Cheng C Yang209ec562019-03-12 16:37:44 +0800222
223if (NOT DISABLE_PSU)
Patrick Venture8a7e2912019-03-28 13:07:08 -0700224 install (TARGETS psusensor DESTINATION bin)
Cheng C Yang209ec562019-03-12 16:37:44 +0800225endif ()