Fix MingW build
authorRoland Schulz <roland@utk.edu>
Mon, 1 Sep 2014 02:25:26 +0000 (22:25 -0400)
committerRoland Schulz <roland@utk.edu>
Wed, 3 Sep 2014 21:02:25 +0000 (17:02 -0400)
Change-Id: Id6025838e274305266f0f90eda2ddbb48355d792

31 files changed:
CMakeLists.txt
cmake/TestWinProcNum.c [new file with mode: 0644]
cmake/ThreadMPI.cmake
cmake/gmxManageOpenMP.cmake
cmake/gmxTestLibXml2.cmake
src/config.h.cmakein
src/external/gmock-1.7.0/CMakeLists.txt
src/external/thread_mpi/src/errhandler.c
src/external/thread_mpi/src/impl.h
src/external/thread_mpi/src/numa_malloc.c
src/external/thread_mpi/src/pthreads.c
src/external/thread_mpi/src/tmpi_init.c
src/external/thread_mpi/src/winthreads.c
src/external/tng_io/include/tng/tng_io.h
src/external/tng_io/src/lib/tng_io.c
src/external/vmd_molfile/vmddlopen.c
src/gromacs/commandline/pargs.cpp
src/gromacs/fileio/futil.cpp
src/gromacs/fileio/tngio.cpp
src/gromacs/fileio/vmdio.c
src/gromacs/gmxlib/checkpoint.c
src/gromacs/gmxlib/gmx_cpuid.c
src/gromacs/gmxlib/gmx_thread_affinity.c
src/gromacs/gmxlib/main.cpp
src/gromacs/gmxpreprocess/readir.c
src/gromacs/gmxpreprocess/toputil.c
src/gromacs/utility/cstringutil.c
src/gromacs/utility/gmx_header_config_gen.h.cmakein
src/gromacs/utility/gmxomp.h
src/gromacs/utility/smalloc.c
src/testutils/integrationtests.cpp

index ce678e504ce1852319479944a09d0a820f73c36d..75e272fd5652314926e877f236c5efed09e4b304 100644 (file)
@@ -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 (file)
index 0000000..669ff3b
--- /dev/null
@@ -0,0 +1,7 @@
+#define _WIN32_WINNT 0x0601 /*Require Windows7 (needed for MingW)*/
+#include <windows.h>
+int main()
+{
+    PROCESSOR_NUMBER p;
+    return 0;
+}
index d039dba5afd39972591a42db46a18341fcc4fa8f..76e4d37b052a50379452a570b257208026c8e2de 100644 (file)
@@ -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 ()
index 0fa2faeb77a7970278b265c099f7854b1de44cfe..cbad40bc671e1eb9a3867c4c7f5042ac28117248 100644 (file)
@@ -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.")
index 4546bfcd7cd03524d01d286ec2d242f642abdda1..48e1c21d661875fc1190684154ac2482d04287a4 100644 (file)
@@ -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()
index 3f734ba30d108617727bffe8988871ce77b5f6a8..a71fdad597d4afdb2f5d77b0018b247b4e7038ff 100644 (file)
@@ -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 */
 /* Define if we have zlib */
 #cmakedefine HAVE_ZLIB
 
+#endif
+
 /*! \endcond */
index 47a30b0358ed2652c7d49621f0596238f83e6301..d0552fb3f968f8d0fcb39e45e6ac343d7d2eaf5a 100644 (file)
@@ -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}")
 
index 60f77420fb0d6080a123ddd9432b91be08d7752d..23cab2b630d6f95b18716a36d82ccf796cf9ac6b 100644 (file)
@@ -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
index 962e80c923e1f7659e5856c18cac6659b56aabe3..7113a44555cdfc4fd8c13e87677cab00cf022ad2 100644 (file)
 #include <unistd.h>
 #endif
 
+#if defined( _WIN32 ) || defined( _WIN64 )
+#include <windows.h>
+#endif
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
index 8bdcbe7b52656a1c363bb9d9d0f59f880bdde06b..c0c455d20a82d75f9ddf266092f21df00008a345 100644 (file)
@@ -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 <unistd.h>
@@ -22,9 +27,7 @@
 #include <dmalloc.h>
 #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 <windows.h>
 
