blob: 8aeb6d125bf0d0401fc7cc4b1eda2c929296845e [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)
Ed Tanousd7967552019-01-08 13:12:39 -08006set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs")
James Feistddb78302018-09-06 11:45:42 -07007set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
8set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
9set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
James Feist3cb5fec2018-01-23 14:41:51 -080010
James Feistddb78302018-09-06 11:45:42 -070011option (YOCTO "Enable Building in Yocto" OFF)
12option (USE_OVERLAYS "Enable Overlay Usage" ON)
James Feist3cb5fec2018-01-23 14:41:51 -080013
James Feistddb78302018-09-06 11:45:42 -070014if (NOT YOCTO)
15 externalproject_add (
16 Boost URL
17 https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
18 URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
19 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
20 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
21 INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
22 ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
James Feist3cb5fec2018-01-23 14:41:51 -080023 )
24
James Feistddb78302018-09-06 11:45:42 -070025 externalproject_add (
26 nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git"
27 GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR
28 "${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR
29 "${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND ""
30 BUILD_COMMAND "" INSTALL_COMMAND mkdir -p
31 "${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r
32 "${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann"
33 "${CMAKE_BINARY_DIR}/nlohmann/include"
James Feist9eb0b582018-04-27 12:15:46 -070034 )
James Feist9eb0b582018-04-27 12:15:46 -070035
James Feistddb78302018-09-06 11:45:42 -070036 externalproject_add (valijson GIT_REPOSITORY
37 "https://github.com/tristanpenman/valijson.git"
38 GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9
39 SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src"
40 BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build"
41 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
42 mkdir -p
43 "${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp
44 -r "${CMAKE_BINARY_DIR}/valijson-src/include"
45 "${CMAKE_BINARY_DIR}/valijson")
James Feist9eb0b582018-04-27 12:15:46 -070046
James Feistddb78302018-09-06 11:45:42 -070047 # requires apt install autoconf-archive and autoconf
48 externalproject_add (sdbusplus-project PREFIX
49 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
50 https://github.com/openbmc/sdbusplus.git GIT_TAG
James Feista465ccc2019-02-08 12:51:01 -080051 bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR
James Feistddb78302018-09-06 11:45:42 -070052 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
53 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
54 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
55 && ./bootstrap.sh && ./configure --enable-transaction
56 && make -j libsdbusplus.la INSTALL_COMMAND ""
57 LOG_DOWNLOAD ON)
James Feist9eb0b582018-04-27 12:15:46 -070058
James Feistddb78302018-09-06 11:45:42 -070059 include_directories (${CMAKE_BINARY_DIR}/sdbusplus-src)
60 include_directories (${CMAKE_BINARY_DIR}/nlohmann/include)
61 include_directories (${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
62 include_directories (${CMAKE_BINARY_DIR}/valijson/include)
63 include_directories (${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
64 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
James Feist3cb5fec2018-01-23 14:41:51 -080065
James Feistddb78302018-09-06 11:45:42 -070066 include_directories (${CMAKE_BINARY_DIR}/boost-src)
67 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
68 option (ENABLE_TEST "Enable Google Test" OFF)
69 if (ENABLE_TEST)
70 hunter_add_package (GTest)
71 find_package (GTest CONFIG REQUIRED)
72 enable_testing ()
73 endif ()
74endif ()
James Feist3cb5fec2018-01-23 14:41:51 -080075
James Feistddb78302018-09-06 11:45:42 -070076add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
77add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
78add_definitions (-DBOOST_ALL_NO_LIB)
79add_definitions (-DBOOST_NO_RTTI)
80add_definitions (-DBOOST_NO_TYPEID)
81add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
James Feist3cb5fec2018-01-23 14:41:51 -080082
James Feistddb78302018-09-06 11:45:42 -070083include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feistddb78302018-09-06 11:45:42 -070084include_directories (${Boost_INCLUDE_DIRS})
James Feistddb78302018-09-06 11:45:42 -070085include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feist3cb5fec2018-01-23 14:41:51 -080086
James Feistddb78302018-09-06 11:45:42 -070087add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
James Feista2a98112018-08-07 11:15:37 -070088
James Feistddb78302018-09-06 11:45:42 -070089target_link_libraries (fru-device pthread)
90target_link_libraries (fru-device stdc++fs)
James Feist3b860982018-10-02 14:34:07 -070091target_link_libraries (fru-device i2c)
James Feistddb78302018-09-06 11:45:42 -070092target_link_libraries (fru-device ${Boost_LIBRARIES})
93target_link_libraries (fru-device -lsystemd)
94target_link_libraries (fru-device sdbusplus)
95
96add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
97 src/Utils.cpp)
98
99target_link_libraries (entity-manager -lsystemd)
100target_link_libraries (entity-manager stdc++fs)
101target_link_libraries (entity-manager ${Boost_LIBRARIES})
102target_link_libraries (entity-manager sdbusplus)
103if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
104 # as of today
105 target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
106endif ()
107
108if (NOT YOCTO)
109 add_dependencies (entity-manager nlohmann-json)
110 add_dependencies (entity-manager sdbusplus-project)
111 add_dependencies (entity-manager valijson)
112 add_dependencies (fru-device sdbusplus-project)
113endif ()
James Feistb5320a72018-01-24 12:28:12 -0800114
James Feistce4367c2018-10-16 09:19:57 -0700115set (
116 SERVICE_FILES
117 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service
118 ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service
119)
120
121set (PACKAGE_DIR /usr/share/entity-manager/)
122target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}")
123install (TARGETS fru-device entity-manager DESTINATION sbin)
124install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR})
125install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR})
126install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations)
127install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)