Skip to content

Commit 450d2fc

Browse files
nrnhinespramodk
andcommitted
CMake build system refactoring/cleanup and variour fixes
* Cmake -DENABLE_INTERVIEWS=OFF works * CMake build system refactoring (#247) - Top level refactoring 5 - Add build status after cmake stage - CMake modules refactoring - Avoid python2 library detection when default python is 3 - Python | 1 - EXE | /usr/local/Cellar/python/3.7.2_2/bin/python - LIB | /usr/lib/libpython2.7.dylib * Prefer version detected as interpreter * Bug fix for python library detection, use pybind11 module which has worked very well. - See: pybind/pybind11#207 * Rpath issue and nrnivmodl fixes (#249) * Remove interview target link while building special * Fix rpath issue with shared libraries - see https://stackoverflow.com/questions/32283062/compiling-c-shared-library-with-distutils-setup-py-when-the-library-depends-on - include IV directories * Fix link error with dynamic mpi * Fix missing darwin definition: (#253) This was causing following error: testNumpyInteraction (neuron.tests.test_vector.VectorTestCase) Testing numpy.array <=> hoc.Vector interaction ... build_cmake.sh: line 16: 11620 Segmentation fault: 11 $python -c 'from neuron import test; test()' * Set missing IV_LIBDIR (#254) * Add missing rpath for interviews lib directory * Small changes while testing on Ubuntu - print python include directory (which could be missing) - check python dir exist to avoid comple time error * Fix missing linking with -lpthread and -ldl with dynamic mpi and python on linux * Fix issue with python dynamic support is enabled - I see below error when trying to use python dynamic build: ``` nrn/install-dir/x86_64/bin/nrniv -python -pyexe python3.7 -c 'import neuron ; neuron.test() ;' NEURON -- VERSION 7.7.1-24-g4524ea3c master (4524ea3) 2019-07-31 Duke, Yale, and the BlueBrain Project -- Copyright 1984-2018 See http://neuron.yale.edu/neuron/credits bash: nrnpyenv.sh: No such file or directory Python not available ``` - This is because popen fails for `bash nrnpyenv.sh` fails. * Install nrnpyenv.sh to install-prefix/bin Co-authored-by: Pramod Kumbhar <[email protected]> Co-authored-by: Michael Hines <[email protected]>
1 parent b0886b0 commit 450d2fc

26 files changed

+1966
-1181
lines changed

CMakeLists.txt

Lines changed: 144 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,87 @@
11
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
2-
project(nrn C CXX)
2+
project(NEURON C CXX)
33

44
# =============================================================================
55
# CMake common project settings
66
# =============================================================================
77
set(PROJECT_VERSION_MAJOR 7)
88
set(PROJECT_VERSION_MINOR 7)
9-
set(CMAKE_BUILD_TYPE Debug)
109
set(CMAKE_CXX_STANDARD 98)
1110
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1211
set(CMAKE_CXX_EXTENSIONS OFF)
12+
set(CMAKE_BUILD_TYPE RelWithDebInfo)
1313
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
14+
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
1415

15-
# needed in several subdirectoy configurations
16-
set (prefix ${CMAKE_INSTALL_PREFIX})
17-
set (host_cpu ${CMAKE_SYSTEM_PROCESSOR})
18-
set (exec_prefix ${prefix})
19-
set (bindir \${exec_prefix}/bin)
20-
set (libdir \${exec_prefix}/lib)
21-
set (PACKAGE "\"nrn\"")
22-
23-
option(NRN_BUILD_SHARED "Build libraries shared or static" ON)
24-
option(ENABLE_INTERVIEWS "Link with INTERVIEWS GUI library" ON)
25-
option(ENABLE_LegacyFR "Original faraday, R, etc. instead of 2017 nist constants in share/lib/nrnunits.lib" ON)
26-
option(ENABLE_NRNMECH_DLL_STYLE "Dynamically load nrnmech shared library" ON)
27-
option(ENABLE_DISCRETE_EVENT_OBSERVER "Set to OFF if do not want Observer to be a subclass of DiscreteEvent" ON)
28-
option(ENABLE_PYTHON "Python interpreter available -- python3 fallback to python" ON)
29-
option(ENABLE_THREADS "Allow use of pthreads" ON)
30-
option(ENABLE_MPI "Allow use of MPI" ON)
31-
option(ENABLE_MEMACS "Allow use of memacs" ON)
32-
option(ENABLE_RX3D "Allow use of rx3d" OFF)
33-
34-
set(INSTALL_NEURON_MODULE "YES" CACHE STRING "\"NO\", means do not \
35-
install the neuron module. \"Yes\", means to install with --home in \
36-
CMAKE_INSTALL_PREFIX. For installation using other modes or locations \
37-
use an appropriate string that goes after python setup.py install")
38-
39-
set(NRNPYTHON_DYNAMIC "NO" CACHE STRING "\"NO\", means the nrnpython
40-
interface is linked into libnrniv.so. \"YES\" means the nrnpython
41-
interface consistent with default python3 (falling back to python) is
42-
built and loaded dynamically at run time (nrniv still works in the
43-
absence of any Python at all). A ';' separated list of executable
44-
pythons are used to create a separate interface for each. When one of
45-
those versions of Python is lauched,
46-
import neuron
47-
will automatically load the appropriate module interface along with the
48-
rest of neuron. (And
49-
nrniv -pyexe <python>
50-
will work with any <python> in the list of python executables.")
16+
# =============================================================================
17+
# Build options (boolean)
18+
# =============================================================================
19+
option(NRN_BUILD_SHARED "Build shared libraries (otherwise static library)" ON)
20+
option(NRN_ENABLE_INTERVIEWS "Enable GUI with INTERVIEWS" ON)
21+
option(NRN_ENABLE_LEGACY_FR "Use original faraday, R, etc. instead of 2017 nist constants" ON)
22+
option(NRN_ENABLE_MECH_DLL_STYLE "Dynamically load nrnmech shared library" ON)
23+
option(NRN_ENABLE_DISCRETE_EVENT_OBSERVER "Enable Observer to be a subclass of DiscreteEvent" ON)
24+
option(NRN_ENABLE_PYTHON "Enable Python interpreter support (default python3 fallback to python)" ON)
25+
option(NRN_ENABLE_THREADS "Allow use of Pthreads" ON)
26+
option(NRN_ENABLE_MPI "Enable MPI support" ON)
27+
option(NRN_ENABLE_MEMACS "Enable use of memacs" ON)
28+
option(NRN_ENABLE_RX3D "Enable rx3d support" OFF)
5129

52-
set(NRNMPI_DYNAMIC "NO" CACHE STRING "\"No\", means the nrnmpi
53-
is linked into libnrniv.so. \"YES\", means the nrnmpi interface
54-
consistent with default mpi is built and loaded dynamically at run
55-
time (nrniv still works in the absence of any mpi at all). A ';'
56-
separated list of paths to mpi package bin directories is used to
57-
create a separate libnrnmpi_xxx.so interface for each. When nrniv
58-
is launched with the -mpi argument, the first mpi found will determine
59-
which interface is dynamically loaded.")
30+
# =============================================================================
31+
# Build options (string)
32+
# =============================================================================
6033

61-
set(USING_CMAKE_FALSE "#")
62-
set(USING_CMAKE_TRUE "")
34+
# NEURON module installation:
35+
# - NO : do not install
36+
# - YES : install with --home in ${CMAKE_INSTALL_PREFIX}
37+
# - <string> : install using other modes or locations using an appropriate
38+
# string that goes after python setup.py install
39+
# Dynamic Python version support:
40+
# - NO : nrnpython interface is linked into libnrniv.so
41+
# - YES : nrnpython interface consistent with default python3 (falling back to python)
42+
# is built and loaded dynamically at run time (nrniv still works in the absence
43+
# of any Python at all).
44+
# - <string> : semicolon (;) separated list of python executable used to create a separate
45+
# interface for each. When one of those versions of Python is lauched,
46+
# "import neuron" will automatically load the appropriate module interface along
47+
# with the rest of neuron. Alsom nrniv -pyexe <python> will work with any <python>
48+
# in the list of python executables.
49+
# Dynamic MPI support:
50+
# - NO : nrnmpi is linked into libnrniv.so
51+
# - YES : nrnmpi interface is consistent with default mpi is built and loaded dynamically
52+
# at run time (nrniv still works in the absence of any mpi at all).
53+
# - <string> : semicolon (;) separated list of MPI's bin directories to create a separate
54+
# libnrnmpi_xxx.so interface for each. When nrniv is launched with the -mpi argument,
55+
# the first mpi found will determine which interface is dynamically loaded."
56+
set(NRN_ENABLE_MODULE_INSTALL YES CACHE STRING "Enable NEURON module installation (with setup.py)")
57+
set(NRN_ENABLE_PYTHON_DYNAMIC "NO" CACHE STRING "Enable dynamic Python version support")
58+
set(NRN_ENABLE_MPI_DYNAMIC "NO" CACHE STRING "Enable dynamic MPI library support")
6359

6460
# =============================================================================
65-
# Compile static libraries with hidden visibility
61+
# Include cmake modules
6662
# =============================================================================
67-
#set(CMAKE_CXX_VISIBILITY_PRESET hidden)
63+
list(APPEND CMAKE_MODULE_PATH
64+
${PROJECT_SOURCE_DIR}/cmake
65+
${PROJECT_SOURCE_DIR}/cmake/modules)
66+
include(CompilerHelper)
67+
include(MacroHelper)
68+
include(RpathHelper)
69+
include(PlatformHelper)
6870

6971
# =============================================================================
7072
# Find required packages
7173
# =============================================================================
72-
message(STATUS "CHECKING FOR X11")
7374
find_package(BISON)
7475
find_package(FLEX)
76+
find_package (Threads)
77+
find_package(readline)
7578

76-
if (ENABLE_MPI)
79+
# =============================================================================
80+
# Enable MPI/Python/IV/Pthead if found
81+
# =============================================================================
82+
# enable mpi if found
83+
if (NRN_ENABLE_MPI)
7784
find_package(MPI REQUIRED)
78-
# TODO : include this for only selective target
7985
include_directories(${MPI_INCLUDE_PATH})
8086
set(NRNMPI 1)
8187
set(PARANEURON 1)
@@ -84,36 +90,35 @@ else()
8490
set(PARANEURON 0)
8591
endif()
8692

87-
if (ENABLE_INTERVIEWS)
93+
# enable interviews if found
94+
if (NRN_ENABLE_INTERVIEWS)
8895
find_package(X11)
8996
if(NOT ${X11_FOUND})
9097
if (APPLE)
9198
message(FATAL_ERROR "You must install XQuartz from https://www.xquartz.org/ to build iv")
9299
else()
93-
find_package(X11 REQUIRED)
100+
message(FATAL_ERROR "You must install X11 to build iv e.g. 'apt install libx11-dev libxcomposite-dev' on Ubuntu")
94101
endif()
95102
endif()
96-
include_directories(${X11_INCLUDE_DIR})
97103
find_package(iv REQUIRED)
104+
get_target_property(IV_INCLUDE_DIR iv_interviews INTERFACE_INCLUDE_DIRECTORIES)
105+
include_directories(${X11_INCLUDE_DIR})
98106
set (HAVE_IV 1)
99107
else()
100-
set (HAVE_IV 0)
108+
set(HAVE_IV 0)
101109
endif()
102110

103-
# python or python3 is also needed to make hocusr.h from neuron.h
104-
set(Python_ADDITIONAL_VERSIONS 3.6) # 3.x priority, then 2.x
105-
find_package(PythonInterp REQUIRED) #currently active
106-
message(NOTICE "ENABLE_PYTHON ${ENABLE_PYTHON}")
107-
if (ENABLE_PYTHON)
108-
message(NOTICE " inside ENABLE_PYTHON")
109-
find_package(PythonLibs REQUIRED) # consistent with above
111+
# enable python support (interpreter needed to make hocusr.h from neuron.h, prefer Python 3)
112+
find_package(PythonInterp REQUIRED)
113+
if (NRN_ENABLE_PYTHON)
114+
find_package(PythonLibsNew ${PYTHON_VERSION_MAJOR} REQUIRED)
110115
set(USE_PYTHON 1)
111-
message(NOTICE "USE_PYTHON ${USE_PYTHON}")
112116
else()
113117
set(USE_PYTHON 0)
114118
endif()
115119

116-
if (ENABLE_THREADS)
120+
# enable threads if found
121+
if (NRN_ENABLE_THREADS)
117122
set(THREADS_PREFER_PTHREAD_FLAG ON)
118123
find_package(Threads REQUIRED)
119124
set(USE_PTHREAD 1)
@@ -122,70 +127,93 @@ else()
122127
endif()
123128

124129
# =============================================================================
125-
# Include cmake modules
130+
# Add CMake modules AFTER setting options
126131
# =============================================================================
127-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
128-
include(RpathHelper)
129-
include(ConfigACFile)
130-
include(NrnPyDynamic)
131-
include(NrnMPIDynamic)
132+
include(ConfigFileSetting)
133+
include(NeuronFileLists)
134+
include(PythonDynamicHelper)
135+
include(MPIDynamicHelper)
132136

133137
# =============================================================================
134138
# Project version from git and project directories
135139
# =============================================================================
136-
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
137-
138-
add_definitions(-DHAVE_CONFIG_H)
139-
140-
if(${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN")
141-
set(CYGWIN 1)
140+
add_subdirectory(cmake_config)
141+
add_subdirectory(src/nrniv)
142+
add_subdirectory(bin)
143+
if (NRN_ENABLE_PYTHON)
144+
add_subdirectory(src/nrnpython)
145+
endif()
146+
if (NRN_MACOS_BUILD OR NOT ${READLINE_FOUND})
147+
add_subdirectory(src/readline)
148+
set(INTERNAL_READLINE readline)
149+
unset(Readline_LIBRARY CACHE)
142150
endif()
143151

144-
add_subdirectory(cmkconfig)
152+
# =============================================================================
153+
# Install targets
154+
# =============================================================================
155+
# find headers to install
156+
nrn_find_project_files(NRN_HEADERS_PATHS ${HEADER_FILES_TO_INSTALL})
145157

146-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/lib
147-
DESTINATION share/nrn)
148-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/demo
149-
DESTINATION share/nrn)
150-
install(FILES ${PROJECT_BINARY_DIR}/share/lib/nrnunits.lib
158+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/lib DESTINATION share/nrn)
159+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/demo DESTINATION share/nrn)
160+
install(FILES
161+
${PROJECT_BINARY_DIR}/share/lib/nrnunits.lib
151162
${PROJECT_BINARY_DIR}/share/lib/nrn.defaults
152163
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/nrn/lib
153164
)
154-
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/share/lib/cleanup
165+
install(PROGRAMS
166+
${CMAKE_CURRENT_SOURCE_DIR}/share/lib/cleanup
155167
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/nrn/lib
156168
)
157-
158-
# paths to *.h files for installing into <prefix>/include
159-
my_find_files(inst_inc
160-
cabvars.h hoc_membf.h neuron.h nrnjava.h options.h
161-
cspmatrix.h hocparse.h nmodlmutex.h nrnoc_ml.h scoplib_ansi.h
162-
cspredef.h md1redef.h nrn_ansi.h scoplib.h
163-
hocassrt.h md2redef.h nrnapi.h nrnran123.h section.h
164-
hocdec.h membdef.h nrnassrt.h nrnredef.h spconfig.h
165-
hocgetsym.h membfunc.h nrncvode.h oc_ansi.h spmatrix.h
166-
hoc.h multicore.h nrnisaac.h ocfunc.h
167-
hoclist.h multisplit.h nrniv_mf.h ocmisc.h
168-
)
169-
install(FILES ${inst_inc} ${PROJECT_BINARY_DIR}/src/oc/nrnpthread.h
169+
install(FILES
170+
${NRN_HEADERS_PATHS} ${PROJECT_BINARY_DIR}/src/oc/nrnpthread.h
170171
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
171172
)
172173

173-
find_package(readline)
174-
175-
# if readline not found or if we are on OSX, use internal readline
176-
# also clear library variable
177-
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR NOT ${READLINE_FOUND})
178-
add_subdirectory(src/readline)
179-
set(INTERNAL_READLINE readline)
180-
unset(Readline_LIBRARY CACHE)
181-
endif()
182-
183-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
184-
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
185-
endif()
186-
187-
add_subdirectory(src/nrniv)
188-
add_subdirectory(bin)
189-
if (ENABLE_PYTHON)
190-
add_subdirectory(src/nrnpython)
174+
# =============================================================================
175+
# Print build status
176+
# =============================================================================
177+
message(STATUS "")
178+
message(STATUS "Configured NEURON ${PROJECT_VERSION}")
179+
message(STATUS "")
180+
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
181+
if(cmake_generator_tolower MATCHES "makefile")
182+
message(STATUS "Some things you can do now:")
183+
message(STATUS "--------------+--------------------------------------------------------------")
184+
message(STATUS "Command | Description")
185+
message(STATUS "--------------+--------------------------------------------------------------")
186+
message(STATUS "make install | Will install NEURON to: ${CMAKE_INSTALL_PREFIX}")
187+
message(STATUS " | Change the install location of NEURON using:")
188+
message(STATUS " | cmake <src_path> -DCMAKE_INSTALL_PREFIX=<install_path>")
189+
message(STATUS "make doc | Build the API documentation, requires Sphinx")
190+
message(STATUS "make uninstall| Removes files installed by make install")
191+
message(STATUS "--------------+--------------------------------------------------------------")
192+
message(STATUS " Build option | Status")
193+
message(STATUS "--------------+--------------------------------------------------------------")
194+
message(STATUS "Interviews | ${HAVE_IV}")
195+
if (${HAVE_IV})
196+
message(STATUS " PATH | ${iv_DIR}")
197+
endif()
198+
message(STATUS "MPI | ${NRNMPI}")
199+
if(NRN_ENABLE_MPI)
200+
message(STATUS " INC | ${MPI_INCLUDE_PATH}")
201+
message(STATUS " LIB | ${MPI_LIBRARY}")
202+
endif()
203+
message(STATUS "Python | ${USE_PYTHON}")
204+
if(NRN_ENABLE_PYTHON)
205+
message(STATUS " EXE | ${PYTHON_EXECUTABLE}")
206+
message(STATUS " INC | ${PYTHON_INCLUDE_DIRS}")
207+
message(STATUS " LIB | ${PYTHON_LIBRARIES}")
208+
if (NOT NRN_ENABLE_PYTHON_DYNAMIC MATCHES "NO")
209+
message(STATUS " INC(2) | ${NRNPYTHON_INCLUDE2}")
210+
message(STATUS " INC(3) | ${NRNPYTHON_INCLUDE3}")
211+
endif()
212+
endif()
213+
message(STATUS "RXD | ${NRN_ENABLE_RX3D}")
214+
message(STATUS "Shared | ${NRN_BUILD_SHARED}")
215+
message(STATUS "--------------+--------------------------------------------------------------")
216+
message(STATUS " See documentation : https://www.neuron.yale.edu/neuron/")
217+
message(STATUS "--------------+--------------------------------------------------------------")
191218
endif()
219+
message(STATUS "")

0 commit comments

Comments
 (0)