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) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 6 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 7 | set ( |
| 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 Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 31 | |
| 32 | # todo: fix these warnings |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 33 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-cast-align") |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 34 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 35 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 36 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 37 | option (YOCTO "Enable Building in Yocto" OFF) |
| 38 | option (USE_OVERLAYS "Enable Overlay Usage" ON) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 39 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 40 | if (NOT YOCTO) |
| 41 | externalproject_add ( |
| 42 | Boost URL |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 43 | https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz |
| 44 | URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 45 | "${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 Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 49 | ) |
| 50 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 51 | 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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 60 | ) |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 61 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 62 | 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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 72 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 73 | # 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 Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 77 | bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 78 | ${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 Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 84 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 85 | 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 Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 91 | link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 92 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 93 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 94 | 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 () |
| 101 | endif () |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 102 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 103 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 104 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 105 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 106 | add_definitions (-DBOOST_NO_RTTI) |
| 107 | add_definitions (-DBOOST_NO_TYPEID) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 108 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 109 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 110 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 111 | add_executable (fru-device src/FruDevice.cpp src/Utils.cpp) |
James Feist | a2a9811 | 2018-08-07 11:15:37 -0700 | [diff] [blame] | 112 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 113 | target_link_libraries (fru-device pthread) |
| 114 | target_link_libraries (fru-device stdc++fs) |
James Feist | 3b86098 | 2018-10-02 14:34:07 -0700 | [diff] [blame] | 115 | target_link_libraries (fru-device i2c) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 116 | target_link_libraries (fru-device ${Boost_LIBRARIES}) |
| 117 | target_link_libraries (fru-device -lsystemd) |
| 118 | target_link_libraries (fru-device sdbusplus) |
| 119 | |
| 120 | add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp |
| 121 | src/Utils.cpp) |
| 122 | |
| 123 | target_link_libraries (entity-manager -lsystemd) |
| 124 | target_link_libraries (entity-manager stdc++fs) |
| 125 | target_link_libraries (entity-manager ${Boost_LIBRARIES}) |
| 126 | target_link_libraries (entity-manager sdbusplus) |
| 127 | if (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) |
| 130 | endif () |
| 131 | |
| 132 | if (NOT YOCTO) |
| 133 | add_dependencies (entity-manager nlohmann-json) |
| 134 | add_dependencies (entity-manager sdbusplus-project) |
| 135 | add_dependencies (entity-manager valijson) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 136 | add_dependencies (fru-device nlohmann-json) |
James Feist | 550d1b5 | 2019-03-04 11:56:02 -0800 | [diff] [blame] | 137 | add_dependencies (fru-device valijson) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 138 | add_dependencies (fru-device sdbusplus-project) |
James Feist | 3bdc4e4 | 2019-02-27 09:38:33 -0800 | [diff] [blame] | 139 | add_dependencies (valijson nlohmann-json) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 140 | endif () |
James Feist | b5320a7 | 2018-01-24 12:28:12 -0800 | [diff] [blame] | 141 | |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 142 | set ( |
| 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 | |
| 148 | set (PACKAGE_DIR /usr/share/entity-manager/) |
James Feist | 444830e | 2019-04-05 08:38:16 -0700 | [diff] [blame] | 149 | target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}" |
| 150 | -DBOOST_ASIO_DISABLE_THREADS) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 151 | target_compile_definitions (fru-device PRIVATE PACKAGE_DIR="${PACKAGE_DIR}") |
Patrick Venture | dd9c79b | 2019-03-28 13:05:10 -0700 | [diff] [blame] | 152 | install (TARGETS fru-device entity-manager DESTINATION bin) |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 153 | install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR}) |
| 154 | install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR}) |
| 155 | install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations) |
| 156 | install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 157 | install (FILES blacklist.json DESTINATION ${PACKAGE_DIR}) |