Skip to content

cmake: export targets, allow building mechanisms via CMake, part 1 #3468

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

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

JCGoran
Copy link
Collaborator

@JCGoran JCGoran commented Jun 4, 2025

Split off from #2746 since that PR was getting a bit too large.

Context

Currently we build mechanisms (mod files) using a hand-written Makefile. As a result, we need to ship a bunch of Make-specific tools with NEURON. This also does not work (or at least, not without a lot of workarounds) in a cross-platform manner.

This PR allows one to build NEURON mechanisms with CMake, using any generator we want. The way it achieves this is by exposing the create_nrnmech CMake function, which works as follows:

cmake_minimum_required(VERSION 3.15)
project(modfile_test)

find_package(neuron REQUIRED)

create_nrnmech(NEURON CORENEURON SPECIAL MOD_FILES
  modfile1.mod
  path/to/modfile2.mod)

Note that the NEURON, CORENEURON, and SPECIAL toggle whether one builds libnrnmech, libcorenrnmech, and the special executable (enabling CORENEURON and SPECIAL together enables the special-core executable as well).

One can then build the targets via:

cmake -B build
cmake --build build

which can then be loaded into NEURON as usual:

nrniv -dll build/libnrnmech.so

Additional notes

  • the NEURON config file must be visible to CMake, i.e. it must be added to CMAKE_PREFIX_PATH, and the nmodl executable must be in PATH. Additionally, until NOCMODL fails to run from build directory without setting MODLUNIT #3470 is resolved, MODLUNIT must also be set
  • at build-time, mechanisms are still built with make, but this can be fixed later (nrnivmodl touches a lot of the internal code as well, so the changeset would be much larger)
  • when shipping wheels, the CMAKE_PREFIX_PATH should include {NEURON_INSTALL_DIR}/.data/lib/cmake, though I am not sure how to obtain it without running any external utilities
  • CMake and any of the generators should be available on the user machine. We could update the Python requirements to include cmake and ninja, but since this feature is a bit experimental, I'm not sure how useful it is
  • I've not tested anything on Windows, so I'm not sure how cross-platform it really is (i.e. we ship NEURON with msys2 or whatever else is there, but CMake would probably try to use MSVC if it's installed)

matz-e and others added 21 commits August 14, 2024 16:03
This PR aims to allow dependent projects to build their models via CMake
rather than a combination of shell scripts and Makefiles.  In the long
term, this may help facilitate building natively on Windows.

To try:
```
git clone -b imported-main https://github.com/BlueBrain/neurodamus-models.git
cd neurodamus-models
```

Create a `CMakeLists.txt` with contents like:
```cmake
cmake_minimum_required(VERSION 3.28)

project(newrodamus)

find_package(neuron REQUIRED)

create_libnrnmech(MOD_FILES
  neocortex/mod/v6/CaDynamics_DC0.mod
  neocortex/mod/v6/Ca_HVA2.mod
  neocortex/mod/v6/Ca_LVAst.mod
  neocortex/mod/v6/DetAMPANMDA.mod
  neocortex/mod/v6/DetGABAAB.mod
  neocortex/mod/v6/GluSynapse.mod
  neocortex/mod/v6/Ih.mod
  neocortex/mod/v6/K_Pst.mod
  neocortex/mod/v6/K_Tst.mod
  neocortex/mod/v6/KdShu2007.mod
  neocortex/mod/v6/NaTg.mod
  neocortex/mod/v6/Nap_Et2.mod
  neocortex/mod/v6/ProbAMPANMDA_EMS.mod
  neocortex/mod/v6/ProbGABAAB_EMS.mod
  neocortex/mod/v6/SK_E2.mod
  neocortex/mod/v6/SKv3_1.mod
  neocortex/mod/v6/StochKv3.mod
  neocortex/mod/v6/TTXDynamicsSwitch.mod
  neocortex/mod/v6/VecStim.mod
  neocortex/mod/v6/gap.mod
  neocortex/mod/v6/netstim_inhpoisson.mod
)
```

Then build and install:
```
cmake -B build -S . -GNinja -DCMAKE_INSTALL_PREFIX=x86_64
cmake --build build
cmake --install build
```

To be continued‥
Always use resolved absolute paths in CMake since nocmodl has some
trouble with symlinks.
* add docs and various args
Also finally add (hacky) test
Copy link
Contributor

github-actions bot commented Jun 4, 2025

✔️ 535bb1c -> artifacts URL

Copy link

✔️ 535bb1c -> Azure artifacts URL

Copy link

✔️ 3a7bb98 -> Azure artifacts URL

Copy link
Contributor

github-actions bot commented Jun 4, 2025

✔️ 3a7bb98 -> artifacts URL

Copy link
Contributor

github-actions bot commented Jun 4, 2025

✔️ 908dc4e -> artifacts URL

Copy link

✔️ 908dc4e -> Azure artifacts URL

Copy link
Contributor

github-actions bot commented Jun 5, 2025

✔️ 1462039 -> artifacts URL

Copy link

✔️ 1462039 -> Azure artifacts URL

Copy link

✔️ 446fb48 -> Azure artifacts URL

# - create a `special-core` executable in the `CMAKE_HOST_SYSTEM_PROCESSOR` subdirectory from the `coreneuron.cpp` file
# - link the above executable to the `corenrnmech` library
# Note that any other files created are basically noise.
# create_nrnmech(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below for the full API of create_nrnmech.

Copy link
Contributor

github-actions bot commented Jun 5, 2025

✔️ ebbe6f5 -> artifacts URL

Copy link

✔️ ebbe6f5 -> Azure artifacts URL

Copy link

sonarqubecloud bot commented Jun 5, 2025

Copy link

✔️ 81c1d1f -> Azure artifacts URL

@JCGoran
Copy link
Collaborator Author

JCGoran commented Jun 5, 2025

launch-nvhpc-ci

Copy link
Contributor

github-actions bot commented Jun 5, 2025

✔️ 81c1d1f -> artifacts URL

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.42%. Comparing base (e560105) to head (81c1d1f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3468      +/-   ##
==========================================
+ Coverage   68.40%   68.42%   +0.02%     
==========================================
  Files         682      682              
  Lines      116565   116565              
==========================================
+ Hits        79731    79760      +29     
+ Misses      36834    36805      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JCGoran
Copy link
Collaborator Author

JCGoran commented Jun 5, 2025

NVHPC CI failed for commit 81c1d1f, see logs at https://gist.github.com/JCGoran/45276e21690eda095f22ed47ca02b052
Possibly missing build files: install_manifest.txt
Possibly missing log files: test.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants