-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
214 lines (184 loc) · 6.96 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# examples/MyModule/CMakeLists.txt
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST 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 2 of the License, or
# (at your option) any later version.
#
# NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required( VERSION 2.8.12 )
# This CMakeLists.txt is configured to build your external module for NEST. For
# illustrative reasons this module is called 'my' (change SHORT_NAME to your
# preferred module name). NEST requires you to extend the 'SLIModule' (see
# mymodule.h and mymodule.cpp as an example) and provide a module header
# (see MODULE_HEADER). The subsequent instructions
#
# The configuration requires a compiled and installed NEST; if `nest-config` is
# not in the PATH, please specify the absolute path with `-Dwith-nest=...`.
#
# For more informations on how to extend and use your module see:
# https://nest.github.io/nest-simulator/extension_modules
# 1) Name your module here, i.e. add later with -Dexternal-modules=my:
set( SHORT_NAME lookback )
# the complete module name is here:
set( MODULE_NAME ${SHORT_NAME}module )
# 2) Add all your sources here
set( MODULE_SOURCES
lookback_exceptions.cpp)
# 3) We require a header name like this:
set( MODULE_HEADERS
lookback_connector_model.h
lookback_connector_model_impl.h
lookback_exceptions.h
lookback_node.h )
# containing the class description of the class extending the SLIModule
# 4) Specify your module version
set( MODULE_VERSION_MAJOR 1 )
set( MODULE_VERSION_MINOR 0 )
set( MODULE_VERSION "${MODULE_VERSION_MAJOR}.${MODULE_VERSION_MINOR}" )
# 5) Leave the rest as is. All files in `sli` will be installed to
# `share/nest/sli/`, so that NEST will find the during initialization.
# Leave the call to "project(...)" for after the compiler is determined.
# 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 ()
else ()
set( NEST_CONFIG ${with-nest} )
endif ()
# Use `nest-config` to get the compile and installation options used with the
# NEST installation.
# Get the compiler that was used for NEST.
execute_process(
COMMAND ${NEST_CONFIG} --compiler
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# One check on first execution, if `nest-config` is working.
if ( NOT RES_VAR EQUAL 0 )
message( FATAL_ERROR "Cannot run `${NEST_CONFIG}`. Please specify correct `nest-config` via -Dwith-nest=... " )
endif ()
# Setting the compiler has to happen before the call to "project(...)" function.
set( CMAKE_CXX_COMPILER "${NEST_COMPILER}" )
project( ${MODULE_NAME} CXX )
# Get the install prefix.
execute_process(
COMMAND ${NEST_CONFIG} --prefix
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Use the `NEST_PREFIX` as `CMAKE_INSTALL_PREFIX`.
set( CMAKE_INSTALL_PREFIX "${NEST_PREFIX}" CACHE STRING "Install path prefix, prepended onto install directories." FORCE )
# Get the CXXFLAGS.
execute_process(
COMMAND ${NEST_CONFIG} --cflags
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_CXXFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the Includes.
execute_process(
COMMAND ${NEST_CONFIG} --includes
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_INCLUDES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ( NEST_INCLUDES )
# make a cmake list
string( REPLACE " " ";" NEST_INCLUDES_LIST "${NEST_INCLUDES}" )
foreach ( inc_complete ${NEST_INCLUDES_LIST} )
# if it is actually a -Iincludedir
if ( "${inc_complete}" MATCHES "^-I.*" )
# get the directory
string( REGEX REPLACE "^-I(.*)" "\\1" inc "${inc_complete}" )
# and check whether it is a directory
if ( IS_DIRECTORY "${inc}" )
include_directories( "${inc}" )
endif ()
endif ()
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
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the data install dir.
execute_process(
COMMAND ${NEST_CONFIG} --datadir
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_DATADIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the documentation install dir.
execute_process(
COMMAND ${NEST_CONFIG} --docdir
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_DOCDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the library install dir.
execute_process(
COMMAND ${NEST_CONFIG} --libdir
RESULT_VARIABLE RES_VAR
OUTPUT_VARIABLE NEST_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# on OS X
set( CMAKE_MACOSX_RPATH ON )
# Install all stuff to NEST's install directories.
set( CMAKE_INSTALL_LIBDIR ${NEST_LIBDIR}/nest CACHE STRING "object code libraries (lib/nest or lib64/nest or lib/<multiarch-tuple>/nest on Debian)" FORCE )
set( CMAKE_INSTALL_DOCDIR ${NEST_DOCDIR} CACHE STRING "documentation root (DATAROOTDIR/doc/nest)" FORCE )
set( CMAKE_INSTALL_DATADIR ${NEST_DATADIR} CACHE STRING "read-only architecture-independent data (DATAROOTDIR/nest)" FORCE )
include( GNUInstallDirs )
# When building shared libraries, also create a module for loading at runtime
# with the `Install` command.
# Build dynamic/static library for standard linking from NEST.
add_library( ${MODULE_NAME} ${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.
endif ()
set_target_properties( ${MODULE_NAME}
PROPERTIES
COMPILE_FLAGS "${NEST_CXXFLAGS}"
OUTPUT_NAME ${MODULE_NAME} )
separate_arguments(NEST_LIBS)
target_link_libraries(${MODULE_NAME} ${NEST_LIBS})
target_link_libraries(${MODULE_NAME} -Wl,--no-undefined)
install( TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} )
install( FILES ${MODULE_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )