Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised module suitable for new NESTExtensionModule interface #26

Merged
merged 12 commits into from
Apr 26, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.12

# Install ubuntu dependencies
- name: Ubuntu dependencies
Expand Down
46 changes: 6 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,18 @@ cmake_minimum_required( VERSION 3.19 )
list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
include( ProcessDependencies )

# Name your module here.
set( SHORT_NAME my )

# Build the complete module name:
set( MODULE_NAME ${SHORT_NAME}module )

# We require a module header containing the class description of the class
# extending the SLIModule
set( MODULE_HEADER src/${MODULE_NAME}.h )
set( MODULE_NAME mymodule )

# Specify your module version
set( MODULE_VERSION_MAJOR 1 )
set( MODULE_VERSION_MINOR 0 )
set( MODULE_VERSION_MAJOR 0 )
set( MODULE_VERSION_MINOR 1 )
set( MODULE_VERSION "${MODULE_VERSION_MAJOR}.${MODULE_VERSION_MINOR}" )

# Set the `nest-config` executable to use during configuration.
set( with-nest OFF CACHE STRING "Specify the `nest-config` executable." )

# If it is not set, look for a `nest-config` in the PATH.
if ( NOT with-nest )
# try find the program ourselves
find_program( NEST_CONFIG
NAMES nest-config
)
if ( NEST_CONFIG STREQUAL "NEST_CONFIG-NOTFOUND" )
message( FATAL_ERROR "Cannot find the program `nest-config`. Specify via -Dwith-nest=... ." )
endif ()
if ( with-nest )
set( NEST_CONFIG ${with-nest} )
else ()
set( NEST_CONFIG ${with-nest} )
message( FATAL_ERROR "-Dwith-nest=<nest_config> is required" )
endif ()

# Use `nest-config` to get the compiler that was used for NEST.
Expand Down Expand Up @@ -124,20 +107,6 @@ if ( NEST_INCLUDES )
endforeach ()
endif ()

