Skip to content

Commit

Permalink
Add CMake code to use NMODL codegenerator.
Browse files Browse the repository at this point in the history
By adding:

    cmake -DNRN_ENABLE_NMODL=On ...

developers can opt into replacing `nocmodl` with `nmodl`.
  • Loading branch information
1uc committed Oct 31, 2024
1 parent 119e918 commit a3aa69b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion bin/nrnivmodl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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\"
Expand Down
2 changes: 1 addition & 1 deletion bin/nrnivmodl_makefile_cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions cmake/MacroHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} $<TARGET_FILE:nocmodl>
${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()

Expand Down

0 comments on commit a3aa69b

Please sign in to comment.