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 | |
| 8 | # this is because peci linux header throws #warning |
| 9 | set (CMAKE_CXX_FLAGS "-Wno-error=#warnings") |
| 10 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 11 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 12 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 13 | option (YOCTO "Enable Building in Yocto" OFF) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 14 | option (HUNTER_ENABLED "Enable hunter package pulling" OFF) |
| 15 | include ("cmake/HunterGate.cmake") |
| 16 | |
| 17 | huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1 |
| 18 | "baf9c8cc4f65306f0e442b5419967b4c4c04589a") |
| 19 | |
| 20 | project (sensors CXX) |
| 21 | |
| 22 | set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp |
| 23 | src/Thresholds.cpp) |
| 24 | |
| 25 | set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp |
| 26 | src/Thresholds.cpp) |
| 27 | |
| 28 | set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp) |
| 29 | |
| 30 | set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp) |
| 31 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 32 | set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp) |
| 33 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 34 | set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json) |
| 35 | set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus) |
| 36 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 37 | if (NOT YOCTO) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 38 | option (ENABLE_TEST "Enable Google Test" OFF) |
| 39 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto) |
| 40 | |
| 41 | externalproject_add ( |
| 42 | Boost URL |
| 43 | https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz |
| 44 | URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR |
| 45 | "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR |
| 46 | "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" |
| 47 | INSTALL_COMMAND "" |
| 48 | ) |
| 49 | include_directories (${CMAKE_BINARY_DIR}/boost-src) |
| 50 | set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH}) |
| 51 | |
| 52 | # requires apt install autoconf-archive and autoconf |
| 53 | externalproject_add (sdbusplus-project PREFIX |
| 54 | ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY |
| 55 | https://github.com/openbmc/sdbusplus.git SOURCE_DIR |
| 56 | ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR |
| 57 | ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND |
| 58 | "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src |
| 59 | && ./bootstrap.sh && ./configure --enable-transaction |
| 60 | && make -j libsdbusplus.la INSTALL_COMMAND "" |
| 61 | LOG_DOWNLOAD ON) |
| 62 | include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src) |
| 63 | link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs) |
| 64 | |
| 65 | externalproject_add (nlohmann-json PREFIX |
| 66 | ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json |
| 67 | GIT_REPOSITORY https://github.com/nlohmann/json.git |
| 68 | SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src |
| 69 | BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build |
| 70 | CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND |
| 71 | "" LOG_DOWNLOAD ON) |
| 72 | include_directories (${CMAKE_BINARY_DIR}/nlohmann-json-src/include) |
| 73 | if (ENABLE_TEST) |
| 74 | option (HUNTER_ENABLED "Enable hunter package pulling" ON) |
| 75 | hunter_add_package (GTest) |
| 76 | |
| 77 | find_package (GTest CONFIG REQUIRED) |
| 78 | |
| 79 | enable_testing () |
| 80 | |
| 81 | add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES}) |
| 82 | add_test (NAME test_fansensor COMMAND runTachTests) |
| 83 | target_link_libraries (runTachTests GTest::main GTest::gtest pthread |
| 84 | ${DBUS_LIBRARIES} stdc++fs) |
| 85 | add_dependencies (runTachTests nlohmann-json) |
| 86 | |
| 87 | add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp |
| 88 | ${HWMON_TEMP_SRC_FILES}) |
| 89 | add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests) |
| 90 | target_link_libraries (runHwmonTempTests GTest::main GTest::gtest |
| 91 | pthread ${DBUS_LIBRARIES} stdc++fs) |
| 92 | add_dependencies (runHwmonTempTests nlohmann-json) |
| 93 | endif () |
| 94 | |
| 95 | endif () |
| 96 | |
| 97 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 98 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 99 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 100 | add_definitions (-DBOOST_NO_RTTI) |
| 101 | add_definitions (-DBOOST_NO_TYPEID) |
| 102 | add_definitions (-DBOOST_ASIO_DISABLE_THREADS) |
| 103 | |
| 104 | link_directories (${EXTERNAL_INSTALL_LOCATION}/lib) |
| 105 | |
| 106 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 107 | |
| 108 | add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES}) |
| 109 | add_dependencies (fansensor sdbusplus) |
| 110 | target_link_libraries (fansensor ${SENSOR_LINK_LIBS}) |
| 111 | |
| 112 | add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES}) |
| 113 | add_dependencies (hwmontempsensor sdbusplus) |
| 114 | target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS}) |
| 115 | |
| 116 | add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES}) |
| 117 | add_dependencies (cpusensor sdbusplus) |
| 118 | target_link_libraries (cpusensor ${SENSOR_LINK_LIBS}) |
| 119 | |
| 120 | add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES}) |
| 121 | add_dependencies (adcsensor sdbusplus) |
| 122 | target_link_libraries (adcsensor ${SENSOR_LINK_LIBS}) |
| 123 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 124 | add_executable (exitairtempsensor src/ExitAirTempSensor.cpp |
| 125 | ${EXIT_AIR_SRC_FILES}) |
| 126 | add_dependencies (exitairtempsensor sdbusplus) |
| 127 | target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS}) |
| 128 | |
James Feist | 582be09 | 2018-11-27 10:54:59 -0800 | [diff] [blame] | 129 | if (NOT YOCTO) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 130 | add_dependencies (fansensor ${EXTERNAL_PACKAGES}) |
| 131 | add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES}) |
| 132 | add_dependencies (adcsensor ${EXTERNAL_PACKAGES}) |
| 133 | add_dependencies (cpusensor ${EXTERNAL_PACKAGES}) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 134 | add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES}) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 135 | endif () |
| 136 | |
Vijay Khemka | 2ef26fb | 2018-11-26 11:38:43 -0800 | [diff] [blame] | 137 | set ( |
| 138 | SERVICE_FILES |
| 139 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.adcsensor.service |
| 140 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.cpusensor.service |
| 141 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.fansensor.service |
| 142 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.hwmontempsensor.service |
| 143 | ) |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 144 | |
| 145 | install (TARGETS fansensor hwmontempsensor cpusensor adcsensor |
| 146 | exitairtempsensor DESTINATION sbin) |
Vijay Khemka | 2ef26fb | 2018-11-26 11:38:43 -0800 | [diff] [blame] | 147 | install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/) |