0001-First-working-verion.patch 13.7 KB
Newer Older
Marek Belisko's avatar
Marek Belisko committed
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
From f9b14d4ffa27e34ff58973014ef27fae81681d42 Mon Sep 17 00:00:00 2001
From: Marek Belisko <marek.belisko@open-nandra.com>
Date: Tue, 6 Oct 2020 22:03:24 +0200
Subject: [PATCH] First working verion

Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
---
 CMakeLists.txt                           |  28 +++++-
 buildMake.sh                             |  24 ++---
 cmake/Component.hxx.in                   |  23 +++++
 cmake/ShapeComponentDeclaration.cmake    | 168 +++++++++++++++++++++++++++++++
 cmake/StartUp.in                         |   1 +
 src/BufferedMqttMessaging/CMakeLists.txt |   2 +-
 src/JsCache/CMakeLists.txt               |   2 +-
 src/MonitorService/CMakeLists.txt        |   2 -
 src/SchedulerMessaging/CMakeLists.txt    |   2 -
 src/WebsocketMessaging/CMakeLists.txt    |   2 +-
 10 files changed, 228 insertions(+), 26 deletions(-)
 create mode 100644 cmake/Component.hxx.in
 create mode 100644 cmake/ShapeComponentDeclaration.cmake
 create mode 100644 cmake/StartUp.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a65905..12af75f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
27
@@ -17,6 +17,13 @@ cmake_minimum_required(VERSION 3.0)
Marek Belisko's avatar
Marek Belisko committed
28
29
30
31
32
33
34
35
36
37
38
39
40
 
 project(iqrf-gateway-daemon)
 
