From fce18dfc2a85a8de1c06ce67a038c2d137347459 Mon Sep 17 00:00:00 2001 From: Goran Jelic-Cizmek Date: Tue, 17 Dec 2024 11:50:29 +0100 Subject: [PATCH] Make `hh.mod` configure-able at compile-time * 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 --- .gitignore | 1 + CMakeLists.txt | 24 ------------------------ cmake/MacroHelper.cmake | 5 +++++ src/nrniv/CMakeLists.txt | 11 +++++++++++ src/nrnoc/{hh.mod => hh.mod.in} | 4 ++-- 5 files changed, 19 insertions(+), 26 deletions(-) rename src/nrnoc/{hh.mod => hh.mod.in} (95%) diff --git a/.gitignore b/.gitignore index 62594fc0bc..7bedc9af56 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ virtualenv docs/_build docs/_generated .vscode +src/nrnoc/hh.mod diff --git a/CMakeLists.txt b/CMakeLists.txt index 48095702a3..e46ae3baf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 # ============================================================================= diff --git a/cmake/MacroHelper.cmake b/cmake/MacroHelper.cmake index d75172ebc9..04951d9c10 100644 --- a/cmake/MacroHelper.cmake +++ b/cmake/MacroHelper.cmake @@ -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 diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 33fd26ceb5..32f21a7ea8 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -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() diff --git a/src/nrnoc/hh.mod b/src/nrnoc/hh.mod.in similarity index 95% rename from src/nrnoc/hh.mod rename to src/nrnoc/hh.mod.in index 0c7305ee1b..7a43a96a8e 100644 --- a/src/nrnoc/hh.mod +++ b/src/nrnoc/hh.mod.in @@ -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 }