-
-
 /*
     __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)
         {
index 8da1df67514b046c5195364fb602500fa4019dde..3aee9c52e55c20a7520784c136a51c23ccb128c8 100644 (file)
@@ -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;
index 4d15b931de4c32bc5aa86bc670e51c67fc2d8846..0728618d30b0f1e19cfdcdf3aa0949ef7f64051e 100644 (file)
@@ -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);
index f78dd73553c3a340f69490c0a00f4a012234d527..98a06ace802ffdc4f7a18cc09cd69394b117fc29 100644 (file)
 #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 <windows.h>
 
 
@@ -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)
     {
index 42119a5328863cd1dbfb538ef71da68fc2b49237..51c1d9b5935f89fa64dc6c2f78c020b21b2157cd 100644 (file)
@@ -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)
index c388f789bfcbae367f3e583bde0c91098c41631f..074b781317ebdc50c78b2455d25d9462affbe095 100644 (file)
 #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);
     }
index a060cf6e18859a0bce2f0eb214353866f6cd55d8..ed9f35e6a76b6da2b3777edf31e74443ac1a88e7 100644 (file)
@@ -153,7 +153,7 @@ const char *vmddlerror( void  ) {
   return errorString;
 }
 
-#elif defined(_MSC_VER)
+#elif defined( _WIN32 ) || defined( _WIN64 )
 
 #include <windows.h>
 
@@ -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;
 }
 
index 944b3089b5ea935dd24de645142239c42ff38dcd..acd27b0f01ab743461ce70ec8c1c9f1ebf3ec15e 100644 (file)
@@ -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)
index f81f4dcbdab70c45a04edd2037e2cbbfcddf7077..a93bf6f1f0a6a55ddda9693fb51e426c874d15a1 100644 (file)
@@ -56,6 +56,7 @@
 #endif
 
 #ifdef GMX_NATIVE_WINDOWS
+#include <windows.h>
 #include <direct.h>
 #include <io.h>
 #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;
index fb8b8f6dcb39e15966351fcfdca1e111be1a90d9..35c94c2eeb6e2766a4e34d74b9e3040d6cbfcd42 100644 (file)
@@ -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))
         {
index 3fd42702d2ac914a165b652f311adff74a5a00c2..7d9c67c779d33613f2baf4c9d32d2be47739eb1c 100644 (file)
@@ -90,6 +90,7 @@
 #include <string.h>
 #include <assert.h>
 
+#include <config.h>
 /*
  * Plugin header files; get plugin source from www.ks.uiuc.edu/Research/vmd"
  */
@@ -98,6 +99,9 @@
 #ifndef GMX_NATIVE_WINDOWS
 #include <glob.h>
 #else
+#ifndef _WIN32_IE
+#define _WIN32_IE 0x0500 /* SHGetFolderPath is available since WinXP/IE5 */
+#endif
 #include <windows.h>
 #include <shlobj.h>
 #endif
index 016c67976dd465e5450f35ba8f7393b161943935..18c0a312a61cd3940d1c7d84573ff7f501935137 100644 (file)
@@ -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
index fb1b076ee870d1be96996293b053e8f0fb511dea..020e37aa55f41544d69724a70708f5113ecd4941 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#ifdef _MSC_VER
+#ifdef GMX_NATIVE_WINDOWS
 /* MSVC definition for __cpuid() */
-#include <intrin.h>
+    #ifdef _MSC_VER
+        #include <intrin.h>
+    #endif
 /* sysinfo functions */
-#include <windows.h>
+    #include <windows.h>
 #endif
 #ifdef HAVE_UNISTD_H
 /* sysconf() definition */
-#include <unistd.h>
+    #include <unistd.h>
 #endif
 
 #include "gmx_cpuid.h"
index fb2064213ef6fe7bdd5de74ee8bdcb8d60c817b8..d38b2cfba1f30a5f51a665df5a106504038456a8 100644 (file)
@@ -35,7 +35,7 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-#if defined(HAVE_SCHED_H)
+#ifdef HAVE_SCHED_AFFINITY
 #  ifndef _GNU_SOURCE
 #    define _GNU_SOURCE 1
 #  endif
index 253e69ce31dcbc604e5d58dc67c544f0523198a8..a80087c754960a602012653bd6b7db5b0396514c 100644 (file)
@@ -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);
index 9d28fe0252d09912669d8dc38bc8bcd40a4f5382..3d2b2b07cd4e2516d3b6c9e742d3a52531c1fd5d 100644 (file)
@@ -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),
index 33db83ee49aa90a11fe2897cea52118e38fdcfef..3cf53cd7d9acba8fe4b519002e3ff7f4f6f53055 100644 (file)
@@ -38,6 +38,7 @@
 #include <config.h>
 #endif
 
+#include <assert.h>
 #include <math.h>
 #include <string.h>
 
@@ -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);
index 29266fd276ba0dedabac479bd3a5e0c5d55ecd99..d71419f70b3261596501c527be227a97a2eb6b87 100644 (file)
@@ -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;
 }
 
index 3e99283735b5aa534529e62cfdc631f4871cfc1a..f9d6835ca8af6fa99c63971e1d11f31ab605c3cb 100644 (file)
@@ -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
 
index af11cac918acdcc739daba306f3a41e8865c0f1a..276aee8c13540b3055289c1e6d79fc14b9f0d0e4 100644 (file)
@@ -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__
index 3ec2536083b9f48cce715c1360ec5476921821f7..7d8e85c029b9cce1cdda8986077a3d4a0fe95ba8 100644 (file)
@@ -48,6 +48,9 @@
 #ifdef WITH_DMALLOC
 #include <dmalloc.h>
 #endif
+#ifdef HAVE__ALIGNED_MALLOC
+#include <malloc.h>
+#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;
index 89845be1e5086a1f71c9446b17004e312fb14798..77355e17161a080f8b145f7138cd5d448647af81 100644 (file)
@@ -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