Skip to content
Snippets Groups Projects
Unverified Commit 58916607 authored by Tomasz Kozak's avatar Tomasz Kozak Committed by GitHub
Browse files

Modernise example template project (#8360)

	- change structure of the project, unify CMakeLists.txt, rename files.
	- remove defineConnections overloading, use ctk::ConnectingDeviceModule instead of ctk::DeviceModule
	- add option to pass name of application in the constructor
parent fc6b2029
No related branches found
No related tags found
No related merge requests found
Showing
with 100 additions and 116 deletions
# CMakeLists.txt template for an ApplicationCore-based server project(TemplateServer)
#
#
project(ChimeraTK-ApplicationCore-TemplateServer)
cmake_minimum_required(VERSION 3.5.1) cmake_minimum_required(VERSION 3.5.1)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
# Use the project template to get the settings required for an application core project # Use the project template to get the settings required for an application core project
set(${PROJECT_NAME}_MAJOR_VERSION 01) set(${PROJECT_NAME}_MAJOR_VERSION 01)
set(${PROJECT_NAME}_MINOR_VERSION 00) set(${PROJECT_NAME}_MINOR_VERSION 00)
set(${PROJECT_NAME}_PATCH_VERSION 00) set(${PROJECT_NAME}_PATCH_VERSION 00)
include(cmake/set_version_numbers.cmake) include(cmake/set_version_numbers.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
include(cmake/add_dependency.cmake)
include(cmake/set_default_build_to_release.cmake) include(cmake/set_default_build_to_release.cmake)
include(cmake/set_default_flags.cmake)
# configure version.h
configure_file(include/version.h.in ${PROJECT_BINARY_DIR}/version/version.h)
include_directories(${PROJECT_BINARY_DIR}/version)
# Add the dependencies. We need ApplicationCore and a control system adapter implementation. # Add the dependencies. We need ApplicationCore and a control system adapter implementation.
# #
# /!\ if you need the DeviceAccess-DoocsBackend, you have to add the dependency _after_ # /!\ if you need the DeviceAccess-DoocsBackend, you have to add the dependency _after_
# /!\ selecting the control system adapter, otherwise your server will not work. # /!\ selecting the control system adapter, otherwise your server will not work.
# #
add_dependency(ChimeraTK-ApplicationCore 01.08 REQUIRED) # Define dependences
include(cmake/add_dependency.cmake)
add_dependency(ChimeraTK-ApplicationCore 02.11 REQUIRED)
# Select the control system adapter # Select the control system adapter
include(cmake/set_control_system_adapter.cmake) include(cmake/set_control_system_adapter.cmake)
# Define compiler and link flags # Define compiler and linker flags - extend compiler flags with flags from dependencies
include(cmake/set_default_flags.cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ChimeraTK-ApplicationCore_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ChimeraTK-ApplicationCore_CXX_FLAGS}")
set(CMAKE_LINK_FLAGS "-Wl,--no-as-needed ${Adapter_LINK_FLAGS} ${ChimeraTK-ApplicationCore_LINK_FLAGS}") set(CMAKE_LINK_FLAGS "-Wl,--no-as-needed ${Adapter_LINK_FLAGS} ${ChimeraTK-ApplicationCore_LINK_FLAGS}")
############################################################################################################
# server library config
# configure version.h ############################################################################################################
configure_file(server/include/version.h.in ${PROJECT_BINARY_DIR}/version/version.h) # set include directories for library
include_directories(${PROJECT_BINARY_DIR}/version) include_directories(${CMAKE_SOURCE_DIR}/include)
# Module and Server include directories file(GLOB library_headers "${CMAKE_SOURCE_DIR}/include/*.h")
include_directories(${CMAKE_SOURCE_DIR}/modules/include ${CMAKE_SOURCE_DIR}/server/include) set(${PROJECT_NAME}_INCLUDE_DIRS ${${PROJECT_NAME}_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/)
# create lists with source files for library
# Process server ApplicationModules aux_source_directory(${CMAKE_SOURCE_DIR}/src library_sources)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules)
# server library (to avoid compiling everyting multiple times)
set(SERVER_SRC_DIR ${CMAKE_SOURCE_DIR}/server/src) add_library(${PROJECT_NAME}lib SHARED ${library_sources} ${library_headers} ${PROJECT_BINARY_DIR}/version/version.h)
set_target_properties(${PROJECT_NAME}lib PROPERTIES VERSION ${${PROJECT_NAME}_FULL_LIBRARY_VERSION}
SOVERSION ${${PROJECT_NAME}_SOVERSION})
target_link_libraries(${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${ADAPTER_LIBRARIES})
############################################################################################################
# server executable config
############################################################################################################
# The server executable. It depends on application core and the control system adapter implementation. # The server executable. It depends on application core and the control system adapter implementation.
add_executable(${PROJECT_NAME} ${SERVER_SRC_DIR}/ApplicationInstance.cc ${SERVER_SRC_DIR}/Server.cc) add_executable(${PROJECT_NAME} src_server/ApplicationInstance.cc)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS}") set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} ) target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
# We compile the same sources with the GENERATE_XML flag to get an xml generator. # We compile the same sources with the GENERATE_XML flag to get an xml generator.
# This one does not depent on a control system adapter implementation. # This one does not depent on a control system adapter implementation.
add_executable(${PROJECT_NAME}-xmlGenerator ${SERVER_SRC_DIR}/ApplicationInstance.cc ${SERVER_SRC_DIR}/Server.cc) add_executable(${PROJECT_NAME}-xmlGenerator src_xmlGenerator/XmlGenerator.cc)
set_target_properties( ${PROJECT_NAME}-xmlGenerator PROPERTIES COMPILE_FLAGS "-DGENERATE_XML") set_target_properties( ${PROJECT_NAME}-xmlGenerator PROPERTIES COMPILE_FLAGS "-DGENERATE_XML")
set_target_properties(${PROJECT_NAME}-xmlGenerator PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS}") set_target_properties(${PROJECT_NAME}-xmlGenerator PROPERTIES LINK_FLAGS "${ChimeraTK-ApplicationCore_LINK_FLAGS}")
target_link_libraries(${PROJECT_NAME}-xmlGenerator ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES}) target_link_libraries(${PROJECT_NAME}-xmlGenerator ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES})
# Process tests: ############################################################################################################
# server tests config
############################################################################################################
enable_testing() enable_testing()
add_subdirectory(${CMAKE_SOURCE_DIR}/tests) find_package(Boost COMPONENTS thread system unit_test_framework REQUIRED)
# Create the executables for automated unit testing (new modular tests).
# add one test executable per source file
aux_source_directory(${CMAKE_SOURCE_DIR}/tests/executables_src testExecutables)
foreach( testExecutableSrcFile ${testExecutables})
#NAME_WE means the base name without path and (longest) extension
get_filename_component(excutableName ${testExecutableSrcFile} NAME_WE)
add_executable(${excutableName} ${testExecutableSrcFile})
target_link_libraries(${excutableName} ${PROJECT_NAME}lib)
set_target_properties(${excutableName} PROPERTIES LINK_FLAGS "${CMAKE_LINK_FLAGS}")
add_test(${excutableName} ${excutableName})
endforeach( testExecutableSrcFile )
# Copy the (test) config files to the build directory # Copy the (test) config files to the build directory
file( COPY ${CMAKE_SOURCE_DIR}/config/ DESTINATION ${PROJECT_BINARY_DIR}) file( COPY ${CMAKE_SOURCE_DIR}/config/ DESTINATION ${PROJECT_BINARY_DIR})
############################################################################################################
# server installation config
############################################################################################################
# Installation: # Installation:
# FIXME: For doocs we need a special treatment when installing to /export/doocs/server (don't install to bin subdirectory, but a directory named like the server). This should go to the project template. # FIXME: For doocs we need a special treatment when installing to /export/doocs/server (don't install to bin subdirectory, but a directory named like the server). This should go to the project template.
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/export/doocs/server") if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/export/doocs/server")
......
<?xml version="1.0" encoding="UTF-8"?>
<device_server xmlns="https://github.com/ChimeraTK/ControlSystemAdapter-DoocsAdapter">
<location name="TEMPLATE_LOCATION">
<!-- Simply import all variables provided by the application
Adapt to your needs!
-->
<import>/</import>
</location>
</device_server>
<configuration> <configuration>
<variable name="config_var1" type="int32" value="42"/> <variable name="config_var1" type="int32" value="42"/>
<module name="Module1"> <module name="Configuration">
<variable name="config_var1" type="int32" value="3"/> <variable name="config_var1" type="int32" value="3"/>
<variable name="config_var2" type="int32" value="7"/> <variable name="config_var2" type="int32" value="7"/>
</module> </module>
......
...@@ -23,15 +23,13 @@ namespace ctk = ChimeraTK; ...@@ -23,15 +23,13 @@ namespace ctk = ChimeraTK;
* (either provided by a Device or a ChimeraTK::PeriodicTrigger). * (either provided by a Device or a ChimeraTK::PeriodicTrigger).
*/ */
struct Server : public ctk::Application { struct Server : public ctk::Application {
Server() : ctk::Application("ApplicationCore_TemplateServer") {} Server(std::string appName = "TemplateServer");
~Server() override { shutdown(); } ~Server() override;
ctk::ConfigReader config{this, "Configuration", getName() + "_base_config.xml"}; ctk::ConfigReader config;
ctk::ConnectingDeviceModule device;
TemplateModule templateModule;
};
ctk::ControlSystemModule cs;
ctk::DeviceModule dev{this, "MappedDummyDevice"};
TemplateModule templateModule{this, "TemplateModule", "This is a template module, adapt as needed!"};
void defineConnections() override;
};
...@@ -8,7 +8,8 @@ namespace ctk = ChimeraTK; ...@@ -8,7 +8,8 @@ namespace ctk = ChimeraTK;
struct TemplateModule : public ctk::ApplicationModule { struct TemplateModule : public ctk::ApplicationModule {
using ctk::ApplicationModule::ApplicationModule; using ctk::ApplicationModule::ApplicationModule;
~TemplateModule() {} /*
* Add input/output definition
* */
void mainLoop() override; void mainLoop() override;
}; };
# CMakeLists.txt for server modules
cmake_minimum_required(VERSION 3.5.1)
include_directories(include)
aux_source_directory(src library_sources)
message("In subdir: ** ${PROJECT_NAME}")
# Build the modules into a shared library so they are only
# instanciated once, if multiple server instances are run
add_library(${PROJECT_NAME}lib SHARED ${library_sources})
set_target_properties(${PROJECT_NAME}lib PROPERTIES VERSION ${${PROJECT_NAME}_FULL_LIBRARY_VERSION}
SOVERSION ${${PROJECT_NAME}_SOVERSION})
target_link_libraries(${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${ADAPTER_LIBRARIES})
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "Server.h"
#include "version.h"
void Server::defineConnections() {
ctk::setDMapFilePath("devices.dmap");
std::cout << "****************************************************************" << std::endl;
std::cout << "*** Template server version " << AppVersion::major << "." << AppVersion::minor << "."
<< AppVersion::patch << std::endl;
dev.connectTo(cs /*, timer.tick*/);
config.connectTo(cs);
dumpConnectionGraph();
dumpGraph();
dumpModuleGraph("module-graph.dot");
}
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "Server.h"
#include "version.h"
Server::Server(std::string appName)
: ctk::Application(appName), config{this, "Configuration", getName() + "-Config.xml"}, device{this,
"MappedDummyDevice"},
templateModule{this, "TemplateModule", "This is a template module, adapt as needed!"} {
std::cout << "*** Construction of " << appName << " in version " << AppVersion::major << "." << AppVersion::minor
<< "." << AppVersion::patch << " starts. ***" << std::endl;
ctk::setDMapFilePath(getName() + ".dmap");
std::cout << "*** Construction of " << appName << " in version " << AppVersion::major << "." << AppVersion::minor
<< "." << AppVersion::patch << " done. ***" << std::endl;
}
Server::~Server() {
shutdown();
}
...@@ -4,5 +4,14 @@ ...@@ -4,5 +4,14 @@
#include "TemplateModule.h" #include "TemplateModule.h"
void TemplateModule::mainLoop() { void TemplateModule::mainLoop() {
std::cout << " Processing TemplateModule::mainLoop()" << std::endl; /*
* Here a main infinite loop for the Module should be defined.
* It is commented out on purpose in this TemplateModule.
*
*/
/*
while(true) {
}
*/
} }
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "Server.h"
/// The Server instance
static Server theServer;
# CMakeLists.txt for test modules
cmake_minimum_required(VERSION 3.5.1)
# Add BOOST dependencies
find_package(Boost COMPONENTS thread system unit_test_framework REQUIRED)
# The tests also require the server headers (TODO Potentially, module includes are also needed)
include_directories(${CMAKE_SOURCE_DIR}/server/include)
# Add all tests residing in the "tests" directory
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} testExecutables)
foreach( testExecutableSrcFile ${testExecutables})
#NAME_WE means the base name without path and (longest) extension
get_filename_component(excutableName ${testExecutableSrcFile} NAME_WE)
add_executable(${excutableName} ${testExecutableSrcFile})
target_sources(${excutableName} PRIVATE ${SERVER_SRC_DIR}/Server.cc)
set_target_properties(${excutableName}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
LINK_FLAGS "${CMAKE_LINK_FLAGS}"
)
target_link_libraries(${excutableName} ${PROJECT_NAME}lib ${ChimeraTK-ApplicationCore_LIBRARIES} ${Adapter_LIBRARIES} )
add_test(
NAME ${excutableName}
COMMAND ${CMAKE_BINARY_DIR}/${excutableName}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endforeach( testExecutableSrcFile )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment