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