forked from openbmc/entity-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
192 lines (167 loc) · 7.81 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
set (BUILD_SHARED_LIBRARIES OFF)
include (ExternalProject)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
if (NOT YOCTO) # to download gtest
include ("cmake/HunterGate.cmake")
huntergate (URL "https://github.com/ruslo/hunter/archive/v0.18.64.tar.gz"
SHA1 "baf9c8cc4f65306f0e442b5419967b4c4c04589a")
endif ()
project (entity-manager CXX)
set (
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -lstdc++fs \
-Werror \
-Wall \
-Wextra \
-Wshadow \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Wcast-align \
-Wunused \
-Woverloaded-virtual \
-Wpedantic \
-Wconversion \
-Wmisleading-indentation \
-Wduplicated-cond \
-Wduplicated-branches \
-Wlogical-op \
-Wnull-dereference \
-Wuseless-cast \
-Wdouble-promotion \
-Wformat=2 \
"
)
# todo: fix these warnings
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-cast-align")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
option (YOCTO "Enable Building in Yocto" OFF)
option (USE_OVERLAYS "Enable Overlay Usage" ON)
if (NOT YOCTO)
externalproject_add (
Boost URL
https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR
"${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
"${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
${CMAKE_BINARY_DIR}/boost-src/boost ${CMAKE_BINARY_DIR}/prefix/include
)
externalproject_add (
nlohmann-json GIT_REPOSITORY "https://github.com/nlohmann/json.git"
GIT_TAG d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe SOURCE_DIR
"${CMAKE_BINARY_DIR}/nlohmann-json-src" BINARY_DIR
"${CMAKE_BINARY_DIR}/nlohmann-json-build" CONFIGURE_COMMAND ""
BUILD_COMMAND "" INSTALL_COMMAND mkdir -p
"${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann" && cp -r
"${CMAKE_BINARY_DIR}/nlohmann-json-src/single_include/nlohmann"
"${CMAKE_BINARY_DIR}/nlohmann/include"
)
externalproject_add (valijson GIT_REPOSITORY
"https://github.com/tristanpenman/valijson.git"
GIT_TAG c2f22fddf599d04dc33fcd7ed257c698a05345d9
SOURCE_DIR "${CMAKE_BINARY_DIR}/valijson-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/valijson-build"
CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND
mkdir -p
"${CMAKE_BINARY_DIR}/valijson/include/vaijson" && cp
-r "${CMAKE_BINARY_DIR}/valijson-src/include"
"${CMAKE_BINARY_DIR}/valijson")
# requires apt install autoconf-archive and autoconf
externalproject_add (sdbusplus-project PREFIX
${CMAKE_BINARY_DIR}/sdbusplus-project GIT_REPOSITORY
https://github.com/openbmc/sdbusplus.git GIT_TAG
bed15f0cee4784acdf151cca14efdfb98cb9d397 SOURCE_DIR
${CMAKE_BINARY_DIR}/sdbusplus-src BINARY_DIR
${CMAKE_BINARY_DIR}/sdbusplus-build CONFIGURE_COMMAND
"" BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/sdbusplus-src
&& ./bootstrap.sh && ./configure --enable-transaction
&& make -j libsdbusplus.la INSTALL_COMMAND ""
LOG_DOWNLOAD ON)
include_directories (SYSTEM ${CMAKE_BINARY_DIR}/sdbusplus-src)
include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include)
include_directories (SYSTEM ${CMAKE_BINARY_DIR}/nlohmann/include/nlohmann)
include_directories (SYSTEM ${CMAKE_BINARY_DIR}/valijson/include)
include_directories (SYSTEM
${CMAKE_BINARY_DIR}/phosphor-dbus-interfaces/include)
link_directories (${CMAKE_BINARY_DIR}/sdbusplus-src/.libs)
include_directories (SYSTEM ${CMAKE_BINARY_DIR}/boost-src)
set (CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/boost-src ${CMAKE_PREFIX_PATH})
option (HUNTER_ENABLED "Enable hunter package pulling" ON)
hunter_add_package (GTest)
find_package (GTest CONFIG REQUIRED)
enable_testing ()
add_executable (entityManagerTests test/test_entity-manager.cpp
src/Utils.cpp)
add_test (NAME test_entitymanager COMMAND entityManagerTests)
target_link_libraries (entityManagerTests GTest::main GTest::gtest)
target_link_libraries (entityManagerTests -lsystemd)
target_link_libraries (entityManagerTests stdc++fs)
target_link_libraries (entityManagerTests ${Boost_LIBRARIES})
target_link_libraries (entityManagerTests sdbusplus)
find_package (PythonInterp REQUIRED)
find_package (Git REQUIRED)
execute_process (COMMAND ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/scripts/autojson.py
${CMAKE_CURRENT_SOURCE_DIR}/configurations)
execute_process (COMMAND ${GIT_EXECUTABLE} -C ${CMAKE_CURRENT_SOURCE_DIR}
diff
--quiet configurations
RESULT_VARIABLE ret)
if (ret EQUAL "1")
message (FATAL_ERROR
"Invalid JSON Format, Please rerun scripts/autojson.")
endif ()
endif ()
add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
add_definitions (-DBOOST_ALL_NO_LIB)
add_definitions (-DBOOST_NO_RTTI)
add_definitions (-DBOOST_NO_TYPEID)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable (fru-device src/FruDevice.cpp src/Utils.cpp)
target_link_libraries (fru-device pthread)
target_link_libraries (fru-device stdc++fs)
target_link_libraries (fru-device i2c)
target_link_libraries (fru-device ${Boost_LIBRARIES})
target_link_libraries (fru-device -lsystemd)
target_link_libraries (fru-device sdbusplus)
add_executable (entity-manager src/EntityManager.cpp src/Overlay.cpp
src/Utils.cpp)
target_link_libraries (entity-manager -lsystemd)
target_link_libraries (entity-manager stdc++fs)
target_link_libraries (entity-manager ${Boost_LIBRARIES})
target_link_libraries (entity-manager sdbusplus)
if (USE_OVERLAYS) # overlays can be disabled because they require a kernel patch
# as of today
target_compile_definitions (entity-manager PRIVATE OVERLAYS=1)
endif ()
if (NOT YOCTO)
add_dependencies (entity-manager nlohmann-json)
add_dependencies (entity-manager sdbusplus-project)
add_dependencies (entity-manager valijson)
add_dependencies (entityManagerTests nlohmann-json)
add_dependencies (entityManagerTests sdbusplus-project)
add_dependencies (entityManagerTests valijson)
add_dependencies (fru-device nlohmann-json)
add_dependencies (fru-device valijson)
add_dependencies (fru-device sdbusplus-project)
add_dependencies (valijson nlohmann-json)
endif ()
set (
SERVICE_FILES
${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.EntityManager.service
${PROJECT_SOURCE_DIR}/service_files/xyz.openbmc_project.FruDevice.service
)
set (PACKAGE_DIR /usr/share/entity-manager/)
target_compile_definitions (entity-manager PRIVATE PACKAGE_DIR="${PACKAGE_DIR}"
-DBOOST_ASIO_DISABLE_THREADS)
target_compile_definitions (fru-device PRIVATE PACKAGE_DIR="${PACKAGE_DIR}")
install (TARGETS fru-device entity-manager DESTINATION bin)
install (DIRECTORY configurations DESTINATION ${PACKAGE_DIR})
install (DIRECTORY overlay_templates DESTINATION ${PACKAGE_DIR})
install (DIRECTORY schemas DESTINATION ${PACKAGE_DIR}/configurations)
install (FILES ${SERVICE_FILES} DESTINATION /lib/systemd/system/)
install (FILES blacklist.json DESTINATION ${PACKAGE_DIR})