Skip to content

Commit

Permalink
Build nocmodl with its own CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Apr 22, 2024
1 parent 084effa commit 54a5131
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 84 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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.
Expand Down
21 changes: 0 additions & 21 deletions cmake/NeuronFileLists.cmake
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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})
Expand Down
3 changes: 0 additions & 3 deletions 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)

Expand Down
49 changes: 49 additions & 0 deletions 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)
6 changes: 0 additions & 6 deletions src/nmodl/units.cpp

This file was deleted.

56 changes: 3 additions & 53 deletions src/nrniv/CMakeLists.txt
Expand Up @@ -18,56 +18,6 @@ endif()
# =============================================================================
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
# =============================================================================
Expand All @@ -92,11 +42,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"
Expand Down

0 comments on commit 54a5131

Please sign in to comment.