blob: d61d12c402b3356ac0a2e4bf85b48d3ba8ff0d92 [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)
6set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs")
7set (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
51 387110bdf265b5c4435b740aed7e24c3975c514b SOURCE_DIR
52 ${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_CURRENT_SOURCE_DIR}/include/non-yocto)
James Feist3cb5fec2018-01-23 14:41:51 -080067
James Feistddb78302018-09-06 11:45:42 -070068 include_directories (${CMAKE_BINARY_DIR}/boost-src)
69 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
70 option (ENABLE_TEST "Enable Google Test" OFF)
71 if (ENABLE_TEST)
72 hunter_add_package (GTest)
73 find_package (GTest CONFIG REQUIRED)
74 enable_testing ()
75 endif ()
76endif ()
James Feist3cb5fec2018-01-23 14:41:51 -080077
James Feistddb78302018-09-06 11:45:42 -070078add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
79add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
80add_definitions (-DBOOST_ALL_NO_LIB)
81add_definitions (-DBOOST_NO_RTTI)
82add_definitions (-DBOOST_NO_TYPEID)
83add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
James Feist3cb5fec2018-01-23 14:41:51 -080084
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 -070087include_directories (${Boost_INCLUDE_DIRS})
88link_directories (${EXTERNAL_INSTALL_LOCATION}/lib)
James Feist3cb5fec2018-01-23 14:41:51 -080089
James Feistddb78302018-09-06 11:45:42 -070090include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
James Feist3cb5fec2018-01-23 14:41:51 -080091
James Feistddb78302018-09-06 11:45:42 -070092add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
James Feista2a98112018-08-07 11:15:37 -070093
James Feistddb78302018-09-06 11:45:42 -070094target_link_libraries (fru-device pthread)
95target_link_libraries (fru-device stdc++fs)
96target_link_libraries (fru-device ${Boost_LIBRARIES})
97target_link_libraries (fru-device -lsystemd)
98target_link_libraries (fru-device sdbusplus)
99
100add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
101 src/Utils.cpp)
102
103target_link_libraries (entity-manager -lsystemd)
104target_link_libraries (entity-manager stdc++fs)
105target_link_libraries (entity-manager ${Boost_LIBRARIES})
106target_link_libraries (entity-manager sdbusplus)
107if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
108 # as of today
109 target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
110endif ()
111
112if (NOT YOCTO)
113 add_dependencies (entity-manager nlohmann-json)
114 add_dependencies (entity-manager sdbusplus-project)
115 add_dependencies (entity-manager valijson)
116 add_dependencies (fru-device sdbusplus-project)
117endif ()
James Feistb5320a72018-01-24 12:28:12 -0800118
James Feist3cb5fec2018-01-23 14:41:51 -0800119install (TARGETS fru-device entity-manager DESTINATION bin)
James Feista7d96252018-08-09 12:04:48 -0700120install (DIRECTORY configurations DESTINATION share)
121install (DIRECTORY overlay_templates DESTINATION share)
James Feistb4383f42018-08-06 16:54:10 -0700122install (DIRECTORY schemas DESTINATION share/configurations)