blob: 4aa0f03b389dd38c8ef84a1e4e62fb558e0e4a27 [file] [log] [blame]
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08001cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
2
3cmake_policy (SET CMP0054 NEW)
4
Jason M. Bills3f7c5e42018-10-03 14:00:41 -07005option (YOCTO "Use YOCTO depedencies system" OFF)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08006include (ExternalProject)
7set (CMAKE_CXX_STANDARD 17)
8set (CMAKE_CXX_STANDARD_REQUIRED ON)
9set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
10
James Feist25690252019-12-23 12:25:49 -080011option (USING_ENTITY_MANAGER_DECORATORS
12 "Enable using EM decorators to map FRUs to entity IDs" ON)
13
James Feist13b00392019-08-19 16:16:08 -070014set (
15 CMAKE_CXX_FLAGS
16 "${CMAKE_CXX_FLAGS} \
17 -Werror \
18 -Wtype-limits \
19 -Wnull-dereference \
20"
21)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080022
23project (intel-ipmi-oem CXX)
24
25add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
26add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
27add_definitions (-DBOOST_ALL_NO_LIB)
28add_definitions (-DBOOST_NO_RTTI)
29add_definitions (-DBOOST_NO_TYPEID)
Vernon Mauery9e7e17a2019-03-20 13:42:06 -070030add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
Vernon Mauery8b69fae2019-03-20 13:43:11 -070031add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
Vernon Mauerya3702c12019-05-22 13:20:59 -070032add_definitions (-Wno-psabi)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080033
Jason M. Billsb08f84e2019-06-10 12:59:42 -070034if (NOT YOCTO) # headers that can't be built without yocto
James Feist13b00392019-08-19 16:16:08 -070035 include_directories (SYSTEM non-yocto)
Vernon Mauerya3702c12019-05-22 13:20:59 -070036
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080037 configure_file (CMakeLists.txt.in 3rdparty/CMakeLists.txt)
Jason M. Billsb08f84e2019-06-10 12:59:42 -070038 execute_process (COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
39 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
40 execute_process (COMMAND ${CMAKE_COMMAND} --build .
41 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080042
43 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/prefix ${CMAKE_PREFIX_PATH})
James Feist13b00392019-08-19 16:16:08 -070044 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/prefix/include)
Vernon Mauery8b69fae2019-03-20 13:43:11 -070045 link_directories (${CMAKE_BINARY_DIR}/prefix/lib)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080046
James Feist13b00392019-08-19 16:16:08 -070047 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080048 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
James Feist13b00392019-08-19 16:16:08 -070049 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/phosphor-logging-src)
James Feistb9683922019-01-02 15:04:45 -080050 link_directories (${CMAKE_BINARY_DIR}/phosphor-logging-src/.libs)
James Feist13b00392019-08-19 16:16:08 -070051 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src)
Yong Li0669d192019-05-06 14:01:46 +080052 link_directories (${CMAKE_BINARY_DIR}/intel-dbus-interfaces-src/.libs)
James Feist13b00392019-08-19 16:16:08 -070053 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/phosphor-ipmi-host/include)
54 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/ipmid/user_channel)
55 include_directories (SYSTEM ${CMAKE_BINARY_DIR}) # link_directories (${CMAK
56 # E_BINARY_DIR}/sdbusplus-
57 # src/.libs)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070058endif ()
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080059
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070060if (YOCTO)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080061 find_package (PkgConfig REQUIRED)
62 pkg_check_modules (LOGGING phosphor-logging REQUIRED)
James Feist13b00392019-08-19 16:16:08 -070063 include_directories (SYSTEM ${LOGGING_INCLUDE_DIRS})
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080064 link_directories (${LOGGING_LIBRARY_DIRS})
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070065
Vernon Mauery8b69fae2019-03-20 13:43:11 -070066 pkg_check_modules (LIBIPMID libipmid REQUIRED)
James Feist13b00392019-08-19 16:16:08 -070067 include_directories (SYSTEM ${LIBIPMID_INCLUDE_DIRS})
Vernon Mauery8b69fae2019-03-20 13:43:11 -070068 link_directories (${LIBIPMID_LIBRARY_DIRS})
69
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080070endif ()
71
72include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
73
James Feistb9683922019-01-02 15:04:45 -080074if (NOT YOCTO)
Jason M. Bills72867de2018-11-28 12:46:59 -080075 set (SENSOR_TEST_SRC tests/test_sensorcommands.cpp)
James Feistb9683922019-01-02 15:04:45 -080076
77 find_package (GTest REQUIRED)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070078
79 enable_testing ()
80
81 add_executable (runSensorTests ${SENSOR_TEST_SRC})
82 add_test (NAME test_sensorcommands COMMAND runSensorTests)
Jason M. Billsb08f84e2019-06-10 12:59:42 -070083 target_link_libraries (runSensorTests ${GTEST_BOTH_LIBRARIES}
84 ${CMAKE_THREAD_LIBS_INIT} sdbusplus -lsystemd)
Jason M. Bills3f7c5e42018-10-03 14:00:41 -070085endif ()
Vernon Mauerya3702c12019-05-22 13:20:59 -070086#
87# import OpenSSL (crypto)
88find_package (OpenSSL REQUIRED)
James Feist13b00392019-08-19 16:16:08 -070089include_directories (SYSTEM ${OPENSSL_INCLUDE_DIR})
Vernon Mauerya3702c12019-05-22 13:20:59 -070090
Vernon Mauery0d0cd162020-01-31 10:04:10 -080091include_directories (SYSTEM ${CMAKE_BINARY_DIR})
92add_custom_command(OUTPUT include/ipmi-whitelist.hpp
93 COMMAND ./generate-whitelist.py
94 ARGS ipmi-whitelist.conf ${CMAKE_BINARY_DIR}/ipmi-whitelist.hpp
95 MAIN_DEPENDENCY ipmi-whitelist.conf
96 DEPENDS generate-whitelist.py
97 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
98
Jason M. Billsb08f84e2019-06-10 12:59:42 -070099add_library (zinteloemcmds
Kuiying Wang6d6dc7a2020-04-02 10:15:19 +0800100 SHARED src/oemcommands.cpp src/sensorcommands.cpp src/biosconfigcommands.cpp
Jason M. Billsb08f84e2019-06-10 12:59:42 -0700101 src/storagecommands.cpp src/multinodecommands.cpp
102 src/firmware-update.cpp src/appcommands.cpp src/smbioshandler.cpp
103 src/smbiosmdrv2handler.cpp src/manufacturingcommands.cpp
104 src/bmccontrolservices.cpp src/bridgingcommands.cpp
Agnieszka Szlendakd2220cc2020-04-17 15:00:12 +0200105 src/ipmi_to_redfish_hooks.cpp src/me_to_redfish_hooks.cpp
106 src/chassiscommands.cpp src/whitelist-filter.cpp
107 include/ipmi-whitelist.hpp)
Richard Marian Thomaiyar6e056412018-11-14 23:26:49 +0530108set_target_properties (zinteloemcmds PROPERTIES VERSION "0.1.0")
109set_target_properties (zinteloemcmds PROPERTIES SOVERSION "0")
Vernon Mauery4ac799d2019-05-20 15:50:37 -0700110target_link_libraries (zinteloemcmds stdc++fs)
Vernon Mauery8b69fae2019-03-20 13:43:11 -0700111target_link_libraries (zinteloemcmds ipmid)
Richard Marian Thomaiyar6e056412018-11-14 23:26:49 +0530112target_link_libraries (zinteloemcmds sdbusplus)
James Feista128f492018-12-20 12:31:56 -0800113target_link_libraries (zinteloemcmds phosphor_logging)
Yong Li0669d192019-05-06 14:01:46 +0800114target_link_libraries (zinteloemcmds intel_dbus)
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530115target_link_libraries (zinteloemcmds -luserlayer)
116target_link_libraries (zinteloemcmds -lchannellayer)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700117target_link_libraries (zinteloemcmds ${OPENSSL_CRYPTO_LIBRARY})
Yong Lid3f2ec32019-12-25 17:51:48 +0800118target_link_libraries (zinteloemcmds gpiodcxx)
Jason M. Billse2d1aee2018-10-03 15:57:18 -0700119
Kuiying Wang6d6dc7a2020-04-02 10:15:19 +0800120find_package (tinyxml2 REQUIRED)
121target_link_libraries (zinteloemcmds tinyxml2)
122
James Feistb9683922019-01-02 15:04:45 -0800123install (TARGETS zinteloemcmds DESTINATION lib/ipmid-providers)
Rajashekar Gade Reddydf5e3272019-09-05 18:10:53 +0530124option (INTEL_PFR_ENABLED "Intel PFR Enabled" OFF)
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530125option (BMC_VALIDATION_UNSECURE_FEATURE
126 "Enables unsecure features required by validation. Note: must
127 be turned off for production images."
128 OFF)
Yong Li38b58f52019-12-24 09:29:25 +0800129option (MDR_V1_SUPPORT "Support these MDR Verseion 1 IPMI OEM commands" OFF)
130
Rajashekar Gade Reddydf5e3272019-09-05 18:10:53 +0530131target_compile_definitions (
132 zinteloemcmds PRIVATE
133 $<$<BOOL:${INTEL_PFR_ENABLED}>: -DINTEL_PFR_ENABLED>
Richard Marian Thomaiyar99d7d352019-11-11 12:11:35 +0530134 $<$<BOOL:${BMC_VALIDATION_UNSECURE_FEATURE}>:
135 -DBMC_VALIDATION_UNSECURE_FEATURE>
Yong Li38b58f52019-12-24 09:29:25 +0800136 $<$<BOOL:${MDR_V1_SUPPORT}>: -DMDR_V1_SUPPORT>
James Feist25690252019-12-23 12:25:49 -0800137 $<$<BOOL:${USING_ENTITY_MANAGER_DECORATORS}>:
138 -DUSING_ENTITY_MANAGER_DECORATORS>
Rajashekar Gade Reddydf5e3272019-09-05 18:10:53 +0530139)
Rui Zhangaedf5a92020-09-03 09:57:33 -0700140
141# Code Coverage
142if (NOT YOCTO)
143 # non-Debug build may generate misleading code coverage results.
144 set(CMAKE_BUILD_TYPE Debug)
145 message(WARNING "Using Debug build type!")
146 include(CodeCoverage)
147 APPEND_COVERAGE_COMPILER_FLAGS()
148 # check-code-coverage is a required name by
149 # openbmc-build-scripts/scripts/unit-test.py#L487.
150 SETUP_TARGET_FOR_COVERAGE_LCOV(
151 NAME check-code-coverage
152 EXECUTABLE runSensorTests
153 DEPENDENCIES runSensorTests
154 EXCLUDE "/usr/include/*" "/usr/local/include/*" "prefix/*"
155 )
156endif ()