Skip to content

Commit

Permalink
Make hh.mod configure-able at compile-time
Browse files Browse the repository at this point in the history
* introduce `NRN_SUPPORTED_KEYWORD` to differentiate whether the backend
  (NEURON or CoreNEURON) supports it
* rename `hh.mod` to `hh.mod.in`
* add `hh.mod` to .gitignore since it's still generated
  • Loading branch information
JCGoran committed Dec 17, 2024
1 parent 8dfe5a3 commit fce18df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ virtualenv
docs/_build
docs/_generated
.vscode
src/nrnoc/hh.mod
24 changes: 0 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -789,30 +789,6 @@ add_custom_target(
COMMENT "Format only files modified with respect to master branch."
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

# =============================================================================
# ~~~
# Update hh.mod for CoreNEURON compatibility
# - Replace GLOBAL variable by RANGE
# - Comment out TABLE
# ~~~
# =============================================================================
if(NRN_ENABLE_CORENEURON OR NRN_ENABLE_MOD_COMPATIBILITY)
set(GLOBAL_VAR_TOGGLE_COMMAND "'s/ GLOBAL minf/ RANGE minf/'")
else()
set(GLOBAL_VAR_TOGGLE_COMMAND "'s/ RANGE minf/ GLOBAL minf/'")
endif()
separate_arguments(GLOBAL_VAR_TOGGLE_COMMAND UNIX_COMMAND "${GLOBAL_VAR_TOGGLE_COMMAND}")
add_custom_target(
hh_update
COMMAND sed ${GLOBAL_VAR_TOGGLE_COMMAND} ${CMAKE_SOURCE_DIR}/src/nrnoc/hh.mod >
${CMAKE_BINARY_DIR}/hh.mod.1
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/hh.mod.1
${CMAKE_SOURCE_DIR}/src/nrnoc/hh.mod
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/hh.mod.1
COMMENT "Update hh.mod for CoreNEURON compatibility"
VERBATIM)
add_dependencies(nrniv_lib hh_update)

# =============================================================================
# Generate help_data.dat
# =============================================================================
Expand Down
5 changes: 5 additions & 0 deletions cmake/MacroHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ macro(nocmodl_mod_to_cpp modfile_basename)
if(CMAKE_VERSION VERSION_LESS "3.17")
set(REMOVE_CMAKE_COMMAND "remove")
endif()
set(MODFILE_CONFIG_FILE ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod.in)
if(EXISTS ${MODFILE_CONFIG_FILE})
configure_file(${MODFILE_CONFIG_FILE} ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod @ONLY)
endif()

get_filename_component(modfile_output_dir ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod DIRECTORY)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/${modfile_basename}.cpp
Expand Down
11 changes: 11 additions & 0 deletions src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ endif()
# Translate all MOD files to C and mark them generated
# =============================================================================
foreach(modfile ${NRN_MODFILE_BASE_NAMES})
# =============================================================================
# ~~~
# Set the correct supported keyword for CoreNEURON compatibility
# - Replace GLOBAL variable by RANGE
# ~~~
# =============================================================================
if(NRN_ENABLE_CORENEURON OR NRN_ENABLE_MOD_COMPATIBILITY)
set(NRN_SUPPORTED_KEYWORD "RANGE")
else()
set(NRN_SUPPORTED_KEYWORD "GLOBAL")
endif()
nocmodl_mod_to_cpp(${modfile})
list(APPEND NRN_MODFILE_CPP ${PROJECT_BINARY_DIR}/${modfile}.cpp)
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions src/nrnoc/hh.mod → src/nrnoc/hh.mod.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ NEURON {
USEION k READ ek WRITE ik REPRESENTS CHEBI:29103
NONSPECIFIC_CURRENT il
RANGE gnabar, gkbar, gl, el, gna, gk
: `GLOBAL minf` will be replaced with `RANGE minf` if CoreNEURON enabled
GLOBAL minf, hinf, ninf, mtau, htau, ntau
: set at compile-time to `GLOBAL` if using NEURON, `RANGE` if using CoreNEURON
@NRN_SUPPORTED_KEYWORD@ minf, hinf, ninf, mtau, htau, ntau
THREADSAFE : assigned GLOBALs will be per thread
}

Expand Down

0 comments on commit fce18df

Please sign in to comment.