diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..819dded48 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,104 @@ +# Main CMakeLists. +# +# @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 . +################################################################################### + +cmake_minimum_required(VERSION 3.0) + +project(VILLASnode) + +set(CMAKE_C_STANDARD 11) + +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON) + +find_package(PkgConfig) +include(CheckIncludeFile) + +# Check OS +check_include_file("sys/eventfd.h" HAS_EVENTFD) + +# 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) + +set(V 2) +set(PREFIX ${CMAKE_INSTALL_PREFIX}) + +set(VARIANT "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") + +# Add git revision and build variant defines +execute_process( + COMMAND git describe --tags --abbrev=0 --match "v*" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +string(SUBSTRING ${VERSION} 2 -1 VERSION_NUM) + +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 ${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(RELEASE 1) +else() + string(REPLACE "-" "_" GIT_BRANCH_NORM ${GIT_BRANCH}) + string(REPLACE "-" "_" VARIANT_NORM ${VARIANT}) + + set(RELEASE "1.${GIT_BRANCH_NORM}_${VARIANT_NORM}.${BUILD_DATE}git${GIT_REV}") +endif() + +set(BUILDID "${VERSION}-${GIT_REV}-${VARIANT}") + +configure_file( + ${CMAKE_SOURCE_DIR}/include/villas/config.h.in + ${CMAKE_BINARY_DIR}/include/villas/config.h +) + +include_directories( + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include +) + +add_subdirectory(lib) +add_subdirectory(src) +add_subdirectory(tools) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 000000000..86f50325a --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,128 @@ +# CMakeLists. +# +# @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 . +################################################################################### + +find_package(OpenSSL REQUIRED) +find_package(curl REQUIRED) + +pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson) + +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 + 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) + +if(WITH_CONFIG) + pkg_check_modules(CONFIG IMPORTED_TARGET REQUIRED libconfig) + + list(APPEND INCLUDE_DIRS ${CONFIG_INCLUDE_DIRS}) + list(APPEND LIBRARIES PkgConfig::CONFIG) +endif() + +if(WITH_IO) + list(APPEND LIB_SRC + io.c + format_type.c + ) + + add_subdirectory(formats) + list(APPEND LIBRARIES villas-formats) +endif() + +if(WITH_HOOKS) + list(APPEND LIB_SRC + hook.c + hook_type.c + ) + + add_subdirectory(hooks) + list(APPEND LIBRARIES villas-hooks) +endif() + +if(WITH_WEB) + list(APPEND LIB_SRC + web.c + ) + + find_package(libwebsockets REQUIRED) + + message("LWS: ${LIBWEBSOCKETS_LIBRARIES}") + + 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 LIBRARIES villas-api) +endif() + +add_library(villas SHARED ${LIB_SRC}) + +target_include_directories(villas PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas PUBLIC ${LIBRARIES}) diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt new file mode 100644 index 000000000..97cc687d8 --- /dev/null +++ b/lib/api/CMakeLists.txt @@ -0,0 +1,42 @@ + +# CMakeLists. +# +# @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 . +################################################################################### + +find_package(openssl REQUIRED) + +set(INCLUDE_DIRS + ${OPENSSL_INCLUDE_DIR} +) + +set(LIBRARIES + ${OPENSSL_LIBRARIES} +) + +file(GLOB ACTION_SRC actions/*.c) + +add_library(villas-api STATIC + ${ACTION_SRC} + session.c +) + +target_include_directories(villas-api PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas-api PUBLIC ${LIBRARIES}) diff --git a/lib/formats/CMakeLists.txt b/lib/formats/CMakeLists.txt new file mode 100644 index 000000000..33670bbd1 --- /dev/null +++ b/lib/formats/CMakeLists.txt @@ -0,0 +1,82 @@ +# CMakeLists. +# +# @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 . +################################################################################### + +set(FORMAT_SRC + json.c + json_reserve.c + villas_binary.c + villas_human.c + csv.c + raw.c +) + +find_package(openssl REQUIRED) + +set(INCLUDE_DIRS + ${OPENSSL_INCLUDE_DIR} +) + +set(LIBRARIES + ${OPENSSL_LIBRARIES} +) + +# Enable Google Protobuf format +find_package(Protobuf) +if(Protobuf_FOUND) + list(APPEND FORMAT_SRC + protobuf.c + ${CMAKE_CURRENT_BINARY_DIR}/villas.pb-c.c + ) + + list(APPEND INCLUDE_DIRS + ${Protobuf_INCLUDE_DIRS} + ${Protobuf_PROTOC_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ) + + list(APPEND LIBRARIES + ${Protobuf_LIBRARY} + ${Protobuf_PROTOC_LIBRARIES} + ) + + set_source_files_properties(villas.pb-c.h villas.pb-c.c + PROPERTIES + GENERATED TRUE + ) + + add_custom_command( + COMMAND ${Protobuf_PROTOC_EXECUTABLE} --c_out=${CMAKE_CURRENT_BINARY_DIR} villas.proto + OUTPUT + villas.pb-c.c + villas.pb-c.h + MAIN_DEPENDENCY villas.proto + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endif() + +add_library(villas-formats STATIC ${FORMAT_SRC}) +target_include_directories(villas-formats PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas-formats PUBLIC ${LIBRARIES}) + +if(Protobuf_FOUND) +# add_dependencies(villas-formats villas.pb-c.c villas.pb-c.h) +endif() diff --git a/lib/hooks/CMakeLists.txt b/lib/hooks/CMakeLists.txt new file mode 100644 index 000000000..e49483d99 --- /dev/null +++ b/lib/hooks/CMakeLists.txt @@ -0,0 +1,57 @@ +# CMakeLists. +# +# @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 . +################################################################################### + +pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson) + +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(villas-hooks STATIC ${HOOK_SRC}) +target_include_directories(villas-hooks PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas-hooks PUBLIC ${LIBRARIES}) diff --git a/lib/nodes/CMakeLists.txt b/lib/nodes/CMakeLists.txt new file mode 100644 index 000000000..ce7ab8a36 --- /dev/null +++ b/lib/nodes/CMakeLists.txt @@ -0,0 +1,48 @@ +# CMakeLists. +# +# @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 . +################################################################################### + +pkg_check_modules(JANSSON IMPORTED_TARGET REQUIRED jansson) + +set(INCLUDE_DIRS + ${JANSSON_INCLUDE_DIRS} +) + +set(LIBRARIES + PkgConfig::JANSSON +) + +set(NODE_SRC + influxdb.c + stats.c + file.c +) + +if(HAS_EVENTFD) + list(APPEND NODE_SRC + loopback.c + cbuilder.c + ) +endif() + +add_library(villas-nodes STATIC ${NODE_SRC}) +target_include_directories(villas-nodes PUBLIC ${INCLUDE_DIRS}) +target_link_libraries(villas-nodes PUBLIC ${LIBRARIES}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..ab489b07b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,16 @@ +link_libraries(villas) + +add_executable(villas-node node.c) +add_executable(villas-test-rtt test-rtt.c) +add_executable(villas-test-shmem test-shmem.c) + +if(WITH_IO) + add_executable(villas-test-cmp test-cmp.c) + add_executable(villas-convert convert.c) + add_executable(villas-pipe pipe.c) + add_executable(villas-signal signal.c) +endif() + +if(WITH_IO AND WITH_HOOKS) + add_executable(villas-hook hook.c) +endif() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..c04a4545d --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,42 @@ +# CMakeLists. +# +# @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 . +################################################################################### + +if(WITH_CONFIG) + add_executable(conf2json conf2json.c) + + target_link_libraries(conf2json PUBLIC villas) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_executable(rmshm rmshm.c) + target_link_libraries(rmshm PUBLIC pthread rt) + + add_executable(rmsem rmsem.c) + target_link_libraries(rmsem PUBLIC pthread rt) +endif() + +pkg_check_modules(ZMQ IMPORTED_TARGET REQUIRED libzmq) +if(ZMQ_FOUND) + add_executable(zmq-keygen zmq-keygen.c) + target_include_directories(zmq-keygen PUBLIC ${ZMQ_INCLUDE_DIRS}) + target_link_libraries(zmq-keygen PUBLIC PkgConfig::ZMQ) +endif()