diff --git a/CMakeLists.txt b/CMakeLists.txt index ecdec04d5f..8eec0cc509 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -572,6 +572,8 @@ endif() # ============================================================================= add_subdirectory(src/sparse13) add_subdirectory(src/gnu) +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 diff --git a/cmake/MacroHelper.cmake b/cmake/MacroHelper.cmake index fa0623c81c..e9e13c6800 100644 --- a/cmake/MacroHelper.cmake +++ b/cmake/MacroHelper.cmake @@ -142,30 +142,23 @@ macro(nrn_print_matching_variables prefix_regex) endmacro() # ============================================================================= -# Run nocmodl to convert NMODL to C +# Run nocmodl to convert NMODL to C++ # ============================================================================= -macro(nocmodl_mod_to_cpp modfile_basename) +macro(nocmodl_mod_to_cpp modfile_basename source_dir target_dir) set(NOCMODL_SED_EXPR "s/_reg()/_reg_()/") if(NOT MSVC) set(NOCMODL_SED_EXPR "'${NOCMODL_SED_EXPR}'") endif() - set(REMOVE_CMAKE_COMMAND "rm") - if(CMAKE_VERSION VERSION_LESS "3.17") - set(REMOVE_CMAKE_COMMAND "remove") - endif() add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/${modfile_basename}.cpp + OUTPUT "${target_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 - 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 - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/nrniv) + ${NRN_NOCMODL_SANITIZER_ENVIRONMENT} $ -o "${target_dir}" + "${source_dir}/${modfile_basename}.mod" + COMMAND sed -i -e ${NOCMODL_SED_EXPR} "${target_dir}/${modfile_basename}.cpp" + DEPENDS nocmodl "${source_dir}/${modfile_basename}.mod" + "${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib" + WORKING_DIRECTORY ${target_dir}) endmacro() # ============================================================================= diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index 309a3f10cb..220da09984 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -349,59 +349,6 @@ set(SCOPMATH_FILES_LIST set(NRNMPI_FILES_LIST nrnmpi.cpp memory_usage.cpp bbsmpipack.cpp mpispike.cpp) -# built-in mod files -set(MODFILE_BASE_NAMES - apcount - exp2syn - expsyn - feature - hh - intfire1 - intfire2 - intfire4 - netstim - oclmp - passive - pattern - ppmark - stim - svclmp - syn - vclmp) - -set(MODLUNIT_FILES_LIST - consist.cpp - declare.cpp - init.cpp - io.cpp - kinunit.cpp - list.cpp - model.cpp - nrnunit.cpp - passn.cpp - symbol.cpp - units.cpp - units1.cpp - version.cpp) - -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 - 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,8 +375,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_MODLUNIT_SRC_DIR ${PROJECT_SOURCE_DIR}/src/modlunit) -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) set(NRN_PARALLEL_SRC_DIR ${PROJECT_SOURCE_DIR}/src/parallel) @@ -457,11 +402,8 @@ nrn_create_file_list(NRN_SPARSE_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sparse ${SPA nrn_create_file_list(NRN_SCOPMATH_SRC_FILES ${PROJECT_SOURCE_DIR}/src/scopmath ${SCOPMATH_FILES_LIST}) nrn_create_file_list(NRN_NRNMPI_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi ${NRNMPI_FILES_LIST}) -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_MODLUNIT_SRC_FILES ${NRN_MODLUNIT_SRC_DIR} ${MODLUNIT_FILES_LIST}) -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 new file mode 100644 index 0000000000..803563eb45 --- /dev/null +++ b/src/modlunit/CMakeLists.txt @@ -0,0 +1,32 @@ +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) + +add_executable( + modlunit + consist.cpp + declare.cpp + init.cpp + io.cpp + kinunit.cpp + list.cpp + model.cpp + nrnunit.cpp + passn.cpp + symbol.cpp + units.cpp + units1.cpp + version.cpp + "${CMAKE_CURRENT_BINARY_DIR}/lex.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/parse1.cpp") +target_compile_definitions(modlunit PRIVATE NRNUNIT=1) +cpp_cc_configure_sanitizers(TARGET modlunit) +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}) +endif() + +install(TARGETS modlunit DESTINATION bin) diff --git a/src/modlunit/model.h b/src/modlunit/model.h index fcc644d6b0..8552a50b44 100644 --- a/src/modlunit/model.h +++ b/src/modlunit/model.h @@ -1,5 +1,5 @@ /* /local/src/master/nrn/src/modlunit/model.h,v 1.2 1997/11/24 16:19:13 hines Exp */ -#include "wrap_sprintf.h" +#include "utils/wrap_sprintf.hpp" #include #include diff --git a/src/modlunit/units.cpp b/src/modlunit/units.cpp index f8ff9a0d79..3c325c3f20 100644 --- a/src/modlunit/units.cpp +++ b/src/modlunit/units.cpp @@ -6,7 +6,6 @@ /* /local/src/master/nrn/src/modlunit/units.c,v 1.5 1997/11/24 16:19:13 hines Exp */ /* Mostly from Berkeley */ #include "model.h" -#include "nrnassrt.h" #include #include #include diff --git a/src/nmodl/CMakeLists.txt b/src/nmodl/CMakeLists.txt new file mode 100644 index 0000000000..64bc08ee85 --- /dev/null +++ b/src/nmodl/CMakeLists.txt @@ -0,0 +1,51 @@ +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}" "${CMAKE_CURRENT_SOURCE_DIR}" + "${CLI11_HEADER_DIRECTORY}" "${PROJECT_SOURCE_DIR}/src") +if(NRN_NMODL_CXX_FLAGS) + target_compile_options(nocmodl PRIVATE ${NRN_NMODL_CXX_FLAGS}) +endif() + +install(TARGETS nocmodl DESTINATION bin) diff --git a/src/nmodl/modl.h b/src/nmodl/modl.h index 0da34de44f..ee5d292dc1 100644 --- a/src/nmodl/modl.h +++ b/src/nmodl/modl.h @@ -1,5 +1,5 @@ #pragma once -#include "wrap_sprintf.h" +#include "utils/wrap_sprintf.hpp" #include #include diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index 3c881e67d8..d354e932d0 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -13,126 +13,18 @@ if(NRN_AVOID_ABSOLUTE_PATHS) add_compile_definitions(NRN_AVOID_ABSOLUTE_PATHS) endif() -# ============================================================================= -# Build modlunit : Mod file units checker -# ============================================================================= -set(BISON_FLEX_WORKING_DIR "${CMAKE_BINARY_DIR}") -set(NRN_MODLUNIT_GEN "${CMAKE_CURRENT_BINARY_DIR}/modlunit_generated") -file(MAKE_DIRECTORY "${NRN_MODLUNIT_GEN}") -file(RELATIVE_PATH NRN_MODLUNIT_GEN_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_MODLUNIT_GEN}") -file(RELATIVE_PATH NRN_MODLUNIT_SRC_REL "${BISON_FLEX_WORKING_DIR}" "${NRN_MODLUNIT_SRC_DIR}") -# Run flex and bison with relative paths, so absolute paths are not present in the generated source -# file because of include, __FILE__ and so on. This improves ccache performance. To generate code -# coverage correctly, the *relative* paths that are present need to be with respect to the build -# directory. -add_custom_command( - OUTPUT "${NRN_MODLUNIT_GEN}/lex.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" - COMMAND "${FLEX_EXECUTABLE}" ARGS -o "${NRN_MODLUNIT_GEN_REL}/lex.cpp" - "${NRN_MODLUNIT_SRC_REL}/lex.lpp" - DEPENDS "${NRN_MODLUNIT_SRC_DIR}/lex.lpp" - COMMENT "[FLEX][modlunitlexer] Building scanner with flex ${FLEX_VERSION}") -add_custom_command( - OUTPUT "${NRN_MODLUNIT_GEN}/parse1.hpp" "${NRN_MODLUNIT_GEN}/parse1.cpp" - WORKING_DIRECTORY "${BISON_FLEX_WORKING_DIR}" - COMMAND "${BISON_EXECUTABLE}" ARGS "--defines=${NRN_MODLUNIT_GEN_REL}/parse1.hpp" -o - "${NRN_MODLUNIT_GEN_REL}/parse1.cpp" "${NRN_MODLUNIT_SRC_REL}/parse1.ypp" - DEPENDS "${NRN_MODLUNIT_SRC_DIR}/parse1.ypp" - COMMENT "[BISON][modlunitparser] Building parser with bison ${BISON_VERSION}") - add_custom_target(generated_source_files true) -add_custom_target(modlunit_generated_files DEPENDS "${NRN_MODLUNIT_GEN}/lex.cpp" - "${NRN_MODLUNIT_GEN}/parse1.cpp") -add_dependencies(generated_source_files modlunit_generated_files) -add_executable(modlunit ${NRN_MODLUNIT_SRC_FILES} "${NRN_MODLUNIT_GEN}/lex.cpp" - "${NRN_MODLUNIT_GEN}/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}" "${NRN_MODLUNIT_GEN}") - -if(NRN_NMODL_CXX_FLAGS) - target_compile_options(modlunit PRIVATE ${NRN_NMODL_CXX_FLAGS}) -endif() - -# ============================================================================= -# Build nocmodl : source-to-source compiler for NMODL -# ============================================================================= -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 -# ============================================================================= -foreach(modfile ${NRN_MODFILE_BASE_NAMES}) - nocmodl_mod_to_cpp(${modfile}) - list(APPEND NRN_MODFILE_CPP ${PROJECT_BINARY_DIR}/${modfile}.cpp) -endforeach() -set_property( - SOURCE ${NRN_MODFILE_CPP} - APPEND - PROPERTY COMPILE_OPTIONS ${NRN_EXTRA_MECH_CXX_FLAGS}) -# we are basically emulating nrnivmodl with CMake here. nrnivmodl uses headers from the include -# directory in the build or install directory. -set_property( - SOURCE ${NRN_MODFILE_CPP} - APPEND - PROPERTY INCLUDE_DIRECTORIES ${PROJECT_BINARY_DIR}/include) -set_source_files_properties(${NRN_MODFILE_CPP} PROPERTIES GENERATED TRUE) # ============================================================================= # Bison parser for HOC interpreter # ============================================================================= 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" @@ -144,6 +36,7 @@ set(NRN_OC_GENERATED_SOURCES "${NRN_OC_GEN}" PARENT_SCOPE) +add_subdirectory(../nrnoc ../nrnoc) # ============================================================================= # Source code lists # ============================================================================= @@ -154,7 +47,6 @@ set(NRN_NRNIV_LIB_SRC_FILES ${NRN_NRNIV_SRC_FILES} ${NRN_NRNOC_SRC_FILES} ${NRN_OC_SRC_FILES} - ${NRN_MODFILE_CPP} ${NRN_SCOPMATH_SRC_FILES} ${NRN_SPARSE_SRC_FILES} ${NRN_SUNDIALS_SRC_FILES} @@ -401,6 +293,7 @@ include_directories(${NRN_INCLUDE_DIRS}) add_library(nrniv_lib ${NRN_LIBRARY_TYPE} ${NRN_NRNIV_LIB_SRC_FILES}) target_link_libraries(nrniv_lib nrngnu) target_link_libraries(nrniv_lib sparse13) +target_link_libraries(nrniv_lib default_mods) target_include_directories(nrniv_lib SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/${NRN_3RDPARTY_DIR}/eigen) cpp_cc_configure_sanitizers(TARGET nrniv_lib) # Source-directory .cpp needs to find generated .hpp. @@ -523,12 +416,6 @@ else() target_link_libraries(nrniv_lib ${X11_LIBRARIES}) endif() -if(NRN_COVERAGE_FILES) - target_link_libraries(nrniv_lib ${NRN_COVERAGE_LIB}) - target_link_libraries(modlunit ${NRN_COVERAGE_LIB}) - target_link_libraries(nocmodl ${NRN_COVERAGE_LIB}) -endif() - # ============================================================================= # Final executable # ============================================================================= @@ -558,7 +445,7 @@ endif() # For now, we keep this distinction as it reduces the PATH and is # expected when ctypes looks for dlls # ~~~ -install(TARGETS nrniv nocmodl modlunit DESTINATION bin) +install(TARGETS nrniv DESTINATION bin) install(TARGETS nrniv_lib DESTINATION ${NRN_INSTALL_SHARE_LIB_DIR}) if(LIBIVX11DYNAM_NAME) install(FILES ${PROJECT_BINARY_DIR}/lib/${LIBIVX11DYNAM_NAME} DESTINATION lib) diff --git a/src/nrnoc/CMakeLists.txt b/src/nrnoc/CMakeLists.txt new file mode 100644 index 0000000000..eeb2352127 --- /dev/null +++ b/src/nrnoc/CMakeLists.txt @@ -0,0 +1,36 @@ +# Compile mod files +set(MODFILE_BASE_NAMES + apcount + exp2syn + expsyn + feature + hh + intfire1 + intfire2 + intfire4 + netstim + oclmp + passive + pattern + ppmark + stim + svclmp + syn + vclmp) +foreach(modfile ${MODFILE_BASE_NAMES}) + nocmodl_mod_to_cpp("${modfile}" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") + list(APPEND NRN_MODFILE_CPP "${CMAKE_CURRENT_BINARY_DIR}/${modfile}.cpp") +endforeach() +set_property( + SOURCE ${NRN_MODFILE_CPP} + APPEND + PROPERTY COMPILE_OPTIONS ${NRN_EXTRA_MECH_CXX_FLAGS}) +# we are basically emulating nrnivmodl with CMake here. nrnivmodl uses headers from the include +# directory in the build or install directory. +set_source_files_properties(${NRN_MODFILE_CPP} PROPERTIES GENERATED TRUE) + +# Create a static library from mod files to be included in nrniv +add_library(default_mods STATIC ${NRN_MODFILE_CPP}) +add_dependencies(default_mods copy_headers_to_build) +target_include_directories(default_mods PRIVATE "${PROJECT_BINARY_DIR}/include") +set_property(TARGET default_mods PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/src/utils/wrap_sprintf.hpp b/src/utils/wrap_sprintf.hpp new file mode 100644 index 0000000000..bba7ddd80f --- /dev/null +++ b/src/utils/wrap_sprintf.hpp @@ -0,0 +1,20 @@ +#include +#include // std::forward + +namespace neuron { +/** + * @brief Redirect sprintf to snprintf if the buffer size can be deduced. + * + * This is useful to avoid deprecation warnings for sprintf. In general it works if the buffer is + * something like char buf[512] in the calling scope, but not if it is char* or char buf[]. + */ +template +int Sprintf(char (&buf)[N], const char* fmt, Args&&... args) { + if constexpr (sizeof...(Args) == 0) { + // try and work around a false positive from -Wformat-security when there are no arguments + return std::snprintf(buf, N, "%s", fmt); + } else { + return std::snprintf(buf, N, fmt, std::forward(args)...); + } +} +} // namespace neuron