James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 2.8.10 FATAL_ERROR) |
| 2 | set (BUILD_SHARED_LIBRARIES OFF) |
| 3 | include (ExternalProject) |
James Feist | 7bc2bab | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 4 | set (CMAKE_CXX_STANDARD 17) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 5 | set (CMAKE_CXX_STANDARD_REQUIRED ON) |
James Feist | 947cd41 | 2018-11-27 12:51:51 -0800 | [diff] [blame] | 6 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs -Werror") |
James Feist | e6c34d0 | 2018-11-30 14:23:54 -0800 | [diff] [blame] | 7 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 9 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 10 | option (YOCTO "Enable Building in Yocto" OFF) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 11 | option (HUNTER_ENABLED "Enable hunter package pulling" OFF) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 12 | |
| 13 | option (DISABLE_ADC "Disable installing ADC sensor" OFF) |
| 14 | option (DISBALE_CPU "Disable installing CPU sensor" OFF) |
| 15 | option (DISABLE_EXIT_AIR "Disable installing Exit Air Temp sensor" OFF) |
| 16 | option (DISABLE_FAN "Disable installing fan sensor" OFF) |
| 17 | option (DISABLE_HWMON_TEMP "Disable installing hwmon temp sensor" OFF) |
| 18 | option (DISABLE_INTRUSION "Disable installing intrusion sensor" OFF) |
| 19 | option (DISABLE_IPMB "Disable installing IPMB sensor" OFF) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 20 | option (DISABLE_PSU "Disable installing PSU sensor" OFF) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 21 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 22 | include ("cmake/HunterGate.cmake") |
| 23 | |
| 24 | huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1 |
| 25 | "baf9c8cc4f65306f0e442b5419967b4c4c04589a") |
| 26 | |
| 27 | project (sensors CXX) |
| 28 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 29 | set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp) |
| 30 | |
| 31 | set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp) |
| 32 | |
| 33 | set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp) |
| 34 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 35 | set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp |
| 36 | src/Thresholds.cpp) |
| 37 | |
| 38 | set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp |
| 39 | src/Thresholds.cpp) |
| 40 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 41 | set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 42 | |
James Feist | 6ef2040 | 2019-01-07 16:45:08 -0800 | [diff] [blame] | 43 | set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp) |
| 44 | |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 45 | set (PSU_SRC_FILES src/Utils.cpp src/PSUSensor.cpp src/Thresholds.cpp) |
| 46 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 47 | set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json) |
| 48 | set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus) |
| 49 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 50 | if (NOT YOCTO) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 51 | 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 | |
| 108 | endif () |
| 109 | |
| 110 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 111 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 112 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 113 | add_definitions (-DBOOST_NO_RTTI) |
| 114 | add_definitions (-DBOOST_NO_TYPEID) |
| 115 | add_definitions (-DBOOST_ASIO_DISABLE_THREADS) |
| 116 | |
| 117 | link_directories (${EXTERNAL_INSTALL_LOCATION}/lib) |
| 118 | |
| 119 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 120 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 121 | add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES}) |
| 122 | add_dependencies (adcsensor sdbusplus-project) |
| 123 | target_link_libraries (adcsensor ${SENSOR_LINK_LIBS}) |
| 124 | |
| 125 | add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES}) |
| 126 | add_dependencies (cpusensor sdbusplus-project) |
| 127 | target_link_libraries (cpusensor ${SENSOR_LINK_LIBS}) |
| 128 | |
| 129 | add_executable (exitairtempsensor src/ExitAirTempSensor.cpp |
| 130 | ${EXIT_AIR_SRC_FILES}) |
| 131 | add_dependencies (exitairtempsensor sdbusplus-project) |
| 132 | target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS}) |
| 133 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 134 | add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES}) |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 135 | add_dependencies (fansensor sdbusplus-project) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 136 | target_link_libraries (fansensor ${SENSOR_LINK_LIBS}) |
| 137 | |
| 138 | add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES}) |
James Feist | cf3bce6 | 2019-01-08 10:07:19 -0800 | [diff] [blame] | 139 | add_dependencies (hwmontempsensor sdbusplus-project) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 140 | target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS}) |
| 141 | |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 142 | add_executable (intrusionsensor src/IntrusionSensorMain.cpp |
| 143 | ${INTRUSION_SRC_FILES}) |
| 144 | add_dependencies (intrusionsensor sdbusplus-project) |
| 145 | target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS}) |
| 146 | target_link_libraries (intrusionsensor i2c) |
| 147 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 148 | add_executable (ipmbsensor src/IpmbSensor.cpp ${IPMB_SRC_FILES}) |
| 149 | add_dependencies (ipmbsensor sdbusplus) |
| 150 | target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS}) |
| 151 | |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 152 | add_executable (psusensor src/PSUSensorMain.cpp ${PSU_SRC_FILES}) |
| 153 | add_dependencies (psusensor sdbusplus-project) |
| 154 | target_link_libraries (psusensor ${SENSOR_LINK_LIBS}) |
| 155 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 156 | if (NOT YOCTO) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 157 | add_dependencies (adcsensor ${EXTERNAL_PACKAGES}) |
| 158 | add_dependencies (cpusensor ${EXTERNAL_PACKAGES}) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 159 | add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES}) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 160 | add_dependencies (fansensor ${EXTERNAL_PACKAGES}) |
| 161 | add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES}) |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 162 | add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES}) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 163 | add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES}) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 164 | endif () |
| 165 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 166 | set (SERVICE_FILE_SRC_DIR ${PROJECT_SOURCE_DIR}/service_files) |
| 167 | set (SERVICE_FILE_INSTALL_DIR /lib/systemd/system/) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 168 | |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 169 | if (NOT DISABLE_ADC) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 170 | install (TARGETS adcsensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 171 | install (FILES |
| 172 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.adcsensor.service |
| 173 | DESTINATION ${SERVICE_FILE_INSTALL_DIR}) |
| 174 | endif () |
| 175 | |
| 176 | if (NOT DISABLE_CPU) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 177 | install (TARGETS cpusensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 178 | install (FILES |
| 179 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.cpusensor.service |
| 180 | DESTINATION ${SERVICE_FILE_INSTALL_DIR}) |
| 181 | endif () |
| 182 | |
| 183 | if (NOT DISABLE_EXIT_AIR) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 184 | install (TARGETS exitairtempsensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 185 | install ( |
| 186 | FILES ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.exitairsensor.service |
| 187 | DESTINATION ${SERVICE_FILE_INSTALL_DIR} |
| 188 | ) |
| 189 | endif () |
| 190 | |
| 191 | if (NOT DISABLE_FAN) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 192 | install (TARGETS fansensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 193 | install (FILES |
| 194 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.fansensor.service |
| 195 | DESTINATION ${SERVICE_FILE_INSTALL_DIR}) |
| 196 | endif () |
| 197 | |
| 198 | if (NOT DISABLE_HWMON_TEMP) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 199 | install (TARGETS hwmontempsensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 200 | install ( |
| 201 | FILES |
| 202 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.hwmontempsensor.service |
| 203 | DESTINATION ${SERVICE_FILE_INSTALL_DIR} |
| 204 | ) |
| 205 | endif () |
| 206 | |
| 207 | if (NOT DISABLE_INTRUSION) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 208 | install (TARGETS intrusionsensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 209 | install ( |
| 210 | FILES |
| 211 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.intrusionsensor.service |
| 212 | DESTINATION ${SERVICE_FILE_INSTALL_DIR} |
| 213 | ) |
| 214 | endif () |
| 215 | |
| 216 | if (NOT DISABLE_IPMB) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 217 | install (TARGETS ipmbsensor DESTINATION bin) |
James Feist | 63abdd4 | 2019-03-01 13:43:44 -0800 | [diff] [blame] | 218 | install (FILES |
| 219 | ${SERVICE_FILE_SRC_DIR}/xyz.openbmc_project.ipmbsensor.service |
| 220 | DESTINATION ${SERVICE_FILE_INSTALL_DIR}) |
| 221 | endif () |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 222 | |
| 223 | if (NOT DISABLE_PSU) |
Patrick Venture | 8a7e291 | 2019-03-28 13:07:08 -0700 | [diff] [blame^] | 224 | install (TARGETS psusensor DESTINATION bin) |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 225 | endif () |