From 0ca6b947688a3766dc573e6d4b0ee1a3ae6c6a5d Mon Sep 17 00:00:00 2001 From: Subhasis Ray Date: Mon, 8 Jul 2024 03:53:57 +0530 Subject: [PATCH] Added meson build files --- CMakeLists.txt | 75 ++++++++++----- WindowsBuild.md | 16 +++- basecode/CMakeLists.txt | 2 +- basecode/meson.build | 35 +++++++ biophysics/meson.build | 48 ++++++++++ builtins/meson.build | 30 ++++++ device/meson.build | 9 ++ diffusion/meson.build | 9 ++ examples/meson.build | 7 ++ hsolve/meson.build | 19 ++++ intfire/meson.build | 12 +++ kinetics/meson.build | 17 ++++ ksolve/meson.build | 18 ++++ mesh/meson.build | 19 ++++ meson.build | 202 ++++++++++++++++++++++++++++++++++++++++ mpi/meson.build | 6 ++ msg/meson.build | 14 +++ pybind11/CMakeLists.txt | 48 +++++----- pybind11/meson.build | 19 ++++ pyproject.toml | 74 +++++++++++++++ randnum/meson.build | 7 ++ scheduling/meson.build | 6 ++ shell/meson.build | 14 +++ signeur/meson.build | 7 ++ synapse/meson.build | 15 +++ utility/CMakeLists.txt | 2 +- utility/meson.build | 11 +++ 27 files changed, 692 insertions(+), 49 deletions(-) create mode 100644 basecode/meson.build create mode 100644 biophysics/meson.build create mode 100644 builtins/meson.build create mode 100644 device/meson.build create mode 100644 diffusion/meson.build create mode 100644 examples/meson.build create mode 100644 hsolve/meson.build create mode 100644 intfire/meson.build create mode 100644 kinetics/meson.build create mode 100644 ksolve/meson.build create mode 100644 mesh/meson.build create mode 100644 meson.build create mode 100644 mpi/meson.build create mode 100644 msg/meson.build create mode 100644 pybind11/meson.build create mode 100644 pyproject.toml create mode 100644 randnum/meson.build create mode 100644 scheduling/meson.build create mode 100644 shell/meson.build create mode 100644 signeur/meson.build create mode 100644 synapse/meson.build create mode 100644 utility/meson.build diff --git a/CMakeLists.txt b/CMakeLists.txt index adb3c96431..f95f453509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ add_definitions(-DUSE_GENESIS_PARSER) # - Subha if(MSVC) add_definitions(-D_USE_MATH_DEFINES) - set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} /bigobj /std:c++14) + set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} /bigobj /std:c++14 /permissive-) else() set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} "-std=c++11") endif() @@ -129,7 +129,7 @@ if(WITH_BOOST OR WITH_BOOST_ODE) set(WITH_GSL OFF) endif() -find_package(HDF5 COMPONENTS CXX HL) +find_package(HDF5 COMPONENTS C CXX HL) if (NOT HDF5_FOUND) message("==================================================================\n" @@ -146,18 +146,20 @@ if (NOT HDF5_FOUND) ) elseif(HDF5_FOUND) set(WITH_NSDF ON) + endif() ################################### TARGETS #################################### link_directories(${CMAKE_BINARY_DIR}) -if(WIN32) - add_library(libmoose SHARED basecode/main.cpp external/getopt/getopt.c) +if(MSVC) + add_library(_moose SHARED basecode/main.cpp external/getopt/getopt.c) + set_target_properties(_moose PROPERTIES PREFIX "") else() add_library(libmoose SHARED basecode/main.cpp) -endif(WIN32) + set_target_properties(libmoose PROPERTIES PREFIX "") +endif() -set_target_properties(libmoose PROPERTIES PREFIX "") # MSVC Linker has a mismatch of binary lib type static/dll/pyd for exe # TODO find how to fix it @@ -172,6 +174,9 @@ set(STATIC_LIBRARIES "") # Collect all shared libraries here. set(SYSTEM_SHARED_LIBS "") +if(WITH_NSDF) + list(APPEND SYSTEM_SHARED_LIBS ${HDF5_LIBRARIES}) +endif() # BOOST ode library performs better than GSL and ideally should be made default. # Unfortunately Boost does not have a very good matrix library; it has ublas # which is not well maintained and emit a lot @@ -314,7 +319,7 @@ list(APPEND MOOSE_LIBRARIES if(WIN32) list(APPEND MOOSE_LIBRARIES getopt) # target_include_directories(moose.bin PRIVATE external/getopt) - target_include_directories(libmoose PRIVATE external/getopt) + target_include_directories(_moose PRIVATE external/getopt) endif() # Make sure to remove duplicates. @@ -343,12 +348,40 @@ if(APPLE) ${CMAKE_DL_LIBS} ) elseif(MSVC) - target_link_libraries(libmoose - ${MOOSE_LIBRARIES} - ${STATIC_LIBRARIES} - ${SYSTEM_SHARED_LIBS} - ) -else(MSVC) + # Static linking throws away any lib that is not called + # The equivalent to gcc --whole-archive has been added to VS 2015 update 2: /WHOLEARCHIVE + # Adding linker option is not as simple as Linux/Apple here because cmake passes /WHOLEARCHIVE argument as an object file name + set_property(TARGET _moose APPEND PROPERTY LINK_FLAGS /WHOLEARCHIVE) + set_property(TARGET _moose APPEND PROPERTY LINK_FLAGS /FORCE:MULTIPLE) + add_library(pymoose SHARED $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) + + # target_link_libraries(libmoose + # ${MOOSE_LIBRARIES} + # ${SYSTEM_SHARED_LIBS} + # ${CMAKE_DL_LIBS} + # "/WHOLEARCHIVE" + # ${STATIC_LIBRARIES} + # ) +else() target_link_libraries(libmoose "-Wl,--whole-archive" ${MOOSE_LIBRARIES} @@ -356,7 +389,7 @@ else(MSVC) "-Wl,--no-whole-archive" ${SYSTEM_SHARED_LIBS} ) -endif(APPLE) +endif() if(NOT MSVC) add_dependencies(moose.bin libmoose) @@ -365,7 +398,7 @@ endif() if( WITH_BOOST AND NOT MSVC) target_link_libraries( moose.bin ${Boost_LIBRARIES} ) -endif( WITH_BOOST ) +endif() ######################### BUILD PYMOOSE ######################################## @@ -375,7 +408,7 @@ endif( WITH_BOOST ) # See: https://pybind11.readthedocs.io/en/stable/installing.html # - Subha, Mon Apr 22 14:26:58 IST 2024 -# The execute_process fails on Windows with Mamba +# execute_process fails on Windows with Mamba # execute_process(COMMAND ${CMAKE_COMMAND} -E pybind11-config --cmakedir OUTPUT_VARIABLE pybind11_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}") add_subdirectory(pybind11) @@ -406,13 +439,13 @@ endif() ######################### INSTALL ############################################## if(MSVC) - configure_file("${CMAKE_BINARY_DIR}/python/moose/${CMAKE_BUILD_TYPE}/_moose.pyd" "${CMAKE_BINARY_DIR}/python/moose/") - file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/python/moose/${CMAKE_BUILD_TYPE}") + install(TARGETS _moose DESTINATION lib CONFIGURATIONS "${CMAKE_BUILD_TYPE}") else() - install(TARGETS moose.bin DESTINATION bin CONFIGURATIONS Debug) + install(TARGETS libmoose DESTINATION lib CONFIGURATIONS "${CMAKE_BUILD_TYPE}") +endif() +if(NOT MSVC) + install(TARGETS moose.bin DESTINATION bin CONFIGURATIONS "${CMAKE_BUILD_TYPE}") endif() - -install(TARGETS libmoose DESTINATION lib CONFIGURATIONS Debug) # Print message to start build process if(${CMAKE_BUILD_TOOL} MATCHES "make") diff --git a/WindowsBuild.md b/WindowsBuild.md index 238bc91c4b..5f4250ac8a 100644 --- a/WindowsBuild.md +++ b/WindowsBuild.md @@ -4,7 +4,7 @@ You may want to use one of the virtual environment systems like Anaconda, Minifo To create an environment, open Anaconda command prompt (below we assume Windows CMD shell, you may need to change some commands for PowerShell) and enter ``` -conda create -n moose +conda create -n moose -c conda-forge ``` Then switch to this environment for your build @@ -27,14 +27,18 @@ conda activate moose * Install cmake Using conda (mamba) ``` -conda install cmake +conda install cmake -c conda-forge ``` -* Install GSL using vcpkg (enter the following in the command line): +* Install GSL using ~~vcpkg~~ conda (enter the following in the command line): ``` .\vcpkg\vcpkg install gsl:x64-windows ``` + +``` +conda install gsl -c conda-forge +``` * Install HDF5 (for NSDF support) @@ -52,8 +56,9 @@ conda install hdf5 ``` .\vcpkg\vcpkg.exe install pybind11 ``` - -* Install doxygen +* [Skip] For MPI install MS-MPI (https://github.com/microsoft/Microsoft-MPI/releases/), the only free MPI for Windows + - TODO: MPI-build on Windows is not supported yet +* [Skip] Install doxygen ``` .\vcpkg\vcpkg.exe install doxygen:x64-windows @@ -72,6 +77,7 @@ pip install vpython C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\LaunchDevCmd.bat ``` +Gotcha: if you are on a 64 bit machine, the machine type is x64. MSVC comes with various cross compilation support (x86, x86_64). Running `"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"` worked. * Clone `moose-core` source code using git * Build moose diff --git a/basecode/CMakeLists.txt b/basecode/CMakeLists.txt index 3bda04203f..2900230dc7 100644 --- a/basecode/CMakeLists.txt +++ b/basecode/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -add_library(basecode +add_library(basecode OBJECT Element.cpp DataElement.cpp GlobalDataElement.cpp diff --git a/basecode/meson.build b/basecode/meson.build new file mode 100644 index 0000000000..35f087baa8 --- /dev/null +++ b/basecode/meson.build @@ -0,0 +1,35 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +basecode_src = ['Element.cpp', + 'DataElement.cpp', + 'GlobalDataElement.cpp', + 'LocalDataElement.cpp', + 'Eref.cpp', + 'Finfo.cpp', + 'DestFinfo.cpp', + 'Cinfo.cpp', + 'SrcFinfo.cpp', + 'ValueFinfo.cpp', + 'SharedFinfo.cpp', + 'FieldElementFinfo.cpp', + 'FieldElement.cpp', + 'Id.cpp', + 'ObjId.cpp', + 'global.cpp', + 'SetGet.cpp', + 'OpFuncBase.cpp', + 'EpFunc.cpp', + 'HopFunc.cpp', + 'SparseMatrix.cpp', + 'doubleEq.cpp', + 'testAsync.cpp'] + +# On windows we provide getopt +if is_windows + basecode_src += '../external/getopt/getopt.c' + basecode_lib = static_library('basecode', basecode_src, + include_directories: '../external/getopt') +else + basecode_lib = static_library('basecode', basecode_src) +endif diff --git a/biophysics/meson.build b/biophysics/meson.build new file mode 100644 index 0000000000..64a00be4a7 --- /dev/null +++ b/biophysics/meson.build @@ -0,0 +1,48 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +biophysics_src = ['IntFire.cpp', + 'SpikeGen.cpp', + 'RandSpike.cpp', + 'CompartmentDataHolder.cpp', + 'CompartmentBase.cpp', + 'Compartment.cpp', + 'SymCompartment.cpp', + 'GapJunction.cpp', + 'ChanBase.cpp', + 'ChanCommon.cpp', + 'HHChannel.cpp', + 'HHChannelBase.cpp', + 'HHChannel2D.cpp', + 'HHGate.cpp', + 'HHGate2D.cpp', + 'HHChannel2D.cpp', + 'CaConcBase.cpp', + 'CaConc.cpp', + 'MgBlock.cpp', + 'Nernst.cpp', + 'Neuron.cpp', + 'ReadCell.cpp', + 'SwcSegment.cpp', + 'ReadSwc.cpp', + 'SynChan.cpp', + 'NMDAChan.cpp', + 'IzhikevichNrn.cpp', + 'DifShellBase.cpp', + 'DifShell.cpp', + 'DifBufferBase.cpp', + 'DifBuffer.cpp', + 'MMPump.cpp', + 'Leakage.cpp', + 'VectorTable.cpp', + 'MarkovRateTable.cpp', + 'MarkovChannel.cpp', + 'MatrixOps.cpp', + 'MarkovSolverBase.cpp', + 'MarkovSolver.cpp', + 'VClamp.cpp', + 'Spine.cpp', + 'MarkovOdeSolver.cpp', + 'testBiophysics.cpp'] + +biophysics_lib = static_library('biophysics', biophysics_src, dependencies: gsl_dep, include_directories: gsl_dep.get_pkgconfig_variable('includedir')) diff --git a/builtins/meson.build b/builtins/meson.build new file mode 100644 index 0000000000..549ec9fcac --- /dev/null +++ b/builtins/meson.build @@ -0,0 +1,30 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +builtins_src = ['Arith.cpp', + 'Group.cpp', + 'Mstring.cpp', + 'Function.cpp', + 'Variable.cpp', + 'InputVariable.cpp', + 'TableBase.cpp', + 'Table.cpp', + 'Interpol.cpp', + 'StimulusTable.cpp', + 'TimeTable.cpp', + 'StreamerBase.cpp', + 'Streamer.cpp', + 'Stats.cpp', + 'Interpol2D.cpp', + 'SpikeStats.cpp', + 'MooseParser.cpp', + '../utility/cnpy.cpp', + '../external/fmt/src/format.cc', + '../external/fmt/src/os.cc', + 'testBuiltins.cpp'] + +if host_machine.system() != 'windows' + builtins_src += files(['SocketStreamer.cpp']) +endif + +builtins_lib = static_library('builtins', builtins_src, include_directories: ['../external/fmt/include']) diff --git a/device/meson.build b/device/meson.build new file mode 100644 index 0000000000..7c5e3b6d83 --- /dev/null +++ b/device/meson.build @@ -0,0 +1,9 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +device_src = ['PulseGen.cpp', + 'DiffAmp.cpp', + 'PIDController.cpp', + 'RC.cpp'] + +device_lib = static_library('device', device_src) diff --git a/diffusion/meson.build b/diffusion/meson.build new file mode 100644 index 0000000000..c14376d383 --- /dev/null +++ b/diffusion/meson.build @@ -0,0 +1,9 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +diffusion_src = ['FastMatrixElim.cpp', + 'DiffPoolVec.cpp', + 'Dsolve.cpp', + 'testDiffusion.cpp'] + +diffusion_lib = static_library('diffusion', diffusion_src, include_directories: gsl_dep.get_pkgconfig_variable('includedir')) diff --git a/examples/meson.build b/examples/meson.build new file mode 100644 index 0000000000..720223f70d --- /dev/null +++ b/examples/meson.build @@ -0,0 +1,7 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +examples_src = ['Example.cpp', + 'Ex.cpp'] + +examples_lib = static_library('examples', examples_src) diff --git a/hsolve/meson.build b/hsolve/meson.build new file mode 100644 index 0000000000..f2aa1c522c --- /dev/null +++ b/hsolve/meson.build @@ -0,0 +1,19 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +hsolve_src = ['HSolveStruct.cpp', + 'HinesMatrix.cpp', + 'Cell.cpp', + 'HSolvePassive.cpp', + 'RateLookup.cpp', + 'HSolveActive.cpp', + 'HSolveActiveSetup.cpp', + 'HSolveInterface.cpp', + 'HSolve.cpp', + 'HSolveUtils.cpp', + 'testHSolve.cpp', + 'ZombieCompartment.cpp', + 'ZombieCaConc.cpp', + 'ZombieHHChannel.cpp'] + +hsolve_lib = static_library('hsolve', hsolve_src) diff --git a/intfire/meson.build b/intfire/meson.build new file mode 100644 index 0000000000..d1868461c7 --- /dev/null +++ b/intfire/meson.build @@ -0,0 +1,12 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +intfire_src = ['AdExIF.cpp', + 'AdThreshIF.cpp', + 'ExIF.cpp', + 'IntFireBase.cpp', + 'IzhIF.cpp', + 'LIF.cpp', + 'QIF.cpp', + 'testIntFire.cpp'] +intfire_lib = static_library('intfire', intfire_src) diff --git a/kinetics/meson.build b/kinetics/meson.build new file mode 100644 index 0000000000..7e083e671c --- /dev/null +++ b/kinetics/meson.build @@ -0,0 +1,17 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +kinetics_src = ['PoolBase.cpp', + 'Reac.cpp', + 'EnzBase.cpp', + 'Enz.cpp', + 'MMenz.cpp', + 'Species.cpp', + 'ConcChan.cpp', + 'ReadKkit.cpp', + 'WriteKkit.cpp', + 'ReadCspace.cpp', + 'lookupVolumeFromMesh.cpp', + 'testKinetics.cpp'] + +kinetics_lib = static_library('kinetics', kinetics_src, include_directories: gsl_dep.get_pkgconfig_variable('includedir')) diff --git a/ksolve/meson.build b/ksolve/meson.build new file mode 100644 index 0000000000..2e6f4784f9 --- /dev/null +++ b/ksolve/meson.build @@ -0,0 +1,18 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +ksolve_src = ['KinSparseMatrix.cpp', + 'VoxelPoolsBase.cpp', + 'VoxelPools.cpp', + 'GssaVoxelPools.cpp', + 'RateTerm.cpp', + 'FuncTerm.cpp', + 'Stoich.cpp', + 'Ksolve.cpp', + 'Gsolve.cpp', + 'KsolveBase.cpp', + 'SteadyStateGsl.cpp', + 'testKsolve.cpp'] + +ksolve_lib = static_library('ksolve', ksolve_src, dependencies: gsl_dep, include_directories: gsl_dep.get_pkgconfig_variable('includedir')) + diff --git a/mesh/meson.build b/mesh/meson.build new file mode 100644 index 0000000000..c7888eeebe --- /dev/null +++ b/mesh/meson.build @@ -0,0 +1,19 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +mesh_src = ['ChemCompt.cpp', + 'MeshCompt.cpp', + 'MeshEntry.cpp', + 'CubeMesh.cpp', + 'CylBase.cpp', + 'CylMesh.cpp', + 'NeuroNode.cpp', + 'NeuroMesh.cpp', + 'SpineEntry.cpp', + 'SpineMesh.cpp', + 'PsdMesh.cpp', + 'EndoMesh.cpp', + 'PresynMesh.cpp', + 'testMesh.cpp'] + +mesh_lib = static_library('mesh', mesh_src) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000000..43ad7fd7c4 --- /dev/null +++ b/meson.build @@ -0,0 +1,202 @@ +# Project to build MOOSE's python module. +# Author: Subhasis Ray +# Date: Mon Jul 8 03:11:13 IST 2024 + +# To build pymoose with meson, run the following +# `meson setup --wipe _build` +# `cd _build` +# `meson compile` + +# To build installable wheels +# python -m build + +project('pymoose', 'c', 'cpp', + default_options: ['default_library=static', 'c_std=c11', 'cpp_std=c++14']) + +pybind_dep = dependency('pybind11') +gsl_dep = dependency('gsl', version: '>=1.16') +mpi_dep = dependency('mpi', required: false) + +add_global_arguments('-DMOOSE_VERSION="4.0.1"', language: ['c', 'cpp']) +add_global_arguments('-DUSE_GSL', language: ['c', 'cpp']) + +############################################################## +# Borrowed from SciPy +############################################################## +python = import('python') +py = python.find_installation() +python_dep = py.dependency() +moose_dir = py.get_install_dir() / 'moose' + +min_numpy_version = '1.23.5' # keep in sync with pyproject.toml + +# Emit a warning for 32-bit Python installs on Windows; users are getting +# unexpected from-source builds there because we no longer provide wheels. +is_windows = host_machine.system() == 'windows' +if is_windows and py.has_variable('EXT_SUFFIX') + ext_suffix = py.get_variable('EXT_SUFFIX') + if ext_suffix.contains('win32') + warning('You are building from source on a 32-bit Python install. pymoose does not provide 32-bit wheels; install 64-bit Python if you are having issues!') + endif +endif + +cc = meson.get_compiler('c') +cpp = meson.get_compiler('cpp') +# cy = meson.get_compiler('cython') + +# Check compiler is recent enough (see "Toolchain Roadmap" for details) +if cc.get_id() == 'gcc' + if not cc.version().version_compare('>=9.1') + error('pymoose requires GCC >= 9.1') + endif +elif cc.get_id() == 'clang' or cc.get_id() == 'clang-cl' + if not cc.version().version_compare('>=12.0') + error('pymoose requires clang >= 12.0') + endif +elif cc.get_id() == 'msvc' + if not cc.version().version_compare('>=19.20') + error('pymoose requires at least vc142 (default with Visual Studio 2019) ' + \ + 'when building with MSVC') + endif +endif + + +_global_c_args = cc.get_supported_arguments( + '-Wno-unused-but-set-variable', + '-Wno-unused-function', + '-Wno-conversion', + '-Wno-misleading-indentation', +) +add_project_arguments(_global_c_args, language : 'c') + + +if host_machine.system() == 'darwin' + if cc.has_link_argument('-Wl,-ld_classic') + # New linker introduced in macOS 14 not working yet, see gh-19357 and gh-19387 + add_project_link_arguments('-Wl,-ld_classic', language : ['c', 'cpp']) + endif + if cc.has_link_argument('-Wl,-dead_strip') + # Allow linker to strip unused symbols + add_project_link_arguments('-Wl,-dead_strip', language : ['c', 'cpp']) + endif +endif + +# Link against conda env GSL +conda_res = run_command('python', '-c', 'import os; print(os.environ["CONDA_PREFIX"])') +if conda_res.returncode() == 0 + conda_lib_path = conda_res.stdout().strip() / 'Library/lib' +else + message('Environment variable CONDA_PREFIX not found. Libraries must be available in PATH, LD_LIBRARY_PARH, etc.') +endif + +if is_windows + # Deal with M_PI & friends; add `use_math_defines` to c_args or cpp_args + add_global_arguments('-D_USE_MATH_DEFINES', language: ['c', 'cpp']) + # On Windows some of the object files are too big + add_global_arguments('/bigobj', language: ['c', 'cpp']) + # Several sub libs link against the same other sublib and MSVC + # linker barfs at multiple defs of the same symbol + add_project_link_arguments('/FORCE:MULTIPLE', language: ['c', 'cpp']) + if conda_res.returncode() == 0 + add_project_link_arguments('/LIBPATH:' + conda_lib_path, language: ['c', 'cpp']) + endif +endif + + + +compilers = { + 'C': cc, + 'CPP': cpp, +} + +machines = { + 'HOST': host_machine, + 'BUILD': build_machine, +} + +conf_data = configuration_data() + +# Set compiler information +foreach name, compiler : compilers + conf_data.set(name + '_COMP', compiler.get_id()) + conf_data.set(name + '_COMP_LINKER_ID', compiler.get_linker_id()) + conf_data.set(name + '_COMP_VERSION', compiler.version()) + conf_data.set(name + '_COMP_CMD_ARRAY', ', '.join(compiler.cmd_array())) + conf_data.set(name + '_COMP_ARGS', ', '.join( + get_option(name.to_lower() + '_args') + ) + ) + conf_data.set(name + '_COMP_LINK_ARGS', ', '.join( + get_option(name.to_lower() + '_link_args') + ) + ) +endforeach + +# Machines CPU and system information +foreach name, machine : machines + conf_data.set(name + '_CPU', machine.cpu()) + conf_data.set(name + '_CPU_FAMILY', machine.cpu_family()) + conf_data.set(name + '_CPU_ENDIAN', machine.endian()) + conf_data.set(name + '_CPU_SYSTEM', machine.system()) +endforeach + + +conf_data.set('CROSS_COMPILED', meson.is_cross_build()) + +# Python information +conf_data.set('PYTHON_PATH', py.full_path()) +conf_data.set('PYTHON_VERSION', py.language_version()) + + +# End Credit: SciPy + +subdir('basecode') +subdir('biophysics') +subdir('builtins') +subdir('device') +subdir('diffusion') +subdir('examples') +subdir('hsolve') +subdir('intfire') +subdir('kinetics') +subdir('ksolve') +subdir('mesh') +subdir('mpi') +subdir('msg') +subdir('pybind11') +subdir('randnum') +subdir('scheduling') +subdir('shell') +subdir('signeur') +subdir('synapse') +subdir('utility') + + +sublibs = [ + basecode_lib, + biophysics_lib, + builtins_lib, + device_lib, + diffusion_lib, + examples_lib, + hsolve_lib, + intfire_lib, + kinetics_lib, + ksolve_lib, + mesh_lib, + mpi_lib, + msg_lib, + pybind11_lib, + randnum_lib, + scheduling_lib, + shell_lib, + signeur_lib, + synapse_lib, + utility_lib, +] + +py.extension_module('moose', 'basecode/main.cpp', + link_with: sublibs, + dependencies: [gsl_dep, mpi_dep], + include_directories: ['external/getopt'], + install: true,) diff --git a/mpi/meson.build b/mpi/meson.build new file mode 100644 index 0000000000..79b82d2b43 --- /dev/null +++ b/mpi/meson.build @@ -0,0 +1,6 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +mpi_src = ['PostMaster.cpp', 'testMpi.cpp'] +mpi_lib = static_library('mpi', mpi_src) +# TODO: add include dirs and link options if USE_MPI is defined and MPI library is available diff --git a/msg/meson.build b/msg/meson.build new file mode 100644 index 0000000000..4015906f98 --- /dev/null +++ b/msg/meson.build @@ -0,0 +1,14 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +msg_src = ['Msg.cpp', + 'DiagonalMsg.cpp', + 'OneToAllMsg.cpp', + 'OneToOneMsg.cpp', + 'SingleMsg.cpp', + 'SparseMsg.cpp', + 'OneToOneDataIndexMsg.cpp', + 'testMsg.cpp'] + +msg_lib = static_library('msg', msg_src) + diff --git a/pybind11/CMakeLists.txt b/pybind11/CMakeLists.txt index aa134472cf..4e95d6dfd8 100644 --- a/pybind11/CMakeLists.txt +++ b/pybind11/CMakeLists.txt @@ -11,24 +11,29 @@ else() OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -pybind11_add_module(_moose - pymoose.cpp - helper.cpp - Finfo.cpp - MooseVec.cpp - PyRun.cpp) - -add_dependencies(_moose libmoose) - -# Use in version_info dict. -target_compile_definitions(_moose PRIVATE - COMPILER_STRING="${CMAKE_CXX_COMPILER_ID},${CMAKE_CXX_COMPILER},${CMAKE_CXX_COMPILER_VERSION}") +if(MSVC) + add_library(pymoose OBJECT + pymoose.cpp + helper.cpp + Finfo.cpp + MooseVec.cpp + PyRun.cpp) +else() + pybind11_add_module(_moose + pymoose.cpp + helper.cpp + Finfo.cpp + MooseVec.cpp + PyRun.cpp) + add_dependencies(_moose libmoose) + # Use in version_info dict. + target_compile_definitions(_moose PRIVATE + COMPILER_STRING="${CMAKE_CXX_COMPILER_ID},${CMAKE_CXX_COMPILER},${CMAKE_CXX_COMPILER_VERSION}") -set_target_properties(_moose PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/python/moose + set_target_properties(_moose PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python/moose PREFIX "") -if(NOT WIN32) set_target_properties(_moose PROPERTIES SUFFIX ".so") endif() @@ -44,11 +49,12 @@ if(APPLE) ${STATIC_LIBRARIES}) target_link_libraries(_moose PRIVATE ${SYSTEM_SHARED_LIBS}) elseif(MSVC) - target_link_libraries(_moose PRIVATE - ${MOOSE_LIBRARIES} - ${STATIC_LIBRARIES} - ${SYSTEM_SHARED_LIBS}) -else(MSVC) + # set_property(TARGET _moose APPEND PROPERTY LINK_FLAGS /WHOLEARCHIVE) + # target_link_libraries(_moose PRIVATE + # ${MOOSE_LIBRARIES} + # ${STATIC_LIBRARIES} ) + # target_link_libraries(_moose PRIVATE ${SYSTEM_SHARED_LIBS}) +else() # Linux target_link_libraries(_moose PRIVATE "-Wl,--whole-archive" @@ -56,7 +62,7 @@ else(MSVC) ${STATIC_LIBRARIES} "-Wl,--no-whole-archive" ${SYSTEM_SHARED_LIBS}) -endif(APPLE) +endif() # Copy python tree to BUILD directory. User can set PYTHONPATH to diff --git a/pybind11/meson.build b/pybind11/meson.build new file mode 100644 index 0000000000..851f1ecbcd --- /dev/null +++ b/pybind11/meson.build @@ -0,0 +1,19 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +pybind11_src = ['Finfo.cpp', + 'helper.cpp', + 'MooseVec.cpp', + 'pymoose.cpp', + 'PyRun.cpp'] + +python_res = run_command('python', '-c', 'from sysconfig import get_paths as gp; print(gp()["include"])') +if python_res.returncode() == 0 + inc_dirs = python_res.stdout().strip() +else + message('ERROR: could not find Python include directory') + inc_dirs = [] +endif + +pybind11_lib = static_library('pybind11', pybind11_src, dependencies: pybind_dep, include_directories: inc_dirs) + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..4d12a61930 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,74 @@ +[build-system] +build-backend = 'mesonpy' +requires = ['meson-python'] + +[project] +name = 'pymoose' +version = '4.1.0.dev' +description = 'Python scripting interface of MOOSE Simulator (https://moose.ncbs.res.in)' +readme = 'README.md' +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Science/Research', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GPL 3', + 'Programming Language :: C', + 'Programming Language :: C++', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Topic :: Software Development :: Libraries', + 'Topic :: Scientific/Engineering', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX :: Linux', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Operating System :: MacOS', +] + +requires-python = '>= 3.8' +license = { file = 'LICENSE' } +authors = [ + {name = 'Upinder S. Bhalla', email = 'bhalla@ncbs.res.in'}, + {name = 'Niraj Dudani', email = ''}, + {name = 'Subhasis Ray', email = 'ray.subhasis@gmail.com'}, + {name = 'Aditya Gilra', email = ''}, + {name = 'Aviral Goel', email = ''}, + {name = 'Dilawar Singh', email = ''}, + {name = 'Dharma Teja', email = ''}, + {name = 'Malav Shah', email = ''}, + {name = 'Dhruva Gowda', email = ''}, + {name = 'G.V. Harsharani', email = 'hrani@ncbs.res.in'}, + ] + +maintainers = [ + {name = 'Upinder S. Bhalla', email = 'bhalla@ncbs.res.in'}, + {name = 'Subhasis Ray', email = 'ray.subhasis@gmail.com'}, + {name = 'G.V. Harsharani', email = 'hrani@ncbs.res.in'}, + ] + +dependencies = ['numpy>=1.23', 'matplotlib', 'vpython', 'pybind11'] + +[project.urls] +homepage = 'https://moose.ncbs.res.in' +documentation = 'https://moose.ncbs.res.in/readthedocs/index.html' +repository = 'https://github.com/BhallaLab/moose-core' + +[project.optional-dependencies] +test = [ + 'coverage', + 'pytest', + 'pytest-cov' +] + +[tool.meson-python.args] +setup = ['--default-library=static', '-Doptimization=3', '--vsenv'] +compile = ['-j4'] +dist = ['--include-subprojects'] +# Force the use of the MSVC compilers on Windows +# [tool.meson-python.args] +# setup = ['--vsenv'] \ No newline at end of file diff --git a/randnum/meson.build b/randnum/meson.build new file mode 100644 index 0000000000..72b61909cf --- /dev/null +++ b/randnum/meson.build @@ -0,0 +1,7 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +randnum_src = ['RNG.cpp', 'randnum.cpp'] +randnum_lib = static_library('randnum', randnum_src) + + diff --git a/scheduling/meson.build b/scheduling/meson.build new file mode 100644 index 0000000000..61c979092d --- /dev/null +++ b/scheduling/meson.build @@ -0,0 +1,6 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +scheduling_src = ['Clock.cpp', 'testScheduling.cpp'] +scheduling_lib = static_library('scheduling', scheduling_src) + diff --git a/shell/meson.build b/shell/meson.build new file mode 100644 index 0000000000..18ecfb7745 --- /dev/null +++ b/shell/meson.build @@ -0,0 +1,14 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +shell_src = ['Shell.cpp', + 'ShellCopy.cpp', + 'ShellThreads.cpp', + 'LoadModels.cpp', + 'SaveModels.cpp', + 'Neutral.cpp', + 'Wildcard.cpp', + 'testShell.cpp'] + +shell_lib = static_library('shell', shell_src) + diff --git a/signeur/meson.build b/signeur/meson.build new file mode 100644 index 0000000000..ccadaa1bea --- /dev/null +++ b/signeur/meson.build @@ -0,0 +1,7 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +signeur_src = ['Adaptor.cpp', 'testSigNeur.cpp'] + +signeur_lib = static_library('signeur', signeur_src) + diff --git a/synapse/meson.build b/synapse/meson.build new file mode 100644 index 0000000000..518597aeee --- /dev/null +++ b/synapse/meson.build @@ -0,0 +1,15 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +synapse_src = ['GraupnerBrunel2012CaPlasticitySynHandler.cpp', + 'RollingMatrix.cpp', + 'SeqSynHandler.cpp', + 'SimpleSynHandler.cpp', + 'STDPSynapse.cpp', + 'STDPSynHandler.cpp', + 'Synapse.cpp', + 'SynHandlerBase.cpp', + 'testSynapse.cpp'] + +synapse_lib = static_library('synapse', synapse_src) + diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 55241a08ca..ac79a2d0a5 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -9,7 +9,7 @@ add_library(utility Vec.cpp cnpy.cpp # fileutils.cpp - # utility.cpp + utility.cpp ) target_link_libraries(utility PRIVATE fmt) diff --git a/utility/meson.build b/utility/meson.build new file mode 100644 index 0000000000..05abaf746b --- /dev/null +++ b/utility/meson.build @@ -0,0 +1,11 @@ +# Author: Subhasis Ray +# Date: Sun Jul 7 + +utility_src = ['strutil.cpp', + 'types.cpp', + 'setupenv.cpp', + 'numutil.cpp', + 'Annotator.cpp', + 'Vec.cpp'] + +utility_lib = static_library('utility', utility_src)