James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.1 FATAL_ERROR) |
| 2 | set (BUILD_SHARED_LIBRARIES OFF) |
| 3 | include (ExternalProject) |
James Feist | 310cb90 | 2018-09-28 10:35:22 -0700 | [diff] [blame] | 4 | set (CMAKE_CXX_STANDARD 17) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 5 | set (CMAKE_CXX_STANDARD_REQUIRED ON) |
Ed Tanous | d796755 | 2019-01-08 13:12:39 -0800 | [diff] [blame] | 6 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs") |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 7 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 8 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") |
| 9 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 10 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 11 | option (YOCTO "Enable Building in Yocto" OFF) |
| 12 | option (USE_OVERLAYS "Enable Overlay Usage" ON) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 13 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 14 | if (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 Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 25 | 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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 34 | ) |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 35 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 36 | 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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 46 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 47 | # 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 Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 51 | bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 58 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 59 | 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 Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 65 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 66 | 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 () |
| 74 | endif () |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 75 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 76 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 77 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 78 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 79 | add_definitions (-DBOOST_NO_RTTI) |
| 80 | add_definitions (-DBOOST_NO_TYPEID) |
| 81 | add_definitions (-DBOOST_ASIO_DISABLE_THREADS) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 82 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 83 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 84 | include_directories (${Boost_INCLUDE_DIRS}) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 85 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 86 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 87 | add_executable (fru-device src/FruDevice.cpp src/Utils.cpp) |
James Feist | a2a9811 | 2018-08-07 11:15:37 -0700 | [diff] [blame] | 88 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 89 | target_link_libraries (fru-device pthread) |
| 90 | target_link_libraries (fru-device stdc++fs) |
James Feist | 3b86098 | 2018-10-02 14:34:07 -0700 | [diff] [blame] | 91 | target_link_libraries (fru-device i2c) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 92 | target_link_libraries (fru-device ${Boost_LIBRARIES}) |
| 93 | target_link_libraries (fru-device -lsystemd) |
| 94 | target_link_libraries (fru-device sdbusplus) |
| 95 | |
| 96 | add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp |
| 97 | src/Utils.cpp) |
| 98 | |
| 99 | target_link_libraries (entity-manager -lsystemd) |
| 100 | target_link_libraries (entity-manager stdc++fs) |
| 101 | target_link_libraries (entity-manager ${Boost_LIBRARIES}) |
| 102 | target_link_libraries (entity-manager sdbusplus) |
| 103 | if (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) |
| 106 | endif () |
| 107 | |
| 108 | if (NOT YOCTO) |
| 109 | add_dependencies (entity-manager nlohmann-json) |
| 110 | add_dependencies (entity-manager sdbusplus-project) |
| 111 | add_dependencies (entity-manager valijson) |
James Feist | 550d1b5 | 2019-03-04 11:56:02 -0800 | [diff] [blame] | 112 | add_dependencies (fru-device valijson) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 113 | add_dependencies (fru-device sdbusplus-project) |
James Feist | 3bdc4e4 | 2019-02-27 09:38:33 -0800 | [diff] [blame] | 114 | add_dependencies (valijson nlohmann-json) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 115 | endif () |
James Feist | b5320a7 | 2018-01-24 12:28:12 -0800 | [diff] [blame] | 116 | |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 117 | set ( |
| 118 | SERVICE_FILES |
| 119 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service |
| 120 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service |
| 121 | ) |
| 122 | |
| 123 | set (PACKAGE_DIR /usr/share/entity-manager/) |
| 124 | target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}") |
Patrick Venture | dd9c79b | 2019-03-28 13:05:10 -0700 | [diff] [blame] | 125 | install (TARGETS fru-device entity-manager DESTINATION bin) |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 126 | install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR}) |
| 127 | install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR}) |
| 128 | install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations) |
| 129 | install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/) |