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

Commit cb56a28

Browse files
authored
mingw/windows buildrtability fixes (#209)
* Use CMAKE_SHARED_LIBRARY_SUFFIX instead of .so (required for windows/mingw) * Fix for exe suffix and make sure to have dlls in bin directory * adjust runtime output only for coreneuron directory * define mingw definition
1 parent 1aafe0b commit cb56a28

File tree

9 files changed

+27
-10
lines changed

9 files changed

+27
-10
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ project(coreneuron)
1313
set(VERSION_MAJOR "0")
1414
set(VERSION_MINOR "16")
1515
set(VERSION_PATCH "0")
16-
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
1716
set(CMAKE_CXX_STANDARD 11)
1817
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1918
set(CMAKE_CXX_EXTENSIONS OFF)
19+
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
2020

2121
# =============================================================================
2222
# Settings to enable project as submodule
@@ -144,6 +144,9 @@ if(CORENRN_ENABLE_REPORTINGLIB)
144144
add_definitions("-DENABLE_REPORTING")
145145
endif()
146146

147+
if(MINGW)
148+
add_definitions("-DMINGW")
149+
endif()
147150

148151
# =============================================================================
149152
# NMODL specific options
@@ -153,8 +156,8 @@ if(CORENRN_ENABLE_NMODL)
153156
include_directories(${nmodl_INCLUDE})
154157

155158
# copy to make nrnivmodl-core work from build as well instal directory
156-
configure_file(${nmodl_BINARY} ${CMAKE_BINARY_DIR}/bin/nmodl COPYONLY)
157-
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/nmodl)
159+
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/nmodl${CMAKE_EXECUTABLE_SUFFIX})
160+
configure_file(${nmodl_BINARY} ${CORENRN_NMODL_BINARY} COPYONLY)
158161

159162
# path to python interface
160163
set(ENV{PYTHONPATH} "${nmodl_PYTHONPATH}:$ENV{PYTHONPATH}")
@@ -165,7 +168,7 @@ if(CORENRN_ENABLE_NMODL)
165168
else()
166169
# use mod2c if nmodl not enabled
167170
include(AddMod2cSubmodule)
168-
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core)
171+
set(CORENRN_NMODL_BINARY ${CMAKE_BINARY_DIR}/bin/mod2c_core${CMAKE_EXECUTABLE_SUFFIX})
169172
endif()
170173

171174

coreneuron/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ include_directories(utils/randoms
1010
${CMAKE_CURRENT_BINARY_DIR}
1111
${CORENEURON_PROJECT_SOURCE_DIR})
1212

13+
# put libraries (e.g. dll) in bin directory
14+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
15+
1316
# =============================================================================
1417
# gather various source files
1518
# =============================================================================

coreneuron/nrniv/memory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ inline void free_memory(void* pointer) {
6464
#include <stdlib.h>
6565

6666
inline void alloc_memory(void*& pointer, size_t num_bytes, size_t alignment) {
67+
#if defined(MINGW)
68+
nrn_assert( (pointer = _aligned_malloc(num_bytes, alignment)) != nullptr);
69+
#else
6770
nrn_assert(posix_memalign(&pointer, alignment, num_bytes) == 0);
71+
#endif
6872
}
6973

7074
inline void calloc_memory(void*& pointer, size_t num_bytes, size_t alignment) {

coreneuron/nrniv/nrn_stats.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ void report_cell_stats(void) {
211211
nrnmpi_barrier();
212212
}
213213
#endif
214-
if (nrnmpi_myid == 0)
214+
if (nrnmpi_myid == 0) {
215215
printf("\n\n");
216+
fflush(stdout);
217+
}
216218
}
217219
} // namespace coreneuron

coreneuron/nrnoc/nrntimeout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ setitimer will conflict with profiler. In that case,
4040
user can disable setitimer which is just safety for
4141
deadlock situations */
4242
namespace coreneuron {
43-
#ifdef DISABLE_TIMEOUT
43+
#if ( defined(DISABLE_TIMEOUT) || defined(MINGW) )
4444

4545
void nrn_timeout(int seconds) {
4646
}

coreneuron/utils/file_utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
3232
#include <sys/stat.h>
3333
#include <errno.h>
3434

35+
#if defined(MINGW)
36+
#define mkdir(dir_name, permission) _mkdir(dir_name)
37+
#endif
38+
3539
/* adapted from : gist@jonathonreinhart/mkdir_p.c */
3640
int mkdir_p(const char* path) {
3741
const int path_len = strlen(path);
@@ -50,6 +54,7 @@ int mkdir_p(const char* path) {
5054
if (*p == '/') {
5155
/* temporarily truncate to sub-dir */
5256
*p = '\0';
57+
5358
if (mkdir(dirpath, S_IRWXU) != 0) {
5459
if (errno != EEXIST)
5560
return -1;

coreneuron/utils/memory_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ double nrn_mallinfo(void) {
7474
KERN_SUCCESS)
7575
return (size_t)0L; /* Can't access? */
7676
return info.resident_size / (1024.0 * 1024.0);
77+
#elif defined(MINGW)
78+
mbs = -1;
7779
#else
7880
std::ifstream file;
7981
file.open("/proc/self/statm");
@@ -87,8 +89,6 @@ double nrn_mallinfo(void) {
8789
struct mallinfo m;
8890
m = mallinfo();
8991
mbs = (m.hblkhd + m.uordblks) / (1024.0 * 1024.0);
90-
#else
91-
mbs = -1;
9292
#endif
9393
}
9494
#endif

extra/nrnivmodl_core_makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ $(coremech_lib): $(mod_func_o) $(dimplic_o) $(mod_c_objs) $(mod_ispc_objs) build
118118
@printf " => $(C_GREEN)LINKING$(C_RESET) library $(coremech_lib) Mod files: $(mod_files)\n"
119119
$(CXX_LINK_SHARED) -I $(incdir) -DADDITIONAL_MECHS $(datadir)/enginemech.cpp -o ${coremech_lib} ${_SONAME} \
120120
$(mod_func_o) $(dimplic_o) $(mod_c_objs) $(mod_ispc_objs) $(libdir)/libscopmath.a $(CORENRNLIB_FLAGS) -Wl,-rpath,$(libdir) $(LDFLAGS)
121-
(rm -f $(OUTPUT)/.libs/libcorenrnmech.so ; mkdir -p $(OUTPUT)/.libs ; ln -s ../../${coremech_lib} $(OUTPUT)/.libs/libcorenrnmech.so)
121+
(rm -f $(OUTPUT)/.libs/libcorenrnmech@CMAKE_SHARED_LIBRARY_SUFFIX@ ; mkdir -p $(OUTPUT)/.libs ; ln -s ../../${coremech_lib} $(OUTPUT)/.libs/libcorenrnmech@CMAKE_SHARED_LIBRARY_SUFFIX@)
122122

123123

124124
# Generic build cpp->.o Need PIC for shared lib

0 commit comments

Comments
 (0)