From: Roland Schulz Date: Mon, 1 Sep 2014 02:25:26 +0000 (-0400) Subject: Fix MingW build X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=e8cba2b9001c5930ed9d52e0be7ff53a2b00b22c;p=alexxy%2Fgromacs.git Fix MingW build Change-Id: Id6025838e274305266f0f90eda2ddbb48355d792 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ce678e504c..75e272fd56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,7 @@ set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT enable_language(C) enable_language(CXX) +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON) set(CPACK_PACKAGE_NAME "gromacs") set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) @@ -378,15 +379,8 @@ if(GMX_SOFTWARE_INVSQRT) endif() if(WIN32 AND NOT CYGWIN) - set(GMX_WSOCKLIB_PATH CACHE PATH "Path to winsock (wsock32.lib) library.") - mark_as_advanced(GMX_WSOCKLIB_PATH) - find_library(WSOCK32_LIBRARY NAMES wsock32 PATHS ${GMX_WSOCKLIB_PATH}) - if(WSOCK32_LIBRARY) - list(APPEND GMX_EXTRA_LIBRARIES ${WSOCK32_LIBRARY}) - add_definitions(-DGMX_HAVE_WINSOCK) - else() - message(STATUS "No winsock found. Cannot use interactive molecular dynamics (IMD).") - endif(WSOCK32_LIBRARY) + list(APPEND GMX_EXTRA_LIBRARIES "wsock32") + add_definitions(-DGMX_HAVE_WINSOCK) endif() diff --git a/cmake/TestWinProcNum.c b/cmake/TestWinProcNum.c new file mode 100644 index 0000000000..669ff3bedb --- /dev/null +++ b/cmake/TestWinProcNum.c @@ -0,0 +1,7 @@ +#define _WIN32_WINNT 0x0601 /*Require Windows7 (needed for MingW)*/ +#include +int main() +{ + PROCESSOR_NUMBER p; + return 0; +} diff --git a/cmake/ThreadMPI.cmake b/cmake/ThreadMPI.cmake index d039dba5af..76e4d37b05 100644 --- a/cmake/ThreadMPI.cmake +++ b/cmake/ThreadMPI.cmake @@ -62,15 +62,16 @@ MACRO(TMPI_TEST_ATOMICS INCDIR) ENDMACRO(TMPI_TEST_ATOMICS VARIABLE) +try_compile(HAVE_PROCESSOR_NUMBER ${CMAKE_BINARY_DIR} "${CMAKE_SOURCE_DIR}/cmake/TestWinProcNum.c") include(FindThreads) -if (CMAKE_USE_PTHREADS_INIT) +if (CMAKE_USE_WIN32_THREADS_INIT AND HAVE_PROCESSOR_NUMBER) + set(THREAD_WINDOWS 1) + set(THREAD_LIB) +elseif (CMAKE_USE_PTHREADS_INIT) check_include_files(pthread.h HAVE_PTHREAD_H) set(THREAD_PTHREADS 1) set(THREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) -elseif (CMAKE_USE_WIN32_THREADS_INIT) - set(THREAD_WINDOWS 1) - set(THREAD_LIB) else() message(FATAL_ERROR "Thread support required") endif () diff --git a/cmake/gmxManageOpenMP.cmake b/cmake/gmxManageOpenMP.cmake index 0fa2faeb77..cbad40bc67 100644 --- a/cmake/gmxManageOpenMP.cmake +++ b/cmake/gmxManageOpenMP.cmake @@ -56,7 +56,7 @@ if(GMX_OPENMP) if(OPENMP_FOUND) # CMake on Windows doesn't support linker flags passed to target_link_libraries # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed. - if(NOT (WIN32 AND NOT CYGWIN)) + if(NOT (WIN32 AND NOT CYGWIN AND NOT MINGW)) if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP AND NOT APPLE) set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread") set(OpenMP_SHARED_LINKER_FLAGS "") @@ -70,6 +70,10 @@ if(GMX_OPENMP) endif() endif() endif() + if(MINGW) + #GCC Bug 48659 + set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS} -mstackrealign") + endif() else() message(WARNING "The compiler you are using does not support OpenMP parallelism. This might hurt your performance a lot, in particular with GPUs. Try using a more recent version, or a different compiler. For now, we are proceeding by turning off OpenMP.") diff --git a/cmake/gmxTestLibXml2.cmake b/cmake/gmxTestLibXml2.cmake index 4546bfcd7c..48e1c21d66 100644 --- a/cmake/gmxTestLibXml2.cmake +++ b/cmake/gmxTestLibXml2.cmake @@ -42,6 +42,7 @@ # VARIABLE will be set to true if libxml2 support is present include(CheckLibraryExists) +include(CheckIncludeFiles) include(gmxOptionUtilities) function(GMX_TEST_LIBXML2 VARIABLE) if(LIBXML2_FOUND) @@ -50,7 +51,24 @@ function(GMX_TEST_LIBXML2 VARIABLE) unset(LIBXML2_LINKS_OK CACHE) endif() check_library_exists("${LIBXML2_LIBRARIES}" "xmlTextWriterEndAttribute" "" LIBXML2_LINKS_OK) - set(${VARIABLE} ${LIBXML2_LINKS_OK} PARENT_SCOPE) + if(LIBXML2_LINKS_OK) + #check that xml headers can be included + set(CMAKE_REQUIRED_INCLUDES "${LIBXML2_INCLUDE_DIR}") + check_include_files("libxml/parser.h" LIBXML2_INCL_OK) + if(NOT LIBXML2_INCL_OK) + #xml headers depend on iconv.h. Test whether adding its path fixes the problem + find_path(ICONV_INCLUDE_DIR iconv.h) + if(ICONV_INCLUDE_DIR) + set(CMAKE_REQUIRED_INCLUDES "${LIBXML2_INCLUDE_DIR};${ICONV_INCLUDE_DIR}") + unset(LIBXML2_INCL_OK CACHE) + check_include_files("libxml/parser.h" LIBXML2_INCL_OK) + set(LIBXML2_INCLUDE_DIR "${LIBXML2_INCLUDE_DIR};${ICONV_INCLUDE_DIR}" CACHE PATH "Libxml2 include path" FORCE) + endif() + endif() + set(${VARIABLE} ${LIBXML2_INCL_OK} PARENT_SCOPE) + else() + set(${VARIABLE} OFF PARENT_SCOPE) + endif() else() set(${VARIABLE} OFF PARENT_SCOPE) endif() diff --git a/src/config.h.cmakein b/src/config.h.cmakein index 3f734ba30d..a71fdad597 100644 --- a/src/config.h.cmakein +++ b/src/config.h.cmakein @@ -41,6 +41,8 @@ * * \inlibraryapi */ +#ifndef GMX_CONFIG_H +#define GMX_CONFIG_H #include "gromacs/utility/gmx_header_config.h" /* TODO: For now, disable Doxygen warnings from here */ @@ -355,4 +357,6 @@ /* Define if we have zlib */ #cmakedefine HAVE_ZLIB +#endif + /*! \endcond */ diff --git a/src/external/gmock-1.7.0/CMakeLists.txt b/src/external/gmock-1.7.0/CMakeLists.txt index 47a30b0358..d0552fb3f9 100644 --- a/src/external/gmock-1.7.0/CMakeLists.txt +++ b/src/external/gmock-1.7.0/CMakeLists.txt @@ -60,6 +60,13 @@ include_directories(BEFORE ${GTEST_INCLUDE_DIRS}) include_directories(BEFORE ${GTEST_DIR}) include_directories(BEFORE ${GMOCK_INCLUDE_DIRS}) include_directories(BEFORE ${GMOCK_DIR}) + +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag(-Wno-unused-variable HAS_NO_UNUSED_VARIABLE) +if (HAS_NO_UNUSED_VARIABLE) + set_source_files_properties(${GTEST_SOURCES} PROPERTIES COMPILE_FLAGS "-Wno-unused-variable") +endif() + add_library(gmock STATIC ${UNITTEST_TARGET_OPTIONS} ${GMOCK_SOURCES} ${GTEST_SOURCES}) set_property(TARGET gmock APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}") diff --git a/src/external/thread_mpi/src/errhandler.c b/src/external/thread_mpi/src/errhandler.c index 60f77420fb..23cab2b630 100644 --- a/src/external/thread_mpi/src/errhandler.c +++ b/src/external/thread_mpi/src/errhandler.c @@ -132,7 +132,7 @@ int tMPI_Error_string(int errorcode, char *strn, size_t *resultlen) if (errorcode != TMPI_ERR_IO) { -#if !(defined( _WIN32 ) || defined( _WIN64 ) ) +#ifndef _MSC_VER strncpy(strn, tmpi_errmsg[errorcode], TMPI_MAX_ERROR_STRING); #else strncpy_s(strn, TMPI_MAX_ERROR_STRING, tmpi_errmsg[errorcode], @@ -141,7 +141,7 @@ int tMPI_Error_string(int errorcode, char *strn, size_t *resultlen) } else { -#if !(defined( _WIN32 ) || defined( _WIN64 ) ) +#ifndef _MSC_VER snprintf(strn, TMPI_MAX_ERROR_STRING, "%s: %s", tmpi_errmsg[errorcode], strerror(errno)); #else diff --git a/src/external/thread_mpi/src/impl.h b/src/external/thread_mpi/src/impl.h index 962e80c923..7113a44555 100644 --- a/src/external/thread_mpi/src/impl.h +++ b/src/external/thread_mpi/src/impl.h @@ -48,6 +48,10 @@ #include #endif +#if defined( _WIN32 ) || defined( _WIN64 ) +#include +#endif + #ifdef HAVE_SYS_TIME_H #include #endif diff --git a/src/external/thread_mpi/src/numa_malloc.c b/src/external/thread_mpi/src/numa_malloc.c index 8bdcbe7b52..c0c455d20a 100644 --- a/src/external/thread_mpi/src/numa_malloc.c +++ b/src/external/thread_mpi/src/numa_malloc.c @@ -9,6 +9,11 @@ #include "config.h" #endif +#ifdef THREAD_WINDOWS + #ifdef __MINGW32__ + #define _WIN32_WINNT 0x0601 /* Windows 7*/ + #endif +#endif #ifdef HAVE_UNISTD_H #include @@ -22,9 +27,7 @@ #include #endif - -#if !(defined(WIN32) || defined( _WIN32 ) || defined(WIN64) || defined( _WIN64 )) || defined (__CYGWIN__) || defined (__CYGWIN32__) - +#ifndef THREAD_WINDOWS /* We don't have specific NUMA aware allocators: */ @@ -81,11 +84,8 @@ int tMPI_Free_numa(void *ptr) Scott Field (sfield@microsoft.com) Jan-2011 */ -//#define _WIN32_WINNT 0x0601 #include - - /* __declspec(align()) may not be supported by all compilers, so define the size of the structure manually to force alignment @@ -218,11 +218,19 @@ InitNumaHeapSupport( return; } +#if defined(WIN64) || defined( _WIN64 ) + hPriorValue = (HANDLE *)InterlockedCompareExchange64( + (LONGLONG volatile *)&g_hHeap, + (LONGLONG) hHeapNew, + 0 + ); +#else hPriorValue = (HANDLE *)InterlockedCompareExchange( (LONG volatile *)&g_hHeap, (LONG) hHeapNew, 0 ); +#endif if (hPriorValue != NULL) { diff --git a/src/external/thread_mpi/src/pthreads.c b/src/external/thread_mpi/src/pthreads.c index 8da1df6751..3aee9c52e5 100644 --- a/src/external/thread_mpi/src/pthreads.c +++ b/src/external/thread_mpi/src/pthreads.c @@ -196,6 +196,9 @@ struct tMPI_Thread_starter }; /* the thread_starter function that sets the thread id */ +#ifdef __MINGW32__ +__attribute__((force_align_arg_pointer)) +#endif static void *tMPI_Thread_starter(void *arg) { struct tMPI_Thread_starter *starter = (struct tMPI_Thread_starter *)arg; diff --git a/src/external/thread_mpi/src/tmpi_init.c b/src/external/thread_mpi/src/tmpi_init.c index 4d15b931de..0728618d30 100644 --- a/src/external/thread_mpi/src/tmpi_init.c +++ b/src/external/thread_mpi/src/tmpi_init.c @@ -810,7 +810,7 @@ int tMPI_Get_processor_name(char *name, int *resultlen) digits = 1; } } -#if !(defined( _WIN32 ) || defined( _WIN64 ) ) +#ifndef _MSC_VER strcpy(name, "thread #"); #else strncpy_s(name, TMPI_MAX_PROCESSOR_NAME, "thread #", TMPI_MAX_PROCESSOR_NAME); diff --git a/src/external/thread_mpi/src/winthreads.c b/src/external/thread_mpi/src/winthreads.c index f78dd73553..98a06ace80 100644 --- a/src/external/thread_mpi/src/winthreads.c +++ b/src/external/thread_mpi/src/winthreads.c @@ -54,6 +54,12 @@ #ifdef THREAD_WINDOWS /* the win32 header */ +#ifdef __MINGW32__ +/* Couple of types (e.g. PROCESSOR_NUMBER) are only available since + * WinServer2008 (0x600) and Windows7 (0x601). MingW doesn't have + * it defined for 0x600 in the headers */ +#define _WIN32_WINNT 0x0601 +#endif #include @@ -66,6 +72,7 @@ #include "thread_mpi/atomic.h" #include "thread_mpi/threads.h" #include "impl.h" +#include "unused.h" #include "winthreads.h" @@ -686,6 +693,9 @@ struct tMPI_Thread_starter_param struct tMPI_Thread *thread; }; +#ifdef __GNUC__ +__attribute__((force_align_arg_pointer)) +#endif static DWORD WINAPI tMPI_Win32_thread_starter( LPVOID lpParam ) { struct tMPI_Thread_starter_param *prm = @@ -823,7 +833,7 @@ int tMPI_Thread_join(tMPI_Thread_t thread, void **value_ptr) } -void tMPI_Thread_exit(void *value_ptr) +void tMPI_Thread_exit(void tmpi_unused *value_ptr) { /* TODO: call destructors for thread-local storage */ ExitThread( 0 ); @@ -1050,7 +1060,7 @@ int tMPI_Thread_mutex_unlock(tMPI_Thread_mutex_t *mtx) -int tMPI_Thread_key_create(tMPI_Thread_key_t *key, void (*destructor)(void *)) +int tMPI_Thread_key_create(tMPI_Thread_key_t *key, void (*destructor)(void *) tmpi_unused) { if (key == NULL) { diff --git a/src/external/tng_io/include/tng/tng_io.h b/src/external/tng_io/include/tng/tng_io.h index 42119a5328..51c1d9b593 100644 --- a/src/external/tng_io/include/tng/tng_io.h +++ b/src/external/tng_io/include/tng/tng_io.h @@ -336,13 +336,18 @@ typedef unsigned __int64 uint64_t; #endif /* USE_STD_INTTYPES_H */ - #ifndef USE_WINDOWS #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #define USE_WINDOWS #endif /* win32... */ #endif /* not defined USE_WINDOWS */ +#ifdef USE_WINDOWS +#define TNG_PRIsize "Iu" +#else +#define TNG_PRIsize "zu" +#endif + #ifndef DECLSPECDLLEXPORT #ifdef USE_WINDOWS #define DECLSPECDLLEXPORT __declspec(dllexport) diff --git a/src/external/tng_io/src/lib/tng_io.c b/src/external/tng_io/src/lib/tng_io.c index c388f789bf..074b781317 100644 --- a/src/external/tng_io/src/lib/tng_io.c +++ b/src/external/tng_io/src/lib/tng_io.c @@ -34,9 +34,17 @@ #include "compression/tng_compress.h" #include "tng/version.h" -#ifdef _MSC_VER -#define fseeko _fseeki64 -#define ftello _ftelli64 +#if defined( _WIN32 ) || defined( _WIN64 ) + #ifndef fseeko + #define fseeko _fseeki64 + #endif + #ifndef ftello + #ifdef __MINGW32__ + #define ftello ftello64 + #else + #define ftello _ftelli64 + #endif + #endif #endif struct tng_bond { @@ -743,7 +751,7 @@ static tng_function_status tng_block_init(struct tng_gen_block **block_p) *block_p = malloc(sizeof(struct tng_gen_block)); if(!*block_p) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_gen_block), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -4731,7 +4739,7 @@ static tng_function_status tng_particle_data_block_create frame_set->n_particle_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_particle_data) * frame_set->n_particle_data_blocks, __FILE__, __LINE__); @@ -4749,7 +4757,7 @@ static tng_function_status tng_particle_data_block_create tng_data->n_particle_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_particle_data) * tng_data->n_particle_data_blocks, __FILE__, __LINE__); @@ -5995,7 +6003,7 @@ static tng_function_status tng_particle_data_block_write temp_name = realloc(block->name, len); if(!temp_name) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lud bytes). %s: %d\n", len, + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", len, __FILE__, __LINE__); free(block->name); block->name = 0; @@ -6449,7 +6457,7 @@ static tng_function_status tng_data_block_create frame_set->n_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_non_particle_data) * frame_set->n_data_blocks, __FILE__, __LINE__); free(frame_set->tr_data); @@ -6465,7 +6473,7 @@ static tng_function_status tng_data_block_create tng_data->n_data_blocks); if(!data) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_non_particle_data) * tng_data->n_data_blocks, __FILE__, __LINE__); free(tng_data->non_tr_data); @@ -9103,7 +9111,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t *molecule_p = malloc(sizeof(struct tng_molecule)); if(!*molecule_p) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_molecule), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -9790,7 +9798,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_ *tng_data_p = malloc(sizeof(struct tng_trajectory)); if(!*tng_data_p) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_trajectory), __FILE__, __LINE__); return(TNG_CRITICAL); } @@ -10311,7 +10319,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector *dest_p = malloc(sizeof(struct tng_trajectory)); if(!*dest_p) { - fprintf(stderr, "TNG library: Cannot allocate memory (%lu bytes). %s: %d\n", + fprintf(stderr, "TNG library: Cannot allocate memory (%"TNG_PRIsize" bytes). %s: %d\n", sizeof(struct tng_trajectory), __FILE__, __LINE__); return(TNG_CRITICAL); } diff --git a/src/external/vmd_molfile/vmddlopen.c b/src/external/vmd_molfile/vmddlopen.c index a060cf6e18..ed9f35e6a7 100644 --- a/src/external/vmd_molfile/vmddlopen.c +++ b/src/external/vmd_molfile/vmddlopen.c @@ -153,7 +153,7 @@ const char *vmddlerror( void ) { return errorString; } -#elif defined(_MSC_VER) +#elif defined( _WIN32 ) || defined( _WIN64 ) #include @@ -165,7 +165,7 @@ const char *vmddlerror(void) { static CHAR szBuf[80]; DWORD dw = GetLastError(); - sprintf(szBuf, "vmddlopen failed: GetLastError returned %u\n", dw); + sprintf(szBuf, "vmddlopen failed: GetLastError returned %lu\n", dw); return szBuf; } diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 944b3089b5..acd27b0f01 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -817,7 +817,7 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags, GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR; /* Set the nice level */ -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) && !defined(__MINGW32__) #ifndef GMX_NO_NICE /* The some system, e.g. the catamount kernel on cray xt3 do not have nice(2). */ if (nicelevel != 0 && !bExit) diff --git a/src/gromacs/fileio/futil.cpp b/src/gromacs/fileio/futil.cpp index f81f4dcbda..a93bf6f1f0 100644 --- a/src/gromacs/fileio/futil.cpp +++ b/src/gromacs/fileio/futil.cpp @@ -56,6 +56,7 @@ #endif #ifdef GMX_NATIVE_WINDOWS +#include #include #include #endif @@ -240,7 +241,11 @@ gmx_off_t gmx_ftell(FILE *stream) return ftello(stream); #else #ifdef HAVE__FSEEKI64 +#ifndef __MINGW32__ return _ftelli64(stream); +#else + return ftello64(stream); +#endif #else return ftell(stream); #endif @@ -548,12 +553,12 @@ FILE *gmx_ffopen(const char *file, const char *mode) /* Our own implementation of dirent-like functionality to scan directories. */ struct gmx_directory { -#ifdef HAVE_DIRENT_H - DIR * dirent_handle; -#elif (defined GMX_NATIVE_WINDOWS) +#if defined(GMX_NATIVE_WINDOWS) intptr_t windows_handle; struct _finddata_t finddata; int first; +#elif defined(HAVE_DIRENT_H) + DIR * dirent_handle; #else int dummy; #endif @@ -570,19 +575,7 @@ gmx_directory_open(gmx_directory_t *p_gmxdir, const char *dirname) *p_gmxdir = gmxdir; -#ifdef HAVE_DIRENT_H - if ( (gmxdir->dirent_handle = opendir(dirname)) != NULL) - { - rc = 0; - } - else - { - sfree(gmxdir); - *p_gmxdir = NULL; - rc = EINVAL; - } -#elif (defined GMX_NATIVE_WINDOWS) - +#if defined(GMX_NATIVE_WINDOWS) if (dirname != NULL && strlen(dirname) > 0) { char * tmpname; @@ -625,6 +618,17 @@ gmx_directory_open(gmx_directory_t *p_gmxdir, const char *dirname) { rc = EINVAL; } +#elif defined(HAVE_DIRENT_H) + if ( (gmxdir->dirent_handle = opendir(dirname)) != NULL) + { + rc = 0; + } + else + { + sfree(gmxdir); + *p_gmxdir = NULL; + rc = EINVAL; + } #else gmx_fatal(FARGS, "Source compiled without POSIX dirent or windows support - cannot scan directories.\n" @@ -642,8 +646,41 @@ gmx_directory_nextfile(gmx_directory_t gmxdir, char *name, int maxlength_name) { int rc; -#ifdef HAVE_DIRENT_H +#if defined(GMX_NATIVE_WINDOWS) + if (gmxdir != NULL) + { + if (gmxdir->windows_handle <= 0) + { + name[0] = '\0'; + rc = ENOENT; + } + else if (gmxdir->first == 1) + { + strncpy(name, gmxdir->finddata.name, maxlength_name); + rc = 0; + gmxdir->first = 0; + } + else + { + if (_findnext(gmxdir->windows_handle, &gmxdir->finddata) == 0) + { + strncpy(name, gmxdir->finddata.name, maxlength_name); + rc = 0; + } + else + { + name[0] = '\0'; + rc = ENOENT; + } + } + } + else + { + name[0] = '\0'; + rc = EINVAL; + } +#elif defined(HAVE_DIRENT_H) struct dirent * direntp_large; struct dirent * p; @@ -674,38 +711,6 @@ gmx_directory_nextfile(gmx_directory_t gmxdir, char *name, int maxlength_name) name[0] = '\0'; rc = EINVAL; } - -#elif (defined GMX_NATIVE_WINDOWS) - - if (gmxdir != NULL) - { - if (gmxdir->windows_handle <= 0) - { - - name[0] = '\0'; - rc = ENOENT; - } - else if (gmxdir->first == 1) - { - strncpy(name, gmxdir->finddata.name, maxlength_name); - rc = 0; - gmxdir->first = 0; - } - else - { - if (_findnext(gmxdir->windows_handle, &gmxdir->finddata) == 0) - { - strncpy(name, gmxdir->finddata.name, maxlength_name); - rc = 0; - } - else - { - name[0] = '\0'; - rc = ENOENT; - } - } - } - #else gmx_fatal(FARGS, "Source compiled without POSIX dirent or windows support - cannot scan directories.\n"); @@ -719,10 +724,10 @@ int gmx_directory_close(gmx_directory_t gmxdir) { int rc; -#ifdef HAVE_DIRENT_H - rc = (gmxdir != NULL) ? closedir(gmxdir->dirent_handle) : EINVAL; -#elif (defined GMX_NATIVE_WINDOWS) +#if defined(GMX_NATIVE_WINDOWS) rc = (gmxdir != NULL) ? _findclose(gmxdir->windows_handle) : EINVAL; +#elif defined(HAVE_DIRENT_H) + rc = (gmxdir != NULL) ? closedir(gmxdir->dirent_handle) : EINVAL; #else gmx_fatal(FARGS, "Source compiled without POSIX dirent or windows support - cannot scan directories.\n"); @@ -867,7 +872,7 @@ void gmx_tmpnam(char *buf) int gmx_truncatefile(char *path, gmx_off_t length) { -#ifdef _MSC_VER +#ifdef GMX_NATIVE_WINDOWS /* Microsoft visual studio does not have "truncate" */ HANDLE fh; LARGE_INTEGER win_length; diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index fb8b8f6dcb..35c94c2eeb 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -147,7 +147,7 @@ void gmx_tng_open(const char *filename, // tng_last_program_name_set(*tng, programInfo); // } -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) && !defined(__MINGW32__) char username[256]; if (!getlogin_r(username, 256)) { diff --git a/src/gromacs/fileio/vmdio.c b/src/gromacs/fileio/vmdio.c index 3fd42702d2..7d9c67c779 100644 --- a/src/gromacs/fileio/vmdio.c +++ b/src/gromacs/fileio/vmdio.c @@ -90,6 +90,7 @@ #include #include +#include /* * Plugin header files; get plugin source from www.ks.uiuc.edu/Research/vmd" */ @@ -98,6 +99,9 @@ #ifndef GMX_NATIVE_WINDOWS #include #else +#ifndef _WIN32_IE +#define _WIN32_IE 0x0500 /* SHGetFolderPath is available since WinXP/IE5 */ +#endif #include #include #endif diff --git a/src/gromacs/gmxlib/checkpoint.c b/src/gromacs/gmxlib/checkpoint.c index 016c67976d..18c0a312a6 100644 --- a/src/gromacs/gmxlib/checkpoint.c +++ b/src/gromacs/gmxlib/checkpoint.c @@ -177,7 +177,11 @@ gmx_wintruncate(const char *filename, __int64 size) return -1; } +#ifdef _MSC_VER return _chsize_s( fileno(fp), size); +#else + return _chsize( fileno(fp), size); +#endif #endif } #endif diff --git a/src/gromacs/gmxlib/gmx_cpuid.c b/src/gromacs/gmxlib/gmx_cpuid.c index fb1b076ee8..020e37aa55 100644 --- a/src/gromacs/gmxlib/gmx_cpuid.c +++ b/src/gromacs/gmxlib/gmx_cpuid.c @@ -47,15 +47,17 @@ #include #include #include -#ifdef _MSC_VER +#ifdef GMX_NATIVE_WINDOWS /* MSVC definition for __cpuid() */ -#include + #ifdef _MSC_VER + #include + #endif /* sysinfo functions */ -#include + #include #endif #ifdef HAVE_UNISTD_H /* sysconf() definition */ -#include + #include #endif #include "gmx_cpuid.h" diff --git a/src/gromacs/gmxlib/gmx_thread_affinity.c b/src/gromacs/gmxlib/gmx_thread_affinity.c index fb2064213e..d38b2cfba1 100644 --- a/src/gromacs/gmxlib/gmx_thread_affinity.c +++ b/src/gromacs/gmxlib/gmx_thread_affinity.c @@ -35,7 +35,7 @@ #ifdef HAVE_CONFIG_H #include #endif -#if defined(HAVE_SCHED_H) +#ifdef HAVE_SCHED_AFFINITY # ifndef _GNU_SOURCE # define _GNU_SOURCE 1 # endif diff --git a/src/gromacs/gmxlib/main.cpp b/src/gromacs/gmxlib/main.cpp index 253e69ce31..a80087c754 100644 --- a/src/gromacs/gmxlib/main.cpp +++ b/src/gromacs/gmxlib/main.cpp @@ -229,7 +229,7 @@ int gmx_gethostname(char *name, size_t len) { gmx_incons("gmx_gethostname called with len<8"); } -#if defined(HAVE_UNISTD_H) && !defined(__native_client__) +#if defined(HAVE_UNISTD_H) && !defined(__native_client__) && !defined(__MINGW32__) if (gethostname(name, len-1) != 0) { strncpy(name, "unknown", 8); diff --git a/src/gromacs/gmxpreprocess/readir.c b/src/gromacs/gmxpreprocess/readir.c index 9d28fe0252..3d2b2b07cd 100644 --- a/src/gromacs/gmxpreprocess/readir.c +++ b/src/gromacs/gmxpreprocess/readir.c @@ -1005,7 +1005,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, sprintf(err_buf, "tau-p must be > 0 instead of %g\n", ir->tau_p); CHECK(ir->tau_p <= 0); - if (ir->tau_p/dt_pcoupl < pcouple_min_integration_steps(ir->epc)) + if (ir->tau_p/dt_pcoupl < pcouple_min_integration_steps(ir->epc) - 10*GMX_REAL_EPS) { sprintf(warn_buf, "For proper integration of the %s barostat, tau-p (%g) should be at least %d times larger than nstpcouple*dt (%g)", EPCOUPLTYPE(ir->epc), ir->tau_p, pcouple_min_integration_steps(ir->epc), dt_pcoupl); @@ -3280,7 +3280,7 @@ void do_index(const char* mdparin, const char *ndx, nstcmin = tcouple_min_integration_steps(ir->etc); if (nstcmin > 1) { - if (tau_min/(ir->delta_t*ir->nsttcouple) < nstcmin) + if (tau_min/(ir->delta_t*ir->nsttcouple) < nstcmin - 10*GMX_REAL_EPS) { sprintf(warn_buf, "For proper integration of the %s thermostat, tau-t (%g) should be at least %d times larger than nsttcouple*dt (%g)", ETCOUPLTYPE(ir->etc), diff --git a/src/gromacs/gmxpreprocess/toputil.c b/src/gromacs/gmxpreprocess/toputil.c index 33db83ee49..3cf53cd7d9 100644 --- a/src/gromacs/gmxpreprocess/toputil.c +++ b/src/gromacs/gmxpreprocess/toputil.c @@ -38,6 +38,7 @@ #include #endif +#include #include #include @@ -86,12 +87,7 @@ void pr_alloc (int extra, t_params *pr) { return; } - if ((pr->nr == 0) && (pr->param != NULL)) - { - fprintf(stderr, "Warning: dangling pointer at %lx\n", - (unsigned long)pr->param); - pr->param = NULL; - } + assert(!((pr->nr == 0) && (pr->param != NULL))); if (pr->nr+extra > pr->maxnr) { pr->maxnr = max(1.2*pr->maxnr, pr->maxnr + extra); diff --git a/src/gromacs/utility/cstringutil.c b/src/gromacs/utility/cstringutil.c index 29266fd276..d71419f70b 100644 --- a/src/gromacs/utility/cstringutil.c +++ b/src/gromacs/utility/cstringutil.c @@ -193,20 +193,22 @@ void trim (char *str) char * gmx_ctime_r(const time_t *clock, char *buf, int n) { - char tmpbuf[STRLEN]; - -#ifdef GMX_NATIVE_WINDOWS +#ifdef _MSC_VER /* Windows */ - ctime_s( tmpbuf, STRLEN, clock ); + ctime_s( buf, n, clock ); +#elif defined(GMX_NATIVE_WINDOWS) + char *tmpbuf = ctime( clock ); + strncpy(buf, tmpbuf, n-1); + buf[n-1] = '\0'; #elif (defined(__sun)) /*Solaris*/ - ctime_r(clock, tmpbuf, n); + ctime_r(clock, buf, n); #else + char tmpbuf[STRLEN]; ctime_r(clock, tmpbuf); -#endif strncpy(buf, tmpbuf, n-1); buf[n-1] = '\0'; - +#endif return buf; } diff --git a/src/gromacs/utility/gmx_header_config_gen.h.cmakein b/src/gromacs/utility/gmx_header_config_gen.h.cmakein index 3e99283735..f9d6835ca8 100644 --- a/src/gromacs/utility/gmx_header_config_gen.h.cmakein +++ b/src/gromacs/utility/gmx_header_config_gen.h.cmakein @@ -52,8 +52,7 @@ #define GMX_CYGWIN #endif -/* We currently don't support MingW. And ICC also defines it */ -#ifdef _MSC_VER +#if defined( _WIN32 ) || defined( _WIN64 ) #define GMX_NATIVE_WINDOWS #endif diff --git a/src/gromacs/utility/gmxomp.h b/src/gromacs/utility/gmxomp.h index af11cac918..276aee8c13 100644 --- a/src/gromacs/utility/gmxomp.h +++ b/src/gromacs/utility/gmxomp.h @@ -122,14 +122,14 @@ void gmx_omp_check_thread_affinity(FILE *fplog, const t_commrec *cr, */ static gmx_inline void gmx_pause() { -#ifndef GMX_NATIVE_WINDOWS +#ifndef _MSC_VER /* Ugly hack because the openmp implementation below hacks into the SIMD * settings to decide when to use _mm_pause(). This should eventually be * changed into proper detection of the intrinsics uses, not SIMD. */ -#if (defined GMX_SIMD_X86_SSE2) || (defined GMX_SIMD_X86_SSE4_1) || \ +#if ((defined GMX_SIMD_X86_SSE2) || (defined GMX_SIMD_X86_SSE4_1) || \ (defined GMX_SIMD_X86_AVX_128_FMA) || (defined GMX_SIMD_X86_AVX_256) || \ - (defined GMX_SIMD_X86_AVX2_256) + (defined GMX_SIMD_X86_AVX2_256)) && !defined(__MINGW32__) /* Replace with tbb::internal::atomic_backoff when/if we use TBB */ _mm_pause(); #elif defined __MIC__ diff --git a/src/gromacs/utility/smalloc.c b/src/gromacs/utility/smalloc.c index 3ec2536083..7d8e85c029 100644 --- a/src/gromacs/utility/smalloc.c +++ b/src/gromacs/utility/smalloc.c @@ -48,6 +48,9 @@ #ifdef WITH_DMALLOC #include #endif +#ifdef HAVE__ALIGNED_MALLOC +#include +#endif #include "gromacs/legacyheaders/gmx_fatal.h" @@ -336,7 +339,7 @@ void *save_calloc_aligned(const char *name, const char *file, int line, } /* This routine can NOT be called with any pointer */ -void save_free_aligned(const char *name, const char *file, int line, void *ptr) +void save_free_aligned(const char gmx_unused *name, const char gmx_unused *file, int gmx_unused line, void *ptr) { int i, j; void *free = ptr; diff --git a/src/testutils/integrationtests.cpp b/src/testutils/integrationtests.cpp index 89845be1e5..77355e1716 100644 --- a/src/testutils/integrationtests.cpp +++ b/src/testutils/integrationtests.cpp @@ -75,7 +75,7 @@ IntegrationTestFixture::IntegrationTestFixture() // TODO fix this when we have an encapsulation layer for handling // environment variables #ifdef GMX_NATIVE_WINDOWS - _putenv_s("GMX_MAXBACKUP", s_maxBackup.c_str()); + _putenv(("GMX_MAXBACKUP="+s_maxBackup).c_str()); #else setenv("GMX_MAXBACKUP", s_maxBackup.c_str(), true); #endif