From a3aa69b9f476a149600affa11dce6c271fb77b2c Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 16 Sep 2024 15:18:43 +0200 Subject: [PATCH] Add CMake code to use NMODL codegenerator. By adding: cmake -DNRN_ENABLE_NMODL=On ... developers can opt into replacing `nocmodl` with `nmodl`. --- bin/CMakeLists.txt | 11 +++++++++++ bin/nrnivmodl.in | 2 +- bin/nrnivmodl_makefile_cmake.in | 2 +- cmake/MacroHelper.cmake | 7 ++++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index cd537ec88e..f2f8761174 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -33,6 +33,17 @@ set(CMAKE_INSTALL_DATADIR_NMODL share/nmodl) # ============================================================================= include(CMakeListsNrnMech) + +# ============================================================================= +# Flags for picking NOCMODL/NMODL +# ============================================================================= +if(NRN_ENABLE_NMODL) + set(NRN_NMODL_--neuron "--neuron") + set(NRN_CODEGENERATOR_NAME "nmodl") +else() + set(NRN_CODEGENERATOR_NAME "nocmodl") +endif() + # ============================================================================= # nrnmech_makefile (based on coreneuron Configure templates) # ============================================================================= diff --git a/bin/nrnivmodl.in b/bin/nrnivmodl.in index ce34ff95fe..93020a817a 100755 --- a/bin/nrnivmodl.in +++ b/bin/nrnivmodl.in @@ -187,7 +187,7 @@ for i in "${files[@]}" ; do echo "\ ${base_name// /\\ }.cpp: ${f}.mod \$(NOCMODL) @printf \" -> \$(C_GREEN)NMODL\$(C_RESET) \$<\\\n\" - (cd \"$dir_name\"; @NRN_NOCMODL_SANITIZER_ENVIRONMENT_STRING@ MODLUNIT=\$(NRNUNITS) \$(NOCMODL) \"$base_name.mod\" -o \"$mdir\" $UserNMODLFLAGS) + (cd \"$dir_name\"; @NRN_NOCMODL_SANITIZER_ENVIRONMENT_STRING@ MODLUNIT=\$(NRNUNITS) \$(NOCMODL) \"$base_name.mod\" @NRN_NMODL_--neuron@ -o \"$mdir\" $UserNMODLFLAGS) ./${base_name// /\\ }.o: ${base_name// /\\ }.cpp @printf \" -> \$(C_GREEN)Compiling\$(C_RESET) ${PWD}/\$<\\\n\" diff --git a/bin/nrnivmodl_makefile_cmake.in b/bin/nrnivmodl_makefile_cmake.in index 49164a7656..da3c6fd0da 100644 --- a/bin/nrnivmodl_makefile_cmake.in +++ b/bin/nrnivmodl_makefile_cmake.in @@ -71,7 +71,7 @@ CXX_LINK_EXE = $(CXX) $(CXXFLAGS) @CMAKE_EXE_LINKER_FLAGS@ @NRN_LINK_FLAGS_STRIN CXX_LINK_SHARED = $(CXX) $(CXXFLAGS) @CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS@ @CMAKE_SHARED_LIBRARY_CXX_FLAGS@ @CMAKE_SHARED_LINKER_FLAGS@ @NRN_LINK_FLAGS_STRING@ ifeq ($(UserNMODLBIN), ) -NOCMODL = $(bindir)/nocmodl +NOCMODL = $(bindir)/@NRN_CODEGENERATOR_NAME@ else NOCMODL = $(UserNMODLBIN) endif diff --git a/cmake/MacroHelper.cmake b/cmake/MacroHelper.cmake index fa0623c81c..d7a91b38d9 100644 --- a/cmake/MacroHelper.cmake +++ b/cmake/MacroHelper.cmake @@ -153,18 +153,19 @@ macro(nocmodl_mod_to_cpp modfile_basename) if(CMAKE_VERSION VERSION_LESS "3.17") set(REMOVE_CMAKE_COMMAND "remove") endif() + get_filename_component(modfile_output_dir ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod DIRECTORY) add_custom_command( OUTPUT ${PROJECT_BINARY_DIR}/${modfile_basename}.cpp COMMAND ${CMAKE_COMMAND} -E env "MODLUNIT=${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib" - ${NRN_NOCMODL_SANITIZER_ENVIRONMENT} $ - ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod + ${NRN_NOCMODL_SANITIZER_ENVIRONMENT} ${CORENRN_NMODL_BINARY} + ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod --neuron -o ${modfile_output_dir} COMMAND sed ${NOCMODL_SED_EXPR} ${PROJECT_SOURCE_DIR}/${modfile_basename}.cpp > ${PROJECT_BINARY_DIR}/${modfile_basename}.cpp COMMAND ${CMAKE_COMMAND} -E ${REMOVE_CMAKE_COMMAND} ${PROJECT_SOURCE_DIR}/${modfile_basename}.cpp DEPENDS nocmodl ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod - ${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib + ${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib ${CORENRN_NMODL_BINARY} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/nrniv) endmacro()