blob: c57956cda14256caded1d0bad464a8e5847350e0 [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 Feist98132792019-07-09 13:29:09 -07007set (
8 CMAKE_CXX_FLAGS
9 "${CMAKE_CXX_FLAGS} -lstdc++fs \
10 -Werror \
11 -Wall \
12 -Wextra \
13 -Wshadow \
14 -Wnon-virtual-dtor \
15 -Wold-style-cast \
16 -Wcast-align \
17 -Wunused \
18 -Woverloaded-virtual \
19 -Wpedantic \
20 -Wconversion \
21 -Wmisleading-indentation \
22 -Wduplicated-cond \
23 -Wduplicated-branches \
24 -Wlogical-op \
25 -Wnull-dereference \
26 -Wuseless-cast \
27 -Wdouble-promotion \
28 -Wformat=2 \
29"
30)
James Feist0eb40352019-04-09 14:44:04 -070031
32# todo: fix these warnings
James Feist98132792019-07-09 13:29:09 -070033set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-cast-align")
James Feist0eb40352019-04-09 14:44:04 -070034
James Feistddb78302018-09-06 11:45:42 -070035set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
James Feist3cb5fec2018-01-23 14:41:51 -080036
James Feistddb78302018-09-06 11:45:42 -070037option (YOCTO "Enable Building in Yocto" OFF)
38option (USE_OVERLAYS "Enable Overlay Usage" ON)
James Feist3cb5fec2018-01-23 14:41:51 -080039
James Feistddb78302018-09-06 11:45:42 -070040if (NOT YOCTO)
41 externalproject_add (
42 Boost URL
James Feist0eb40352019-04-09 14:44:04 -070043 https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
44 URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070045 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
46 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
47 INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
48 ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
James Feist3cb5fec2018-01-23 14:41:51 -080049 )
50
James Feistddb78302018-09-06 11:45:42 -070051 externalproject_add (
52 nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git"
53 GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR
54 "${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR
55 "${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND ""
56 BUILD_COMMAND "" INSTALL_COMMAND mkdir -p
57 "${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r
58 "${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann"
59 "${CMAKE_BINARY_DIR}/nlohmann/include"
James Feist9eb0b582018-04-27 12:15:46 -070060 )
James Feist9eb0b582018-04-27 12:15:46 -070061
James Feistddb78302018-09-06 11:45:42 -070062 externalproject_add (valijson GIT_REPOSITORY
63 "https://github.com/tristanpenman/valijson.git"
64 GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9
65 SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src"
66 BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build"
67 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
68 mkdir -p
69 "${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp
70 -r "${CMAKE_BINARY_DIR}/valijson-src/include"
71 "${CMAKE_BINARY_DIR}/valijson")
James Feist9eb0b582018-04-27 12:15:46 -070072
James Feistddb78302018-09-06 11:45:42 -070073 # requires apt install autoconf-archive and autoconf
74 externalproject_add (sdbusplus-project PREFIX
75 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
76 https://github.com/openbmc/sdbusplus.git GIT_TAG
James Feista465ccc2019-02-08 12:51:01 -080077 bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070078 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
79 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
80 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
81 && ./bootstrap.sh && ./configure --enable-transaction
82 && make -j libsdbusplus.la INSTALL_COMMAND ""
83 LOG_DOWNLOAD ON)
James Feist9eb0b582018-04-27 12:15:46 -070084
James Feist98132792019-07-09 13:29:09 -070085 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
86 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include)
87 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
88 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/valijson/include)
89 include_directories (SYSTEM
90 ${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
James Feistddb78302018-09-06 11:45:42 -070091 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
James Feist3cb5fec2018-01-23 14:41:51 -080092
James Feist98132792019-07-09 13:29:09 -070093 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
James Feistddb78302018-09-06 11:45:42 -070094 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
95 option (ENABLE_TEST "Enable Google Test" OFF)
96 if (ENABLE_TEST)
97 hunter_add_package (GTest)
98 find_package (GTest CONFIG REQUIRED)
99 enable_testing ()
100 endif ()
101endif ()
James Feist3cb5fec2018-01-23 14:41:51 -0800102
James Feistddb78302018-09-06 11:45:42 -0700103add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
104add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
105add_definitions (-DBOOST_ALL_NO_LIB)
106add_definitions (-DBOOST_NO_RTTI)
107add_definitions (-DBOOST_NO_TYPEID)
James Feist3cb5fec2018-01-23 14:41:51 -0800108
James Feistddb78302018-09-06 11:45:42 -0700109include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feist3cb5fec2018-01-23 14:41:51 -0800110
James Feistddb78302018-09-06 11:45:42 -0700111add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
James Feista2a98112018-08-07 11:15:37 -0700112
James Feistddb78302018-09-06 11:45:42 -0700113target_link_libraries (fru-device pthread)
114target_link_libraries (fru-device stdc++fs)
James Feist3b860982018-10-02 14:34:07 -0700115target_link_libraries (fru-device i2c)
James Feistddb78302018-09-06 11:45:42 -0700116target_link_libraries (fru-device ${Boost_LIBRARIES})
117target_link_libraries (fru-device -lsystemd)
118target_link_libraries (fru-device sdbusplus)
119
120add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
121 src/Utils.cpp)
122
123target_link_libraries (entity-manager -lsystemd)
124target_link_libraries (entity-manager stdc++fs)
125target_link_libraries (entity-manager ${Boost_LIBRARIES})
126target_link_libraries (entity-manager sdbusplus)
127if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
128 # as of today
129 target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
130endif ()
131
132if (NOT YOCTO)
133 add_dependencies (entity-manager nlohmann-json)
134 add_dependencies (entity-manager sdbusplus-project)
135 add_dependencies (entity-manager valijson)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700136 add_dependencies (fru-device nlohmann-json)
James Feist550d1b52019-03-04 11:56:02 -0800137 add_dependencies (fru-device valijson)
James Feistddb78302018-09-06 11:45:42 -0700138 add_dependencies (fru-device sdbusplus-project)
James Feist3bdc4e42019-02-27 09:38:33 -0800139 add_dependencies (valijson nlohmann-json)
James Feistddb78302018-09-06 11:45:42 -0700140endif ()
James Feistb5320a72018-01-24 12:28:12 -0800141
James Feistce4367c2018-10-16 09:19:57 -0700142set (
143 SERVICE_FILES
144 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service
145 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service
146)
147
148set (PACKAGE_DIR /usr/share/entity-manager/)
James Feist444830e2019-04-05 08:38:16 -0700149target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}"
150 -DBOOST_ASIO_DISABLE_THREADS)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700151target_compile_definitions (fru-device PRIVATE PACKAGE_DIR="${PACKAGE_DIR}")
Patrick Venturedd9c79b2019-03-28 13:05:10 -0700152install (TARGETS fru-device entity-manager DESTINATION bin)
James Feistce4367c2018-10-16 09:19:57 -0700153install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR})
154install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR})
155install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations)
156install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
Patrick Venture11f1ff42019-08-01 10:42:12 -0700157install (FILES blacklist.json DESTINATION ${PACKAGE_DIR})