Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 523ef4f

Browse files
authored
Prevent nrnivmodl running on every build (#496)
* Prevent nrnivmodl running on every build. Also run cmake-format for the sake of the CI. * Fix standalone build of CoreNEURON. * Declare {build}/share/modfile/*.mod dependencies. This means that modifying {source}/coreneuron/mechanism/mech/modfile/{foo}.mod and running cmake --build will update {build}/share/modfile/{foo}.mod.
1 parent a0bd5c9 commit 523ef4f

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

coreneuron/CMakeLists.txt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,29 @@ set(KINDERIV_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/_kinderiv.h")
5353

5454
set(NMODL_UNITS_FILE "${CMAKE_BINARY_DIR}/share/mod2c/nrnunits.lib")
5555

56-
# copy inbuilt mod files to share
57-
file(COPY ${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/mechanism/mech/modfile
58-
DESTINATION ${CMAKE_BINARY_DIR}/share)
56+
# copy inbuilt mod files {source}/coreneuron/mechanism/mech/modfile/*.mod to
57+
# {build_dir}/share/modfile/
58+
file(GLOB builtin_modfiles
59+
"${CORENEURON_PROJECT_SOURCE_DIR}/coreneuron/mechanism/mech/modfile/*.mod")
60+
# get the corresponding list of paths to the modfiles in the build directory
61+
set(builtin_modfile_in_build_dir)
62+
foreach(builtin_modfile ${builtin_modfiles})
63+
get_filename_component(builtin_modfile_name "${builtin_modfile}" NAME)
64+
list(APPEND builtin_modfile_in_build_dir
65+
"${CMAKE_BINARY_DIR}/share/modfile/${builtin_modfile_name}")
66+
endforeach()
67+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/share/modfile")
68+
# set up a build rule that ensures the modfiles in the build directory are updated if their
69+
# counterparts in the source directory are touched
70+
add_custom_command(
71+
OUTPUT ${builtin_modfile_in_build_dir}
72+
DEPENDS ${builtin_modfiles}
73+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${builtin_modfiles}
74+
"${CMAKE_BINARY_DIR}/share/modfile")
75+
add_custom_target(copy-builtin-modfiles ALL DEPENDS ${builtin_modfile_in_build_dir})
76+
set(CORENEURON_BUILTIN_MODFILES
77+
"${builtin_modfile_in_build_dir}"
78+
CACHE STRING "List of builtin modfiles that nrnivmodl-core implicitly depends on" FORCE)
5979

6080
# =============================================================================
6181
# coreneuron GPU library
@@ -155,14 +175,18 @@ set_target_properties(
155175
# =============================================================================
156176
# create special-core with halfgap.mod for tests
157177
# =============================================================================
158-
add_custom_target(
159-
nrniv-core ALL
178+
set(modfile_directory "${CORENEURON_PROJECT_SOURCE_DIR}/tests/integration/ring_gap/mod")
179+
file(GLOB modfiles "${modfile_directory}/*.mod")
180+
set(output_binaries "${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}/special-core"
181+
"${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}/libcorenrnmech.a")
182+
add_custom_command(
183+
OUTPUT ${output_binaries}
184+
DEPENDS scopmath coreneuron ${NMODL_TARGET_TO_DEPEND} ${modfiles} ${CORENEURON_BUILTIN_MODFILES}
160185
COMMAND ${CMAKE_BINARY_DIR}/bin/nrnivmodl-core -b STATIC -m ${CORENRN_MOD2CPP_BINARY} -p 1
161-
${CORENEURON_PROJECT_SOURCE_DIR}/tests/integration/ring_gap/mod
186+
"${modfile_directory}"
162187
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
163-
BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}/special-core
164188
COMMENT "Running nrnivmodl-core with halfgap.mod")
165-
add_dependencies(nrniv-core scopmath coreneuron ${NMODL_TARGET_TO_DEPEND})
189+
add_custom_target(nrniv-core ALL DEPENDS ${output_binaries})
166190

167191
include_directories(${CORENEURON_PROJECT_SOURCE_DIR})
168192

0 commit comments

Comments
 (0)