blob: 10d542e3ef46cd1c44628da20506c0b1cd687a59 [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 Feist0eb40352019-04-09 14:44:04 -07007set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -Werror -Wall")
8
9# todo: fix these warnings
10set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-catch-value")
11
James Feistddb78302018-09-06 11:45:42 -070012set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
James Feist3cb5fec2018-01-23 14:41:51 -080013
James Feistddb78302018-09-06 11:45:42 -070014option (YOCTO "Enable Building in Yocto" OFF)
15option (USE_OVERLAYS "Enable Overlay Usage" ON)
James Feist3cb5fec2018-01-23 14:41:51 -080016
James Feistddb78302018-09-06 11:45:42 -070017if (NOT YOCTO)
18 externalproject_add (
19 Boost URL
James Feist0eb40352019-04-09 14:44:04 -070020 https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
21 URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070022 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
23 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
24 INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
25 ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
James Feist3cb5fec2018-01-23 14:41:51 -080026 )
27
James Feistddb78302018-09-06 11:45:42 -070028 externalproject_add (
29 nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git"
30 GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR
31 "${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR
32 "${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND ""
33 BUILD_COMMAND "" INSTALL_COMMAND mkdir -p
34 "${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r
35 "${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann"
36 "${CMAKE_BINARY_DIR}/nlohmann/include"
James Feist9eb0b582018-04-27 12:15:46 -070037 )
James Feist9eb0b582018-04-27 12:15:46 -070038
James Feistddb78302018-09-06 11:45:42 -070039 externalproject_add (valijson GIT_REPOSITORY
40 "https://github.com/tristanpenman/valijson.git"
41 GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9
42 SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src"
43 BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build"
44 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
45 mkdir -p
46 "${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp
47 -r "${CMAKE_BINARY_DIR}/valijson-src/include"
48 "${CMAKE_BINARY_DIR}/valijson")
James Feist9eb0b582018-04-27 12:15:46 -070049
James Feistddb78302018-09-06 11:45:42 -070050 # requires apt install autoconf-archive and autoconf
51 externalproject_add (sdbusplus-project PREFIX
52 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
53 https://github.com/openbmc/sdbusplus.git GIT_TAG
James Feista465ccc2019-02-08 12:51:01 -080054 bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070055 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
56 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
57 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
58 && ./bootstrap.sh && ./configure --enable-transaction
59 && make -j libsdbusplus.la INSTALL_COMMAND ""
60 LOG_DOWNLOAD ON)
James Feist9eb0b582018-04-27 12:15:46 -070061
James Feistddb78302018-09-06 11:45:42 -070062 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
63 include_directories (${CMAKE_BINARY_DIR}/nlohmann/include)
64 include_directories (${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
65 include_directories (${CMAKE_BINARY_DIR}/valijson/include)
66 include_directories (${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
67 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
James Feist3cb5fec2018-01-23 14:41:51 -080068
James Feistddb78302018-09-06 11:45:42 -070069 include_directories (${CMAKE_BINARY_DIR}/boost-src)
70 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
71 option (ENABLE_TEST "Enable Google Test" OFF)
72 if (ENABLE_TEST)
73 hunter_add_package (GTest)
74 find_package (GTest CONFIG REQUIRED)
75 enable_testing ()
76 endif ()
77endif ()
James Feist3cb5fec2018-01-23 14:41:51 -080078
James Feistddb78302018-09-06 11:45:42 -070079add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
80add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
81add_definitions (-DBOOST_ALL_NO_LIB)
82add_definitions (-DBOOST_NO_RTTI)
83add_definitions (-DBOOST_NO_TYPEID)
James Feist3cb5fec2018-01-23 14:41:51 -080084
James Feistddb78302018-09-06 11:45:42 -070085include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feistddb78302018-09-06 11:45:42 -070086include_directories (${Boost_INCLUDE_DIRS})
James Feistddb78302018-09-06 11:45:42 -070087include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feist3cb5fec2018-01-23 14:41:51 -080088
James Feistddb78302018-09-06 11:45:42 -070089add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
James Feista2a98112018-08-07 11:15:37 -070090
James Feistddb78302018-09-06 11:45:42 -070091target_link_libraries (fru-device pthread)
92target_link_libraries (fru-device stdc++fs)
James Feist3b860982018-10-02 14:34:07 -070093target_link_libraries (fru-device i2c)
James Feistddb78302018-09-06 11:45:42 -070094target_link_libraries (fru-device ${Boost_LIBRARIES})
95target_link_libraries (fru-device -lsystemd)
96target_link_libraries (fru-device sdbusplus)
97
98add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
99 src/Utils.cpp)
100
101target_link_libraries (entity-manager -lsystemd)
102target_link_libraries (entity-manager stdc++fs)
103target_link_libraries (entity-manager ${Boost_LIBRARIES})
104target_link_libraries (entity-manager sdbusplus)
105if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
106 # as of today
107 target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
108endif ()
109
110if (NOT YOCTO)
111 add_dependencies (entity-manager nlohmann-json)
112 add_dependencies (entity-manager sdbusplus-project)
113 add_dependencies (entity-manager valijson)
James Feist550d1b52019-03-04 11:56:02 -0800114 add_dependencies (fru-device valijson)
James Feistddb78302018-09-06 11:45:42 -0700115 add_dependencies (fru-device sdbusplus-project)
James Feist3bdc4e42019-02-27 09:38:33 -0800116 add_dependencies (valijson nlohmann-json)
James Feistddb78302018-09-06 11:45:42 -0700117endif ()
James Feistb5320a72018-01-24 12:28:12 -0800118
James Feistce4367c2018-10-16 09:19:57 -0700119set (
120 SERVICE_FILES
121 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service
122 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service
123)
124
125set (PACKAGE_DIR /usr/share/entity-manager/)
James Feist444830e2019-04-05 08:38:16 -0700126target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}"
127 -DBOOST_ASIO_DISABLE_THREADS)
Patrick Venturedd9c79b2019-03-28 13:05:10 -0700128install (TARGETS fru-device entity-manager DESTINATION bin)
James Feistce4367c2018-10-16 09:19:57 -0700129install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR})
130install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR})
131install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations)
132install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)