From 5bbf174a131e796b2b3564d2c7ecc5df0d1d9f36 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Jul 2018 20:16:14 +0200 Subject: [PATCH 1/4] cmake: allow VILLASnode to be included into other CMake projects via add_subdirectory() --- CMakeLists.txt | 15 +++++---------- cmake/VILLASnodePackaging.cmake | 4 ++-- doc/CMakeLists.txt | 2 +- lib/CMakeLists.txt | 4 +++- lib/api/CMakeLists.txt | 8 -------- lib/formats/CMakeLists.txt | 10 +--------- lib/hooks/CMakeLists.txt | 8 -------- lib/nodes/CMakeLists.txt | 8 -------- packaging/docker/CMakeLists.txt | 4 ++-- plugins/CMakeLists.txt | 1 - 10 files changed, 14 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e32c1c49e..c5cbc9b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,7 @@ set(PROJECT_SOVERSION 1) execute_process( COMMAND git describe --tags --abbrev=0 --match "v*" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE PROJECT_VERSION_STR OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -149,14 +149,14 @@ if(DEFINED ENV{CI}) else() execute_process( COMMAND git rev-parse --short=7 HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -173,11 +173,6 @@ endif() set(BUILDID "v${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}-${GIT_REV}-${VARIANT}") -include_directories( - ${CMAKE_SOURCE_DIR}/include - ${CMAKE_BINARY_DIR}/include -) - add_subdirectory(etc) add_subdirectory(lib) add_subdirectory(src) @@ -205,8 +200,8 @@ if(WITH_TESTS) endif() configure_file( - ${CMAKE_SOURCE_DIR}/include/villas/config.h.in - ${CMAKE_BINARY_DIR}/include/villas/config.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/villas/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/villas/config.h ) # Show feature summary diff --git a/cmake/VILLASnodePackaging.cmake b/cmake/VILLASnodePackaging.cmake index 39e07c942..9e8a1fc80 100644 --- a/cmake/VILLASnodePackaging.cmake +++ b/cmake/VILLASnodePackaging.cmake @@ -61,8 +61,8 @@ set(CPACK_RPM_PACKAGE_LICENSE "GPLv3") set(CPACK_RPM_PACKAGE_URL "http://www.fein-aachen.org/projects/villas-node/") set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.md") -set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "${VILLASnode_SOURCE_DIR}/COPYING.md") +set(CPACK_RESOURCE_FILE_README "${VILLASnode_SOURCE_DIR}/README.md") set(CPACK_SOURCE_IGNORE_FILES "build/;\\\\.gitmodules;\\\\.git/;\\\\.vscode;\\\\.editorconfig;\\\\.gitlab-ci.yml;\\\\.(docker|git)ignore;\\\\.DS_Store") diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index aa3f57c67..687123271 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -53,7 +53,7 @@ if(DOXYGEN_FOUND) doxygen_add_docs(doc README.md CONTRIBUTING.md COPYING.md src/ lib/ tests/ include/ doc/ - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${PROJECT_DIR} ) install( diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4245b3189..dd8753a5a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -22,10 +22,12 @@ add_compile_options(-fPIC) -set(INCLUDE_DIRS +list(APPEND INCLUDE_DIRS ${JANSSON_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CURL_INCLUDE_DIRS} + ${VILLASnode_BINARY_DIR}/include + ${VILLASnode_SOURCE_DIR}/include ) set(LIBRARIES diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt index 453cd2dca..34ece0463 100644 --- a/lib/api/CMakeLists.txt +++ b/lib/api/CMakeLists.txt @@ -21,14 +21,6 @@ # along with this program. If not, see . ################################################################################### -set(INCLUDE_DIRS - ${OPENSSL_INCLUDE_DIR} -) - -set(LIBRARIES - ${OPENSSL_LIBRARIES} -) - set(API_SRC session.c actions/capabiltities.c diff --git a/lib/formats/CMakeLists.txt b/lib/formats/CMakeLists.txt index 3b5090166..169d661ab 100644 --- a/lib/formats/CMakeLists.txt +++ b/lib/formats/CMakeLists.txt @@ -20,7 +20,7 @@ # along with this program. If not, see . ################################################################################### -set(FORMAT_SRC +list(APPEND FORMAT_SRC json.c json_reserve.c villas_binary.c @@ -30,14 +30,6 @@ set(FORMAT_SRC msg.c ) -set(INCLUDE_DIRS - ${OPENSSL_INCLUDE_DIR} -) - -set(LIBRARIES - ${OPENSSL_LIBRARIES} -) - # Enable Google Protobuf format if(PROTOBUFC_FOUND) list(APPEND FORMAT_SRC diff --git a/lib/hooks/CMakeLists.txt b/lib/hooks/CMakeLists.txt index 137381e61..636405ba0 100644 --- a/lib/hooks/CMakeLists.txt +++ b/lib/hooks/CMakeLists.txt @@ -20,14 +20,6 @@ # along with this program. If not, see . ################################################################################### -set(INCLUDE_DIRS - ${JANSSON_INCLUDE_DIRS} -) - -set(LIBRARIES - PkgConfig::JANSSON -) - set(HOOK_SRC convert.c decimate.c diff --git a/lib/nodes/CMakeLists.txt b/lib/nodes/CMakeLists.txt index c12a96dab..5feea97db 100644 --- a/lib/nodes/CMakeLists.txt +++ b/lib/nodes/CMakeLists.txt @@ -20,14 +20,6 @@ # along with this program. If not, see . ################################################################################### -set(INCLUDE_DIRS - ${JANSSON_INCLUDE_DIRS} -) - -set(LIBRARIES - PkgConfig::JANSSON -) - set(NODE_SRC influxdb.c stats.c diff --git a/packaging/docker/CMakeLists.txt b/packaging/docker/CMakeLists.txt index 832df0d2c..c9a11f488 100644 --- a/packaging/docker/CMakeLists.txt +++ b/packaging/docker/CMakeLists.txt @@ -33,7 +33,7 @@ set(DOCKER_RUN_OPTS --publish 2345:2345 --privileged --security-opt seccomp:unconfined - --volume \"${CMAKE_SOURCE_DIR}:/villas\" + --volume \"${VILLASnode_SOURCE_DIR}:/villas\" ) foreach(SUFFIX app dev dev-centos dev-ubuntu) @@ -59,7 +59,7 @@ foreach(SUFFIX app dev dev-centos dev-ubuntu) --build-arg GIT_REV=${GIT_REV} --build-arg VERSION=${PROJECT_VERSION} --build-arg VARIANT=${VARIANT} - ${DOCKER_BUILD_OPTS} ${CMAKE_SOURCE_DIR} + ${DOCKER_BUILD_OPTS} ${VILLASnode_SOURCE_DIR} COMMENT "Build Docker image: ${DOCKER_IMAGE}-${SUFFIX}:${DOCKER_TAG}" ) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index a2e195c35..d83a3d0a0 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -22,7 +22,6 @@ # Plugins link_libraries(villas) -include_directories("${CMAKE_SOURCE_DIR}/include") add_definitions("-DVILLAS") add_library(simple_circuit MODULE models/simple_circuit.c) From aac99d626e92fdd03a4069d720eda33c6db9ed3d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Jul 2018 20:16:22 +0200 Subject: [PATCH 2/4] remove obsolete Makefile --- lib/kernel/Makefile.inc | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 lib/kernel/Makefile.inc diff --git a/lib/kernel/Makefile.inc b/lib/kernel/Makefile.inc deleted file mode 100644 index 87e905d7d..000000000 --- a/lib/kernel/Makefile.inc +++ /dev/null @@ -1,23 +0,0 @@ -# Makefile. -# -# @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC -# @license GNU General Public License (version 3) -# -# VILLASnode -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -################################################################################### - -LIB_SRCS += $(addprefix lib/kernel/, kernel.c rt.c) From 7c555ccb9c919499c04b4eee173dde584503eb30 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Jul 2018 20:16:59 +0200 Subject: [PATCH 3/4] node: fix node_{read,write}() interface for comedi and iec61850_sv --- include/villas/nodes/comedi.h | 4 ++-- include/villas/nodes/iec61850_sv.h | 4 ++-- lib/nodes/comedi.c | 6 +++--- lib/nodes/iec61850_sv.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/villas/nodes/comedi.h b/include/villas/nodes/comedi.h index 3aa01f5b3..f7d938682 100644 --- a/include/villas/nodes/comedi.h +++ b/include/villas/nodes/comedi.h @@ -97,10 +97,10 @@ int comedi_start(struct node *n); int comedi_stop(struct node *n); /** @see node_type::read */ -int comedi_read(struct node *n, struct sample *smps[], unsigned cnt); +int comedi_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); /** @see node_type::write */ -int comedi_write(struct node *n, struct sample *smps[], unsigned cnt); +int comedi_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release); /** @} */ diff --git a/include/villas/nodes/iec61850_sv.h b/include/villas/nodes/iec61850_sv.h index 7213c20fb..347d448cb 100644 --- a/include/villas/nodes/iec61850_sv.h +++ b/include/villas/nodes/iec61850_sv.h @@ -95,9 +95,9 @@ int iec61850_sv_stop(struct node *n); int iec61850_sv_destroy(struct node *n); -int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt); +int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *released); -int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt); +int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *released); int iec61850_sv_fd(struct node *n); diff --git a/lib/nodes/comedi.c b/lib/nodes/comedi.c index 624cec3d8..2049d9ba3 100644 --- a/lib/nodes/comedi.c +++ b/lib/nodes/comedi.c @@ -525,7 +525,7 @@ int comedi_stop(struct node *n) #if COMEDI_USE_READ -int comedi_read(struct node *n, struct sample *smps[], unsigned cnt) +int comedi_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { int ret; struct comedi *c = (struct comedi *) n->_vd; @@ -648,7 +648,7 @@ int comedi_read(struct node *n, struct sample *smps[], unsigned cnt) #else -int comedi_read(struct node *n, struct sample *smps[], unsigned cnt) +int comedi_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { int ret; struct comedi *c = (struct comedi *) n->_vd; @@ -833,7 +833,7 @@ int comedi_read(struct node *n, struct sample *smps[], unsigned cnt) #endif -int comedi_write(struct node *n, struct sample *smps[], unsigned cnt) +int comedi_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) { int ret; struct comedi *c = (struct comedi *) n->_vd; diff --git a/lib/nodes/iec61850_sv.c b/lib/nodes/iec61850_sv.c index c4050dfb8..8945a61ae 100644 --- a/lib/nodes/iec61850_sv.c +++ b/lib/nodes/iec61850_sv.c @@ -344,7 +344,7 @@ int iec61850_sv_destroy(struct node *n) return 0; } -int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt) +int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *released) { int pulled; struct iec61850_sv *i = (struct iec61850_sv *) n->_vd; @@ -361,7 +361,7 @@ int iec61850_sv_read(struct node *n, struct sample *smps[], unsigned cnt) return pulled; } -int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt) +int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *released) { struct iec61850_sv *i = (struct iec61850_sv *) n->_vd; From b70c86cff62ac56646b5883d442e92187aade158 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 16 Jul 2018 20:17:08 +0200 Subject: [PATCH 4/4] fix indention --- lib/nodes/mqtt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/nodes/mqtt.c b/lib/nodes/mqtt.c index c0045ee90..26f852df5 100644 --- a/lib/nodes/mqtt.c +++ b/lib/nodes/mqtt.c @@ -391,16 +391,16 @@ int mqtt_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *re if (ret < 0) return ret; - if(m->publish) { - ret = mosquitto_publish(m->client, NULL /* mid */, m->publish, wbytes, data, m->qos, + if (m->publish) { + ret = mosquitto_publish(m->client, NULL /* mid */, m->publish, wbytes, data, m->qos, m->retain); - if (ret != MOSQ_ERR_SUCCESS) { - warn("MQTT: publish failed for node %s: %s", node_name(n), mosquitto_strerror(ret)); - return -abs(ret); - } - } - else{ - warn("MQTT: no publish for node %s possible because no publish topic is given", node_name(n)); + if (ret != MOSQ_ERR_SUCCESS) { + warn("MQTT: publish failed for node %s: %s", node_name(n), mosquitto_strerror(ret)); + return -abs(ret); + } + } + else { + warn("MQTT: no publish for node %s possible because no publish topic is given", node_name(n)); } return cnt;