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 | f69ee42 | 2019-08-20 10:28:08 -0700 | [diff] [blame] | 7 | if (NOT YOCTO) # to download gtest |
| 8 | include ("cmake/HunterGate.cmake") |
| 9 | huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz" |
| 10 | SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a") |
| 11 | endif () |
James Feist | 481c5d5 | 2019-08-13 14:40:40 -0700 | [diff] [blame] | 12 | |
| 13 | project (entity-manager CXX) |
| 14 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 15 | set ( |
| 16 | CMAKE_CXX_FLAGS |
| 17 | "${CMAKE_CXX_FLAGS} -lstdc++fs \ |
| 18 | -Werror \ |
| 19 | -Wall \ |
| 20 | -Wextra \ |
| 21 | -Wshadow \ |
| 22 | -Wnon-virtual-dtor \ |
| 23 | -Wold-style-cast \ |
| 24 | -Wcast-align \ |
| 25 | -Wunused \ |
| 26 | -Woverloaded-virtual \ |
| 27 | -Wpedantic \ |
| 28 | -Wconversion \ |
| 29 | -Wmisleading-indentation \ |
| 30 | -Wduplicated-cond \ |
| 31 | -Wduplicated-branches \ |
| 32 | -Wlogical-op \ |
| 33 | -Wnull-dereference \ |
| 34 | -Wuseless-cast \ |
| 35 | -Wdouble-promotion \ |
| 36 | -Wformat=2 \ |
| 37 | " |
| 38 | ) |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 39 | |
| 40 | # todo: fix these warnings |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 41 | 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] | 42 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 43 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti") |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 44 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 45 | option (YOCTO "Enable Building in Yocto" OFF) |
| 46 | option (USE_OVERLAYS "Enable Overlay Usage" ON) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 47 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 48 | if (NOT YOCTO) |
| 49 | externalproject_add ( |
| 50 | Boost URL |
James Feist | 0eb4035 | 2019-04-09 14:44:04 -0700 | [diff] [blame] | 51 | https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz |
| 52 | URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 53 | "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR |
| 54 | "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" |
| 55 | INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R |
| 56 | ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 57 | ) |
| 58 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 59 | externalproject_add ( |
| 60 | nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git" |
| 61 | GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR |
| 62 | "${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR |
| 63 | "${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND "" |
| 64 | BUILD_COMMAND "" INSTALL_COMMAND mkdir -p |
| 65 | "${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r |
| 66 | "${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann" |
| 67 | "${CMAKE_BINARY_DIR}/nlohmann/include" |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 68 | ) |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 69 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 70 | externalproject_add (valijson GIT_REPOSITORY |
| 71 | "https://github.com/tristanpenman/valijson.git" |
| 72 | GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9 |
| 73 | SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src" |
| 74 | BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build" |
| 75 | CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND |
| 76 | mkdir -p |
| 77 | "${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp |
| 78 | -r "${CMAKE_BINARY_DIR}/valijson-src/include" |
| 79 | "${CMAKE_BINARY_DIR}/valijson") |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 80 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 81 | # requires apt install autoconf-archive and autoconf |
| 82 | externalproject_add (sdbusplus-project PREFIX |
| 83 | ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY |
| 84 | https://github.com/openbmc/sdbusplus.git GIT_TAG |
James Feist | a465ccc | 2019-02-08 12:51:01 -0800 | [diff] [blame] | 85 | bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 86 | ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR |
| 87 | ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND |
| 88 | "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src |
| 89 | && ./bootstrap.sh && ./configure --enable-transaction |
| 90 | && make -j libsdbusplus.la INSTALL_COMMAND "" |
| 91 | LOG_DOWNLOAD ON) |
James Feist | 9eb0b58 | 2018-04-27 12:15:46 -0700 | [diff] [blame] | 92 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 93 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src) |
| 94 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include) |
| 95 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann) |
| 96 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/valijson/include) |
| 97 | include_directories (SYSTEM |
| 98 | ${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 99 | link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 100 | |
James Feist | 9813279 | 2019-07-09 13:29:09 -0700 | [diff] [blame] | 101 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 102 | set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH}) |
James Feist | 481c5d5 | 2019-08-13 14:40:40 -0700 | [diff] [blame] | 103 | |
| 104 | option (HUNTER_ENABLED "Enable hunter package pulling" ON) |
| 105 | hunter_add_package (GTest) |
| 106 | |
| 107 | find_package (GTest CONFIG REQUIRED) |
| 108 | |
| 109 | enable_testing () |
| 110 | |
| 111 | add_executable (entityManagerTests test/test_entity-manager.cpp |
| 112 | src/Utils.cpp) |
| 113 | add_test (NAME test_entitymanager COMMAND entityManagerTests) |
| 114 | target_link_libraries (entityManagerTests GTest::main GTest::gtest) |
| 115 | target_link_libraries (entityManagerTests -lsystemd) |
| 116 | target_link_libraries (entityManagerTests stdc++fs) |
| 117 | target_link_libraries (entityManagerTests ${Boost_LIBRARIES}) |
| 118 | target_link_libraries (entityManagerTests sdbusplus) |
| 119 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 120 | endif () |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 121 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 122 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 123 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 124 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 125 | add_definitions (-DBOOST_NO_RTTI) |
| 126 | add_definitions (-DBOOST_NO_TYPEID) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 127 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 128 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
James Feist | 3cb5fec | 2018-01-23 14:41:51 -0800 | [diff] [blame] | 129 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 130 | add_executable (fru-device src/FruDevice.cpp src/Utils.cpp) |
James Feist | a2a9811 | 2018-08-07 11:15:37 -0700 | [diff] [blame] | 131 | |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 132 | target_link_libraries (fru-device pthread) |
| 133 | target_link_libraries (fru-device stdc++fs) |
James Feist | 3b86098 | 2018-10-02 14:34:07 -0700 | [diff] [blame] | 134 | target_link_libraries (fru-device i2c) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 135 | target_link_libraries (fru-device ${Boost_LIBRARIES}) |
| 136 | target_link_libraries (fru-device -lsystemd) |
| 137 | target_link_libraries (fru-device sdbusplus) |
| 138 | |
| 139 | add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp |
| 140 | src/Utils.cpp) |
| 141 | |
| 142 | target_link_libraries (entity-manager -lsystemd) |
| 143 | target_link_libraries (entity-manager stdc++fs) |
| 144 | target_link_libraries (entity-manager ${Boost_LIBRARIES}) |
| 145 | target_link_libraries (entity-manager sdbusplus) |
| 146 | if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch |
| 147 | # as of today |
| 148 | target_compile_definitions (entity-manager PRIVATE OVERLAYS=1) |
| 149 | endif () |
| 150 | |
| 151 | if (NOT YOCTO) |
| 152 | add_dependencies (entity-manager nlohmann-json) |
| 153 | add_dependencies (entity-manager sdbusplus-project) |
| 154 | add_dependencies (entity-manager valijson) |
James Feist | 481c5d5 | 2019-08-13 14:40:40 -0700 | [diff] [blame] | 155 | add_dependencies (entityManagerTests nlohmann-json) |
| 156 | add_dependencies (entityManagerTests sdbusplus-project) |
| 157 | add_dependencies (entityManagerTests valijson) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 158 | add_dependencies (fru-device nlohmann-json) |
James Feist | 550d1b5 | 2019-03-04 11:56:02 -0800 | [diff] [blame] | 159 | add_dependencies (fru-device valijson) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 160 | add_dependencies (fru-device sdbusplus-project) |
James Feist | 3bdc4e4 | 2019-02-27 09:38:33 -0800 | [diff] [blame] | 161 | add_dependencies (valijson nlohmann-json) |
James Feist | ddb7830 | 2018-09-06 11:45:42 -0700 | [diff] [blame] | 162 | endif () |
James Feist | b5320a7 | 2018-01-24 12:28:12 -0800 | [diff] [blame] | 163 | |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 164 | set ( |
| 165 | SERVICE_FILES |
| 166 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service |
| 167 | ${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service |
| 168 | ) |
| 169 | |
| 170 | set (PACKAGE_DIR /usr/share/entity-manager/) |
James Feist | 444830e | 2019-04-05 08:38:16 -0700 | [diff] [blame] | 171 | target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}" |
| 172 | -DBOOST_ASIO_DISABLE_THREADS) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 173 | target_compile_definitions (fru-device PRIVATE PACKAGE_DIR="${PACKAGE_DIR}") |
Patrick Venture | dd9c79b | 2019-03-28 13:05:10 -0700 | [diff] [blame] | 174 | install (TARGETS fru-device entity-manager DESTINATION bin) |
James Feist | ce4367c | 2018-10-16 09:19:57 -0700 | [diff] [blame] | 175 | install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR}) |
| 176 | install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR}) |
| 177 | install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations) |
| 178 | install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/) |
Patrick Venture | 11f1ff4 | 2019-08-01 10:42:12 -0700 | [diff] [blame] | 179 | install (FILES blacklist.json DESTINATION ${PACKAGE_DIR}) |