Skip to content

Commit

Permalink
Added meson build files
Browse files Browse the repository at this point in the history
  • Loading branch information
subhacom committed Jul 7, 2024
1 parent c0e0229 commit 0ca6b94
Show file tree
Hide file tree
Showing 27 changed files with 692 additions and 49 deletions.
75 changes: 54 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -343,20 +348,48 @@ 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_OBJECTS:moose_builtins>
$<TARGET_OBJECTS:msg>
$<TARGET_OBJECTS:shell>
$<TARGET_OBJECTS:randnum>
$<TARGET_OBJECTS:scheduling>
$<TARGET_OBJECTS:moose_mpi>
$<TARGET_OBJECTS:biophysics>
$<TARGET_OBJECTS:utility>
$<TARGET_OBJECTS:kinetics>
$<TARGET_OBJECTS:synapse>
$<TARGET_OBJECTS:intfire>
$<TARGET_OBJECTS:hsolve>
$<TARGET_OBJECTS:mesh>
$<TARGET_OBJECTS:signeur>
$<TARGET_OBJECTS:diffusion>
$<TARGET_OBJECTS:ksolve>
$<TARGET_OBJECTS:lsoda>
$<TARGET_OBJECTS:device>
$<TARGET_OBJECTS:basecode>
$<TARGET_OBJECTS:pymoose>)

# 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}
${STATIC_LIBRARIES}
"-Wl,--no-whole-archive"
${SYSTEM_SHARED_LIBS}
)
endif(APPLE)
endif()

if(NOT MSVC)
add_dependencies(moose.bin libmoose)
Expand All @@ -365,7 +398,7 @@ endif()

if( WITH_BOOST AND NOT MSVC)
target_link_libraries( moose.bin ${Boost_LIBRARIES} )
endif( WITH_BOOST )
endif()


######################### BUILD PYMOOSE ########################################
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
16 changes: 11 additions & 5 deletions WindowsBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion basecode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
add_library(basecode
add_library(basecode OBJECT
Element.cpp
DataElement.cpp
GlobalDataElement.cpp
Expand Down
35 changes: 35 additions & 0 deletions basecode/meson.build
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions biophysics/meson.build
Original file line number Diff line number Diff line change
@@ -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'))
30 changes: 30 additions & 0 deletions builtins/meson.build
Original file line number Diff line number Diff line change
@@ -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'])
9 changes: 9 additions & 0 deletions device/meson.build
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions diffusion/meson.build
Original file line number Diff line number Diff line change
@@ -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'))
7 changes: 7 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Author: Subhasis Ray
# Date: Sun Jul 7

examples_src = ['Example.cpp',
'Ex.cpp']

examples_lib = static_library('examples', examples_src)
19 changes: 19 additions & 0 deletions hsolve/meson.build
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions intfire/meson.build
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 0ca6b94

Please sign in to comment.