]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix msvc annoyances (#5963)
authoradrido <robots_only_adrido@gmx.com>
Tue, 27 Jun 2017 09:54:40 +0000 (11:54 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 27 Jun 2017 09:54:40 +0000 (11:54 +0200)
* MSVC: Fix '/std:c++11' is not a valid compiler option

* MSVC/MINGW: Define 'WIN32_LEAN_AND_MEAN' for the whole project

In some obscure cases 'Windows.h" got includet before that definition, which leaded to compilation warnings+errors

* MSVC: '/arch:SSE' is only available for x86

* MSVC: Fix float conversation

* MSVC/MINGW: use winthreads on Windows

* MSVC: 'USE_CMAKE_CONFIG' might be already definied by CMake build system

* MSVC: Use all available cpu cores for compiling

* Add missing include ctime and use std::time_t

misc/winresource.rc
src/CMakeLists.txt
src/database-postgresql.cpp
src/debug.h
src/mesh_generator_thread.cpp
src/mesh_generator_thread.h
src/noise.cpp
src/socket.cpp
src/socket.h
src/threading/thread.cpp

index 6b82e261b233695461d1c4ef56abd9ceb0f99088..e1e82581b1cbe1e05b377758ce64e3700991e9be 100644 (file)
@@ -1,7 +1,9 @@
 #include <windows.h>\r
 #include <commctrl.h>\r
 #include <richedit.h>\r
+#ifndef USE_CMAKE_CONFIG_H\r
 #define USE_CMAKE_CONFIG_H\r
+#endif\r
 #include "config.h"\r
 #undef USE_CMAKE_CONFIG_H\r
 \r
index 04f4635d19a272c69ac8cafef07b0e7b82878d72..e03f3f397e096ff42de95a69e5c1745791e32ec7 100644 (file)
@@ -703,9 +703,12 @@ include(CheckCXXCompilerFlag)
 
 if(MSVC)
        # Visual Studio
-       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11")
+       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D WIN32_LEAN_AND_MEAN /MP")
        # EHa enables SEH exceptions (used for catching segfaults)
-       set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
+       set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
+       if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+               set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE")
+       endif()
        #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
        set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
 
@@ -748,6 +751,7 @@ else()
 
        if(MINGW)
                set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN")
        endif()
 
        set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")
index 3c54f48d1e8318a50e43e4cba82153b4eb127933..78f59419f15d304bcf638409ab15075c6b753a1d 100644 (file)
@@ -23,9 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "database-postgresql.h"
 
 #ifdef _WIN32
-        #ifndef WIN32_LEAN_AND_MEAN
-                #define WIN32_LEAN_AND_MEAN
-        #endif
         // Without this some of the network functions are not found on mingw
         #ifndef _WIN32_WINNT
                 #define _WIN32_WINNT 0x0501
index 415797f43d56207a63305c74d60235fcf8c8cf77..639ba673d075e4ce8d7d8a044c1869cd033ffcbf 100644 (file)
@@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "gettime.h"
 #include "log.h"
 
-#if (defined(WIN32) || defined(_WIN32_WCE))
-       #define WIN32_LEAN_AND_MEAN
+#ifdef _WIN32
        #ifndef _WIN32_WINNT
                #define _WIN32_WINNT 0x0501
        #endif
index f06bddb573bd03a33aa156d6606e9691ac2e6dd6..b69d7f484bfd3eb1c3078b1364dc0b1c4263be44 100644 (file)
@@ -223,7 +223,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
 
        data->fillBlockDataBegin(q->p);
 
-       int t_now = time(0);
+       std::time_t t_now = std::time(0);
 
        // Collect data for 3*3*3 blocks from cache
        v3s16 dp;
index 77b34a3ce1addbcf0b698a19b99017778d11645d..051a0dc8808d5d47361a0a2e4b801417d0bca360 100644 (file)
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef MESH_GENERATOR_THREAD_HEADER
 #define MESH_GENERATOR_THREAD_HEADER
 
+#include <ctime>
 #include <mutex>
 #include "mapblock_mesh.h"
 #include "threading/mutex_auto_lock.h"
@@ -30,7 +31,7 @@ struct CachedMapBlockData
        v3s16 p = v3s16(-1337, -1337, -1337);
        MapNode *data = nullptr; // A copy of the MapBlock's data member
        int refcount_from_queue = 0;
-       int last_used_timestamp = std::time(0);
+       std::time_t last_used_timestamp = std::time(0);
 
        CachedMapBlockData() {}
        ~CachedMapBlockData();
index e75fb8278b3dc61c6422989f614428592bcf6fe6..f67771b8885e3679b90cc7619cccfd1d73bbedb1 100644 (file)
@@ -47,8 +47,8 @@ typedef float (*Interp3dFxn)(
                float x, float y, float z);
 
 float cos_lookup[16] = {
-       1.0,  0.9238,  0.7071,  0.3826, 0, -0.3826, -0.7071, -0.9238,
-       1.0, -0.9238, -0.7071, -0.3826, 0,  0.3826,  0.7071,  0.9238
+       1.0f,  0.9238f,  0.7071f,  0.3826f, .0f, -0.3826f, -0.7071f, -0.9238f,
+       1.0f, -0.9238f, -0.7071f, -0.3826f, .0f,  0.3826f,  0.7071f,  0.9238f
 };
 
 FlagDesc flagdesc_noiseparams[] = {
index d0ab16cab0af9228479bde80a459f2dbce5e8d49..0bd2702a194b6c6e80a34121dc9092706b9684f1 100644 (file)
@@ -34,9 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 
 #ifdef _WIN32
-       #ifndef WIN32_LEAN_AND_MEAN
-               #define WIN32_LEAN_AND_MEAN
-       #endif
        // Without this some of the network functions are not found on mingw
        #ifndef _WIN32_WINNT
                #define _WIN32_WINNT 0x0501
index 77ce31921d76aa735348d1c44041eb4ea7ed3f23..b1f1e0875c4d7a842eed2ec8173981d6522d4b89 100644 (file)
@@ -21,9 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define SOCKET_HEADER
 
 #ifdef _WIN32
-       #ifndef WIN32_LEAN_AND_MEAN
-               #define WIN32_LEAN_AND_MEAN
-       #endif
 #ifndef _WIN32_WINNT
        #define _WIN32_WINNT 0x0501
 #endif
index 8f54fb76286669838c74c7c326d3c1ea1633bcf0..09cc7d836f1786c2957c9c437da971b1c81d8c3d 100644 (file)
@@ -261,10 +261,14 @@ bool Thread::bindToProcessor(unsigned int proc_number)
 
        return false;
 
-#elif USE_WIN_THREADS
+#elif _MSC_VER
 
        return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number);
 
+#elif __MINGW32__
+
+       return SetThreadAffinityMask(pthread_gethandle(getThreadHandle()), 1 << proc_number);
+
 #elif __FreeBSD_version >= 702106 || defined(__linux__)
 
        cpu_set_t cpuset;
@@ -309,10 +313,14 @@ bool Thread::bindToProcessor(unsigned int proc_number)
 
 bool Thread::setPriority(int prio)
 {
-#if USE_WIN_THREADS
+#ifdef _MSC_VER
 
        return SetThreadPriority(getThreadHandle(), prio);
 
+#elif __MINGW32__
+
+       return SetThreadPriority(pthread_gethandle(getThreadHandle()), prio);
+
 #else
 
        struct sched_param sparam;