diff --git a/.distignore b/.distignore deleted file mode 100644 index 979ecd28d..000000000 --- a/.distignore +++ /dev/null @@ -1,17 +0,0 @@ -build/ -thirdparty/ - -.git/ - -.gitmodules -.gitignore -.dockerignore -.distignore - -.DS_Store -*~ - -*.o -*.d - -villas-* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 809867c71..ab64b3ff2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,12 +4,15 @@ variables: PREFIX: /usr/ RSYNC_OPTS: --recursive --ignore-missing-args --chown ${DEPLOY_USER}:${DEPLOY_USER} CRITERION_OPTS: --ignore-warnings + DOCKER_TAG: $CI_COMMIT_TAG DOCKER_TAG_DEV: ${CI_COMMIT_REF_NAME} + DOCKER_IMAGE: villas/node DOCKER_IMAGE_DEV: villas/node-dev stages: - prepare - build + - build2 - test - deploy - docker @@ -25,7 +28,7 @@ before_script: docker-dev: stage: prepare script: - - make docker-dev + - docker build -f packaging/docker/Dockerfile.dev -t ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} . tags: - shell - linux @@ -36,12 +39,14 @@ docker-dev: build:source: stage: build script: + - mkdir -p build && cd build + - cmake .. - make artifacts: expire_in: 1 week name: ${CI_PROJECT_NAME}-${CI_BUILD_REF} paths: - - build/release/ + - build/ image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} tags: - docker @@ -51,8 +56,10 @@ build:docs: artifacts: name: ${CI_PROJECT_NAME}-doc-${CI_BUILD_REF} paths: - - build/release/doc/ + - build/doc/ script: + - mkdir -p build && cd build + - cmake .. - make doc image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} tags: @@ -61,19 +68,20 @@ build:docs: - tags - master -build:packages: - stage: build - before_script: - - dnf -y config-manager --add-repo https://${DEPLOY_USER}:${DEPLOY_PASS}@${DEPLOY_HOST}/packages/villas.repo - - dnf -y --refresh install openssl-devel libconfig-devel libnl3-devel libcurl-devel jansson-devel libxil-devel libwebsockets-devel zeromq-devel nanomsg-devel +build2:packages: + stage: build2 + dependencies: + - build:docs script: - - make rpm-villas-node + - mkdir -p build && cd build + - cmake .. + - make package artifacts: expire_in: 1 week name: ${CI_PROJECT_NAME}-packages-${CI_BUILD_REF} paths: - - build/release/packaging/*.tar.gz - - build/release/packaging/rpm/RPMS/ + - build/*.tar.gz + - build/*.rpm image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} tags: - docker @@ -85,28 +93,13 @@ build:packages: # Stage: test ############################################################################## -test:coverage: - stage: test - variables: - COVERAGE: "1" - script: - - make coverage - artifacts: - name: ${CI_PROJECT_NAME}-coverage-${CI_BUILD_REF} - paths: - - build/release-coverage/coverage/ - - build/release-coverage/coverage.txt - - build/release-coverage/coverage.xml - image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} - coverage: '/lines: (\d+\.\d+\%)/' - tags: - - docker - test:unit: stage: test dependencies: - build:source script: + - mkdir -p build && cd build + - cmake .. - make run-unit-tests image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} tags: @@ -117,6 +110,8 @@ test:integration: dependencies: - build:source script: + - mkdir -p build && cd build + - cmake .. - make run-integration-tests artifacts: name: ${CI_PROJECT_NAME}-integration-tests-${CI_BUILD_REF} @@ -127,19 +122,6 @@ test:integration: tags: - docker -test:valgrind: - stage: test - variables: - DEBUG: "1" - script: - - make run-valgrind - dependencies: - - build:source - allow_failure: true - image: ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} - tags: - - docker - # Stage: deploy ############################################################################## @@ -147,13 +129,10 @@ deploy:web: stage: deploy script: - ssh ${DEPLOY_USER}@${DEPLOY_HOST} mkdir -p ${DEPLOY_PATH}/{coverage,doc}/${CI_BUILD_REF_NAME}/ - - rsync ${RSYNC_OPTS} build/release-coverage/coverage/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/coverage/$CI_BUILD_REF_NAME/ - - rsync ${RSYNC_OPTS} build/release/doc/html/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/doc/$CI_BUILD_REF_NAME/ + - rsync ${RSYNC_OPTS} build/doc/html/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/doc/$CI_BUILD_REF_NAME/ - rsync ${RSYNC_OPTS} web/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/ dependencies: - build:docs - - build:packages - - test:coverage only: - tags tags: @@ -163,48 +142,25 @@ deploy:packages: stage: deploy script: - ssh ${DEPLOY_USER}@${DEPLOY_HOST} mkdir -p ${DEPLOY_PATH}/{dist,../packages} - - rsync ${RSYNC_OPTS} build/release/packaging/rpm/RPMS/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/../packages/ - - rsync ${RSYNC_OPTS} build/release/packaging/*.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/dist/ + - rsync ${RSYNC_OPTS} build/*.rpm ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/../packages/x86_64/ + - rsync ${RSYNC_OPTS} build/*.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/dist/ - ssh ${DEPLOY_USER}@${DEPLOY_HOST} createrepo ${DEPLOY_PATH}/../packages dependencies: - - build:packages + - build2:packages tags: - villas-deploy only: - tags -.deploy:git-mirror: - stage: deploy - script: - - git push --force --mirror https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/VILLASframework/VILLASnode.git - # Stage: docker ############################################################################## docker: stage: docker - variables: - DOCKER_IMAGE: villas/node - DOCKER_TAG: $CI_COMMIT_TAG script: - - make docker - - make deploy-docker - - docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest - - docker push ${DOCKER_IMAGE}:latest - dependencies: - - build:packages + - docker build -f packaging/docker/Dockerfile.app -t ${DOCKER_IMAGE}:${DOCKER_TAG} . + - docker push ${DOCKER_IMAGE}:${DOCKER_TAG} + - docker push ${DOCKER_IMAGE_DEV}:${DOCKER_TAG_DEV} tags: - shell - linux - only: - - tags - -docker:dev: - stage: docker - script: - - make deploy-docker-dev - tags: - - shell - - linux - only: - - develop diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..64b01ad13 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,230 @@ +# Main CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +cmake_minimum_required(VERSION 3.3) + +# Policies +cmake_policy(SET CMP0068 NEW) + +project(VILLASnode C CXX) + +# Several CMake settings/defaults +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_THREAD_PREFER_PTHREAD ON) +#set(CMAKE_SKIP_INSTALL_RPATH ON) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +if(APPLE) + set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/opt/local/lib/pkgconfig") +endif() + +include(FindPkgConfig) +include(CheckIncludeFile) +include(FeatureSummary) +include(GNUInstallDirs) + +# Compiler flags +if(BUILD32) + add_compile_options(-m32) + link_libraries(-m32) +endif() + +if(APPLE) + add_definitions(-D_DARWIN_C_SOURCE) +endif() + +add_definitions(-D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE) +add_compile_options(-fdiagnostics-color=auto) + +if(MSVC) + add_compile_options(/W4 /WX) +else() + add_compile_options(-Wall -Werror) +endif() + +# Check OS +check_include_file("sys/eventfd.h" HAS_EVENTFD) +check_include_file("semaphore.h" HAS_SEMAPHORE) +check_include_file("sys/mman.h" HAS_MMAN) + +# Check packages +find_package(PkgConfig REQUIRED) +find_package(Threads REQUIRED) +find_package(Libwebsockets REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(CURL REQUIRED) +find_package(Opal) + +# Check programs +find_program(PROTOBUFC_COMPILER NAMES protoc-c) +find_program(PROTOBUF_COMPILER NAMES protoc) + +set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig") + +pkg_check_modules(PROTOBUFC IMPORTED_TARGET libprotobuf-c) +pkg_check_modules(CRITERION IMPORTED_TARGET criterion) +pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson) +pkg_check_modules(LIBNL3_ROUTE IMPORTED_TARGET libnl-route-3.0) +pkg_check_modules(LIBIEC61850 IMPORTED_TARGET libiec61850>=1.2.0) +pkg_check_modules(LIBCONFIG IMPORTED_TARGET libconfig) +pkg_check_modules(RABBITMQ_C IMPORTED_TARGET librabbitmq) +pkg_check_modules(COMEDILIB IMPORTED_TARGET comedilib) +pkg_check_modules(LIBZMQ IMPORTED_TARGET libzmq) +pkg_check_modules(NANOMSG IMPORTED_TARGET nanomsg) +if(NOT NANOMSG_FOUND) + pkg_check_modules(NANOMSG IMPORTED_TARGET libnanomsg) +endif() + +# Build options +option(WITH_HOOKS "Build with support for processing hook plugins" ON) +option(WITH_IO "Build with support format plugins" ON) +option(WITH_WEB "Build with internal webserver" ON) +option(WITH_API "Build with remote control API" ON) +option(WITH_CONFIG "Build with support for libconfig configuration syntax" ON) +option(WITH_TOOLS "Build auxilary tools" ON) +option(WITH_TESTS "Run tests" ON) +option(WITH_PLUGINS "Build plugins" ON) +option(WITH_CLIENTS "Build client applications" ON) +option(WITH_DOC "Build documentation" ON) + +set(V 2) +set(PREFIX ${CMAKE_INSTALL_PREFIX}) + +if(CMAKE_BUILD_TYPE) + string(TOLOWER "${CMAKE_BUILD_TYPE}" VARIANT) +else() + set(VARIANT "release") +endif() + +# Add more build configurations +include(cmake/config/Debug.cmake) +include(cmake/config/Release.cmake) +include(cmake/config/Coverage.cmake) +include(cmake/config/Profiling.cmake) + +# Add git revision and build variant defines +set(PROJECT_AUTHOR "Steffen Vogel") +set(PROJECT_COPYRIGHT "2018, Institute for Automation of Complex Power Systems, RWTH Aachen University") + +set(PROJECT_SOVERSION 1) + +execute_process( + COMMAND git describe --tags --abbrev=0 --match "v*" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE PROJECT_VERSION_STR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" PROJECT_VERSION ${PROJECT_VERSION_STR}) +string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\1" PROJECT_MAJOR_VERSION ${PROJECT_VERSION_STR}) +string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\2" PROJECT_MINOR_VERSION ${PROJECT_VERSION_STR}) +string(REGEX REPLACE "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$" "\\3" PROJECT_PATCH_VERSION ${PROJECT_VERSION_STR}) + +string(TIMESTAMP BUILD_DATE "%Y%m%d") + +if(DEFINED ENV{CI}) + string(APPEND VARIANT "-ci") + string(SUBSTRING $ENV{CI_COMMIT_SHA} 0 7 GIT_REV) + set(GIT_BRANCH $ENV{CI_COMMIT_REF_NAME}) +else() + execute_process( + COMMAND git rev-parse --short=7 HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REV + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() + +if(DEFINED ENV{CI_COMMIT_TAG}) + set(PROJECT_RELEASE 1) +else() + string(REPLACE "-" "_" GIT_BRANCH_NORM ${GIT_BRANCH}) + string(REPLACE "-" "_" VARIANT_NORM ${VARIANT}) + + set(PROJECT_RELEASE "1.${GIT_BRANCH_NORM}_${VARIANT_NORM}.${BUILD_DATE}git${GIT_REV}") +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) +add_subdirectory(web) +add_subdirectory(packaging) + +if(WITH_TOOLS) + add_subdirectory(tools) +endif() + +if(WITH_TOOLS) + add_subdirectory(plugins) +endif() + +if(WITH_DOC) + add_subdirectory(doc) +endif() + +if(WITH_CLIENTS) + add_subdirectory(clients) +endif() + +if(WITH_TESTS) + add_subdirectory(tests) +endif() + +configure_file( + ${CMAKE_SOURCE_DIR}/include/villas/config.h.in + ${CMAKE_BINARY_DIR}/include/villas/config.h +) + +# Show feature summary +add_feature_info(HOOKS WITH_HOOKS "Build with support for processing hook plugins") +add_feature_info(IO WITH_IO "Build with support format plugins") +add_feature_info(WEB WITH_WEB "Build with internal webserver") +add_feature_info(API WITH_API "Build with remote control API") +add_feature_info(CONFIG WITH_CONFIG "Build with support for libconfig configuration syntax") +add_feature_info(TOOLS WITH_TOOLS "Build auxilary tools") +add_feature_info(TESTS WITH_TESTS "Run tests") +add_feature_info(PLUGINS WITH_PLUGINS "Build plugins") +add_feature_info(CLIENTS WITH_CLIENTS "Build client applications") +add_feature_info(DOC WITH_DOC "Build documentation") + +if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) + feature_summary(WHAT ALL VAR FEATURES) + message(STATUS "${FEATURES}") + message(STATUS "Building VILLASnode: ${BUILDID}") +endif() + +include(VILLASnodePackaging) diff --git a/Makefile b/Makefile deleted file mode 100644 index 23cc84d0f..000000000 --- a/Makefile +++ /dev/null @@ -1,182 +0,0 @@ -## Main project Makefile -# -# The build system of this project is based on GNU Make and pkg-config -# -# To retain maintainability, the project is divided into multiple modules. -# Each module has its own Makefile which gets included. -# -# Please read "Recursive Make Considered Harmful" from Peter Miller -# to understand the motivation for this structure. -# -# [1] http://aegis.sourceforge.net/auug97.pdf -# -# @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 . -################################################################################### - -# Project modules -MODULES = lib packaging doc etc web tests - -# Modules which are not included in default, install and clean targets -MODULES_EXCLUDE = thirdparty packaging doc - -# Default prefix for install target -PREFIX ?= /usr/local - -# Default out-of-source build path -BUILDDIR ?= build - -# Default debug level for executables -V ?= 2 - -# Platform -PLATFORM ?= $(shell uname) - -include Makefile.config - -ifeq ($(WITH_SRC),1) - MODULES += src -endif - -ifeq ($(WITH_TOOLS),1) - MODULES += tools -endif - -ifeq ($(WITH_PLUGINS),1) - MODULES += plugins -endif - -ifeq ($(WITH_TESTS),1) - MODULES += tests -endif - -# Common flags -LDLIBS = -CFLAGS += -std=c11 -MMD -mcx16 -I$(BUILDDIR)/include -I$(SRCDIR)/include -CFLAGS += -Wall -Werror -fdiagnostics-color=auto -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE=1 - -ifeq ($(PLATFORM),Darwin) - CFLAGS += -D_DARWIN_C_SOURCE -endif - -LDFLAGS += -L$(BUILDDIR) - -# Some tools -PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):/opt/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig - -PKGCONFIG := PKG_CONFIG_PATH=:$(PKG_CONFIG_PATH) pkg-config -SHELL := bash - -# We must compile without optimizations for gcov! -ifdef DEBUG - CFLAGS += -O0 -g - VARIANTS += debug -else - CFLAGS += -O3 - VARIANTS += release -endif - -ifdef PROFILE - CFLAGS += -pg - LDFLAGS += -pg - - VARIANTS += profile -endif - -ifdef COVERAGE - CFLAGS += --coverage - LDLIBS += -lgcov - - VARIANTS += coverage -endif - -EMPTY := -SPACE := $(EMPTY) $(EMPTY) - -VARIANT = $(shell uname -s)-$(shell uname -m)-$(subst $(SPACE),-,$(strip $(VARIANTS))) -BUILDDIR := $(BUILDDIR)/$(VARIANT) -SRCDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) - -VPATH = $(SRCDIR) - -# Add git revision and build variant defines -VERSION := $(shell git describe --tags --abbrev=0 --match 'v*') -VERSION_NUM := $(shell VERSION=$(VERSION); echo $${VERSION:1}) - -export BUILDDIR VARIANT VERSION VERSION_NUM - -ifdef CI - VARIANT := $(VARIANT)-ci - - GIT_REV := $(shell echo $${CI_COMMIT_SHA:0:7}) - GIT_BRANCH := $(CI_COMMIT_REF_NAME) - - ifdef CI_COMMIT_TAG - RELEASE = 1 - else - RELEASE = 1.$(subst -,_,$(CI_COMMIT_REF_NAME))_$(subst -,_,$(VARIANT)).$(shell date +%Y%m%d)git$(GIT_REV) - endif -else - GIT_REV := $(shell git rev-parse --short=7 HEAD) - GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) - - RELEASE = 1.$(subst -,_,$(GIT_BRANCH))_$(subst -,_,$(VARIANT)).$(shell date +%Y%m%d)git$(GIT_REV) -endif - -BUILDID = "$(VERSION)-$(GIT_REV)-$(VARIANT)" - -# pkg-config dependencies -PKGS = openssl jansson - -ifeq ($(WITH_CONFIG),1) - PKGS += libconfig -endif - -######## Targets ######## - -# Add flags by pkg-config -CFLAGS += $(shell $(PKGCONFIG) --cflags ${PKGS}) -LDLIBS += $(shell $(PKGCONFIG) --libs ${PKGS}) - -all: $(filter-out $(MODULES_EXCLUDE),$(MODULES)) -install: $(addprefix install-,$(filter-out $(MODULES_EXCLUDE),$(MODULES))) -clean: $(addprefix clean-, $(filter-out $(MODULES_EXCLUDE),$(MODULES))) - -src plugins tools tests: lib - -# Build all variants: debug, coverage, ... -everything: - $(MAKE) RELEASE=1 - $(MAKE) DEBUG=1 - $(MAKE) COVERAGE=1 - $(MAKE) PROFILE=1 - -# Create non-existent directories -.SECONDEXPANSION: -.PRECIOUS: %/ -%/: - mkdir -p $@ - -escape = $(shell echo $1 | tr a-z- A-Z_ | tr -dc ' A-Z0-9_') - -.PHONY: all everything clean install - -include $(wildcard $(BUILDDIR)/**/*.d) -include $(patsubst %,$(SRCDIR)/%/Makefile.inc,$(MODULES)) -include Makefile.help diff --git a/Makefile.config b/Makefile.config deleted file mode 100644 index fbb80c5c9..000000000 --- a/Makefile.config +++ /dev/null @@ -1,74 +0,0 @@ -## Main project Makefile -# -# The build system of this project is based on GNU Make and pkg-config -# -# To retain maintainability, the project is divided into multiple modules. -# Each module has its own Makefile which gets included. -# -# Please read "Recursive Make Considered Harmful" from Peter Miller -# to understand the motivation for this structure. -# -# [1] http://aegis.sourceforge.net/auug97.pdf -# -# @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 . -################################################################################### - -# Select modules -WITH_SRC ?= 1 -WITH_TOOLS ?= 1 -WITH_PLUGINS ?= 1 -WITH_TESTS ?= 0 -WITH_CLIENTS ?= 0 - -# Select features -WITH_CONFIG ?= 1 -WITH_HOOKS ?= 1 -WITH_WEB ?= 1 -WITH_API ?= 1 -WITH_IO ?= 1 - -# Select IO formats -WITH_FORMAT_PROTOBUF ?= 1 - -# Select node-types -ifeq ($(PLATFORM),Linux) - IS_LINUX = 1 -else - IS_LINUX = 0 -endif - -WITH_NODE_FPGA ?= $(IS_LINUX) -WITH_NODE_CBUILDER ?= $(IS_LINUX) -WITH_NODE_LOOPBACK ?= $(IS_LINUX) -WITH_NODE_COMEDI ?= $(IS_LINUX) -WITH_NODE_TEST_RTT ?= 1 -WITH_NODE_FILE ?= 1 -WITH_NODE_SIGNAL ?= 1 -WITH_NODE_NGSI ?= 1 -WITH_NODE_WEBSOCKET ?= 1 -WITH_NODE_SOCKET ?= 1 -WITH_NODE_ZEROMQ ?= 1 -WITH_NODE_NANOMSG ?= 1 -WITH_NODE_SHMEM ?= 1 -WITH_NODE_STATS ?= 1 -WITH_NODE_INFLUXDB ?= 1 -WITH_NODE_AMQP ?= 1 -WITH_NODE_IEC61850 ?= 1 -WITH_NODE_MQTT ?= 1 diff --git a/Makefile.help b/Makefile.help deleted file mode 100644 index 5b2a17d97..000000000 --- a/Makefile.help +++ /dev/null @@ -1,102 +0,0 @@ -# Makefile for clang autocompletion -# -# This Makefile produces .clang_complete files containing compiler flags -# which are used by clang autocompletion tools such as: -# -# - https://atom.io/packages/autocomplete-clang -# - https://github.com/Rip-Rip/clang_complete -# -# @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 . -################################################################################### - -E = @echo - -help: - $E "The following make targets are available:" - $E - $E " - make all" - $E " Build libvillas, villas CLI tools, tests" - $E - $E " - make everything" - $E " Build all in all available build variants" - $E - $E " - make docker" - $E " - make run-docker" - $E " - make deploy-docker" - $E - $E " - make docker-{app,dev,dev-centos,dev-fedora}" - $E " Build Docker images" - $E - $E " - make run-docker-{app,dev,dev-centos,dev-fedora}" - $E " Run Docker containers" - $E - $E " - make deploy-docker-{app,dev,dev-centos,dev-fedora}" - $E " Deploy Docker images to official registry" - $E - $E "The following environment variables can change the build:" - $E " DEBUG = 1" - $E " COVERAGE = 1" - $E - $E "Use the following variables to enable/disabled certain features of VILLASnode" - $E " The list also shows the currently active (default) value" - $E - $E "Enable modules:" - $E " WITH_SRC = $(WITH_SRC)" - $E " WITH_TOOLS = $(WITH_TOOLS)" - $E " WITH_PLUGINS = $(WITH_PLUGINS)" - $E " WITH_TESTS = $(WITH_TESTS)" - $E " WITH_CLIENTS = $(WITH_CLIENTS)" - $E - $E "Enable features:" - $E " WITH_CONFIG = $(WITH_CONFIG)" - $E " WITH_HOOKS = $(WITH_HOOKS)" - $E " WITH_WEB = $(WITH_WEB)" - $E " WITH_API = $(WITH_API)" - $E " WITH_IO = $(WITH_IO)" - $E - $E "Enable IO formats:" - $E " WITH_FORMAT_PROTOBUF = $(WITH_FORMAT_PROTOBUF)" - $E - $E "Enable node-types:" - $E " WITH_NODE_FPGA = $(WITH_NODE_FPGA)" - $E " WITH_NODE_CBUILDER = $(WITH_NODE_CBUILDER)" - $E " WITH_NODE_LOOPBACK = $(WITH_NODE_LOOPBACK)" - $E " WITH_NODE_TEST_RTT = $(WITH_NODE_TEST_RTT)" - $E " WITH_NODE_FILE = $(WITH_NODE_FILE)" - $E " WITH_NODE_SIGNAL = $(WITH_NODE_SIGNAL)" - $E " WITH_NODE_NGSI = $(WITH_NODE_NGSI)" - $E " WITH_NODE_WEBSOCKET = $(WITH_NODE_WEBSOCKET)" - $E " WITH_NODE_SOCKET = $(WITH_NODE_SOCKET)" - $E " WITH_NODE_ZEROMQ = $(WITH_NODE_ZEROMQ)" - $E " WITH_NODE_NANOMSG = $(WITH_NODE_NANOMSG)" - $E " WITH_NODE_SHMEM = $(WITH_NODE_SHMEM)" - $E " WITH_NODE_STATS = $(WITH_NODE_STATS)" - $E " WITH_NODE_INFLUXDB = $(WITH_NODE_INFLUXDB)" - $E " WITH_NODE_AMQP = $(WITH_NODE_AMQP)" - $E " WITH_NODE_MQTT = $(WITH_NODE_MQTT)" - $E " WITH_NODE_IEC61850 = $(WITH_NODE_IEC61850)" - $E " WITH_NODE_MQTT = $(WITH_NODE_MQTT)" - $E " WITH_NODE_COMEDI = $(WITH_NODE_COMEDI)" - $E - $E "Available dependencies: $(LIB_PKGS)" - $E "Enabled node-types: $(LIB_NODES)" - $E "Enabled formats: $(LIB_FORMATS)" - -.PHONY: help diff --git a/README.md b/README.md index a9163095a..cca9b365e 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,16 @@ VILLASnode is a client/server application to connect simulation equipment and so by using protcols such as: - IEEE 802.2 Ethernet / IP / UDP, - - ZeroMQ, - - nanomsg, + - ZeroMQ & nanomsg, + - MQTT & AMQP - WebSockets - Shared Memory - Files + - IEC 61850 Sampled Values / GOOSE + - Analog/Digital IO via Comedi drivers + - Infiniband (ibverbs) -Planned: - - - IEC 61850-9-2 Sampled Values, - - IEC 61850-8-1 GOOSE, - - AMQP - -It's designed with a focus on very low latency to achieve almost realtime exchange of simulation data. +It's designed with a focus on very low latency to achieve real-time exchange of simulation data. VILLASnode is used in distributed- and co-simulation scenarios and developed for the field of power grid simulation at the EON Energy Research Center in Aachen, Germany. ## Documentation @@ -37,7 +34,7 @@ User documentation is available here: -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -20,6 +20,5 @@ # along with this program. If not, see . ################################################################################### -LIB_SRCS += $(wildcard lib/api/*.c) - -include lib/api/actions/Makefile.inc +add_subdirectory(python) +add_subdirectory(opal) diff --git a/clients/opal/CMakeLists.txt b/clients/opal/CMakeLists.txt new file mode 100644 index 000000000..8bdbeeedb --- /dev/null +++ b/clients/opal/CMakeLists.txt @@ -0,0 +1,32 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +if(OPAL_FOUND) + set(ASYNCIP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/models/send_receive) + + set(ASYNCIP_OPTS RTLAB_INTEL_COMPILER=0 PROTOCOL=GTNET_SKT OPAL_LIBS="-lSystem -luuid" OPAL_LIBPATH=-L$(SRCDIR)/thirdparty/libopal/ OPAL_INCPATH=-I$(SRCDIR)/thirdparty/libopal/include/opal) + + # Just call the original Makefile + add_custom_target(clients-opal + COMMAND make -C ${ASYNCIP_PATH} -f Makefile.mk AsyncIP ${ASYNCIP_OPTS} + ) +endif() diff --git a/clients/opal/Makefile.inc b/clients/opal/Makefile.inc deleted file mode 100644 index 2eca9f803..000000000 --- a/clients/opal/Makefile.inc +++ /dev/null @@ -1,46 +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 . -################################################################################### - -ifneq ($(wildcard $(SRCDIR)/thirdparty/libopal/include/opal/AsyncApi.h),) - -CLIENTS += opal - -ASYNCIP_PATH = $(SRCDIR)/clients/opal/models/send_receive - -ASYNCIP_OPTS = RTLAB_INTEL_COMPILER=0 \ - PROTOCOL=GTNET_SKT \ - OPAL_LIBS="-lSystem -luuid" \ - OPAL_LIBPATH=-L$(SRCDIR)/thirdparty/libopal/ \ - OPAL_INCPATH=-I$(SRCDIR)/thirdparty/libopal/include/opal - -clients-opal: - $(MAKE) -C $(ASYNCIP_PATH) -f Makefile.mk AsyncIP $(ASYNCIP_OPTS) - -clean-clients-opal: - $(MAKE) -C $(ASYNCIP_PATH) -f Makefile.mk clean $(ASYNCIP_OPTS) - -install-clients-opal: - $(MAKE) -C $(ASYNCIP_PATH) -f Makefile.mk install $(ASYNCIP_OPTS) - -.PHONY: clients-opal clean-clients-opal install-clients-opal - -endif diff --git a/lib/api/actions/Makefile.inc b/clients/python/CMakeLists.txt similarity index 95% rename from lib/api/actions/Makefile.inc rename to clients/python/CMakeLists.txt index e45e291b7..e9bfca724 100644 --- a/lib/api/actions/Makefile.inc +++ b/clients/python/CMakeLists.txt @@ -20,4 +20,4 @@ # along with this program. If not, see . ################################################################################### -LIB_SRCS += $(wildcard lib/api/actions/*.c) + diff --git a/cmake/FindMosquitto.cmake b/cmake/FindMosquitto.cmake new file mode 100644 index 000000000..0d65c6780 --- /dev/null +++ b/cmake/FindMosquitto.cmake @@ -0,0 +1,40 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +find_path(MOSQUITTO_INCLUDE_DIR + NAMES mosquitto.h +) + +find_library(MOSQUITTO_LIBRARY + NAMES mosquitto +) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set VILLASNODE_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(Mosquitto DEFAULT_MSG + MOSQUITTO_LIBRARY MOSQUITTO_INCLUDE_DIR) + +mark_as_advanced(MOSQUITTO_INCLUDE_DIR MOSQUITTO_LIBRARY) + +set(MOSQUITTO_LIBRARIES ${MOSQUITTO_LIBRARY}) +set(MOSQUITTO_INCLUDE_DIRS ${MOSQUITTO_INCLUDE_DIR}) diff --git a/clients/Makefile.inc b/cmake/FindOpal.cmake similarity index 64% rename from clients/Makefile.inc rename to cmake/FindOpal.cmake index c1106196c..fca8ad7f2 100644 --- a/clients/Makefile.inc +++ b/cmake/FindOpal.cmake @@ -1,7 +1,7 @@ -# Makefile. +# CMakeLists.txt. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -20,13 +20,18 @@ # along with this program. If not, see . ################################################################################### -CLIENTS = +find_path(OPAL_INCLUDE_DIR + NAMES opal/AsyncApi.h +) -include $(SRCDIR)/clients/python/Makefile.inc -include $(SRCDIR)/clients/opal/Makefile.inc +find_library(OPAL_LIBRARY + NAMES OpalAsyncApiCore +) -clients: $(addprefix clients-,$(filter-out opal,$(CLIENTS))) -clean-clients: $(addprefix clean-clients-,$(filter-out opal,$(CLIENTS))) -install-clients: $(addprefix install-clients-,$(filter-out opal,$(CLIENTS))) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Opal DEFAULT_MSG OPAL_LIBRARY OPAL_INCLUDE_DIR) -.PHONY: clients clean-clients install-clients +mark_as_advanced(OPAL_INCLUDE_DIR OPAL_LIBRARY) + +set(OPAL_LIBRARIES ${OPAL_LIBRARY} OpalCore OpalUtils irc) +set(OPAL_INCLUDE_DIRS ${OPAL_INCLUDE_DIR}) diff --git a/cmake/VILLASnodePackaging.cmake b/cmake/VILLASnodePackaging.cmake new file mode 100644 index 000000000..39e07c942 --- /dev/null +++ b/cmake/VILLASnodePackaging.cmake @@ -0,0 +1,73 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_VENDOR ${PROJECT_AUTHOR}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "This is VILLASnode, a gateway for processing and forwardning simulation data between real-time simulators.") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_MAJOR_VERSION}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_MINOR_VERSION}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_PATCH_VERSION}) + +set(CPACK_RPM_COMPONENT_INSTALL ON) +set(CPACK_RPM_MAIN_COMPONENT bin) + +set(CPACK_RPM_LIB_PACKAGE_NAME libvillas) +set(CPACK_RPM_DEVEL_PACKAGE_NAME libvillas-devel) +set(CPACK_RPM_BIN_PACKAGE_NAME villas-node) +set(CPACK_RPM_PLUGINS_PACKAGE_NAME villas-node-plugins) +set(CPACK_RPM_TOOLS_PACKAGE_NAME villas-node-tools) +set(CPACK_RPM_DOC_PACKAGE_NAME villas-node-doc) + +set(SUFFIX "${CPACK_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}.${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") +set(CPACK_RPM_LIB_FILE_NAME "${CPACK_RPM_LIB_PACKAGE_NAME}-${SUFFIX}") +set(CPACK_RPM_DEVEL_FILE_NAME "${CPACK_RPM_DEVEL_PACKAGE_NAME}-devel-${SUFFIX}") +set(CPACK_RPM_BIN_FILE_NAME "${CPACK_RPM_BIN_PACKAGE_NAME}-${SUFFIX}") +set(CPACK_RPM_PLUGINS_FILE_NAME "${CPACK_RPM_PLUGINS_PACKAGE_NAME}-${SUFFIX}") +set(CPACK_RPM_TOOLS_FILE_NAME "${CPACK_RPM_TOOLS_PACKAGE_NAME}-${SUFFIX}") +set(CPACK_RPM_DOC_FILE_NAME "${CPACK_RPM_DOC_PACKAGE_NAME}-${SUFFIX}") + +set(CPACK_RPM_LIB_PACKAGE_REQUIRES "openssl libconfig libnl3 libcurl jansson libwebsockets zeromq nanomsg libiec61850 librabbitmq mosquitto comedilib") +set(CPACK_RPM_BIN_PACKAGE_REQUIRES ${CPACK_RPM_LIB_PACKAGE_NAME}) +set(CPACK_RPM_PLUGINS_PACKAGE_REQUIRES ${CPACK_RPM_LIB_PACKAGE_NAME}) +set(CPACK_RPM_TOOLS_PACKAGE_REQUIRES ${CPACK_RPM_LIB_PACKAGE_NAME}) + +set(CPACK_RPM_DEVEL_PACKAGE_SUGGESTS ${CPACK_RPM_LIB_PACKAGE_NAME}) +set(CPACK_RPM_BIN_PACKAGE_SUGGESTS "villas-node-tools villas-node-plugins villas-node-doc") + +set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) +set(CPACK_RPM_PACKAGE_RELEASE ${PROJECT_RELEASE}) +set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") +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_SOURCE_IGNORE_FILES "build/;\\\\.gitmodules;\\\\.git/;\\\\.vscode;\\\\.editorconfig;\\\\.gitlab-ci.yml;\\\\.(docker|git)ignore;\\\\.DS_Store") + +if(NOT DEFINED CPACK_GENERATOR) + set(CPACK_GENERATOR "RPM;TGZ") +endif() + +include(CPack) diff --git a/cmake/config/Coverage.cmake b/cmake/config/Coverage.cmake new file mode 100644 index 000000000..d92286c4f --- /dev/null +++ b/cmake/config/Coverage.cmake @@ -0,0 +1,56 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(CMAKE_CXX_FLAGS_COVERAGE + "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE +) + +set(CMAKE_C_FLAGS_COVERAGE + "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE +) + +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "${CMAKE_EXE_LINKER_FLAGS}" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE +) + +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "${CMAKE_SHARED_LINKER_FLAGS_COVERAGE}" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE +) + +mark_as_advanced( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE +) + +if(CMAKE_BUILD_TYPE STREQUAL "Coverage") + target_link_libraries("gcov") +endif() diff --git a/clients/python/Makefile.inc b/cmake/config/Debug.cmake similarity index 82% rename from clients/python/Makefile.inc rename to cmake/config/Debug.cmake index c802e18da..4aa187da1 100644 --- a/clients/python/Makefile.inc +++ b/cmake/config/Debug.cmake @@ -1,7 +1,7 @@ -# Makefile. +# CMakeLists.txt. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -19,6 +19,3 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . ################################################################################### - -clients/python/villas_pb2.py: lib/io/villas.proto - protoc --proto_path=$(dir $^) --python_out=$(dir $@) $^ diff --git a/cmake/config/Profiling.cmake b/cmake/config/Profiling.cmake new file mode 100644 index 000000000..27bd63863 --- /dev/null +++ b/cmake/config/Profiling.cmake @@ -0,0 +1,54 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(CMAKE_CXX_FLAGS_PROFILING + "${CMAKE_CXX_FLAGS} -pg" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE +) + +set(CMAKE_C_FLAGS_PROFILING + "${CMAKE_C_FLAGS} -pg" + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE +) + +set(CMAKE_EXE_LINKER_FLAGS_PROFILING + "${CMAKE_EXE_LINKER_FLAGS} -pg" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE +) + +set(CMAKE_SHARED_LINKER_FLAGS_PROFILING + "${CMAKE_SHARED_LINKER_FLAGS_COVERAGE} -pg" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE +) + +mark_as_advanced( + CMAKE_CXX_FLAGS_PROFILING + CMAKE_C_FLAGS_PROFILING + CMAKE_EXE_LINKER_FLAGS_PROFILING + CMAKE_SHARED_LINKER_FLAGS_PROFILING +) + + diff --git a/tests/integration/Makefile.inc b/cmake/config/Release.cmake similarity index 81% rename from tests/integration/Makefile.inc rename to cmake/config/Release.cmake index b2c5e068c..4aa187da1 100644 --- a/tests/integration/Makefile.inc +++ b/cmake/config/Release.cmake @@ -1,7 +1,7 @@ -# Makefile. +# CMakeLists.txt. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -19,8 +19,3 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . ################################################################################### - -integration-tests: src tools - -run-integration-tests: integration-tests - @$(SRCDIR)/tools/integration-tests.sh diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 000000000..aa3f57c67 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,64 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +find_package(Doxygen) + +if(DOXYGEN_FOUND) + set(DOXYGEN_PROJECT_LOGO doc/pictures/villas_node.svg) + set(DOXYGEN_WARN_LOGFILE ${CMAKE_CURRENT_BINARY_DIR}/warnings.log) + set(DOXYGEN_TAB_SIZE 8) + set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) + set(DOXYGEN_LAYOUT_FILE doc/theme/layout.xml) + set(DOXYGEN_RECURSIVE YES) + set(DOXYGEN_EXAMPLE_PATH etc/) + set(DOXYGEN_EXAMPLE_RECURSIVE YES) + set(DOXYGEN_IMAGE_PATH doc/pictures) + set(DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md) + set(DOXYGEN_SOURCE_BROWSER YES) + set(DOXYGEN_REFERENCED_BY_RELATION YES) + set(DOXYGEN_HTML_HEADER doc/theme/header.html) + set(DOXYGEN_HTML_EXTRA_STYLESHEET doc/theme/style.css) + set(DOXYGEN_HTML_EXTRA_FILES doc/pictures/acs_eonerc_logo.svg) + set(DOXYGEN_HTML_COLORSTYLE_HUE 209) + set(DOXYGEN_HTML_COLORSTYLE_SAT 88) + set(DOXYGEN_HTML_TIMESTAMP YES) + set(DOXYGEN_HTML_DYNAMIC_SECTIONS YES) + set(DOXYGEN_GENERATE_TREEVIEW YES) + set(DOXYGEN_TREEVIEW_WIDTH 280) + set(DOXYGEN_UML_LOOK YES) + set(DOXYGEN_CALL_GRAPH YES) + set(DOXYGEN_CALLER_GRAPH YES) + set(DOXYGEN_DOT_IMAGE_FORMAT svg) + set(DOXYGEN_INTERACTIVE_SVG YES) + set(DOXYGEN_DIAFILE_DIRS doc/figures/) + + doxygen_add_docs(doc + README.md CONTRIBUTING.md COPYING.md src/ lib/ tests/ include/ doc/ + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + + install( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/villas/node + COMPONENT doc + ) +endif() diff --git a/Doxyfile b/doc/Doxyfile.in similarity index 99% rename from Doxyfile rename to doc/Doxyfile.in index f901b6c0d..4db7e3af4 100644 --- a/Doxyfile +++ b/doc/Doxyfile.in @@ -58,7 +58,7 @@ PROJECT_LOGO = doc/pictures/villas_node.svg # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = build/doc/ +OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@ # If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and diff --git a/doc/Makefile.inc b/doc/Makefile.inc deleted file mode 100644 index 552ceb33c..000000000 --- a/doc/Makefile.inc +++ /dev/null @@ -1,33 +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 . -################################################################################### - -doc: | $(BUILDDIR)/doc/ - ( cat Doxyfile ; echo "OUTPUT_DIRECTORY=$(BUILDDIR)/doc/" ) | doxygen - - -install-doc: doc - mkdir -p $(DESTDIR)$(PREFIX)/share/villas/node/doc/ - cp -R $(BUILDDIR)/doc/html/* $(DESTDIR)$(PREFIX)/share/villas/node/doc/ - -clean-doc: - rm -rf $(BUILDDIR)/doc/ - -.PHONY: doc install-doc clean-doc \ No newline at end of file diff --git a/etc/Makefile.inc b/etc/CMakeLists.txt similarity index 78% rename from etc/Makefile.inc rename to etc/CMakeLists.txt index f12aa55cc..412ee2b07 100644 --- a/etc/Makefile.inc +++ b/etc/CMakeLists.txt @@ -1,7 +1,7 @@ -# Makefile. +# CMakeLists.txt. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -20,11 +20,11 @@ # along with this program. If not, see . ################################################################################### -etc: - -install-etc: | $(DESTDIR)/etc/villas/node/ - install -D -t $(DESTDIR)/etc/villas/node $(SRCDIR)/etc/*.conf - -clean-etc: - -.PHONY: etc install-etc clean-etc \ No newline at end of file +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMPONENT bin + DESTINATION etc/villas/node + FILES_MATCHING + PATTERN "*.conf" + PATTERN "*.json" +) diff --git a/include/villas/config.h.in b/include/villas/config.h.in index 419f0fa61..d62812107 100644 --- a/include/villas/config.h.in +++ b/include/villas/config.h.in @@ -61,6 +61,27 @@ extern "C"{ #define KERNEL_VERSION_MAJ 3 #define KERNEL_VERSION_MIN 6 +#cmakedefine BUILDID "@BUILDID@" +#cmakedefine V @V@ +#cmakedefine PREFIX "@PREFIX@" + +/* Available Features */ +#cmakedefine WITH_WEB +#cmakedefine WITH_API +#cmakedefine WITH_HOOKS +#cmakedefine WITH_IO + +/* OS Headers */ +#cmakedefine HAS_EVENTFD + +#cmakedefine HAS_SEMAPHORE + +#cmakedefine LIBWEBSOCKETS_FOUND +#cmakedefine HDF5_FOUND +#cmakedefine PROTOBUF_FOUND +#cmakedefine LIBNL3_ROUTE_FOUND +#cmakedefine LIBCONFIG_FOUND + #ifdef __cplusplus } #endif diff --git a/include/villas/kernel/if.h b/include/villas/kernel/if.h index 1d6420098..1ff8fc68a 100644 --- a/include/villas/kernel/if.h +++ b/include/villas/kernel/if.h @@ -24,7 +24,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/kernel/kernel.h b/include/villas/kernel/kernel.h index 265e125f4..d02735139 100644 --- a/include/villas/kernel/kernel.h +++ b/include/villas/kernel/kernel.h @@ -21,7 +21,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/kernel/nl.h b/include/villas/kernel/nl.h index 894df4f9f..13f03eff1 100644 --- a/include/villas/kernel/nl.h +++ b/include/villas/kernel/nl.h @@ -21,7 +21,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/kernel/rt.h b/include/villas/kernel/rt.h index c6c5c0e9b..9877882d1 100644 --- a/include/villas/kernel/rt.h +++ b/include/villas/kernel/rt.h @@ -22,7 +22,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/kernel/tc.h b/include/villas/kernel/tc.h index 0b5afbbc3..283f7a89d 100644 --- a/include/villas/kernel/tc.h +++ b/include/villas/kernel/tc.h @@ -26,7 +26,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/kernel/tc_netem.h b/include/villas/kernel/tc_netem.h index b6d0a86c4..76db24db0 100644 --- a/include/villas/kernel/tc_netem.h +++ b/include/villas/kernel/tc_netem.h @@ -26,7 +26,9 @@ * along with this program. If not, see . *********************************************************************************/ -/** @addtogroup kernel Kernel @{ */ +/** @addtogroup kernel Kernel + * @{ + */ #pragma once diff --git a/include/villas/nodes/iec61850.h b/include/villas/nodes/iec61850.h index 9f7944b4b..349549ffa 100644 --- a/include/villas/nodes/iec61850.h +++ b/include/villas/nodes/iec61850.h @@ -31,6 +31,12 @@ #include +#ifdef __APPLE__ + #include +#else + #include +#endif + #include #include #include diff --git a/include/villas/nodes/socket.h b/include/villas/nodes/socket.h index 6cccdf848..ad2ed1372 100644 --- a/include/villas/nodes/socket.h +++ b/include/villas/nodes/socket.h @@ -40,13 +40,13 @@ #include #include -#ifdef WITH_LIBNL_ROUTE_30 +#ifdef LIBNL3_ROUTE_FOUND #include #include #include #define WITH_NETEM -#endif /* WITH_LIBNL_ROUTE_30 */ +#endif /* LIBNL3_ROUTE_FOUND */ #include diff --git a/include/villas/queue_signalled.h b/include/villas/queue_signalled.h index 2d2a44fb3..9ad916b82 100644 --- a/include/villas/queue_signalled.h +++ b/include/villas/queue_signalled.h @@ -36,7 +36,7 @@ enum queue_signalled_flags { QUEUE_SIGNALLED_AUTO = (0 << 0), /**< We will choose the best method available on the platform */ QUEUE_SIGNALLED_PTHREAD = (1 << 0), QUEUE_SIGNALLED_POLLING = (2 << 0), -#ifdef __linux__ +#ifdef HAS_EVENTFD QUEUE_SIGNALLED_EVENTFD = (3 << 0), #elif defined(__APPLE__) QUEUE_SIGNALLED_PIPE = (3 << 0), diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 000000000..a05a596ca --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,171 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +add_compile_options(-fPIC) + +set(INCLUDE_DIRS + ${JANSSON_INCLUDE_DIRS} + ${OPENSSL_INCLUDE_DIR} + ${CURL_INCLUDE_DIRS} +) + +set(LIBRARIES + PkgConfig::JANSSON + ${OPENSSL_LIBRARIES} + ${CURL_LIBRARIES} +) + +set(LIB_SRC + kernel/kernel.c + kernel/rt.c + sample.c + path.c + node.c + log.c + log_config.c + utils.c + super_node.c + hist.c + timing.c + pool.c + list.c + hash_table.c + queue.c + queue_signalled.c + memory.c + advio.c + plugin.c + node_type.c + stats.c + mapping.c + shmem.c + config_helper.c + crypt.c + compat.c + log_helper.c + task.c + buffer.c + table.c + bitset.c + signal.c +) + +add_subdirectory(nodes) +list(APPEND WHOLE_ARCHIVES nodes) + +if(LIBCONFIG_FOUND) + list(APPEND INCLUDE_DIRS ${LIBCONFIG_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::LIBCONFIG) +endif() + +if(WITH_IO) + list(APPEND LIB_SRC + io.c + format_type.c + ) + + add_subdirectory(formats) + list(APPEND WHOLE_ARCHIVES formats) +endif() + +if(WITH_HOOKS) + list(APPEND LIB_SRC + hook.c + hook_type.c + ) + + add_subdirectory(hooks) + list(APPEND WHOLE_ARCHIVES hooks) +endif() + +if(WITH_WEB) + list(APPEND LIB_SRC + web.c + ) + + list(APPEND INCLUDE_DIRS ${LIBWEBSOCKETS_INCLUDE_DIRS}) + list(APPEND LIBRARIES websockets_shared) +endif() + +if(WITH_API AND WITH_WEB) + list(APPEND LIB_SRC + api.c + ) + + add_subdirectory(api) + list(APPEND WHOLE_ARCHIVES api) +endif() + +# libnl3 is optional but required for network emulation and IRQ pinning +if(LIBNL3_ROUTE_FOUND) + list(APPEND LIB_SRC + kernel/nl.c + kernel/tc.c + kernel/tc_netem.c + kernel/if.c + ) + + list(APPEND INCLUDE_DIRS ${LIBNL3_ROUTE_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::LIBNL3_ROUTE) +endif() + +add_library(villas SHARED ${LIB_SRC}) + +target_include_directories(villas PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas PUBLIC ${LIBRARIES}) + +if(APPLE) + target_link_libraries(villas PRIVATE -Wl,-all_load ${WHOLE_ARCHIVES} -Wl,-noall_load) +else() + target_link_libraries(villas PRIVATE -Wl,--whole-archive ${WHOLE_ARCHIVES} -Wl,--no-whole-archive) +endif() + + +set_target_properties(villas PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_SOVERSION} +) + +install( + TARGETS villas + EXPORT VILLASNodeConfig + COMPONENT lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +install( + DIRECTORY ../include/villas/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/villas + COMPONENT devel + FILES_MATCHING + PATTERN "*.h" +) + +#install( +# EXPORT VILLASNodeConfig +# DESTINATION share/VILLASNode/cmake +#) + +#export( +# TARGETS villas +# FILE VILLASNodeConfig.cmake +#) diff --git a/lib/Makefile.inc b/lib/Makefile.inc deleted file mode 100644 index 29e513a41..000000000 --- a/lib/Makefile.inc +++ /dev/null @@ -1,64 +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 . -################################################################################### - -SONAMES = villas villas-ext - -LIBS = $(patsubst %, lib%, $(SONAMES)) - -LIB_CFLAGS += $(CFLAGS) -fPIC - -include $(patsubst %, lib/Makefile.%.inc, $(SONAMES)) - -$(BUILDDIR)/include/villas/config.h: include/villas/config.h.in Makefile.config | $$(dir $$@) - cp $< $@ - - echo -e "\n" >> $@ - echo "#define BUILDID \"$(BUILDID)\"" >> $@ - echo "#define V $(V)" >> $@ - echo "#define PREFIX \"$(PREFIX)\"" >> $@ - - echo -e "\n" >> $@ - echo "/* Available Features */" >> $@ - - if (( $(WITH_WEB) )); then echo "#define WITH_WEB 1" >> $@; fi - if (( $(WITH_API) )); then echo "#define WITH_API 1" >> $@; fi - if (( $(WITH_HOOKS) )); then echo "#define WITH_HOOKS 1" >> $@; fi - if (( $(WITH_IO) )); then echo "#define WITH_IO 1" >> $@; fi - if (( $(WITH_CONFIG) )); then echo "#define WITH_CONFIG 1" >> $@; fi - - for NODE in $(call escape,$(LIB_NODES)); do echo "#define WITH_NODE_$${NODE} 1" >> $@; done - for FORMAT in $(call escape,$(LIB_FORMATS)); do echo "#define WITH_FORMAT_$${FORMAT} 1" >> $@; done - for PKG in $(call escape,$(LIB_PKGS)); do echo "#define WITH_$${PKG} 1" >> $@; done - -# Compile -$(BUILDDIR)/lib/%.o: lib/%.c $(BUILDDIR)/include/villas/config.h | $$(dir $$@) - $(CC) $(LIB_CFLAGS) -c $< -o $@ - -lib: $(patsubst %, lib%, $(SONAMES)) - -install-lib: $(patsubst %, install-lib%, $(SONAMES)) - -clean-lib: $(patsubst %, clean-lib%, $(SONAMES)) - rm -rf $(BUILDDIR)/lib - rm -rf $(BUILDDIR)/include - -.PHONY: lib install-lib clean-lib diff --git a/lib/Makefile.villas-ext.inc b/lib/Makefile.villas-ext.inc deleted file mode 100644 index b8558a46a..000000000 --- a/lib/Makefile.villas-ext.inc +++ /dev/null @@ -1,54 +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 . -################################################################################### - -LIBEXT_NAME = libvillas-ext -LIBEXT_ABI_VERSION = 1 -LIBEXT = $(BUILDDIR)/$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) - -LIBEXT_SRCS += $(addprefix lib/, sample.c queue.c queue_signalled.c \ - memory.c log.c shmem.c utils.c kernel/kernel.c list.c \ - timing.c pool.c log_helper.c \ - ) - -LIBEXT_LDFLAGS = -shared -LIBEXT_LDLIBS += - -ifeq ($(PLATFORM),Linux) - LIBEXT_LDLIBS += -ldl -lrt -Wl,-soname,$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) -endif - -LIBEXT_OBJS = $(patsubst %.c, $(BUILDDIR)/%.o, $(LIBEXT_SRCS)) - -$(LIBEXT_NAME): $(LIBEXT) - -$(LIBEXT): $(LIBEXT_OBJS) - $(CC) $(LIBEXT_LDFLAGS) -o $@ $^ $(LIBEXT_LDLIBS) - ln -srf $@ $(BUILDDIR)/$(LIBEXT_NAME).so - -install-libvillas-ext: libvillas-ext - install -m 0755 -D -T $(LIBEXT) $(DESTDIR)$(PREFIX)/lib/$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) - ln -srf $(DESTDIR)$(PREFIX)/lib/$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) $(DESTDIR)$(PREFIX)/lib/$(LIBEXT_NAME).so - -clean-libvillas-ext: - rm -f $(LIBEXT) - -.PHONY: install-libvillas-ext clean-libvillas-ext $(LIBEXT_NAME) diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc deleted file mode 100644 index 68ff0b83d..000000000 --- a/lib/Makefile.villas.inc +++ /dev/null @@ -1,94 +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_NAME = libvillas -LIB_ABI_VERSION = 1 -LIB = $(BUILDDIR)/$(LIB_NAME).so.$(LIB_ABI_VERSION) - -# Object files for libvillas -LIB_SRCS += $(addprefix lib/kernel/, kernel.c rt.c) \ - $(addprefix lib/, sample.c path.c node.c hook.c log.c log_config.c \ - utils.c super_node.c hist.c timing.c pool.c list.c queue.c \ - queue_signalled.c memory.c advio.c plugin.c node_type.c stats.c \ - mapping.c shmem.c config_helper.c crypt.c compat.c \ - log_helper.c task.c buffer.c table.c bitset.c signal.c \ - hash_table.c \ - ) - -LIB_LDFLAGS += -shared -LIB_LDLIBS += $(LDLIBS) - -ifeq ($(PLATFORM),Linux) - LIB_LDLIBS += -ldl -lrt -Wl,-soname,$(LIB_NAME).so.$(LIB_ABI_VERSION) -endif - -LIB_PKGS += openssl libcurl - -include lib/nodes/Makefile.inc - -ifeq ($(WITH_IO),1) - LIB_SRCS += lib/io.c lib/format_type.c - include lib/formats/Makefile.inc -endif - -ifeq ($(WITH_HOOKS),1) - LIB_SRCS += lib/hook.c lib/hook_type.c - include lib/hooks/Makefile.inc -endif - -ifeq ($(WITH_WEB),1) - LIB_SRCS += lib/web.c - LIB_PKGS += libwebsockets -endif - -ifeq ($(WITH_API),1) - LIB_SRCS += lib/api.c - include lib/api/Makefile.inc -endif - -LIB_SRCS += $(patsubst %, lib/nodes/%.c, $(LIB_NODES)) -LIB_SRCS += $(patsubst %, lib/formats/%.c, $(LIB_FORMATS)) - -# Add flags by pkg-config -LIB_LDLIBS += $(shell $(PKGCONFIG) --libs $(LIB_PKGS)) -LIB_CFLAGS += $(shell $(PKGCONFIG) --cflags $(LIB_PKGS)) - -LIB_OBJS = $(patsubst %.c, $(BUILDDIR)/%.o, $(LIB_SRCS)) - -$(LIB_NAME): $(LIB) - -# Link -$(LIB): $(LIB_OBJS) - $(CC) $(LIB_LDFLAGS) -o $@ $^ $(LIB_LDLIBS) - ln -srf $@ $(BUILDDIR)/$(LIB_NAME).so - -# Install -install-libvillas: libvillas | $(DESTDIR)$(PREFIX)/include/villas/ - install -m 0755 -D -T $(LIB) $(DESTDIR)$(PREFIX)/lib/$(LIB_NAME).so.$(LIB_ABI_VERSION) - install -m 0644 -D -t $(DESTDIR)$(PREFIX)/include/villas/ include/villas/*.h - ln -srf $(DESTDIR)$(PREFIX)/lib/$(LIB_NAME).so.$(LIB_ABI_VERSION) $(DESTDIR)$(PREFIX)/lib/$(LIB_NAME).so - if [ "$(PLATFORM)" == "Linux" ]; then ldconfig; fi - -clean-libvillas: - rm -f $(LIB) - -.PHONY: install-libvillas clean-libvillas $(LIB_NAME) diff --git a/lib/hooks/Makefile.inc b/lib/api/CMakeLists.txt similarity index 63% rename from lib/hooks/Makefile.inc rename to lib/api/CMakeLists.txt index 31455293c..453cd2dca 100644 --- a/lib/hooks/Makefile.inc +++ b/lib/api/CMakeLists.txt @@ -1,7 +1,8 @@ -# Makefile. + +# CMakeLists. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -20,10 +21,25 @@ # along with this program. If not, see . ################################################################################### -LIB_SRCS += $(addprefix lib/hooks/, convert.c decimate.c drop.c jitter_calc.c \ - map.c restart.c shift_seq.c shift_ts.c \ - skip_first.c stats.c ts.c limit_rate.c scale.c) +set(INCLUDE_DIRS + ${OPENSSL_INCLUDE_DIR} +) -ifeq ($(WITH_IO),1) - LIB_SRCS += lib/hooks/print.c -endif +set(LIBRARIES + ${OPENSSL_LIBRARIES} +) + +set(API_SRC + session.c + actions/capabiltities.c + actions/config.c + actions/nodes.c + actions/paths.c + actions/restart.c + actions/shutdown.c + actions/status.c +) + +add_library(api STATIC ${API_SRC}) +target_include_directories(api PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(api INTERFACE ${LIBRARIES}) diff --git a/lib/config_helper.c b/lib/config_helper.c index 320e759f1..2e3cb8f1a 100644 --- a/lib/config_helper.c +++ b/lib/config_helper.c @@ -26,7 +26,7 @@ #include #include -#ifdef WITH_CONFIG +#ifdef LIBCONFIG_FOUND static int json_to_config_type(int type) { @@ -143,7 +143,7 @@ int json_to_config(json_t *json, config_setting_t *parent) return 0; } -#endif /* WITH_CONFIG */ +#endif /* LIBCONFIG_FOUND */ void json_object_extend_key_value(json_t *obj, const char *key, const char *value) { diff --git a/lib/formats/CMakeLists.txt b/lib/formats/CMakeLists.txt new file mode 100644 index 000000000..8e4ecee3f --- /dev/null +++ b/lib/formats/CMakeLists.txt @@ -0,0 +1,92 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(FORMAT_SRC + json.c + json_reserve.c + villas_binary.c + villas_human.c + csv.c + raw.c + msg.c +) + +set(INCLUDE_DIRS + ${OPENSSL_INCLUDE_DIR} +) + +set(LIBRARIES + ${OPENSSL_LIBRARIES} +) + +if(DEFINED PROTOBUF_COMPILER) + add_custom_target(protobuf ALL + COMMAND ${PROTOBUF_COMPILER} + --python_out=${CMAKE_CURRENT_BINARY_DIR} + #--php_out=${CMAKE_BINARY_DIR} + --js_out=${CMAKE_CURRENT_BINARY_DIR} + --cpp_out=${CMAKE_CURRENT_BINARY_DIR} + villas.proto + DEPENDS villas.proto + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endif() + +if(DEFINED PROTOBUFC_COMPILER) + add_custom_target(protobuf-c ALL + COMMAND ${PROTOBUFC_COMPILER} + --c_out=${CMAKE_CURRENT_BINARY_DIR} + villas.proto + DEPENDS villas.proto + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + add_dependencies(protobuf protobuf-c) +endif() + +# Enable Google Protobuf format +if(ProtobufC_FOUND) + list(APPEND FORMAT_SRC + protobuf.c + ${CMAKE_CURRENT_BINARY_DIR}/villas.pb-c.c + ) + + list(APPEND INCLUDE_DIRS + ${PROTOBUFC_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ) + + list(APPEND LIBRARIES + ${PROTOBUFC_LIBRARIES} + ) + + set_source_files_properties(villas.pb-c.h villas.pb-c.c + PROPERTIES + GENERATED TRUE + ) + + add_dependencies(formats protobuf-c) +endif() + +add_library(formats STATIC ${FORMAT_SRC}) +target_include_directories(formats PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(formats INTERFACE ${LIBRARIES}) diff --git a/lib/formats/Makefile.inc b/lib/formats/Makefile.inc deleted file mode 100644 index dc8e9b087..000000000 --- a/lib/formats/Makefile.inc +++ /dev/null @@ -1,41 +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_FORMATS += json json_reserve villas_binary villas_human csv raw -LIB_SRCS += lib/formats/msg.c - -# Enable Google Protobuf format -ifeq ($(WITH_FORMAT_PROTOBUF),1) -ifeq ($(shell $(PKGCONFIG) libprotobuf-c; echo $$?),0) - LIB_SRCS += lib/formats/protobuf.c lib/formats/villas.pb-c.c - LIB_PKGS += libprotobuf-c - LIB_FORMATS += protobuf -endif -endif - -%.pb-c.c %.pb-c.h: %.proto - protoc-c --proto_path=$(SRCDIR) --c_out=$(SRCDIR) --dependency_out=$(BUILDDIR)/$*.d $(realpath $^) - -$(BUILDDIR)/%.pb-c.o: LIB_CFLAGS += -I$(SRCDIR) -$(BUILDDIR)/lib/formats/protobuf.o: LIB_CFLAGS += -I$(SRCDIR)/lib/formats - -$(BUILDDIR)/lib/formats/protobuf.o: lib/formats/villas.pb-c.h diff --git a/lib/hooks/CMakeLists.txt b/lib/hooks/CMakeLists.txt new file mode 100644 index 000000000..137381e61 --- /dev/null +++ b/lib/hooks/CMakeLists.txt @@ -0,0 +1,55 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(INCLUDE_DIRS + ${JANSSON_INCLUDE_DIRS} +) + +set(LIBRARIES + PkgConfig::JANSSON +) + +set(HOOK_SRC + convert.c + decimate.c + drop.c + jitter_calc.c + map.c + restart.c + shift_seq.c + shift_ts.c + skip_first.c + stats.c + ts.c + limit_rate.c + scale.c +) + +if(WITH_IO) + list(APPEND HOOK_SRC + print.c + ) +endif() + +add_library(hooks STATIC ${HOOK_SRC}) +target_include_directories(hooks PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(hooks INTERFACE ${LIBRARIES}) diff --git a/lib/log.c b/lib/log.c index c2c328df6..8bb6e058f 100644 --- a/lib/log.c +++ b/lib/log.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/lib/nodes/CMakeLists.txt b/lib/nodes/CMakeLists.txt new file mode 100644 index 000000000..d4e07cb71 --- /dev/null +++ b/lib/nodes/CMakeLists.txt @@ -0,0 +1,131 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(INCLUDE_DIRS + ${JANSSON_INCLUDE_DIRS} +) + +set(LIBRARIES + PkgConfig::JANSSON +) + +set(NODE_SRC + influxdb.c + stats.c + signal_generator.c +) + +if(LIBNL3_ROUTE_FOUND) + list(APPEND LIBRARIES PkgConfig::LIBNL3_ROUTE) + list(APPEND INCLUDE_DIRS LIBNL3_ROUTE_INCLUDE_DIRS) +endif() + +if(WITH_IO) + list(APPEND NODE_SRC + test_rtt.c + file.c + socket.c + ) +endif() + +if(HAS_EVENTFD) + list(APPEND NODE_SRC + loopback.c + cbuilder.c + ) +endif() + +# Enable shared memory node-type +if(HAS_SEMAPHORE AND HAS_MMAN) + list(APPEND NODE_SRC shmem.c) + + if(CMAKE_SUSTEM_NAME STREQUAL Linux) + list(APPEND LIBRARIES rt) + endif() +endif() + +# Enable IEC61850 node-types when libiec61850 is available +if(LIBIEC61850_FOUND) + list(APPEND NODE_SRC iec61850_sv.c iec61850.c) + list(APPEND INCLUDE_DIRS ${LIBIEC61850_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::LIBIEC61850) +endif() + +# Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!) +if(OPAL_FOUND AND BUILD32) + list(APPEND NODE_SRC opal.c) + list(APPEND INCLUDE_DIRS ${OPAL_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${OPAL_LIBRARIES}) +endif() + +# Enable nanomsg node type when libnanomsg is available +if(NANOMSG_FOUND AND WITH_IO) + list(APPEND NODE_SRC nanomsg.c) + list(APPEND INCLUDE_DIRS ${NANOMSG_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::NANOMSG) +endif() + +# Enable ZeroMQ node type when libzmq is available +if(LIBZMQ_FOUND AND WITH_IO) + list(APPEND NODE_SRC zeromq.c) + list(APPEND INCLUDE_DIRS ${LIBZMQ_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::LIBZMQ) +endif() + +# Enable NGSI support +if(CURL_FOUND) + list(APPEND NODE_SRC ngsi.c) + list(APPEND INCLUDE_DIRS ${CURL_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${CURL_LIBRARIES}) +endif() + +# Enable WebSocket support +if(LIBWEBSOCKETS_FOUND AND WITH_WEB AND WITH_IO) + list(APPEND NODE_SRC websockets.c) + list(APPEND INCLUDE_DIRS ${LIBWEBSOCKETS_INCLUDE_DIRS}) + list(APPEND LIBRARIES websockets_shared) +endif() + +# Enable AMQP support +if(RABBITMQ_C_FOUND AND WITH_IO) + list(APPEND NODE_SRC amqp.c) + list(APPEND INCLUDE_DIRS ${RABBITMQ_C_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::RABBITMQ_C) +endif() + +# Enable MQTT support +if(MOSQUITTO_FOUND AND WITH_IO) + list(APPEND NODE_SRC mqtt.c) + list(APPEND INCLUDE_DIRS ${MOSQUITTO_INCLUDE_DIRS}) + list(APPEND LIBRARIES ${MOSQUITTO_LIBRARIES}) +endif() + +# Enable Comedi support +if(COMEDILIB_FOUND) + list(APPEND NODE_SRC comedi.c) + list(APPEND INCLUDE_DIRS ${COMEDILIB_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::COMEDILIB) +endif() + +add_library(nodes STATIC ${NODE_SRC}) +target_include_directories(nodes PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(nodes LINK_PRIVATE ${LIBRARIES}) diff --git a/lib/nodes/Makefile.inc b/lib/nodes/Makefile.inc deleted file mode 100644 index 180a98669..000000000 --- a/lib/nodes/Makefile.inc +++ /dev/null @@ -1,166 +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 . -################################################################################### - -# Enabled loopback node-type -ifeq ($(WITH_NODE_LOOPBACK),1) - LIB_NODES += loopback -endif - -# Enabled Cbuilder node-type -ifeq ($(WITH_NODE_CBUILDER),1) - LIB_NODES += cbuilder -endif - -# Enable InfluxDB node-type -ifeq ($(WITH_NODE_INFLUXDB),1) - LIB_NODES += influxdb -endif - -# Enable stats node-type -ifeq ($(WITH_NODE_STATS),1) - LIB_NODES += stats -endif - -# Enable file node-type -ifeq ($(WITH_NODE_FILE),1) - LIB_NODES += file - WITH_IO = 1 -endif - -# Enable shared memory node-type -ifeq ($(WITH_NODE_SHMEM),1) - LIB_NODES += shmem -endif - -# Enable signal generator node-type -ifeq ($(WITH_NODE_SIGNAL),1) - LIB_NODES += signal_generator -endif - -# Enable RTT test node-tyoe -ifeq ($(WITH_NODE_TEST_RTT),1) - LIB_NODES += test_rtt - WITH_IO = 1 -endif - -# Enable IEC61850 node-types when libiec61850 is available -ifeq ($(WITH_NODE_IEC61850),1) -ifeq ($(shell $(PKGCONFIG) --atleast-version=1.2.0 libiec61850; echo $$?),0) - LIB_SRCS += lib/nodes/iec61850_sv.c - LIB_NODES += iec61850 - LIB_PKGS += libiec61850 -endif -endif - -# Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!) -ifeq ($(WITH_NODE_OPAL),1) -ifneq ($(wildcard $(SRCDIR)/thirdparty/libopal/include/opal/AsyncApi.h),) - LIB_CFLAGS += -I $(SRCDIR)/thirdparty/libopal/include/opal/ - LIB_LDFLAGS += -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -L$(SRCDIR)/thirdparty/libopal/ - LIB_LDLIBS += -lOpalAsyncApiCore -lOpalCore -lOpalUtils -lirc - LIB_NODES += opal - - # libOpalAsyncApi is a 32bit library. So we need to build everything in 32bit - CFLAGS += -m32 - LDFLAGS += -m32 -endif -endif - -# Enable Socket node type when libnl3 is available -ifeq ($(WITH_NODE_SOCKET),1) - LIB_NODES += socket - WITH_IO = 1 - - # libnl3 is optional but required for network emulation and IRQ pinning - ifeq ($(shell $(PKGCONFIG) libnl-route-3.0; echo $$?),0) - LIB_SRCS += $(addprefix lib/kernel/, nl.c tc.c tc_netem.c if.c) - LIB_PKGS += libnl-route-3.0 - endif -endif - -# Enable nanomsg node type when libnanomsg is available -ifeq ($(WITH_NODE_NANOMSG),1) -ifeq ($(shell $(PKGCONFIG) nanomsg; echo $$?),0) - LIB_PKGS += nanomsg - LIB_NODES += nanomsg - WITH_IO = 1 -else ifeq ($(shell $(PKGCONFIG) libnanomsg; echo $$?),0) - LIB_PKGS += libnanomsg - LIB_NODES += nanomsg - WITH_IO = 1 -endif -endif - -# Enable ZeroMQ node type when libzmq is available -ifeq ($(WITH_NODE_ZEROMQ),1) -ifeq ($(shell $(PKGCONFIG) libzmq; echo $$?),0) - LIB_PKGS += libzmq - LIB_NODES += zeromq - WITH_IO = 1 -endif -endif - -# Enable NGSI support -ifeq ($(WITH_NODE_NGSI),1) -ifeq ($(shell $(PKGCONFIG) libcurl; echo $$?),0) - LIB_PKGS += libcurl - LIB_NODES += ngsi -endif -endif - -# Enable WebSocket support -ifeq ($(WITH_NODE_WEBSOCKET),1) -ifeq ($(shell $(PKGCONFIG) libwebsockets; echo $$?),0) - LIB_PKGS += libwebsockets - LIB_NODES += websocket - WITH_IO = 1 - WITH_WEB = 1 -endif -endif - -# Enable AMQP support -ifeq ($(WITH_NODE_AMQP),1) -ifeq ($(shell $(PKGCONFIG) librabbitmq; echo $$?),0) - LIB_PKGS += librabbitmq - LIB_NODES += amqp - WITH_IO = 1 -endif -endif - -# Enable MQTT support -ifeq ($(WITH_NODE_MQTT),1) -ifneq ($(wildcard /usr/include/mosquitto.h),) - LIB_SRCS += lib/nodes/mqtt.c - LIB_NODES += mqtt - LIB_LDLIBS += -lmosquitto - WITH_IO = 1 -endif -endif - -# Enable Comedi support -ifeq ($(WITH_NODE_COMEDI),1) -ifeq ($(shell $(PKGCONFIG) comedilib; echo $$?),0) - LIB_PKGS += comedilib - LIB_SRCS += lib/nodes/comedi.c - LIB_NODES += comedi -endif -endif diff --git a/lib/nodes/iec61850.c b/lib/nodes/iec61850.c index c14a5a21b..b6aae1706 100644 --- a/lib/nodes/iec61850.c +++ b/lib/nodes/iec61850.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "villas/nodes/iec61850_sv.h" #include "villas/plugin.h" diff --git a/lib/nodes/iec61850_sv.c b/lib/nodes/iec61850_sv.c index 70c91efca..13699049e 100644 --- a/lib/nodes/iec61850_sv.c +++ b/lib/nodes/iec61850_sv.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "villas/nodes/iec61850_sv.h" #include "villas/plugin.h" @@ -166,8 +165,14 @@ int iec61850_sv_parse(struct node *n, json_t *json) if (interface) i->interface = strdup(interface); - if (dst_address) + if (dst_address) { +#ifdef __APPLE__ + struct ether_addr *ether = ether_aton(dst_address); + memcpy(&i->dst_address, ether, sizeof(struct ether_addr)); +#else ether_aton_r(dst_address, &i->dst_address); +#endif + } if (json_pub) { i->publisher.enabled = true; diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index c4c4b4f02..61c7fa2a1 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include diff --git a/lib/nodes/test_rtt.c b/lib/nodes/test_rtt.c index 6ccbae612..2de5d887f 100644 --- a/lib/nodes/test_rtt.c +++ b/lib/nodes/test_rtt.c @@ -188,11 +188,7 @@ int test_rtt_parse(struct node *n, json_t *cfg) else c->limit = 1000; /* default value */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-result" - asprintf(&c->filename, "%s/%s_%d_%.0f.log", t->output, t->prefix, c->values, c->rate); -#pragma GCC diagnostic pop - + c->filename = strf("%s/%s_%d_%.0f.log", t->output, t->prefix, c->values, c->rate); list_push(&t->cases, c); } diff --git a/lib/path.c b/lib/path.c index 7763e1aa5..27e66861a 100644 --- a/lib/path.c +++ b/lib/path.c @@ -589,7 +589,7 @@ int path_parse(struct path *p, json_t *cfg, struct list *nodes) } } -#if WITH_HOOKS +#ifdef WITH_HOOKS if (json_hooks) { ret = hook_parse_list(&p->hooks, json_hooks, p, NULL); if (ret) diff --git a/lib/queue_signalled.c b/lib/queue_signalled.c index a37caa316..dc6d6f9f6 100644 --- a/lib/queue_signalled.c +++ b/lib/queue_signalled.c @@ -21,10 +21,11 @@ * along with this program. If not, see . *********************************************************************************/ +#include #include #include -#ifdef __linux__ +#ifdef HAS_EVENTFD #include #endif @@ -83,7 +84,7 @@ int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memtype else if (qs->mode == QUEUE_SIGNALLED_POLLING) { /* Nothing todo */ } -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { qs->eventfd = eventfd(0, 0); if (qs->eventfd < 0) @@ -117,7 +118,7 @@ int queue_signalled_destroy(struct queue_signalled *qs) else if (qs->mode == QUEUE_SIGNALLED_POLLING) { /* Nothing todo */ } -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { ret = close(qs->eventfd); if (ret) @@ -152,7 +153,7 @@ int queue_signalled_push(struct queue_signalled *qs, void *ptr) else if (qs->mode == QUEUE_SIGNALLED_POLLING) { /* Nothing todo */ } -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { int ret; uint64_t incr = 1; @@ -191,7 +192,7 @@ int queue_signalled_push_many(struct queue_signalled *qs, void *ptr[], size_t cn else if (qs->mode == QUEUE_SIGNALLED_POLLING) { /* Nothing todo */ } -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { int ret; uint64_t incr = 1; @@ -233,7 +234,7 @@ int queue_signalled_pull(struct queue_signalled *qs, void **ptr) pthread_cond_wait(&qs->pthread.ready, &qs->pthread.mutex); else if (qs->mode == QUEUE_SIGNALLED_POLLING) continue; /* Try again */ -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { int ret; uint64_t cntr; @@ -282,7 +283,7 @@ int queue_signalled_pull_many(struct queue_signalled *qs, void *ptr[], size_t cn pthread_cond_wait(&qs->pthread.ready, &qs->pthread.mutex); else if (qs->mode == QUEUE_SIGNALLED_POLLING) continue; /* Try again */ -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { int ret; uint64_t cntr; @@ -328,7 +329,7 @@ int queue_signalled_close(struct queue_signalled *qs) else if (qs->mode == QUEUE_SIGNALLED_POLLING) { /* Nothing todo */ } -#ifdef __linux__ +#ifdef HAS_EVENTFD else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { int ret; uint64_t incr = 1; @@ -356,7 +357,7 @@ int queue_signalled_close(struct queue_signalled *qs) int queue_signalled_fd(struct queue_signalled *qs) { switch (qs->mode) { -#ifdef __linux__ +#ifdef HAS_EVENTFD case QUEUE_SIGNALLED_EVENTFD: return qs->eventfd; #elif defined(__APPLE__) diff --git a/lib/super_node.c b/lib/super_node.c index 705b8cab7..7f00521f2 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -103,7 +103,7 @@ int super_node_parse_uri(struct super_node *sn, const char *uri) /* Parse config */ sn->cfg = json_loadf(f, 0, &err); if (sn->cfg == NULL) { -#ifdef WITH_CONFIG +#ifdef LIBCONFIG_FOUND int ret; config_t cfg; @@ -150,7 +150,7 @@ int super_node_parse_uri(struct super_node *sn, const char *uri) config_destroy(&cfg); #else jerror(&err, "Failed to parse configuration file"); -#endif /* WITH_CONFIG */ +#endif /* LIBCONFIG_FOUND */ } /* Close configuration file */ diff --git a/lib/web.c b/lib/web.c index a9b3d9030..106dc4e34 100644 --- a/lib/web.c +++ b/lib/web.c @@ -58,14 +58,14 @@ lws_callback_function websocket_protocol_cb; .rx_buffer_size = 0 }, #endif /* WITH_API */ -#ifdef WITH_NODE_WEBSOCKET +#ifdef LIBWEBSOCKETS_FOUND { .name = "live", .callback = websocket_protocol_cb, .per_session_data_size = sizeof(struct websocket_connection), .rx_buffer_size = 0 }, -#endif /* WITH_NODE_WEBSOCKET */ +#endif /* LIBWEBSOCKETS_FOUND */ #if 0 /* not supported yet */ { .name = "log", diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt new file mode 100644 index 000000000..dac32b74a --- /dev/null +++ b/packaging/CMakeLists.txt @@ -0,0 +1,56 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +if (NOT DEFINED DEPLOY_USER) + set(DEPLOY_USER deploy) +endif() + +if (NOT DEFINED DEPLOY_HOST) + set(DEPLOY_USER acs-os-fein-website) +endif() + +if (NOT DEFINED DEPLOY_PATH) + set(DEPLOY_USER /var/www/villas/node) +endif() + +add_custom_target(deploy-dist + COMMAND rsync ${CMAKE_BINARY_DIR}/*.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/src +) + +add_custom_target(deploy-rpm + COMMAND rsync -a --progress ${CMAKE_BINARY_DIR}/*.rpm ${DEPLOY_USER}@${DEPLOY_HOST}:/var/www/packages/redhat/ + COMMAND ssh ${DEPLOY_USER}@${DEPLOY_HOST} createrepo /var/www/packages/redhat +) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/libvillas.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libvillas.pc + @ONLY +) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libvillas.pc + COMPONENT devel + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig +) + +add_subdirectory(docker) diff --git a/packaging/Makefile.inc b/packaging/Makefile.inc deleted file mode 100644 index f945f14eb..000000000 --- a/packaging/Makefile.inc +++ /dev/null @@ -1,56 +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 . -################################################################################### - -TAR_OPTS = --exclude-ignore-recursive=$(SRCDIR)/.distignore --transform='s|^\.|villas-node-$(VERSION_NUM)|' --show-transformed-names - -TAR_VILLAS = $(BUILDDIR)/packaging/villas-node-$(VERSION_NUM)-$(RELEASE).tar.gz - -DEPLOY_USER ?= deploy -DEPLOY_HOST ?= acs-os-fein-website -DEPLOY_PATH ?= /var/www/villas/node - -packaging: rpm dist - -deploy: deploy-dist deploy-rpm deploy-docker - -# Source tarballs -dist: $(TAR_VILLAS) - -$(TAR_VILLAS): | $$(dir $$@) - tar $(TAR_OPTS) -C $(SRCDIR) -czf $@ . - -deploy-dist: $(TAR_VILLAS) - rsync $(TAR_VILLAS) $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)/src - -deploy-rpm: - rsync -a --progress $(BUILDDIR)/../Linux-x86_64-release/packaging/rpm/RPMS/ $(DEPLOY_USER)@$(DEPLOY_HOST):/var/www/packages/redhat/ - ssh $(DEPLOY_USER)@$(DEPLOY_HOST) createrepo /var/www/packages/redhat - -clean-packaging: - rm -f $(BUILDDIR)/packaging/villas-node-$(VERSION_NUM).tar.gz - -install-packaging: - -.PHONY: packaging install-packaging clean-packaging deploy deploy-dist deploy-rpm dist $(TAR_VILLAS) - -include packaging/rpm/Makefile.inc -include packaging/docker/Makefile.inc diff --git a/packaging/docker/CMakeLists.txt b/packaging/docker/CMakeLists.txt new file mode 100644 index 000000000..8ac13b4ff --- /dev/null +++ b/packaging/docker/CMakeLists.txt @@ -0,0 +1,84 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +set(DOCKER_FILE Dockerfile) +set(DOCKER_IMAGE villas/node) +set(DOCKER_TAG ${GIT_BRANCH}) +set(DOCKER_RUN_OPTS + --interactive + --tty + --publish 80:80 + --publish 443:443 + --publish 12000:12000/udp + --publish 12001:12001/udp + --publish 2345:2345 + --privileged + --security-opt seccomp:unconfined + --volume \"${CMAKE_SOURCE_DIR}:/villas\" +) + +foreach(SUFFIX app dev dev-centos dev-ubuntu) + add_custom_target(deploy-docker-${SUFFIX} + COMMAND docker push ${DOCKER_IMAGE}-${SUFFIX}:${DOCKER_TAG} + COMMAND docker push ${DOCKER_IMAGE}-${SUFFIX}:latest + ) + + add_custom_target(run-docker-${SUFFIX} + COMMAND docker run ${DOCKER_RUN_OPTS} ${DOCKER_IMAGE}-${SUFFIX}:${DOCKER_TAG} + ) + + add_custom_target(docker-${SUFFIX} + COMMAND docker build + --file ${CMAKE_CURRENT_SOURCE_DIR}/Dockerfile.${SUFFIX} + --tag ${DOCKER_IMAGE}-${SUFFIX}:${DOCKER_TAG} + --tag ${DOCKER_IMAGE}-${SUFFIX}:latest + --build-arg BUILDER_IMAGE=${DOCKER_IMAGE}-dev:${DOCKER_TAG} + --build-arg DOCKER_TAG=${DOCKER_TAG} + --build-arg GIT_BRANCH=${GIT_BRANCH} + --build-arg GIT_REV=${GIT_REV} + --build-arg VERSION=${PROJECT_VERSION} + --build-arg VARIANT=${VARIANT} + ${DOCKER_BUILD_OPTS} ${CMAKE_SOURCE_DIR} + ) + + add_dependencies(deploy-docker-${SUFFIX} docker-${SUFFIX}) + add_dependencies(run-docker-${SUFFIX} docker-${SUFFIX}) +endforeach() + +# Special cases for 'docker'target +add_custom_target(run-docker + COMMAND docker run ${DOCKER_RUN_OPTS} ${DOCKER_IMAGE}:${DOCKER_TAG} node -h +) + +add_custom_target(docker + COMMAND docker tag ${DOCKER_IMAGE}-app:${DOCKER_TAG} ${DOCKER_IMAGE}:${DOCKER_TAG} + COMMAND docker tag ${DOCKER_IMAGE}-app:${DOCKER_TAG} ${DOCKER_IMAGE}:latest +) + +add_custom_target(deploy-docker DEPENDS docker-app + COMMAND docker push ${DOCKER_IMAGE}:${DOCKER_TAG} + COMMAND docker push ${DOCKER_IMAGE}:latest +) + +add_dependencies(docker docker-app) +add_dependencies(deploy-docker deploy-docker-app) +add_dependencies(run-docker docker) diff --git a/packaging/docker/Dockerfile.app b/packaging/docker/Dockerfile.app index 950c3a7cb..8128abb9c 100644 --- a/packaging/docker/Dockerfile.app +++ b/packaging/docker/Dockerfile.app @@ -1,11 +1,11 @@ -# Dockerfile for VILLASnode dependencies. +# Dockerfile # -# This Dockerfile builds an image which contains all library dependencies -# and tools to build VILLASnode. -# However, VILLASnode itself it not part of the image. +# This image can be used for running VILLASnode +# by running: +# make docker # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -25,45 +25,29 @@ ################################################################################### ARG BUILDER_IMAGE=villas/node-dev +ARG DOCKER_TAG=latest +ARG GIT_REV=unknown +ARG GIT_BRANCH=unknown +ARG VERSION=unknown +ARG VARIANT=unknown # This image is built by villas-node-git/packaging/docker/Dockerfile.dev -FROM villas/node-dev:develop AS builder +FROM $BUILDER_IMAGE AS builder -COPY . /villas-node/ +COPY . /villas/ -RUN rm -rf /villas-node/build -WORKDIR /villas-node - -#RUN dnf -y install - -RUN make -j2 rpm-villas-node +RUN rm -rf /villas/build && mkdir /villas/build +WORKDIR /villas/build +RUN cmake -DCPACK_GENERATOR=RPM .. +RUN make -j$(nproc) doc +RUN make -j$(nproc) package FROM fedora:28 - -ARG GIT_REV=unkown -ARG GIT_BRANCH=unkown -ARG VERSION=unkown -ARG VARIANT=unkown # Some of the dependencies are only available in our own repo ADD https://packages.fein-aachen.org/redhat/fein.repo /etc/yum.repos.d/ -# Usually the following dependecies would be resolved by dnf -# when installing villas-node. -# We add them here to utilise Dockers caching and layer feature -# in order reduce bandwidth and space usage. -RUN dnf -y install \ - openssl \ - libconfig \ - libnl3 \ - libcurl \ - jansson \ - iproute \ - module-init-tools - -ADD https://villas.fein-aachen.org/packages/villas.repo /etc/yum.repos.d/ - -COPY --from=builder /villas-node/build/Linux-x86_64-release/packaging/rpm/RPMS/x86_64/*.rpm /tmp/ +COPY --from=builder /villas/build/*.rpm /tmp/ RUN dnf -y install /tmp/*.rpm # For WebSocket / API access diff --git a/packaging/docker/Dockerfile.dev b/packaging/docker/Dockerfile.dev index 20fee6ef9..33045f21d 100644 --- a/packaging/docker/Dockerfile.dev +++ b/packaging/docker/Dockerfile.dev @@ -6,10 +6,10 @@ # # This image can be used for developing VILLASnode # by running: -# make docker +# make docker-dev # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -30,17 +30,15 @@ FROM fedora:28 -ARG GIT_REV=unkown -ARG GIT_BRANCH=unkown -ARG VERSION=unkown -ARG VARIANT=unkown +ARG GIT_REV=unknown +ARG GIT_BRANCH=unknown +ARG VERSION=unknown +ARG VARIANT=unknown # Toolchain RUN dnf -y install \ gcc gcc-c++ \ - pkgconfig make cmake \ - autoconf automake autogen libtool \ - flex bison \ + pkgconfig cmake make ninja-build \ texinfo git curl tar \ protobuf-compiler protobuf-c-compiler @@ -64,6 +62,11 @@ RUN pip install \ # Some of the dependencies are only available in our own repo ADD https://packages.fein-aachen.org/redhat/fein.repo /etc/yum.repos.d/ +# We need to use our own RPM packages of libwebsockets +# as the official ones do contain the CMake files +RUN dnf -y install --repo=villas \ + libwebsockets-2.4.2 + # Dependencies RUN dnf -y install \ openssl openssl-devel \ @@ -71,9 +74,9 @@ RUN dnf -y install \ libnl3-devel \ libcurl-devel \ jansson-devel \ - libwebsockets-devel \ zeromq-devel \ nanomsg-devel \ + protobuf-devel \ protobuf-c-devel \ libiec61850-devel \ librabbitmq-devel \ diff --git a/packaging/docker/Dockerfile.dev-centos b/packaging/docker/Dockerfile.dev-centos index 575ba79c6..505aa27bf 100644 --- a/packaging/docker/Dockerfile.dev-centos +++ b/packaging/docker/Dockerfile.dev-centos @@ -30,10 +30,10 @@ FROM centos:7 -ARG GIT_REV=unkown -ARG GIT_BRANCH=unkown -ARG VERSION=unkown -ARG VARIANT=unkown +ARG GIT_REV=unknown +ARG GIT_BRANCH=unknown +ARG VERSION=unknown +ARG VARIANT=unknown # Some of the dependencies are only available in our own repo ADD https://villas.fein-aachen.org/packages/villas.repo /etc/yum.repos.d/ diff --git a/packaging/docker/Dockerfile.dev-ubuntu b/packaging/docker/Dockerfile.dev-ubuntu index 32685b9d4..9541bf283 100644 --- a/packaging/docker/Dockerfile.dev-ubuntu +++ b/packaging/docker/Dockerfile.dev-ubuntu @@ -32,10 +32,10 @@ FROM ubuntu:xenial #FROM debian:jessie -ARG GIT_REV=unkown -ARG GIT_BRANCH=unkown -ARG VERSION=unkown -ARG VARIANT=unkown +ARG GIT_REV=unknown +ARG GIT_BRANCH=unknown +ARG VERSION=unknown +ARG VARIANT=unknown # Toolchain RUN apt-get update && apt-get install -y \ diff --git a/packaging/docker/Makefile.inc b/packaging/docker/Makefile.inc deleted file mode 100644 index 599a6afce..000000000 --- a/packaging/docker/Makefile.inc +++ /dev/null @@ -1,74 +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 . -################################################################################### - -DOCKER = docker - -DOCKER_FILE ?= Dockerfile -DOCKER_IMAGE ?= villas/node -DOCKER_TAG ?= $(GIT_BRANCH) - -DOCKER_TARGETS = docker-app docker-dev docker-dev-centos docker-dev-ubuntu -DOCKER_RUN_TARGETS = $(addprefix run-,$(DOCKER_TARGETS)) -DOCKER_DEPLOY_TARGETS = $(addprefix deploy-,$(DOCKER_TARGETS)) - -ifneq ($(CI_COMMIT_TAG),) - DOCKER_OPTS += --tag $(DOCKER_IMAGE)-$*:$(CI_COMMIT_TAG) -endif - -DOCKER_RUN_OPTS = --interactive --tty \ - --publish 80:80 --publish 443:443 --publish 12000:12000/udp --publish 12001:12001/udp \ - --privileged --security-opt seccomp:unconfined --volume "$(SRCDIR):/villas" - -# Special cases for 'docker'target -run-docker: run-docker-app -deploy-docker: deploy-docker-app -docker: docker-app - $(DOCKER) tag $(DOCKER_IMAGE)-app:$(DOCKER_TAG) $(DOCKER_IMAGE):$(DOCKER_TAG) - $(DOCKER) tag $(DOCKER_IMAGE)-app:$(DOCKER_TAG) $(DOCKER_IMAGE):latest - -.PHONY: docker run-docker deploy-docker - -$(DOCKER_DEPLOY_TARGETS): deploy-docker-%: docker-% - $(DOCKER) push $(DOCKER_IMAGE)-$*:$(DOCKER_TAG) - -$(DOCKER_RUN_TARGETS): run-docker-%: docker-% - $(DOCKER) run $(DOCKER_RUN_OPTS) $(DOCKER_IMAGE)-$*:$(DOCKER_TAG) - -$(DOCKER_TARGETS): docker-%: $(BUILDDIR)/packaging/docker/Image.% - -# The docker build targets use the --iidfile option to write the newly build image -# id to an file. Make is using the modification timestamp of this file and the Dockerfile -# to determine when the image needs to be rebuild. -$(BUILDDIR)/packaging/docker/Image.%: packaging/docker/Dockerfile.% | $(BUILDDIR)/packaging/docker/ - $(DOCKER) build \ - --file $< --iidfile $@ \ - --tag $(DOCKER_IMAGE)-$*:$(DOCKER_TAG) \ - --tag $(DOCKER_IMAGE)-$*:latest \ - --build-arg BUILDER_IMAGE=$(DOCKER_IMAGE)-dev:$(DOCKER_TAG) \ - --build-arg DOCKER_TAG=${DOCKER_TAG} \ - --build-arg GIT_BRANCH=${GIT_BRANCH} \ - --build-arg GIT_REV=${GIT_REV} \ - --build-arg VERSION=${VERSION} \ - --build-arg VARIANT=${VARIANT} \ - $(DOCKER_OPTS) $(SRCDIR) - -.PHONY: $(DOCKER_TARGETS) $(DOCKER_RUN_TARGETS) $(DOCKER_DEPLOY_TARGETS) diff --git a/packaging/libvillas.pc.in b/packaging/libvillas.pc.in new file mode 100644 index 000000000..512fbcf78 --- /dev/null +++ b/packaging/libvillas.pc.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@CMAKE_INSTALL_LIBDIR@ +sharedlibdir=@CMAKE_INSTALL_LIBDIR@ +includedir=@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -L${sharedlibdir} -lz +Cflags: -I${includedir} diff --git a/packaging/rpm/libiec61850.spec b/packaging/rpm/libiec61850.spec deleted file mode 100644 index 4e0b9d42f..000000000 --- a/packaging/rpm/libiec61850.spec +++ /dev/null @@ -1,70 +0,0 @@ -Name: libiec61850 -Version: 1.2 -Vendor: MZ Automation -Packager: Steffen Vogel -Release: 1%{?dist} -Summary: Open source libraries for IEC 61850 and IEC 60870-5-104 - -License: GPL-3.0 -URL: https://github.com/mz-automation/libiec61850 -#Source0: https://github.com/mz-automation/libiec61850/repository/archive.tar.gz?ref=v1.2.0 -Source0: libiec61850_1.2.0.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) - -BuildRequires: gcc cmake - -%description - -IEC 61850 is an international standard for communication systems in Substation Automation Systems (SAS) and management of Decentralized Energy Resources (DER). -It is seen as one of the communication standards of the emerging Smart Grid. -Despite of its complexity and other drawbacks that make it difficult to implement and to use, the protocol is the only one of its kind that is in widespread use by utility companies and equipment manufacturers. - -The project libIEC61850 provides a server and client library for the IEC 61850/MMS, IEC 61850/GOOSE and IEC 61850-9-2/Sampled Values communication protocols written in C. -It is available under the GPLv3 license. With this library available everybody can now become easily familiar with IEC 61850. -A tabular overview of the provided IEC 61850 ACSI services is available on the project website. - -The library is designed according to edition 2 of the IEC 61850 standard series, but should be compatible to edition 1 in most cases. - -%package devel - -Summary: Headers and libraries for building apps that use libiec61850 -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel - -The development headers for libiec61850. - -%prep -%setup -q -n libiec61850_1.2.0/ - -%build -mkdir -p build -cd build -rm CMakeCache.txt -%cmake -DCMAKE_INSTALL_LIBDIR=${_libdir} -DBUILD_EXAMPLES=0 -DBUILD_PYTHON_BINDINGS=0 .. -make %{?_smp_mflags} - -%install -rm -rf $RPM_BUILD_ROOT -cd build -make install DESTDIR=$RPM_BUILD_ROOT - -%post -p /sbin/ldconfig -%postun -p /sbin/ldconfig - -%clean -rm -rf $RPM_BUILD_ROOT - -%files -%{_prefix}/lib/libiec61850.so.1.2.0 -%{_prefix}/lib/libiec61850.so - -%files devel -%{_includedir}/libiec61850/* -%{_prefix}/share/pkgconfig/libiec61850.pc -%{_prefix}/lib/libiec61850.a - -%changelog -* Mon Nov 6 2017 Steffen Vogel - 1.0.0-1 -- Updated to 1.0.0 final release -- nanomsg moved to CMake, so this spec did too -- Changed source URL -- Moved contents of -doc package into -devel -- Removed conditional check, all tests should pass -- The nanocat symlink stuff is gone, nanocat is now a single binary with options - -* Tue Oct 27 2015 Japheth Cleaver 0.7-0.1.beta -- update to 0.7-beta release - -* Fri Nov 14 2014 Japheth Cleaver 0.5-0.1.beta -- update to 0.5-beta release - -* Sun Jul 27 2014 Japheth Cleaver 0.4-0.3.beta -- compile with correct Fedora flags -- move documentation back to base package -- spec file cleanups - -* Thu Jul 17 2014 Japheth Cleaver 0.4-0.2.beta -- drop the 'lib' prefix from package name -- remove explicit pkgconfig requires in nanomsg-devel -- move overview man pages to devel subpackage -- move html to doc subpackage - -* Thu Jul 17 2014 Japheth Cleaver 0.4-0.1.beta -- new "libnanomsg" package based on BZ#1012392, with current versioning -- devel and utils subpackages created, static lib a build conditional -- check section added as a build conditional -- ensure man pages for nanocat symlinks present -- disable RPATH in library -- License set to MIT diff --git a/packaging/rpm/villas-node.spec b/packaging/rpm/villas-node.spec deleted file mode 100644 index 71a8a3255..000000000 --- a/packaging/rpm/villas-node.spec +++ /dev/null @@ -1,89 +0,0 @@ -Name: villas-node -Version: §VERSION§ -Vendor: Institute for Automation of Complex Power Systems -Packager: Steffen Vogel -Release: §RELEASE§%{?dist} -Summary: This is VILLASnode, a gateway for processing and forwardning simulation data between real-time simulators. - -License: GPLv3 -URL: https://git.rwth-aachen.de/VILLASframework/VILLASnode -Source0: villas-node-§VERSION§-§RELEASE§.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) - -BuildRequires: gcc pkgconfig make - -Requires: iproute module-init-tools - -BuildRequires: openssl-devel libconfig-devel libnl3-devel libcurl-devel jansson-devel libwebsockets-devel zeromq-devel nanomsg-devel libiec61850-devel librabbitmq-devel mosquitto-devel comedilib-devel comedilib -Requires: openssl libconfig libnl3 libcurl jansson libwebsockets zeromq nanomsg libiec61850 librabbitmq mosquitto comedilib - -%description - -%package doc - -Summary: HTML documentation for users and developers. -Group: Documentation - -%package devel - -Summary: Headers and libraries for building apps that use libvillas. -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel - -The development headers for libvillas. - -%description doc - -%prep -%setup -q - -%build -make DEBUG=1 PREFIX=/usr - -%install -rm -rf %{?buildroot} -make DEBUG=1 PREFIX=/usr DESTDIR=%{?buildroot} install -make DEBUG=1 PREFIX=/usr DESTDIR=%{?buildroot} install-doc - -%check -make DEBUG=1 run-unit-tests -make DEBUG=1 run-integration-tests - -%post -p /sbin/ldconfig -%postun -p /sbin/ldconfig - -%clean -rm -rf %{?buildroot} - -%files -/usr/bin/rmsem -/usr/bin/rmshm -/usr/bin/villas -/usr/bin/villas-* -/usr/bin/conf2json -/usr/bin/zmq-keygen - -/usr/lib/libvillas.so -/usr/lib/libvillas.so.* - -/usr/lib/libvillas-ext.so -/usr/lib/libvillas-ext.so.* - -/usr/share/villas/node/web/ -/usr/share/villas/node/plugins/ - -%config /etc/villas/node/*.conf -%license COPYING.md - -%files doc -%docdir /usr/share/villas/node/doc/ -/usr/share/villas/node/doc/ - -%files devel -/usr/include/villas/ - -%changelog -* Fri Mar 17 2017 Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +# Plugins +link_libraries(villas) +include_directories("${CMAKE_SOURCE_DIR}/include") +add_definitions("-DVILLAS") + +add_library(simple_circuit MODULE models/simple_circuit.c) +install( + TARGETS simple_circuit + COMPONENT plugins + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/villas/node/plugins +) + +if(WITH_HOOKS) + add_library(example_hook MODULE hooks/example_hook.c) + install( + TARGETS example_hook + COMPONENT plugins + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/villas/node/plugins + ) +endif() diff --git a/plugins/Makefile.inc b/plugins/Makefile.inc deleted file mode 100644 index c8e45e9fb..000000000 --- a/plugins/Makefile.inc +++ /dev/null @@ -1,55 +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 . -################################################################################### - -# Plugins -PLUGINS = $(BUILDDIR)/simple_circuit.so - -ifeq ($(WITH_HOOKS),1) - PLUGINS += $(BUILDDIR)/example_hook.so -endif - -PLUGIN_CFLAGS = -fPIC -DVILLAS -I../include/villas -PLUGIN_LDFLAGS = -shared -L$(BUILDDIR) -PLUGIN_LDLIBS = -lvillas - -# Dependencies for plugins -$(BUILDDIR)/example_hook.so: $(BUILDDIR)/plugins/hooks/example_hook.o -$(BUILDDIR)/simple_circuit.so: $(BUILDDIR)/plugins/models/simple_circuit.o - -plugins: $(PLUGINS) - -# Compile -$(BUILDDIR)/plugins/%.o: plugins/%.c | $$(dir $$@) - $(CC) $(CFLAGS) $(PLUGIN_CFLAGS) -c $< -o $@ - -# Link -$(PLUGINS): - $(CC) $(PLUGIN_LDFLAGS) -o $@ $^ $(PLUGIN_LDLIBS) - -# Plugins are not installed to the system for now... -install-plugins: plugins | $(DESTDIR)$(PREFIX)/share/villas/node/plugins/ - install -D -t $(DESTDIR)$(PREFIX)/share/villas/node/plugins $(PLUGINS) - -clean-plugins: - rm -rf $(BUILDDIR)/plugins $(PLUGINS) - -.PHONY: plugins install-plugins clean-plugins diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..538b55703 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,60 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +# All executables link against libvillas +link_libraries(villas) + +add_executable(villas-node villas-node.c) +add_executable(villas-test-rtt villas-test-rtt.c) +add_executable(villas-test-shmem villas-test-shmem.c) + +install( + TARGETS villas-node villas-test-rtt villas-test-shmem + COMPONENT bin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(WITH_IO) + add_executable(villas-test-cmp villas-test-cmp.c) + add_executable(villas-convert villas-convert.c) + add_executable(villas-pipe villas-pipe.c) + add_executable(villas-signal villas-signal.c) + + target_link_libraries(villas-pipe PUBLIC Threads::Threads) + + install( + TARGETS villas-convert villas-pipe villas-signal villas-test-cmp + COMPONENT bin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +endif() + +if(WITH_IO AND WITH_HOOKS) + add_executable(villas-hook villas-hook.c) + + install( + TARGETS villas-hook + COMPONENT bin + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +endif() + diff --git a/src/Makefile.inc b/src/Makefile.inc deleted file mode 100644 index c7a26614e..000000000 --- a/src/Makefile.inc +++ /dev/null @@ -1,66 +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 . -################################################################################### - -# Executables -TARGETS = $(BUILDDIR)/villas-node \ - $(BUILDDIR)/villas-test-rtt \ - $(BUILDDIR)/villas-test-shmem \ - $(BUILDDIR)/villas-convert - -ifeq ($(WITH_IO),1) - ifeq ($(WITH_HOOKS),1) - TARGETS += $(BUILDDIR)/villas-hook - endif - - TARGETS += $(BUILDDIR)/villas-pipe \ - $(BUILDDIR)/villas-signal \ - $(BUILDDIR)/villas-test-cmp -endif - -SRC_LDLIBS = $(LDLIBS) -pthread -lm -lvillas -SRC_CFLAGS = $(CFLAGS) -SRC_LDFLAGS = $(LDFLAGS) -Wl,-rpath,'$$ORIGIN' - -src: $(TARGETS) - -$(TARGETS): $(BUILDDIR)/villas-%: $(BUILDDIR)/src/%.o - -# Compile executable objects -$(BUILDDIR)/src/%.o: src/%.c | $$(dir $$@) - $(CC) $(SRC_CFLAGS) -c $< -o $@ - -# Build villas-shmem only with libvillas-ext (to ensure that libext contains everything needed) -$(BUILDDIR)/villas-shmem: $(BUILDDIR)/src/shmem.o libvillas-ext - $(CC) $(SRC_LDFLAGS) $(BUILDDIR)/src/shmem.o $(filter-out -lvillas,$(SRC_LDLIBS)) -lvillas-ext -o $@ - -# Link target executables -$(TARGETS): | $(LIBS) - $(CC) $(SRC_LDFLAGS) $^ $(SRC_LDLIBS) -o $@ - -# Install -install-src: src - install -m 0755 -D -t $(DESTDIR)$(PREFIX)/bin $(TARGETS) - -clean-src: - rm -rf $(BUILDDIR)/src $(TARGETS) - -.PHONY: src src-tests src-tests diff --git a/src/convert.c b/src/villas-convert.c similarity index 100% rename from src/convert.c rename to src/villas-convert.c diff --git a/src/hook.c b/src/villas-hook.c similarity index 100% rename from src/hook.c rename to src/villas-hook.c diff --git a/src/node.c b/src/villas-node.c similarity index 100% rename from src/node.c rename to src/villas-node.c diff --git a/src/pipe.c b/src/villas-pipe.c similarity index 99% rename from src/pipe.c rename to src/villas-pipe.c index ee27df078..7b387645e 100644 --- a/src/pipe.c +++ b/src/villas-pipe.c @@ -341,13 +341,13 @@ check: if (optarg == endptr) if (!node) error("Node '%s' does not exist!", nodestr); -#ifdef WITH_NODE_WEBSOCKET +#ifdef LIBWEBSOCKETS_FOUND /* Only start web subsystem if villas-pipe is used with a websocket node */ if (node->_vt->start == websocket_start) { web_start(&sn.web); api_start(&sn.api); } -#endif /* WITH_NODE_WEBSOCKET */ +#endif /* LIBWEBSOCKETS_FOUND */ if (reverse) node_reverse(node); diff --git a/src/signal.c b/src/villas-signal.c similarity index 100% rename from src/signal.c rename to src/villas-signal.c diff --git a/src/test-cmp.c b/src/villas-test-cmp.c similarity index 100% rename from src/test-cmp.c rename to src/villas-test-cmp.c diff --git a/src/test-rtt.c b/src/villas-test-rtt.c similarity index 100% rename from src/test-rtt.c rename to src/villas-test-rtt.c diff --git a/src/test-shmem.c b/src/villas-test-shmem.c similarity index 100% rename from src/test-shmem.c rename to src/villas-test-shmem.c diff --git a/packaging/rpm/Makefile.inc b/tests/CMakeLists.txt similarity index 51% rename from packaging/rpm/Makefile.inc rename to tests/CMakeLists.txt index 230ded665..03bb103c4 100644 --- a/packaging/rpm/Makefile.inc +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ # Makefile. # # @author Steffen Vogel -# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @copyright 2018, Institute for Automation of Complex Power Systems, EONERC # @license GNU General Public License (version 3) # # VILLASnode @@ -20,25 +20,23 @@ # along with this program. If not, see . ################################################################################### -RPMDIR = $(BUILDDIR)/packaging/rpm +add_subdirectory(unit) +add_subdirectory(integration) -SPEC_VILLAS = $(BUILDDIR)/packaging/rpm/villas-node.spec +add_custom_target(tests + DEPENDS unit-tests integration-tests +) -rpm: rpm-villas-node +add_custom_target(run-tests + DEPENDS run-unit-tests run-integration-tests +) -rpm-villas-node: $(TAR_VILLAS) $(SPEC_VILLAS) | $(RPMDIR)/SOURCES/ - cp $(TAR_VILLAS) $(RPMDIR)/SOURCES - rpmbuild -ba --define="_topdir $$(pwd)/$(RPMDIR)" $(BUILDDIR)/packaging/rpm/villas-node.spec +set(VALGRIND "valgrind --leak-check=full --show-leak-kinds=all --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp") -# We patch version number and release fields of the spec file based on the current Git commit -$(SPEC_VILLAS): packaging/rpm/villas-node.spec | $$(dir $$@) - sed -e "s/§VERSION§/$(VERSION_NUM)/g" \ - -e "s/§RELEASE§/$(RELEASE)/g" < $^ > $@ - -sign-rpm: - rpmsign $(RPMDIR)/RPMS/*/.rpm - -clean-rpm: - rm -rf $(RPMDIR) - -.PHONY: rpm clean-rpm rpm-libwebsockets rpm-libxil $(SPEC_VILLAS) +add_custom_target(run-valgrind + COMMAND ${VALGRIND} $ & sleep 2; kill %1 + COMMAND ${VALGRIND} $ -t 2 ${CMAKE_SOURCE_DIR}/etc/websocket-loopback.conf ws1 + COMMAND ${VALGRIND} $ mixed -v 4 -l 10 + COMMAND ${VALGRIND} $ stats < <($ mixed -l 5) + DEPENDS villas-node villas-pipe villas-signal villas-hook +) diff --git a/tests/Makefile.inc b/tests/Makefile.inc deleted file mode 100644 index 6f7c61178..000000000 --- a/tests/Makefile.inc +++ /dev/null @@ -1,43 +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 . -################################################################################### - -include tests/unit/Makefile.inc - -ifdef COVERAGE - include tests/unit/Makefile.gcov.inc -endif - -include tests/integration/Makefile.inc - -tests: unit-tests integration-tests - -run-tests: run-unit-tests run-integration-tests run-valgrind - -VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --suppressions=$(SRCDIR)/tests/valgrind.supp - -run-valgrind: src - $(VALGRIND) $(BUILDDIR)/villas-node & sleep 2; kill %1 - $(VALGRIND) $(BUILDDIR)/villas-pipe -t 2 $(SRCDIR)/etc/websocket-loopback.conf ws1 - $(VALGRIND) $(BUILDDIR)/villas-signal mixed -v 4 -l 10 - $(VALGRIND) $(BUILDDIR)/villas-hook stats < <($(BUILDDIR)/villas-signal mixed -l 5) - -.PHONY: tests run-tests run-valgrind diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt new file mode 100644 index 000000000..1cd7fb6df --- /dev/null +++ b/tests/integration/CMakeLists.txt @@ -0,0 +1,33 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +add_custom_target(run-integration-tests + COMMAND + SRCDIR=${CMAKE_SOURCE_DIR} + BUILDDIR=${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/tools/integration-tests.sh + DEPENDS + villas-node + villas-pipe + villas-signal + villas-hook +) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt new file mode 100644 index 000000000..1bae9350b --- /dev/null +++ b/tests/unit/CMakeLists.txt @@ -0,0 +1,57 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +if(CRITERION_FOUND) + + set(TEST_SRC + advio.c + bitset.c + config_json.c + hist.c + io.c + json.c + kernel.c + list.c + log.c + main.c + mapping.c + memory.c + pool.c + queue.c + queue_signalled.c + task.c + timing.c + utils.c + ) + + add_executable(unit-tests ${TEST_SRC}) + target_link_libraries(unit-tests PUBLIC + ${CRITERION_LIBRARIES} + villas + Threads::Threads + ) + + add_custom_target(run-unit-tests + COMMAND $ ${CRITERION_OPTS} + DEPENDS unit-tests + ) +endif() diff --git a/tests/unit/Makefile.gcov.inc b/tests/unit/Makefile.gcov.inc deleted file mode 100644 index 973ee2a48..000000000 --- a/tests/unit/Makefile.gcov.inc +++ /dev/null @@ -1,56 +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 . -################################################################################### - -COVERAGE_TESTS = $(BUILDDIR)/unit-tests -COVERAGE_OBJS = $(LIB_OBJS) $(SRC_OBJS) - -GCDAS = $(COVERAGE_OBJS:.o=.gcda) -GCNOS = $(COVERAGE_OBJS:.o=.gcno) - -GCOVR_OPTS = --exclude $(SRCDIR)/include --root $(SRCDIR) --sort-percentage --print-summary - -coverage: $(BUILDDIR)/coverage/index.html $(BUILDDIR)/coverage.xml $(BUILDDIR)/coverage.txt - -$(BUILDDIR)/coverage.txt: $(addsuffix .gcdas,$(COVERAGE_TESTS)) | $$(dir $$@) - gcovr $(GCOVR_OPTS) -o $@ - -$(BUILDDIR)/coverage.xml: $(addsuffix .gcdas,$(COVERAGE_TESTS)) | $$(dir $$@) - gcovr $(GCOVR_OPTS) --xml --xml-pretty -o $@ - -$(BUILDDIR)/coverage/index.html: $(addsuffix .gcdas,$(COVERAGE_TESTS)) | $$(dir $$@) - gcovr $(GCOVR_OPTS) --html --html-details -o $@ - -# This is an intermediate target. It is used to run the test only once for all gcovr rules. -%.gcdas: % - @echo "Delete previous coverage information" - rm -f $(GCDAS) - @echo "Run $< for collecting coverage information (.gcda)" - $^ $(CRITERION_OPTS) - -clean-coverage: - rm -rf $(BUILDDIR)/coverage $(BUILDDIR)/coverage.txt $(BUILDDIR)/coverage.xml - rm -f $(GCDAS) - -install-coverage: - -.INTERMEDIATE: $(addsuffix .gcdas,$(COVERAGE_TESTS)) -.PHONY: coverage gcda clean-coverage install-coverage diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc deleted file mode 100644 index ae50469fd..000000000 --- a/tests/unit/Makefile.inc +++ /dev/null @@ -1,49 +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 . -################################################################################### - -TEST_SRCS = $(wildcard tests/unit/*.c) -TEST_OBJS = $(patsubst %.c,$(BUILDDIR)/%.o,$(TEST_SRCS)) - -TEST_CFLAGS = $(CFLAGS) -TEST_LDFLAGS = $(LDFLAGS) -Wl,-rpath,'$$ORIGIN' -TEST_LDLIBS = $(LDLIBS) -lcriterion -lvillas -pthread -ljansson - -unit-tests: $(BUILDDIR)/unit-tests - -run-unit-tests: tests - $(BUILDDIR)/unit-tests $(CRITERION_OPTS) - -# Compile -$(BUILDDIR)/tests/unit/%.o: tests/unit/%.c $(BUILDDIR)/include/villas/config.h | $$(dir $$@) - $(CC) $(TEST_CFLAGS) -c $< -o $@ - -# Link -$(BUILDDIR)/unit-tests: $(TEST_OBJS) $(LIB) - $(CC) $(TEST_LDFLAGS) $^ $(TEST_LDLIBS) -o $@ - -# Tests are not installed -install-tests: - -clean-tests: - rm -rf $(BUILDDIR)/tests $(BUILDDIR)/testsuite - -.PHONY: unit-tests install-unit-tests clean-unit-tests run-unit-tests diff --git a/tests/unit/config_json.c b/tests/unit/config_json.c index fff947dd4..274e653ff 100644 --- a/tests/unit/config_json.c +++ b/tests/unit/config_json.c @@ -22,7 +22,7 @@ #include -#ifdef WITH_LIBCONFIG +#ifdef LIBCONFIG_FOUND #include #include @@ -117,4 +117,4 @@ Test(utils, json_to_config) json_decref(json); } -#endif +#endif /* LIBCONFIG_FOUND */ diff --git a/tests/unit/io.c b/tests/unit/io.c index 4abdc57a2..cf8d5e162 100644 --- a/tests/unit/io.c +++ b/tests/unit/io.c @@ -39,10 +39,10 @@ #define NUM_VALUES 10 static char formats[][32] = { -#ifdef WITH_FORMAT_HDF5 +#ifdef LIBHDF5_FOUND "hdf5", #endif -#ifdef WITH_FORMAT_PROTOBUF +#ifdef LIBPROTOBUF_FOUND "protobuf", #endif "raw.int8", diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..107c7bfae --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,61 @@ +# CMakeLists. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +if(LIBCONFIG_FOUND) + add_executable(conf2json conf2json.c) + target_link_libraries(conf2json PUBLIC villas) + + list(APPEND TOOLS conf2json) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_executable(rmshm rmshm.c) + target_link_libraries(rmshm PUBLIC Threads::Threads rt) + + add_executable(rmsem rmsem.c) + target_link_libraries(rmsem PUBLIC Threads::Threads rt) + + list(APPEND TOOLS rmsem rmshm) +endif() + +if(LIBZMQ_FOUND) + add_executable(zmq-keygen zmq-keygen.c) + target_include_directories(zmq-keygen PUBLIC ${LIBZMQ_INCLUDE_DIRS}) + target_link_libraries(zmq-keygen PUBLIC PkgConfig::LIBZMQ) + + list(APPEND TOOLS zmq-keygen) +endif() + +install( + TARGETS ${TOOLS} + COMPONENT tools + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +install( + PROGRAMS villas.sh + COMPONENT bin + DESTINATION ${CMAKE_INSTALL_BINDIR} + RENAME villas +) diff --git a/tools/Makefile.inc b/tools/Makefile.inc deleted file mode 100644 index da01a51ba..000000000 --- a/tools/Makefile.inc +++ /dev/null @@ -1,61 +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 . -################################################################################### - -ifeq ($(WITH_CONFIG),1) -ifeq ($(shell $(PKGCONFIG) libconfig; echo $$?),0) - TOOLS += $(BUILDDIR)/conf2json -endif -endif - -TOOLS_CFLAGS = $(CFLAGS) -TOOLS_LDLIBS = $(LDLIBS) -lconfig -ljansson -lvillas -TOOLS_LDFLAGS = $(LDFLAGS) -Wl,-rpath,'$$ORIGIN' - -ifeq ($(shell $(PKGCONFIG) libzmq; echo $$?),0) - TOOLS += $(BUILDDIR)/zmq-keygen - TOOLS_CFLAGS += $(shell $(PKGCONFIG) --cflags libzmq) - TOOLS_LDLIBS += $(shell $(PKGCONFIG) --libs libzmq) -endif - -ifeq ($(IS_LINUX),1) - TOOLS += $(BUILDDIR)/rmshm $(BUILDDIR)/rmsem - TOOLS_LDLIBS += -lrt -pthread -endif - -# Compile executable objects -$(BUILDDIR)/tools/%.o: tools/%.c | $$(dir $$@) - $(CC) $(TOOLS_CFLAGS) -c $< -o $@ - -# Link target executables -$(TOOLS): $(BUILDDIR)/%: $(BUILDDIR)/tools/%.o | $(LIBS) - $(CC) $(TOOLS_LDFLAGS) $^ $(TOOLS_LDLIBS) -o $@ - -tools: $(TOOLS) - -clean-tools: - rm -rf $(BUILDDIR)/tools $(TOOLS) - -install-tools: $(TOOLS) - install -m 0755 tools/villas.sh $(DESTDIR)$(PREFIX)/bin/villas - install -m 0755 -D -t $(DESTDIR)$(PREFIX)/bin $(TOOLS) - -.PHONY: tools clean-tools install-tools diff --git a/tools/integration-tests.sh b/tools/integration-tests.sh index 1c2934640..f3360d1d1 100755 --- a/tools/integration-tests.sh +++ b/tools/integration-tests.sh @@ -25,13 +25,11 @@ SCRIPT=$(realpath ${BASH_SOURCE[0]}) SCRIPTPATH=$(dirname $SCRIPT) -VARIANTS=${VARIANTS:-"release"} -VARIANT=${VARIANT:-$(uname -s)-$(uname -m)-$(echo ${VARIANTS} | tr ' ' '_')} SRCDIR=${SRCDIR:-$(realpath ${SCRIPTPATH}/..)} -BUILDDIR=${BUILDDIR:-${SRCDIR}/build/${VARIANT}} +BUILDDIR=${BUILDDIR:-${SRCDIR}/build} LOGDIR=${BUILDDIR}/tests/integration -PATH=${BUILDDIR}:${PATH} +PATH=${BUILDDIR}/src:${PATH} export PATH SRCDIR BUILDDIR LOGDIR diff --git a/web/CMakeLists.txt b/web/CMakeLists.txt new file mode 100644 index 000000000..edf2cc5ed --- /dev/null +++ b/web/CMakeLists.txt @@ -0,0 +1,27 @@ +# CMakeLists.txt. +# +# @author Steffen Vogel +# @copyright 2018, 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 . +################################################################################### + +install( + DIRECTORY socket/ + COMPONENT bin + DESTINATION share/villas/node/web +) diff --git a/web/Makefile.inc b/web/Makefile.inc deleted file mode 100644 index dbfd3e647..000000000 --- a/web/Makefile.inc +++ /dev/null @@ -1,29 +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 . -################################################################################### - -install-web: - mkdir -p $(DESTDIR)$(PREFIX)/share/villas/node/web/ - cp -R $(SRCDIR)/web/socket/* $(DESTDIR)$(PREFIX)/share/villas/node/web/ - -clean-web: - -.PHONY: web install-web clean-web \ No newline at end of file