blob: 498fccad1da6ffc9ca41c9101455bdd113827e35 [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
8# this is because peci linux header throws #warning
9set (CMAKE_CXX_FLAGS "-Wno-error=#warnings")
10
James Feist6714a252018-09-10 15:26:18 -070011set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
12
James Feist582be092018-11-27 10:54:59 -080013option (YOCTO "Enable Building in Yocto" OFF)
James Feist6714a252018-09-10 15:26:18 -070014option (HUNTER_ENABLED "Enable hunter package pulling" OFF)
15include ("cmake/HunterGate.cmake")
16
17huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" SHA1
18 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
19
20project (sensors CXX)
21
22set (FAN_SRC_FILES src/TachSensor.cpp src/PwmSensor.cpp src/Utils.cpp
23 src/Thresholds.cpp)
24
25set (HWMON_TEMP_SRC_FILES src/Utils.cpp src/HwmonTempSensor.cpp
26 src/Thresholds.cpp)
27
28set (CPU_SRC_FILES src/Utils.cpp src/CPUSensor.cpp src/Thresholds.cpp)
29
30set (ADC_SRC_FILES src/Utils.cpp src/ADCSensor.cpp src/Thresholds.cpp)
31
James Feistbc896df2018-11-26 16:28:17 -080032set (EXIT_AIR_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
33
James Feist6ef20402019-01-07 16:45:08 -080034set (IPMB_SRC_FILES src/Utils.cpp src/Thresholds.cpp)
35
Qiang XUe28d1fa2019-02-27 13:50:56 +080036set (INTRUSION_SRC_FILES src/Utils.cpp src/ChassisIntrusionSensor.cpp)
37
James Feist6714a252018-09-10 15:26:18 -070038set (EXTERNAL_PACKAGES Boost sdbusplus-project nlohmann-json)
39set (SENSOR_LINK_LIBS -lsystemd stdc++fs sdbusplus)
40
James Feist582be092018-11-27 10:54:59 -080041if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -070042 option (ENABLE_TEST "Enable Google Test" OFF)
43 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include/non-yocto)
44
45 externalproject_add (
46 Boost URL
47 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
48 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
49 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
50 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
51 INSTALL_COMMAND ""
52 )
53 include_directories (${CMAKE_BINARY_DIR}/boost-src)
54 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
55
56 # requires apt install autoconf-archive and autoconf
57 externalproject_add (sdbusplus-project PREFIX
58 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
59 https://github.com/openbmc/sdbusplus.git SOURCE_DIR
60 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
61 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
62 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
63 && ./bootstrap.sh && ./configure --enable-transaction
64 && make -j libsdbusplus.la INSTALL_COMMAND ""
65 LOG_DOWNLOAD ON)
66 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
67 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
68
69 externalproject_add (nlohmann-json PREFIX
70 ${CMAKE_CURRENT_BINARY_DIR}/nlohmann-json
71 GIT_REPOSITORY https://github.com/nlohmann/json.git
72 SOURCE_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-src
73 BINARY_DIR ${CMAKE_BINARY_DIR}/nlohmann-json-build
74 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
75 "" LOG_DOWNLOAD ON)
76 include_directories (${CMAKE_BINARY_DIR}/nlohmann-json-src/include)
77 if (ENABLE_TEST)
78 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
79 hunter_add_package (GTest)
80
81 find_package (GTest CONFIG REQUIRED)
82
83 enable_testing ()
84
85 add_executable (runTachTests tests/test_TachSensor.cpp ${FAN_SRC_FILES})
86 add_test (NAME test_fansensor COMMAND runTachTests)
87 target_link_libraries (runTachTests GTest::main GTest::gtest pthread
88 ${DBUS_LIBRARIES} stdc++fs)
89 add_dependencies (runTachTests nlohmann-json)
90
91 add_executable (runHwmonTempTests tests/test_HwmonTempSensor.cpp
92 ${HWMON_TEMP_SRC_FILES})
93 add_test (NAME test_hwmontempsensor COMMAND runHwmonTempTests)
94 target_link_libraries (runHwmonTempTests GTest::main GTest::gtest
95 pthread ${DBUS_LIBRARIES} stdc++fs)
96 add_dependencies (runHwmonTempTests nlohmann-json)
97 endif ()
98
99endif ()
100
101add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
102add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
103add_definitions (-DBOOST_ALL_NO_LIB)
104add_definitions (-DBOOST_NO_RTTI)
105add_definitions (-DBOOST_NO_TYPEID)
106add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
107
108link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
109
110include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
111
112add_executable (fansensor src/FanMain.cpp ${FAN_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800113add_dependencies (fansensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700114target_link_libraries (fansensor ${SENSOR_LINK_LIBS})
115
116add_executable (hwmontempsensor src/HwmonTempMain.cpp ${HWMON_TEMP_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800117add_dependencies (hwmontempsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700118target_link_libraries (hwmontempsensor ${SENSOR_LINK_LIBS})
119
120add_executable (cpusensor src/CPUSensorMain.cpp ${CPU_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800121add_dependencies (cpusensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700122target_link_libraries (cpusensor ${SENSOR_LINK_LIBS})
123
124add_executable (adcsensor src/ADCSensorMain.cpp ${ADC_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800125add_dependencies (adcsensor sdbusplus-project)
James Feist6714a252018-09-10 15:26:18 -0700126target_link_libraries (adcsensor ${SENSOR_LINK_LIBS})
127
James Feistbc896df2018-11-26 16:28:17 -0800128add_executable (exitairtempsensor src/ExitAirTempSensor.cpp
129 ${EXIT_AIR_SRC_FILES})
James Feistcf3bce62019-01-08 10:07:19 -0800130add_dependencies (exitairtempsensor sdbusplus-project)
James Feistbc896df2018-11-26 16:28:17 -0800131target_link_libraries (exitairtempsensor ${SENSOR_LINK_LIBS})
132
James Feist6ef20402019-01-07 16:45:08 -0800133add_executable (ipmbsensor src/IpmbSensor.cpp
134 ${IPMB_SRC_FILES})
135add_dependencies (ipmbsensor sdbusplus)
136target_link_libraries (ipmbsensor ${SENSOR_LINK_LIBS})
137
Qiang XUe28d1fa2019-02-27 13:50:56 +0800138add_executable (intrusionsensor src/IntrusionSensorMain.cpp
139 ${INTRUSION_SRC_FILES})
140add_dependencies (intrusionsensor sdbusplus-project)
141target_link_libraries (intrusionsensor ${SENSOR_LINK_LIBS})
142target_link_libraries (intrusionsensor i2c)
143
James Feist582be092018-11-27 10:54:59 -0800144if (NOT YOCTO)
James Feist6714a252018-09-10 15:26:18 -0700145 add_dependencies (fansensor ${EXTERNAL_PACKAGES})
146 add_dependencies (hwmontempsensor ${EXTERNAL_PACKAGES})
147 add_dependencies (adcsensor ${EXTERNAL_PACKAGES})
148 add_dependencies (cpusensor ${EXTERNAL_PACKAGES})
James Feistbc896df2018-11-26 16:28:17 -0800149 add_dependencies (exitairtempsensor ${EXTERNAL_PACKAGES})
James Feist6ef20402019-01-07 16:45:08 -0800150 add_dependencies (ipmbsensor ${EXTERNAL_PACKAGES})
Qiang XUe28d1fa2019-02-27 13:50:56 +0800151 add_dependencies (intrusionsensor ${EXTERNAL_PACKAGES})
James Feist6714a252018-09-10 15:26:18 -0700152endif ()
153
Vijay Khemka2ef26fb2018-11-26 11:38:43 -0800154set (
155 SERVICE_FILES
156 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.adcsensor.service
157 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.cpusensor.service
158 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.fansensor.service
159 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.hwmontempsensor.service
James Feist1d123a12018-12-06 14:19:15 -0800160 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.exitairsensor.service
James Feist8424b492019-01-29 15:49:11 -0800161 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.ipmbsensor.service
Qiang XUe28d1fa2019-02-27 13:50:56 +0800162 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.intrusionsensor.service
Vijay Khemka2ef26fb2018-11-26 11:38:43 -0800163)
James Feistbc896df2018-11-26 16:28:17 -0800164
James Feist6ef20402019-01-07 16:45:08 -0800165install (TARGETS fansensor hwmontempsensor cpusensor adcsensor ipmbsensor
Qiang XUe28d1fa2019-02-27 13:50:56 +0800166 exitairtempsensor intrusionsensor DESTINATION sbin)
Vijay Khemka2ef26fb2018-11-26 11:38:43 -0800167install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)