Feist, James | c95cf67 | 2019-08-29 16:10:35 -0700 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.1 FATAL_ERROR) |
| 2 | set (BUILD_SHARED_LIBRARIES OFF) |
| 3 | include (ExternalProject) |
| 4 | set (CMAKE_CXX_STANDARD 17) |
| 5 | set (CMAKE_CXX_STANDARD_REQUIRED ON) |
| 6 | set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 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 () |
| 12 | |
| 13 | project (hsbp-manager CXX) |
| 14 | |
| 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 | -fno-rtti" |
| 38 | ) |
| 39 | |
| 40 | option (YOCTO "Enable Building in Yocto" OFF) |
| 41 | |
| 42 | if (NOT YOCTO) |
| 43 | externalproject_add ( |
| 44 | Boost URL |
| 45 | https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz |
| 46 | URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR |
| 47 | "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR |
| 48 | "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" |
| 49 | INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R |
| 50 | ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include |
| 51 | ) # requires apt install autoconf-archive and autoconf |
| 52 | externalproject_add (sdbusplus-project PREFIX |
| 53 | ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY |
| 54 | https://github.com/openbmc/sdbusplus.git GIT_TAG |
James Feist | d0d36f1 | 2019-11-21 10:19:44 -0800 | [diff] [blame] | 55 | 4212292bcf136d04b38ba5116aa568b0fa312798 SOURCE_DIR |
Feist, James | c95cf67 | 2019-08-29 16:10:35 -0700 | [diff] [blame] | 56 | ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR |
| 57 | ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND |
| 58 | "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src |
| 59 | && ./bootstrap.sh && ./configure --enable-transaction |
| 60 | && make -j libsdbusplus.la INSTALL_COMMAND "" |
| 61 | LOG_DOWNLOAD ON) |
| 62 | |
| 63 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src) |
| 64 | link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs) |
| 65 | |
| 66 | include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src) |
| 67 | set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH}) |
| 68 | |
| 69 | option (HUNTER_ENABLED "Enable hunter package pulling" ON) |
| 70 | hunter_add_package (GTest) |
| 71 | |
| 72 | find_package (GTest CONFIG REQUIRED) |
| 73 | endif () |
| 74 | |
| 75 | add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY) |
| 76 | add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED) |
| 77 | add_definitions (-DBOOST_ALL_NO_LIB) |
| 78 | add_definitions (-DBOOST_NO_RTTI) |
| 79 | add_definitions (-DBOOST_NO_TYPEID) |
| 80 | add_definitions (-DBOOST_ASIO_DISABLE_THREADS) |
| 81 | |
| 82 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) |
| 83 | |
| 84 | add_executable (hsbp-manager src/hsbp_manager.cpp) |
| 85 | |
| 86 | target_link_libraries (hsbp-manager -lsystemd) |
| 87 | target_link_libraries (hsbp-manager i2c) |
| 88 | target_link_libraries (hsbp-manager ${Boost_LIBRARIES}) |
| 89 | target_link_libraries (hsbp-manager sdbusplus) |
James Feist | 0b236ab | 2019-10-02 09:09:16 -0700 | [diff] [blame] | 90 | target_link_libraries (hsbp-manager stdc++fs) |
Feist, James | c95cf67 | 2019-08-29 16:10:35 -0700 | [diff] [blame] | 91 | |
| 92 | if (NOT YOCTO) |
| 93 | add_dependencies (hsbp-manager sdbusplus-project) |
| 94 | endif () |
| 95 | |
| 96 | set (SERVICE_FILES ${PROJECT_SOURCE_DIR}/service_files/hsbp-manager.service) |
| 97 | |
| 98 | install (TARGETS hsbp-manager DESTINATION bin) |
| 99 | install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/) |