# Get, if NEST is build as a (mostly) static application. If yes, also only build
# static library.
execute_process(
COMMAND ${NEST_CONFIG} --static-libraries
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_STATIC_LIB
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ( NEST_STATIC_LIB )
set( BUILD_SHARED_LIBS OFF )
else ()
set( BUILD_SHARED_LIBS ON )
endif ()

# Get all linked libraries.
execute_process(
COMMAND ${NEST_CONFIG} --libs
Expand Down Expand Up @@ -232,9 +201,6 @@ endforeach()

add_subdirectory( src )

# Install header file
install( FILES ${MODULE_HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${MODULE_NAME} )

# Install help --- based on doc/CMakeLists.txt
# Install only if Py >= 2.7.8 and NEST was installed with help
if ( ( NOT CMAKE_CROSSCOMPILING )
Expand Down
43 changes: 12 additions & 31 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# Add all your sources here and specify dependencies, e.g., link libraries
set( MODULE_SOURCES
mymodule.h mymodule.cpp
mymodule.cpp
pif_psc_alpha.h pif_psc_alpha.cpp
drop_odd_spike_connection.h drop_odd_spike_connection.cpp
step_pattern_builder.h step_pattern_builder.cpp
Expand All @@ -37,34 +37,15 @@ else ()
message( "-- Skip build of recording backend >SoundClick<. sfml-audio is not installed." )
endif ()

if ( BUILD_SHARED_LIBS )
# When building shared libraries, also create a module for loading at runtime
# with the `Install` command.
add_library( ${MODULE_NAME}_module MODULE ${MODULE_SOURCES} )
target_link_libraries(${MODULE_NAME}_module ${USER_LINK_LIBRARIES})
set_target_properties( ${MODULE_NAME}_module
PROPERTIES
COMPILE_FLAGS "${NEST_CXXFLAGS} -DLTX_MODULE"
LINK_FLAGS "${NEST_LIBS}"
PREFIX ""
OUTPUT_NAME ${MODULE_NAME} )
install( TARGETS ${MODULE_NAME}_module
DESTINATION ${CMAKE_INSTALL_LIBDIR}/nest
)
endif ()

# Build dynamic/static library for standard linking from NEST.
add_library( ${MODULE_NAME}_lib ${MODULE_SOURCES} )
if ( BUILD_SHARED_LIBS )
# Dynamic libraries are initiated by a `global` variable of the `SLIModule`,
# which is included, when the flag `LINKED_MODULE` is set.
target_compile_definitions( ${MODULE_NAME}_lib PRIVATE -DLINKED_MODULE )
endif ()
set_target_properties( ${MODULE_NAME}_lib
PROPERTIES
COMPILE_FLAGS "${NEST_CXXFLAGS}"
LINK_FLAGS "${NEST_LIBS}"
OUTPUT_NAME ${MODULE_NAME} )
add_library( ${MODULE_NAME}_module MODULE ${MODULE_SOURCES} )
target_link_libraries(${MODULE_NAME}_module ${USER_LINK_LIBRARIES})
set_target_properties( ${MODULE_NAME}_module
PROPERTIES
COMPILE_FLAGS "${NEST_CXXFLAGS} -DLTX_MODULE"
LINK_FLAGS "${NEST_LIBS}"
PREFIX ""
OUTPUT_NAME ${MODULE_NAME} )
install( TARGETS ${MODULE_NAME}_module
DESTINATION ${CMAKE_INSTALL_LIBDIR}/nest
)

# Install library
install( TARGETS ${MODULE_NAME}_lib DESTINATION ${CMAKE_INSTALL_LIBDIR}/nest )
102 changes: 22 additions & 80 deletions src/mymodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
*
*/

#include "mymodule.h"

// Generated includes:
#include "config.h"

// include headers with your own stuff
#include "drop_odd_spike_connection.h"
#include "pif_psc_alpha.h"
Expand All @@ -34,95 +29,42 @@
#endif
#include "recording_backend_socket.h"

// Includes from nestkernel:
#include "connection_manager_impl.h"
#include "connector_model_impl.h"
#include "dynamicloader.h"
#include "exceptions.h"
#include "genericmodel.h"
#include "genericmodel_impl.h"
#include "io_manager_impl.h"
#include "kernel_manager.h"
#include "model.h"
#include "model_manager_impl.h"
#include "nest.h"
#include "nest_impl.h"
#include "nestmodule.h"
#include "target_identifier.h"

// Includes from sli:
#include "booldatum.h"
#include "integerdatum.h"
#include "sliexceptions.h"
#include "tokenarray.h"

// -- Interface to dynamic module loader ---------------------------------------

/*
* There are three scenarios, in which MyModule can be loaded by NEST:
*
* 1) When loading your module with `Install`, the dynamic module loader must
* be able to find your module. You make the module known to the loader by
* defining an instance of your module class in global scope. (LTX_MODULE is
* defined) This instance must have the name
*
* <modulename>_LTX_mod
*
* The dynamicloader can then load modulename and search for symbol "mod" in it.
*
* 2) When you link the library dynamically with NEST during compilation, a new
* object has to be created. In the constructor the DynamicLoaderModule will
* register your module. (LINKED_MODULE is defined)
*
* 3) When you link the library statically with NEST during compilation, the
* registration will take place in the file `static_modules.h`, which is
* generated by cmake.
*/
#if defined( LTX_MODULE ) | defined( LINKED_MODULE )
mynest::MyModule mymodule_LTX_mod;
#endif
// -- DynModule functions ------------------------------------------------------
// Includes from NEST
#include "nest_extension_interface.h"

mynest::MyModule::MyModule()
namespace mynest
{
#ifdef LINKED_MODULE
// register this module at the dynamic loader
// this is needed to allow for linking in this module at compile time
// all registered modules will be initialized by the main app's dynamic loader
nest::DynamicLoaderModule::registerLinkedModule( this );
#endif
}
class MyModule : public nest::NESTExtensionInterface
{
public:
MyModule() {}
virtual ~MyModule() {}

mynest::MyModule::~MyModule() = default;

const std::string
mynest::MyModule::name() const
{
return std::string( "My NEST Module" ); // Return name of the module
void initialize() override;
};
}

//-------------------------------------------------------------------------------------
// Define module instance outside of namespace to avoid name-mangling problems
mynest::MyModule mymodule_LTX_module;

void
mynest::MyModule::init( SLIInterpreter* i )
void mynest::MyModule::initialize()
{
/* Register a neuron or device model.
Give node type as template argument and the name as second argument.
*/
register_pif_psc_alpha( "pif_psc_alpha" );
*/
mynest::register_pif_psc_alpha( "pif_psc_alpha" );

/* Register a synapse type.
Give synapse type as template argument and the name as second argument.
*/
register_drop_odd_spike_connection( "drop_odd_synapse" );

*/
mynest::register_drop_odd_spike_connection( "drop_odd_synapse" );

// Register connection rule.
nest::kernel().connection_manager.register_conn_builder< StepPatternBuilder >( "step_pattern" );
nest::kernel().connection_manager.register_conn_builder< mynest::StepPatternBuilder >( "step_pattern" );

#ifdef HAVE_SFML_AUDIO
// Register recording backends.
nest::kernel().io_manager.register_recording_backend< nest::RecordingBackendSoundClick >( "soundclick" );
#endif

nest::kernel().io_manager.register_recording_backend< nest::RecordingBackendSocket >( "socket" );
} // MyModule::init()
nest::kernel().io_manager.register_recording_backend< mynest::RecordingBackendSocket >( "socket" );
}

68 changes: 0 additions & 68 deletions src/mymodule.h

This file was deleted.

Loading
Loading