blob: 214db49c76e973ef563387bd4b83332100a5759f [file] [log] [blame]
James Feistddb78302018-09-06 11:45:42 -07001cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
2set (BUILD_SHARED_LIBRARIES OFF)
3include (ExternalProject)
James Feist310cb902018-09-28 10:35:22 -07004set (CMAKE_CXX_STANDARD 17)
James Feistddb78302018-09-06 11:45:42 -07005set (CMAKE_CXX_STANDARD_REQUIRED ON)
James Feistddb78302018-09-06 11:45:42 -07006set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
James Feistf69ee422019-08-20 10:28:08 -07007if (NOT YOCTO) # to download gtest
8 include ("cmake/HunterGate.cmake")
9 huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
10 SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
11endif ()
James Feist481c5d52019-08-13 14:40:40 -070012
13project (entity-manager CXX)
14
James Feist98132792019-07-09 13:29:09 -070015set (
16 CMAKE_CXX_FLAGS
17 "${CMAKE_CXX_FLAGS} -lstdc++fs \
18 -Werror \
19 -Wall \
20 -Wextra \
21 -Wshadow \
22 -Wnon-virtual-dtor \
23 -Wold-style-cast \
24 -Wcast-align \
25 -Wunused \
26 -Woverloaded-virtual \
27 -Wpedantic \
28 -Wconversion \
29 -Wmisleading-indentation \
30 -Wduplicated-cond \
31 -Wduplicated-branches \
32 -Wlogical-op \
33 -Wnull-dereference \
34 -Wuseless-cast \
35 -Wdouble-promotion \
36 -Wformat=2 \
37"
38)
James Feist0eb40352019-04-09 14:44:04 -070039
40# todo: fix these warnings
James Feist98132792019-07-09 13:29:09 -070041set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-cast-align")
James Feist0eb40352019-04-09 14:44:04 -070042
James Feistddb78302018-09-06 11:45:42 -070043set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
James Feist3cb5fec2018-01-23 14:41:51 -080044
James Feistddb78302018-09-06 11:45:42 -070045option (YOCTO "Enable Building in Yocto" OFF)
46option (USE_OVERLAYS "Enable Overlay Usage" ON)
James Feist3cb5fec2018-01-23 14:41:51 -080047
James Feistddb78302018-09-06 11:45:42 -070048if (NOT YOCTO)
49 externalproject_add (
50 Boost URL
James Feist0eb40352019-04-09 14:44:04 -070051 https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
52 URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070053 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
54 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
55 INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
56 ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
James Feist3cb5fec2018-01-23 14:41:51 -080057 )
58
James Feistddb78302018-09-06 11:45:42 -070059 externalproject_add (
60 nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git"
61 GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR
62 "${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR
63 "${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND ""
64 BUILD_COMMAND "" INSTALL_COMMAND mkdir -p
65 "${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r
66 "${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann"
67 "${CMAKE_BINARY_DIR}/nlohmann/include"
James Feist9eb0b582018-04-27 12:15:46 -070068 )
James Feist9eb0b582018-04-27 12:15:46 -070069
James Feistddb78302018-09-06 11:45:42 -070070 externalproject_add (valijson GIT_REPOSITORY
71 "https://github.com/tristanpenman/valijson.git"
72 GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9
73 SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src"
74 BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build"
75 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
76 mkdir -p
77 "${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp
78 -r "${CMAKE_BINARY_DIR}/valijson-src/include"
79 "${CMAKE_BINARY_DIR}/valijson")
James Feist9eb0b582018-04-27 12:15:46 -070080
James Feistddb78302018-09-06 11:45:42 -070081 # requires apt install autoconf-archive and autoconf
82 externalproject_add (sdbusplus-project PREFIX
83 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
84 https://github.com/openbmc/sdbusplus.git GIT_TAG
James Feista465ccc2019-02-08 12:51:01 -080085 bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070086 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
87 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
88 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
89 && ./bootstrap.sh && ./configure --enable-transaction
90 && make -j libsdbusplus.la INSTALL_COMMAND ""
91 LOG_DOWNLOAD ON)
James Feist9eb0b582018-04-27 12:15:46 -070092
James Feist98132792019-07-09 13:29:09 -070093 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
94 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include)
95 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
96 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/valijson/include)
97 include_directories (SYSTEM
98 ${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
James Feistddb78302018-09-06 11:45:42 -070099 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
James Feist3cb5fec2018-01-23 14:41:51 -0800100
James Feist98132792019-07-09 13:29:09 -0700101 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
James Feistddb78302018-09-06 11:45:42 -0700102 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
James Feist481c5d52019-08-13 14:40:40 -0700103
104 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
105 hunter_add_package (GTest)
106
107 find_package (GTest CONFIG REQUIRED)
108
109 enable_testing ()
110
111 add_executable (entityManagerTests test/test_entity-manager.cpp
112 src/Utils.cpp)
113 add_test (NAME test_entitymanager COMMAND entityManagerTests)
114 target_link_libraries (entityManagerTests GTest::main GTest::gtest)
115 target_link_libraries (entityManagerTests -lsystemd)
116 target_link_libraries (entityManagerTests stdc++fs)
117 target_link_libraries (entityManagerTests ${Boost_LIBRARIES})
118 target_link_libraries (entityManagerTests sdbusplus)
119
James Feistddb78302018-09-06 11:45:42 -0700120endif ()
James Feist3cb5fec2018-01-23 14:41:51 -0800121
James Feistddb78302018-09-06 11:45:42 -0700122add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
123add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
124add_definitions (-DBOOST_ALL_NO_LIB)
125add_definitions (-DBOOST_NO_RTTI)
126add_definitions (-DBOOST_NO_TYPEID)
James Feist3cb5fec2018-01-23 14:41:51 -0800127
James Feistddb78302018-09-06 11:45:42 -0700128include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feist3cb5fec2018-01-23 14:41:51 -0800129
James Feistddb78302018-09-06 11:45:42 -0700130add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
James Feista2a98112018-08-07 11:15:37 -0700131
James Feistddb78302018-09-06 11:45:42 -0700132target_link_libraries (fru-device pthread)
133target_link_libraries (fru-device stdc++fs)
James Feist3b860982018-10-02 14:34:07 -0700134target_link_libraries (fru-device i2c)
James Feistddb78302018-09-06 11:45:42 -0700135target_link_libraries (fru-device ${Boost_LIBRARIES})
136target_link_libraries (fru-device -lsystemd)
137target_link_libraries (fru-device sdbusplus)
138
139add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
140 src/Utils.cpp)
141
142target_link_libraries (entity-manager -lsystemd)
143target_link_libraries (entity-manager stdc++fs)
144target_link_libraries (entity-manager ${Boost_LIBRARIES})
145target_link_libraries (entity-manager sdbusplus)
146if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
147 # as of today
148 target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
149endif ()
150
151if (NOT YOCTO)
152 add_dependencies (entity-manager nlohmann-json)
153 add_dependencies (entity-manager sdbusplus-project)
154 add_dependencies (entity-manager valijson)
James Feist481c5d52019-08-13 14:40:40 -0700155 add_dependencies (entityManagerTests nlohmann-json)
156 add_dependencies (entityManagerTests sdbusplus-project)
157 add_dependencies (entityManagerTests valijson)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700158 add_dependencies (fru-device nlohmann-json)
James Feist550d1b52019-03-04 11:56:02 -0800159 add_dependencies (fru-device valijson)
James Feistddb78302018-09-06 11:45:42 -0700160 add_dependencies (fru-device sdbusplus-project)
James Feist3bdc4e42019-02-27 09:38:33 -0800161 add_dependencies (valijson nlohmann-json)
James Feistddb78302018-09-06 11:45:42 -0700162endif ()
James Feistb5320a72018-01-24 12:28:12 -0800163
James Feistce4367c2018-10-16 09:19:57 -0700164set (
165 SERVICE_FILES
166 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service
167 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service
168)
169
170set (PACKAGE_DIR /usr/share/entity-manager/)
James Feist444830e2019-04-05 08:38:16 -0700171target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}"
172 -DBOOST_ASIO_DISABLE_THREADS)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700173target_compile_definitions (fru-device PRIVATE PACKAGE_DIR="${PACKAGE_DIR}")
Patrick Venturedd9c79b2019-03-28 13:05:10 -0700174install (TARGETS fru-device entity-manager DESTINATION bin)
James Feistce4367c2018-10-16 09:19:57 -0700175install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR})
176install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR})
177install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations)
178install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700179install (FILES blacklist.json DESTINATION ${PACKAGE_DIR})