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

Commit 0b3b9e9

Browse files
authored
Add *NRN_VERSION_* macros, new version 8.2.0 (#796)
* CoreNEURON version bumped to 8.2.0 to match NEURON; from now on CoreNEURON versions will track NEURON ones. - Checks are added at the CMake level to make sure these do not drift out of sync. * Add *NRN_VERSION_* macros and variables. - Based on CoreNEURON version when standalone, NEURON version when built as a submodule. - These are implicitly available in all translated mechanisms.
1 parent 4cf453f commit 0b3b9e9

File tree

7 files changed

+97
-15
lines changed

7 files changed

+97
-15
lines changed

CMake/coreneuron-config.cmake.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =============================================================================
2-
# Copyright (C) 2016-2021 Blue Brain Project
2+
# Copyright (C) 2016-2022 Blue Brain Project
33
#
44
# See top-level LICENSE file for details.
55
# =============================================================================
@@ -8,6 +8,9 @@
88

99
get_filename_component(CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)
1010

11+
set(CORENRN_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
12+
set(CORENRN_VERSION_MINOR @PROJECT_VERSION_MINOR@)
13+
set(CORENRN_VERSION_PATCH @PROJECT_VERSION_PATCH@)
1114
set(CORENRN_ENABLE_GPU @CORENRN_ENABLE_GPU@)
1215
set(CORENRN_ENABLE_NMODL @CORENRN_ENABLE_NMODL@)
1316
set(CORENRN_ENABLE_REPORTING @CORENRN_ENABLE_REPORTING@)

CMakeLists.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
# See top-level LICENSE file for details.
55
# =============================================================================
66
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
7+
# CoreNEURON's version jumped from 1.0 to 8.2.0 with the introduction of the NRN_VERSION_* macros
8+
# for use in VERBATIM blocks. Starting from this version, the NEURON and CoreNEURON versions are
9+
# locked together. A version has to be hardcoded here to handle the case that CoreNEURON is built
10+
# standalone.
711
project(
812
coreneuron
9-
VERSION 1.0
13+
VERSION 8.2.0
1014
LANGUAGES CXX)
1115

1216
# ~~~
@@ -36,11 +40,40 @@ endif()
3640
# =============================================================================
3741
# Settings to enable project as submodule
3842
# =============================================================================
43+
set(CORENEURON_PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
3944
set(CORENEURON_PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
4045
set(CORENEURON_AS_SUBPROJECT OFF)
4146
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
4247
set(CORENEURON_AS_SUBPROJECT ON)
43-
endif()
48+
# Make these visible to the parent project (NEURON) so it can do some sanity checking.
49+
set_property(GLOBAL PROPERTY CORENRN_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
50+
set_property(GLOBAL PROPERTY CORENRN_VERSION_MINOR ${PROJECT_VERSION_MINOR})
51+
set_property(GLOBAL PROPERTY CORENRN_VERSION_PATCH ${PROJECT_VERSION_PATCH})
52+
endif()
53+
if(NOT DEFINED NRN_VERSION_MAJOR
54+
OR NOT DEFINED NRN_VERSION_MINOR
55+
OR NOT DEFINED NRN_VERSION_PATCH)
56+
if(CORENEURON_AS_SUBPROJECT)
57+
set(level WARNING)
58+
else()
59+
set(level STATUS)
60+
endif()
61+
# Typically in this case CoreNEURON is being built standalone. In this case NRN_VERSION_* macros
62+
# resolve to the CoreNEURON version, which is supposed to be moving in lockstep with the NEURON
63+
# version.
64+
set(NRN_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
65+
set(NRN_VERSION_MINOR ${PROJECT_VERSION_MINOR})
66+
set(NRN_VERSION_PATCH ${PROJECT_VERSION_PATCH})
67+
message(${level} "CoreNEURON could not determine the NEURON version, using the hardcoded "
68+
"${NRN_VERSION_MAJOR}.${NRN_VERSION_MINOR}.${NRN_VERSION_PATCH}")
69+
endif()
70+
# Regardless of whether we are being built as a submodule of NEURON, NRN_VERSION_{MAJOR,MINOR,PATCH}
71+
# are now set to the version that we should claim compatibility with when compiling translated MOD
72+
# files. Generate a header under a special `generated` prefix in the build directory, so that
73+
# -I/path/to/src -I/path/to/build/generated is safe (headers from the source prefix are copied
74+
# elsewhere under the build prefix, so there is scope for confusion)
75+
configure_file(coreneuron/config/neuron_version.hpp.in
76+
generated/coreneuron/config/neuron_version.hpp)
4477

4578
# =============================================================================
4679
# Include cmake modules path

coreneuron/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ set(CORENRN_MPI_LIB_NAME
187187
if(CORENRN_ENABLE_MPI AND NOT CORENRN_ENABLE_MPI_DYNAMIC)
188188
add_library(${CORENRN_MPI_LIB_NAME} OBJECT ${MPI_LIB_FILES})
189189
target_include_directories(
190-
${CORENRN_MPI_LIB_NAME}
191-
PRIVATE ${MPI_INCLUDE_PATH}
192-
PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR})
190+
${CORENRN_MPI_LIB_NAME} PRIVATE ${MPI_INCLUDE_PATH} ${CORENEURON_PROJECT_SOURCE_DIR}
191+
${CORENEURON_PROJECT_BINARY_DIR}/generated)
193192
set_property(TARGET ${CORENRN_MPI_LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
194193
set(CORENRN_MPI_OBJ $<TARGET_OBJECTS:${CORENRN_MPI_LIB_NAME}>)
195194
endif()
@@ -206,7 +205,8 @@ add_library(
206205
${MPI_CORE_FILES}
207206
${CORENRN_MPI_OBJ})
208207

209-
target_include_directories(coreneuron PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR})
208+
target_include_directories(coreneuron PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR}
209+
${CORENEURON_PROJECT_BINARY_DIR}/generated)
210210
# we can link to MPI libraries in non-dynamic-mpi build
211211
if(CORENRN_ENABLE_MPI AND NOT CORENRN_ENABLE_MPI_DYNAMIC)
212212
target_link_libraries(coreneuron ${MPI_CXX_LIBRARIES})
@@ -234,9 +234,8 @@ if(CORENRN_ENABLE_MPI AND CORENRN_ENABLE_MPI_DYNAMIC)
234234
add_library(${CORENRN_MPI_LIB_NAME} SHARED ${MPI_LIB_FILES})
235235
target_link_libraries(${CORENRN_MPI_LIB_NAME} ${MPI_CXX_LIBRARIES})
236236
target_include_directories(
237-
${CORENRN_MPI_LIB_NAME}
238-
PRIVATE ${MPI_INCLUDE_PATH}
239-
PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR})
237+
${CORENRN_MPI_LIB_NAME} PRIVATE ${MPI_INCLUDE_PATH} ${CORENEURON_PROJECT_SOURCE_DIR}
238+
${CORENEURON_PROJECT_BINARY_DIR}/generated)
240239
set_property(TARGET ${CORENRN_MPI_LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
241240
list(APPEND corenrn_mpi_targets ${CORENRN_MPI_LIB_NAME})
242241
else()
@@ -259,7 +258,7 @@ if(CORENRN_ENABLE_MPI AND CORENRN_ENABLE_MPI_DYNAMIC)
259258
target_include_directories(
260259
core${libname}_lib
261260
PUBLIC ${include}
262-
PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR})
261+
PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR} ${CORENEURON_PROJECT_BINARY_DIR}/generated)
263262

264263
# ~~~
265264
# TODO: somehow mingw requires explicit linking. This needs to be verified
@@ -295,7 +294,8 @@ add_dependencies(coreneuron kin_deriv_header nrnivmodl-core)
295294

296295
# scopmath is created separately for nrnivmodl-core workflow
297296
add_library(scopmath STATIC ${CORENEURON_HEADER_FILES} ${SCOPMATH_CODE_FILES})
298-
target_include_directories(scopmath PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR})
297+
target_include_directories(scopmath PRIVATE ${CORENEURON_PROJECT_SOURCE_DIR}
298+
${CORENEURON_PROJECT_BINARY_DIR}/generated)
299299

300300
target_link_libraries(coreneuron ${reportinglib_LIBRARY} ${sonatareport_LIBRARY} ${CALIPER_LIB}
301301
${likwid_LIBRARIES})
@@ -374,6 +374,8 @@ file(
374374
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
375375
*.h *.hpp *.ispc)
376376

377+
configure_file("${CORENEURON_PROJECT_BINARY_DIR}/generated/coreneuron/config/neuron_version.hpp"
378+
"${CMAKE_BINARY_DIR}/include/coreneuron/config/neuron_version.hpp" COPYONLY)
377379
foreach(header ${main_headers})
378380
configure_file("${header}" "${CMAKE_BINARY_DIR}/include/coreneuron/${header}" COPYONLY)
379381
endforeach()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
# =============================================================================
3+
# Copyright (c) 2022 Blue Brain Project/EPFL
4+
#
5+
# See top-level LICENSE file for details.
6+
# =============================================================================
7+
*/
8+
#pragma once
9+
10+
// This is the CoreNEURON analogue of nrnsemanticversion.h in NEURON. Hopefully
11+
// the duplication can go away soon.
12+
#define NRN_VERSION_MAJOR @NRN_VERSION_MAJOR@
13+
#define NRN_VERSION_MINOR @NRN_VERSION_MINOR@
14+
#define NRN_VERSION_PATCH @NRN_VERSION_PATCH@
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
# =============================================================================
3+
# Copyright (c) 2022 Blue Brain Project/EPFL
4+
#
5+
# See top-level LICENSE file for details.
6+
# =============================================================================
7+
*/
8+
#pragma once
9+
10+
// This is the CoreNEURON analogue of nrnversionmacros.h in NEURON. Hopefully
11+
// the duplication can go away soon.
12+
#include "coreneuron/config/neuron_version.hpp"
13+
#define NRN_VERSION_INT(maj, min, pat) (10000 * maj + 100 * min + pat)
14+
#define NRN_VERSION NRN_VERSION_INT(NRN_VERSION_MAJOR, NRN_VERSION_MINOR, NRN_VERSION_PATCH)
15+
#define NRN_VERSION_EQ(maj, min, pat) (NRN_VERSION == NRN_VERSION_INT(maj, min, pat))
16+
#define NRN_VERSION_NE(maj, min, pat) (NRN_VERSION != NRN_VERSION_INT(maj, min, pat))
17+
#define NRN_VERSION_GT(maj, min, pat) (NRN_VERSION > NRN_VERSION_INT(maj, min, pat))
18+
#define NRN_VERSION_LT(maj, min, pat) (NRN_VERSION < NRN_VERSION_INT(maj, min, pat))
19+
#define NRN_VERSION_GTEQ(maj, min, pat) (NRN_VERSION >= NRN_VERSION_INT(maj, min, pat))
20+
#define NRN_VERSION_LTEQ(maj, min, pat) (NRN_VERSION <= NRN_VERSION_INT(maj, min, pat))
21+
22+
// 8.2.0 is significant because all versions >=8.2.0 should contain definitions
23+
// of these macros, and doing #ifndef NRN_VERSION_GTEQ_8_2_0 is a more
24+
// descriptive way of writing #if defined(NRN_VERSION_GTEQ). Testing for 8.2.0
25+
// is likely to be a common pattern when adapting MOD file VERBATIM blocks for
26+
// C++ compatibility.
27+
#if NRN_VERSION_GTEQ(8, 2, 0)
28+
#define NRN_VERSION_GTEQ_8_2_0
29+
#endif

coreneuron/nrnconf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
22
# =============================================================================
3-
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
3+
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
44
#
55
# See top-level LICENSE file for details.
66
# =============================================================================.
77
*/
8-
98
#pragma once
109

10+
#include "coreneuron/config/version_macros.hpp"
1111
#include "coreneuron/utils/offload.hpp"
1212

1313
#include <cstdio>

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
include(TestHelpers)
88

9-
include_directories(${CORENEURON_PROJECT_SOURCE_DIR} ${Boost_INCLUDE_DIRS})
9+
include_directories(${CORENEURON_PROJECT_SOURCE_DIR} ${CORENEURON_PROJECT_BINARY_DIR}/generated
10+
${Boost_INCLUDE_DIRS})
1011

1112
if(NOT Boost_USE_STATIC_LIBS)
1213
add_definitions(-DBOOST_TEST_DYN_LINK=TRUE)

0 commit comments

Comments
 (0)