blob: 4b4ecfa6726c859668812778d6df6b77c25f2d44 [file] [log] [blame]
Feist, Jamesc95cf672019-08-29 16:10:35 -07001cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
2set (BUILD_SHARED_LIBRARIES OFF)
3include (ExternalProject)
4set (CMAKE_CXX_STANDARD 17)
5set (CMAKE_CXX_STANDARD_REQUIRED ON)
6set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
7if (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")
11endif ()
12
13project (hsbp-manager CXX)
14
15set (
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 \
Jason M. Billsa83c8272020-12-09 12:16:34 -080037 "
Feist, Jamesc95cf672019-08-29 16:10:35 -070038)
Jason M. Billsa83c8272020-12-09 12:16:34 -080039# Temporarily disable rtti
40# See https://github.com/chriskohlhoff/asio/issues/533
41# -fno-rtti
Feist, Jamesc95cf672019-08-29 16:10:35 -070042
43option (YOCTO "Enable Building in Yocto" OFF)
44
45if (NOT YOCTO)
46 externalproject_add (
47 Boost URL
Rohit Chandeldad853a2021-05-14 02:10:46 +053048 https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
49 URL_MD5 e425bf1f1d8c36a3cd464884e74f007a SOURCE_DIR
Feist, Jamesc95cf672019-08-29 16:10:35 -070050 "${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
51 "${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
52 INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
53 ${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
54 ) # requires apt install autoconf-archive and autoconf
55 externalproject_add (sdbusplus-project PREFIX
56 ${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
57 https://github.com/openbmc/sdbusplus.git GIT_TAG
Patrick Williams0d26db32020-06-01 07:45:28 -050058 fa3137a78e952134559bf7c41c4f29fa4afabe02 SOURCE_DIR
Feist, Jamesc95cf672019-08-29 16:10:35 -070059 ${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
60 ${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
61 "" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
Patrick Williams0d26db32020-06-01 07:45:28 -050062 && meson build -Ddefault_library=static && ninja -C
63 build libsdbusplus.a INSTALL_COMMAND ""
Feist, Jamesc95cf672019-08-29 16:10:35 -070064 LOG_DOWNLOAD ON)
65
66 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
Patrick Williams0d26db32020-06-01 07:45:28 -050067 link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/build)
Feist, Jamesc95cf672019-08-29 16:10:35 -070068
69 include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
70 set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
71
72 option (HUNTER_ENABLED "Enable hunter package pulling" ON)
73 hunter_add_package (GTest)
74
75 find_package (GTest CONFIG REQUIRED)
76endif ()
77
78add_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)
84
85include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
86
87add_executable (hsbp-manager src/hsbp_manager.cpp)
88
89target_link_libraries (hsbp-manager -lsystemd)
90target_link_libraries (hsbp-manager i2c)
91target_link_libraries (hsbp-manager ${Boost_LIBRARIES})
92target_link_libraries (hsbp-manager sdbusplus)
James Feist0b236ab2019-10-02 09:09:16 -070093target_link_libraries (hsbp-manager stdc++fs)
Rohit Chandel52639be2021-04-14 15:10:41 +053094target_link_libraries (hsbp-manager gpiodcxx)
Feist, Jamesc95cf672019-08-29 16:10:35 -070095
96if (NOT YOCTO)
97 add_dependencies (hsbp-manager sdbusplus-project)
98endif ()
99
100set (SERVICE_FILES ${PROJECT_SOURCE_DIR}/service_files/hsbp-manager.service)
101
102install (TARGETS hsbp-manager DESTINATION bin)
103install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)