+set(PROJECT_CMAKE_MODULE_PATH ${PROJECT_CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
+set(shape_CMAKE_MODULE_PATH ${PROJECT_CMAKE_MODULE_PATH})
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
+message("PROJECT_CMAKE_MODULE_PATH:${PROJECT_CMAKE_MODULE_PATH}")
+
+include(${CMAKE_MODULE_PATH}/ShapeComponentDeclaration.cmake)
+
 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
41
@@ -96,13 +103,28 @@ endif()
Marek Belisko's avatar
Marek Belisko committed
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
 
 set_directory_properties(PROPERTIES COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG>)
 
-find_package(shape REQUIRED)
+#find_library(SHAPE_LIBRARY NAMES  libTraceFormatService.so
+#		                             HINTS "/usr/local/Debug/shape/lib")
+find_path(SHAPE_INCLUDE_DIR Args.h)
+
+
+message("!!!!SHAPE LIB: ${SHAPE_LIBRARY} - ${SHAPE_INCLUDE_DIR}")
+  
+include_directories(${SHAPE_INCLUDE_DIR})
+
+#find_library(SHAPEWARE_LIBRARY NAMES libCommandLineService.so
+#		                             HINTS "/usr/local/Debug/shapeware/lib")
+find_path(SHAPEWARE_INCLUDE_DIR IBufferService.h
+        HINTS "/usr/local/include/shapeware" )
+
+
+message("!!!!SHAPEWARE LIB: ${SHAPEWARE_LIBRARY} - ${SHAPEWARE_INCLUDE_DIR}")
+  
+include_directories(${SHAPEWARE_INCLUDE_DIR})
 
 message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
-include(${CMAKE_MODULE_PATH}/ShapeComponentDeclaration.cmake)
 
 set(PROJECT_INSTALL_PREFIX ${PROJECT_NAME})
-set(CMAKE_INSTALL_PREFIX ${shape_DEPLOY})
 
 add_definitions(
   -DRAPIDJSON_HAS_STDSTRING
diff --git a/buildMake.sh b/buildMake.sh
index a8ccb37..31223dc 100755
--- a/buildMake.sh
+++ b/buildMake.sh
77
78
@@ -17,12 +17,14 @@
 
Marek Belisko's avatar
Marek Belisko committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 # Script for building IQRF daemon on Linux machine
 
+rm -rf build
+
 set -e
 
 project=IqrfGwDaemon
 
 #expected build dir structure
-buildexp=build/Unix_Makefiles
+buildexp=build
 
 LIB_DIRECTORY=..
 currentdir=$PWD
93
@@ -29,24 +31,14 @@ builddir=./${buildexp}
Marek Belisko's avatar
Marek Belisko committed
94
95
96
97
 
 mkdir -p ${builddir}
 
-#get path to shape libs
98
-shape=../shape/${buildexp}
Marek Belisko's avatar
Marek Belisko committed
99
100
101
102
103
-pushd ${shape}
-shape=$PWD
-popd
-
-#get path to shapeware libs
104
-shapeware=../shapeware/${buildexp}
Marek Belisko's avatar
Marek Belisko committed
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
-pushd ${shapeware}
-shapeware=$PWD
-popd
-
 #launch cmake to generate build environment
 pushd ${builddir}
 pwd
-cmake -G "Unix Makefiles" -DBUILD_TESTING:BOOL=true -Dshape_DIR:PATH=${shape} -Dshapeware_DIR:PATH=${shapeware} ${currentdir} -DCMAKE_BUILD_TYPE=Debug
+cmake -DBUILD_TESTING:BOOL=false ${currentdir} -DCMAKE_BUILD_TYPE=Debug || exit 1
+make -j `nproc`
+sudo make install
 popd
 
 #build from generated build environment
-cmake --build ${builddir} --config Debug --target install
-cmake --build ${builddir} --config Release --target install
+#cmake --build ${builddir} --config Debug --target install
+#cmake --build ${builddir} --config Release --target install
diff --git a/cmake/Component.hxx.in b/cmake/Component.hxx.in
new file mode 100644
index 0000000..97ad171
--- /dev/null
+++ b/cmake/Component.hxx.in
@@ -0,0 +1,23 @@
+/*!!!!!!!!!!!
+ * This is generated header file according CMakeLists.txt of this project
+ * Don't edit it manually as this file is refreshed after rebuild.
+ * Fix CMakeLists.txt instead and assure required declarations are in place (included) above include of this file
+ *!!!!!!!!!!!
+*/
+#pragma once
+
+#include <ShapeComponent.h>
+
+extern "C" {
+  SHAPE_ABI_EXPORT void* get_component_@NAMESPACE_COMPONENT@(unsigned long* compiler, size_t* typehash)
+  {
+    *compiler = SHAPE_PREDEF_COMPILER;
+    *typehash = std::type_index(typeid(shape::ComponentMeta)).hash_code();
+
+    static shape::ComponentMetaTemplate<@COMPONENT@> component("@COMPONENT@");
+	
+@PROVIDED_INTERFACES@
+@REQUIRED_INTERFACES@
+    return &component;
+  }
+}
diff --git a/cmake/ShapeComponentDeclaration.cmake b/cmake/ShapeComponentDeclaration.cmake
new file mode 100644
index 0000000..fe47549
--- /dev/null
+++ b/cmake/ShapeComponentDeclaration.cmake
@@ -0,0 +1,168 @@
+function(DeclareShapeComponent componentName)
+	message(STATUS "DeclareShapeComponent(): ${componentName}")
+	string(REPLACE ":" "_" NAMESPACE_COMPONENT ${componentName})
+    set(SHAPE_COMPONENT_${NAMESPACE_COMPONENT} ${componentName} PARENT_SCOPE)
+endfunction()
+
+function(AddShapeProvidedInterface componentName interface)
+	string(REPLACE ":" "_" NAMESPACE_COMPONENT ${componentName})
+	if(${SHAPE_COMPONENT_${NAMESPACE_COMPONENT}} STREQUAL ${componentName})
+		set(IFACE
+			"    component.provideInterface<${interface}>(\"${interface}\");"
+		)
+		set(SHAPE_COMPONENT_PROVIDED_IFACES_${NAMESPACE_COMPONENT} ${SHAPE_COMPONENT_PROVIDED_IFACES_${NAMESPACE_COMPONENT}} "${IFACE}" PARENT_SCOPE)
+	else()
+		message( SEND_ERROR "AddShapeProvidedInterface(): Component ${componentName} must be declared in advance by DeclareShapeComponent()")
+	endif()
+endfunction()
+
+function(AddShapeRequiredInterface componentName interface optionality cardinality)
+	string(REPLACE ":" "_" NAMESPACE_COMPONENT ${componentName})
+	if(${SHAPE_COMPONENT_${NAMESPACE_COMPONENT}} STREQUAL ${componentName})
+		if(NOT ((${optionality} MATCHES MANDATORY) OR (${optionality} MATCHES UNREQUIRED)))
+			message( SEND_ERROR "optionality must be UNREQUIRED|MANDATORY" )
+		endif()
+		if(NOT ((${cardinality} MATCHES SINGLE) OR (${cardinality} MATCHES MULTIPLE)))
+			message( SEND_ERROR "optionality must be UNREQUIRED|MANDATORY" )
+		endif()
+		set(IFACE
+			"    component.requireInterface<${interface}>(\"${interface}\", shape::Optionality::${optionality}, shape::Cardinality::${cardinality});"
+		)
+		set(SHAPE_COMPONENT_REQUIRED_IFACES_${NAMESPACE_COMPONENT} ${SHAPE_COMPONENT_REQUIRED_IFACES_${NAMESPACE_COMPONENT}} "${IFACE}" PARENT_SCOPE)
+	else()
+		message( SEND_ERROR "AddShapeRequiredInterface(): Component ${componentName} must be declared in advance by DeclareShapeComponent()")
+	endif()
+endfunction()
+
+function(ConfigureShapeComponent componentName componentHeader)
+	string(REPLACE ":" "_" NAMESPACE_COMPONENT ${componentName})
+	if(${SHAPE_COMPONENT_${NAMESPACE_COMPONENT}} STREQUAL ${componentName})
+		string(REPLACE ";" ";\n" PROVIDED_INTERFACES "${SHAPE_COMPONENT_PROVIDED_IFACES_${NAMESPACE_COMPONENT}}")
+		string(REPLACE ";" ";\n" REQUIRED_INTERFACES "${SHAPE_COMPONENT_REQUIRED_IFACES_${NAMESPACE_COMPONENT}}")
+		set(TARGET_FILE "${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE_COMPONENT}.hxx")
+		configure_file(${shape_CMAKE_MODULE_PATH}/Component.hxx.in ${TARGET_FILE} @ONLY)
+		set(${componentHeader} ${TARGET_FILE} PARENT_SCOPE)
+		message(STATUS "Component ${componentName} configured to ${TARGET_FILE}")
+	else()
+		message( SEND_ERROR "ConfigureShapeComponent(): Component ${componentName} must be declared in advance by DeclareShapeComponent()")
+	endif()
+endfunction()
+
+function(DeployShapeComponent componentName)
+	INSTALL(TARGETS ${componentName}
+		RUNTIME DESTINATION "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/bin"
+		LIBRARY DESTINATION "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/lib"
+		ARCHIVE DESTINATION "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/lib"
+	)
+
+	string(REPLACE ":" "_" NAMESPACE_COMPONENT ${componentName})
+	set(schemafile "${CMAKE_CURRENT_SOURCE_DIR}/schema__${NAMESPACE_COMPONENT}.json")
+	if(EXISTS "${schemafile}")
+		install(
+			FILE
+			"${schemafile}"
+			DESTINATION "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/bin"
+		)
+		endif()
+endfunction()
+
+function(DeployShapeConfiguration cfgName)
+	set(cfgPath "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/runcfg/${cfgName}")
+	
+	set(ix 1)
+	while(ix LESS ${ARGC})
+		list(GET ARGV ${ix} src)
+		MATH(EXPR ix "${ix}+1")	
+		if(NOT ix LESS ${ARGC})
+			break()
+		endif()
+
+		list(GET ARGV ${ix} dst)
+		set(dst "${cfgPath}/${dst}")
+		MATH(EXPR ix "${ix}+1")	
+
+		install(
+			DIRECTORY "${src}/"
+			DESTINATION ${dst}
+			USE_SOURCE_PERMISSIONS
+		)
+	endwhile()
+
+endfunction()
+
+function(DeployShapeConfigurationStartUp executable cfgName)
+	set(cfgPath "\${CMAKE_INSTALL_CONFIG_NAME}/${PROJECT_INSTALL_PREFIX}/runcfg/${cfgName}")
+	
+	set(_ARGS "./configuration/config.json")
+	if(UNIX)
+	  set(_SUFFIX sh)
+	else()
+	  set(_SUFFIX bat)
+	endif()
+
+	set(_TMP_FILE ${CMAKE_CURRENT_BINARY_DIR}/tmp/runcfg/${cfgName}/StartUp)
+	
+	set(_EXE "${shape_DEPLOY}/Debug/${executable}")		
+	configure_file(${shape_CMAKE_MODULE_PATH}/StartUp.in ${_TMP_FILE}.Debug @ONLY)
+	set(_EXE "${shape_DEPLOY}/Release/${executable}")		
+	configure_file(${shape_CMAKE_MODULE_PATH}/StartUp.in ${_TMP_FILE}.Release @ONLY)
+
+	install(
+		PROGRAMS "${_TMP_FILE}.Debug"
+		CONFIGURATIONS Debug
+		DESTINATION ${cfgPath}
+		RENAME StartUp.${_SUFFIX}
+	)
+	install(
+		PROGRAMS "${_TMP_FILE}.Release"
+		CONFIGURATIONS Release
+		DESTINATION ${cfgPath}
+		RENAME StartUp.${_SUFFIX}
+	)
+endfunction()
+
+function(DeployShapeConfigurationTest executable cfgName)
+	set(cfgPath ${shape_DEPLOY}/$<CONFIGURATION>/${PROJECT_INSTALL_PREFIX}/runcfg/${cfgName})
+	set(_ARGS "./configuration/config.json")
+
+	add_test(
+		NAME ${cfgName}
+		COMMAND ${shape_DEPLOY}/$<CONFIGURATION>/${executable} ${_ARGS}
+		WORKING_DIRECTORY ${cfgPath}
+	)
+endfunction()
+
+# This is temporary. MSVC cmake support shall be used in next MSVC ver.
+# The file <Project>.vcxpro.user is configured only if it doesn't exist - it keeps possible manual changes
+function(ConfigureMsvcProject executable cfgName)
+    if(MSVC)
+		set(_vcxProjUserName "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user")
+        if (NOT EXISTS ${_vcxProjUserName})
+			if(${MSVC_VERSION} EQUAL 1700)
+				set(VS_VER 11.0)
+			elseif(${MSVC_VERSION} EQUAL 1800)
+				set(VS_VER 12.0)
+			elseif(${MSVC_VERSION} EQUAL 1900)
+				set(VS_VER 14.0)
+			elseif(${MSVC_VERSION} EQUAL 1912)
+				set(VS_VER 15.0)
+			elseif(${MSVC_VERSION} EQUAL 1915)
+				set(VS_VER 15.0)
+			elseif(${MSVC_VERSION} EQUAL 1916)
+				set(VS_VER 15.0)
+			else()
+				message(FATAL_ERROR "Unknown/unsupported VS version: ${MSVC_VERSION}")
+			endif()
+
+			set(DEBUG_EXE "${shape_DEPLOY}/Debug/${executable}")		
+			set(RELEASE_EXE "${shape_DEPLOY}/Release/${executable}")		
+			set(DEBUG_ARGS "./configuration/config.json")		
+			set(RELEASE_ARGS "./configuration/config.json")		
+			set(DEBUG_WD "${shape_DEPLOY}/Debug/${PROJECT_INSTALL_PREFIX}/runcfg/${cfgName}")		
+			set(RELEASE_WD "${shape_DEPLOY}/Release/${PROJECT_INSTALL_PREFIX}/runcfg/${cfgName}")		
+
+			configure_file(${shape_CMAKE_MODULE_PATH}/project.vcxproj.user.in ${_vcxProjUserName} @ONLY)
+        endif()
+    endif()
+
+endfunction()
diff --git a/cmake/StartUp.in b/cmake/StartUp.in
new file mode 100644
index 0000000..cc4a0b1
--- /dev/null
+++ b/cmake/StartUp.in
@@ -0,0 +1 @@
+@_EXE@ @_ARGS@
\ No newline at end of file
diff --git a/src/BufferedMqttMessaging/CMakeLists.txt b/src/BufferedMqttMessaging/CMakeLists.txt
index c928c00..998989b 100644
--- a/src/BufferedMqttMessaging/CMakeLists.txt
+++ b/src/BufferedMqttMessaging/CMakeLists.txt
338
@@ -16,6 +6,6 @@
Marek Belisko's avatar
Marek Belisko committed
339
340
341
342
343
344
345
346
347
348
349
 project(BufferedMqttMessaging)
 
-FIND_PACKAGE(shapeware REQUIRED)
+#FIND_PACKAGE(shapeware REQUIRED)
 
 set(COMPONENT iqrf::BufferedMqttMessaging)
 DeclareShapeComponent(${COMPONENT})
diff --git a/src/JsCache/CMakeLists.txt b/src/JsCache/CMakeLists.txt
index f466cf2..f50dfb6 100644
--- a/src/JsCache/CMakeLists.txt
+++ b/src/JsCache/CMakeLists.txt
350
@@ -18,7 +18,7 @@ project(JsCache)
Marek Belisko's avatar
Marek Belisko committed
351
352
353
354
355
356
357
358
359
360
361
362
 find_package(Boost REQUIRED COMPONENTS filesystem )
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
 find_package(LIBZIP REQUIRED)
-find_package(shapeware REQUIRED)
+#find_package(shapeware REQUIRED)
 
 set(COMPONENT iqrf::JsCache)
 DeclareShapeComponent(${COMPONENT})
diff --git a/src/MonitorService/CMakeLists.txt b/src/MonitorService/CMakeLists.txt
index 8a3ea14..5d766d7 100644
--- a/src/MonitorService/CMakeLists.txt
+++ b/src/MonitorService/CMakeLists.txt
363
@@ -16,7 +16,5 @@
Marek Belisko's avatar
Marek Belisko committed
364
365
366
367
368
369
370
371
372
373
374
 project(MonitorService)
 
-FIND_PACKAGE(shapeware REQUIRED)
-
 set(COMPONENT iqrf::MonitorService)
 DeclareShapeComponent(${COMPONENT})
 AddShapeProvidedInterface(${COMPONENT} iqrf::IMonitorService)
diff --git a/src/SchedulerMessaging/CMakeLists.txt b/src/SchedulerMessaging/CMakeLists.txt
index 9ca2983..3602d27 100644
--- a/src/SchedulerMessaging/CMakeLists.txt
+++ b/src/SchedulerMessaging/CMakeLists.txt
375
@@ -16,7 +16,5 @@
Marek Belisko's avatar
Marek Belisko committed
376
377
378
379
380
381
382
383
384
385
386
 project(SchedulerMessaging)
 
-FIND_PACKAGE(shapeware REQUIRED)
-
 set(COMPONENT iqrf::SchedulerMessaging)
 DeclareShapeComponent(${COMPONENT})
 AddShapeProvidedInterface(${COMPONENT} iqrf::IMessagingService)
diff --git a/src/WebsocketMessaging/CMakeLists.txt b/src/WebsocketMessaging/CMakeLists.txt
index e35de5e..020e027 100644
--- a/src/WebsocketMessaging/CMakeLists.txt
+++ b/src/WebsocketMessaging/CMakeLists.txt
387
@@ -16,6 +16,6 @@
Marek Belisko's avatar
Marek Belisko committed
388
389
390
391
392
393
394
395
396
397
 project(WebsocketMessaging)
 
-FIND_PACKAGE(shapeware REQUIRED)
+#FIND_PACKAGE(shapeware REQUIRED)
 
 set(COMPONENT iqrf::WebsocketMessaging)
 DeclareShapeComponent(${COMPONENT})
-- 
2.7.4