diff --git a/CMakeLists.txt b/CMakeLists.txt index 68a89cecf5..8eec0cc509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -572,8 +572,9 @@ endif() # ============================================================================= add_subdirectory(src/sparse13) add_subdirectory(src/gnu) -add_subdirectory(src/nrniv) add_subdirectory(src/modlunit) +add_subdirectory(src/nmodl) +add_subdirectory(src/nrniv) # Collect the environment variables that are needed to execute NEURON from the build directory. This # is used when configuring tests, and when building documentation targets. diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index f14464a85d..19414a9267 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -393,25 +393,6 @@ set(MODFILE_BASE_NAMES syn vclmp) -set(NMODL_FILES_LIST - consist.cpp - deriv.cpp - discrete.cpp - init.cpp - io.cpp - kinetic.cpp - list.cpp - modl.cpp - nocpout.cpp - noccout.cpp - parsact.cpp - netrec_discon.cpp - simultan.cpp - solve.cpp - symbol.cpp - units.cpp - version.cpp) - set(IVOS_FILES_LIST observe.cpp resource.cpp) set(MPI_DYNAMIC_INCLUDE nrnmpi_dynam.h nrnmpi_dynam_cinc nrnmpi_dynam_wrappers.inc) @@ -428,7 +409,6 @@ set(NRN_IVOC_SRC_DIR ${PROJECT_SOURCE_DIR}/src/ivoc) set(NRN_NODEORDEROPTIM_SRC_DIR ${PROJECT_SOURCE_DIR}/src/coreneuron/permute) set(NRN_NRNCVODE_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nrncvode) set(NRN_NRNIV_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nrniv) -set(NRN_NMODL_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nmodl) set(NRN_IVOS_SRC_DIR ${PROJECT_SOURCE_DIR}/src/ivos) set(NRN_MUSIC_SRC_DIR ${PROJECT_SOURCE_DIR}/src/neuronmusic) @@ -457,7 +437,6 @@ nrn_create_file_list(NRN_NRNPYTHON_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnpython nrn_create_file_list(NRN_MODFILE_BASE_NAMES src/nrnoc ${MODFILE_BASE_NAMES}) nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/ivoc/ nrnmain.cpp) nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/oc/ ockludge.cpp modlreg.cpp) -nrn_create_file_list(NRN_NMODL_SRC_FILES ${NRN_NMODL_SRC_DIR} ${NMODL_FILES_LIST}) nrn_create_file_list(NRNMPI_DYNAMIC_INCLUDE_FILE ${PROJECT_SOURCE_DIR}/src/nrnmpi ${MPI_DYNAMIC_INCLUDE}) nrn_create_file_list(NRN_IVOS_SRC_FILES ${NRN_IVOS_SRC_DIR} ${IVOS_FILES_LIST}) diff --git a/src/modlunit/CMakeLists.txt b/src/modlunit/CMakeLists.txt index 1553e8f341..aebcf57a35 100644 --- a/src/modlunit/CMakeLists.txt +++ b/src/modlunit/CMakeLists.txt @@ -1,6 +1,3 @@ -# ============================================================================= -# Build modlunit : Mod file units checker -# ============================================================================= flex_target(modlunit_lex lex.lpp ${CMAKE_CURRENT_BINARY_DIR}/lex.cpp) bison_target(modlunit_parse parse1.ypp ${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parse1.hpp) @@ -22,8 +19,7 @@ add_executable(modlunit "${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp") target_compile_definitions(modlunit PRIVATE NRNUNIT=1) cpp_cc_configure_sanitizers(TARGET modlunit) -# Generated .cpp needs to find source-directory .hpp and vice versa. -target_include_directories(modlunit PRIVATE "${NRN_MODLUNIT_SRC_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/src") +target_include_directories(modlunit PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}") if(NRN_NMODL_CXX_FLAGS) target_compile_options(modlunit PRIVATE ${NRN_NMODL_CXX_FLAGS}) diff --git a/src/nmodl/CMakeLists.txt b/src/nmodl/CMakeLists.txt new file mode 100644 index 0000000000..7725c64646 --- /dev/null +++ b/src/nmodl/CMakeLists.txt @@ -0,0 +1,49 @@ +flex_target(nocmodl_lex lex.lpp ${CMAKE_CURRENT_BINARY_DIR}/lex.cpp) +bison_target(nocmodl_parse parse1.ypp ${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parse1.hpp) +bison_target(nocmodl_diffeq diffeq.ypp ${CMAKE_CURRENT_BINARY_DIR}/diffeq.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/diffeq.hpp) + +add_custom_target( + nocmodl_generated_files + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/lex.cpp" "${CMAKE_CURRENT_BINARY_DIR}/parse1.hpp" "${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/diffeq.hpp" "${CMAKE_CURRENT_BINARY_DIR}/diffeq.cpp") + # add_dependencies(generated_source_files nocmodl_generated_files) +add_executable(nocmodl + consist.cpp + deriv.cpp + discrete.cpp + init.cpp + io.cpp + kinetic.cpp + list.cpp + modl.cpp + nocpout.cpp + noccout.cpp + parsact.cpp + netrec_discon.cpp + simultan.cpp + solve.cpp + symbol.cpp + ../modlunit/units.cpp + version.cpp + "${CMAKE_CURRENT_BINARY_DIR}/lex.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/diffeq.cpp") +cpp_cc_configure_sanitizers(TARGET nocmodl) +target_compile_definitions(nocmodl PRIVATE COMPILE_DEFINITIONS NMODL=1 CVODE=1) + +# Otherwise the generated code in the binary directory does not find headers in the modlunit source +# directory and the source files in the source directory do not find generated headers in the binary +# directory. TODO: (see also coreneuron) fix adding a dependency on CLI11::CLI11 when CLI11 is a +# submodule. Right now this doesn't work because the CLI11 targets are not exported/installed but +# coreneuron-core is. +get_target_property(CLI11_HEADER_DIRECTORY CLI11::CLI11 INTERFACE_INCLUDE_DIRECTORIES) +target_include_directories(nocmodl PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "${CLI11_HEADER_DIRECTORY}" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/src") +if(NRN_NMODL_CXX_FLAGS) + target_compile_options(nocmodl PRIVATE ${NRN_NMODL_CXX_FLAGS}) +endif() + +if(NRN_COVERAGE_FILES) + target_link_libraries(nocmodl ${NRN_COVERAGE_LIB}) +endif() + +install(TARGETS nocmodl DESTINATION bin) diff --git a/src/nmodl/units.cpp b/src/nmodl/units.cpp deleted file mode 100755 index a618b6e73b..0000000000 --- a/src/nmodl/units.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include <../../nrnconf.h> -/* - * Automake doesn't deal well with sources that live in other directories. - * This is a quick and dirty workaround. - */ -#include "../modlunit/units.cpp" diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 98ffc31067..5dd6a3ed3e 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -13,61 +13,8 @@ if(NRN_AVOID_ABSOLUTE_PATHS) add_compile_definitions(NRN_AVOID_ABSOLUTE_PATHS) endif() -# ============================================================================= -# Build modlunit : Mod file units checker -# ============================================================================= add_custom_target(generated_source_files true) -# ============================================================================= -# Build nocmodl : source-to-source compiler for NMODL -# ============================================================================= -set(BISON_FLEX_WORKING_DIR "${CMAKE_BINARY_DIR}") -set(NRN_NMODL_GEN "${CMAKE_CURRENT_BINARY_DIR}/nocmodl_generated") -file(MAKE_DIRECTORY "${NRN_NMODL_GEN}") -file(RELATIVE_PATH NRN_NMODL_GEN_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_NMODL_GEN}") -file(RELATIVE_PATH NRN_NMODL_SRC_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_NMODL_SRC_DIR}") -add_custom_command( - OUTPUT "${NRN_NMODL_GEN}/lex.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" - COMMAND "${FLEX_EXECUTABLE}" ARGS -o "${NRN_NMODL_GEN_REL}/lex.cpp" "${NRN_NMODL_SRC_REL}/lex.lpp" - DEPENDS "${NRN_NMODL_SRC_DIR}/lex.lpp" - COMMENT "[FLEX][nocmodllexer] Building scanner with flex ${FLEX_VERSION}") -add_custom_command( - OUTPUT "${NRN_NMODL_GEN}/parse1.hpp" "${NRN_NMODL_GEN}/parse1.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" - COMMAND "${BISON_EXECUTABLE}" ARGS "--defines=${NRN_NMODL_GEN_REL}/parse1.hpp" -o - "${NRN_NMODL_GEN_REL}/parse1.cpp" "${NRN_NMODL_SRC_REL}/parse1.ypp" - DEPENDS "${NRN_NMODL_SRC_DIR}/parse1.ypp" - COMMENT "[BISON][nocmodlparser] Building parser with bison ${BISON_VERSION}") -add_custom_command( - OUTPUT "${NRN_NMODL_GEN}/diffeq.hpp" "${NRN_NMODL_GEN}/diffeq.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" - COMMAND "${BISON_EXECUTABLE}" ARGS "--defines=${NRN_NMODL_GEN_REL}/diffeq.hpp" -o - "${NRN_NMODL_GEN_REL}/diffeq.cpp" "${NRN_NMODL_SRC_REL}/diffeq.ypp" - DEPENDS "${NRN_NMODL_SRC_DIR}/diffeq.ypp" - COMMENT "[BISON][nocmodlparser] Building parser with bison ${BISON_VERSION}") - -add_custom_target( - nocmodl_generated_files - DEPENDS "${NRN_NMODL_GEN}/lex.cpp" "${NRN_NMODL_GEN}/parse1.hpp" "${NRN_NMODL_GEN}/parse1.cpp" - "${NRN_NMODL_GEN}/diffeq.hpp" "${NRN_NMODL_GEN}/diffeq.cpp") -add_dependencies(generated_source_files nocmodl_generated_files) -add_executable(nocmodl ${NRN_NMODL_SRC_FILES} "${NRN_NMODL_GEN}/lex.cpp" - "${NRN_NMODL_GEN}/parse1.cpp" "${NRN_NMODL_GEN}/diffeq.cpp") -cpp_cc_configure_sanitizers(TARGET nocmodl) -target_compile_definitions(nocmodl PRIVATE COMPILE_DEFINITIONS NMODL=1 CVODE=1) -# Otherwise the generated code in the binary directory does not find headers in the modlunit source -# directory and the source files in the source directory do not find generated headers in the binary -# directory. TODO: (see also coreneuron) fix adding a dependency on CLI11::CLI11 when CLI11 is a -# submodule. Right now this doesn't work because the CLI11 targets are not exported/installed but -# coreneuron-core is. -get_target_property(CLI11_HEADER_DIRECTORY CLI11::CLI11 INTERFACE_INCLUDE_DIRECTORIES) -target_include_directories(nocmodl PRIVATE "${NRN_NMODL_GEN}" "${NRN_NMODL_SRC_DIR}" - "${CLI11_HEADER_DIRECTORY}") -if(NRN_NMODL_CXX_FLAGS) - target_compile_options(nocmodl PRIVATE ${NRN_NMODL_CXX_FLAGS}) -endif() - # ============================================================================= # Translate all MOD files to C and mark them generated # ============================================================================= @@ -92,11 +39,11 @@ set_source_files_properties(${NRN_MODFILE_CPP} PROPERTIES GENERATED TRUE) # ============================================================================= set(NRN_OC_GEN "${CMAKE_CURRENT_BINARY_DIR}/oc_generated") file(MAKE_DIRECTORY "${NRN_OC_GEN}") -file(RELATIVE_PATH NRN_OC_GEN_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_OC_GEN}") -file(RELATIVE_PATH NRN_OC_SRC_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_OC_SRC_DIR}") +file(RELATIVE_PATH NRN_OC_GEN_REL "${CMAKE_CURRENT_BINARY_DIR}" "${NRN_OC_GEN}") +file(RELATIVE_PATH NRN_OC_SRC_REL "${CMAKE_CURRENT_BINARY_DIR}" "${NRN_OC_SRC_DIR}") add_custom_command( OUTPUT "${NRN_OC_GEN}/parse.hpp" "${NRN_OC_GEN}/parse.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" COMMAND "${BISON_EXECUTABLE}" ARGS "--defines=${NRN_OC_GEN_REL}/parse.hpp" -o "${NRN_OC_GEN_REL}/parse.cpp" "${NRN_OC_SRC_REL}/parse.ypp" DEPENDS "${NRN_OC_SRC_DIR}/parse.ypp"