cmake: export targets, allow building mechanisms via CMake, part 1 - #3468
Conversation
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.
lcov was complaining
Only report a warning (not an error) if Bison < 3.7 and using lcov
…o jelic/alternative_nmodl_fix
* add docs and various args
|
✔️ d0f8f46 -> Azure artifacts URL |
|
✔️ d0f8f46 -> artifacts URL |
|
After a bunch of tweaking, I think this actually works now, albeit it's a bit of a large changeset. I also added the
On my machine with 24 cores this is about 3x faster than via Usage is same as The only difference of using the convenience script(s) w.r.t. the "original" This is due to the fact that the so the relative path between the mod file(s) and where the source is can be quite long. This has no impact whatsoever on the loading of mechanisms since the loading procedure only cares about where TODO (either in this PR or another one):
|
|
|
✔️ 5d59350 -> Azure artifacts URL |
|
✔️ 52728a8 -> Azure artifacts URL |
|
✔️ 94081a3 -> Azure artifacts URL |
|
|
✔️ 504d229 -> Azure artifacts URL |
|
I reviewed this PR and I think it looks good to merge. I read through the changes and I checked that the tests run and pass. Someday we're going to want more documentation. This is a complicated change to the program, and I feel like a few flow-charts would go a long way towards explaining how each file fits into the program. But that is an issue for later, after we're done fixing up the build system. |



Split off from #2746 since that PR was getting a bit too large.
Needs #3674.
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_nrnmechCMake function, which works as follows:Note that the
NEURON,CORENEURON, andSPECIALtoggle whether one buildslibnrnmech,libcorenrnmech, and thespecialexecutable (enablingCORENEURONandSPECIALtogether enables thespecial-coreexecutable as well).One can then build the targets via:
which can then be loaded into NEURON as usual:
Additional notes
CMAKE_PREFIX_PATH,and thenmodlexecutable must be inPATHnmodlis now installed as a NEURON target so we only needCMAKE_PREFIX_PATH.Additionally, until NOCMODL fails to run from build directory without settingissue fixed!MODLUNIT#3470 is resolved,MODLUNITmust also be setnrnivmodltouches a lot of the internal code as well, so the changeset would be much larger)CMAKE_PREFIX_PATHshould include{NEURON_WHEEL_DIR}/.data/lib/cmake, though I am not sure how to obtain it without running any external utilitiescmakeandninja, but since this feature is a bit experimental, I'm not sure how useful it iswe are hardcoding some of the CLI options for now, which means that one should build NEURON from source, and then use the same installation for building mechanisms (otherwise I cannot guarantee that the mechanism-building will work)looks like it works without too much hardcodingrunningadded the same workaround as we use for wheels so now it worksspecialwhen building from a wheel currently does not work OOTB because of the fact that NEURON hardcodes the path tonrnpyenv.sh. The workaround is to addNEURONHOME=${NEURON_WHEEL_DIR}/.data/share/nrn"to the envspecial-corewith NVHPC 25.3 and it works without issues. I did not want to add too many new tests since that will be tested anyway once the CMake build itself starts usingcreate_nrnmechinstead of callingnrnivmodl(that's planned for part 2)CMAKE_PREFIX_PATH)