diff options
author | adrido <robots_only_adrido@gmx.com> | 2017-06-27 11:54:40 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-06-27 11:54:40 +0200 |
commit | d7343b6c930d22857f858929ea684acbbeefe482 (patch) | |
tree | a4611d3bc6546af879e8cf433cf49ce8df41ab55 | |
parent | 48cd217e3b6f53af32802c1897ddd1914d215078 (diff) | |
download | minetest-d7343b6c930d22857f858929ea684acbbeefe482.tar.gz minetest-d7343b6c930d22857f858929ea684acbbeefe482.tar.bz2 minetest-d7343b6c930d22857f858929ea684acbbeefe482.zip |
Fix msvc annoyances (#5963)
* 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
-rw-r--r-- | misc/winresource.rc | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/database-postgresql.cpp | 3 | ||||
-rw-r--r-- | src/debug.h | 3 | ||||
-rw-r--r-- | src/mesh_generator_thread.cpp | 2 | ||||
-rw-r--r-- | src/mesh_generator_thread.h | 3 | ||||
-rw-r--r-- | src/noise.cpp | 4 | ||||
-rw-r--r-- | src/socket.cpp | 3 | ||||
-rw-r--r-- | src/socket.h | 3 | ||||
-rw-r--r-- | src/threading/thread.cpp | 12 |
10 files changed, 24 insertions, 19 deletions
diff --git a/misc/winresource.rc b/misc/winresource.rc index 6b82e261b..e1e82581b 100644 --- a/misc/winresource.rc +++ b/misc/winresource.rc @@ -1,7 +1,9 @@ #include <windows.h>
#include <commctrl.h>
#include <richedit.h>
+#ifndef USE_CMAKE_CONFIG_H
#define USE_CMAKE_CONFIG_H
+#endif
#include "config.h"
#undef USE_CMAKE_CONFIG_H
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04f4635d1..e03f3f397 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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") diff --git a/src/database-postgresql.cpp b/src/database-postgresql.cpp index 3c54f48d1..78f59419f 100644 --- a/src/database-postgresql.cpp +++ b/src/database-postgresql.cpp @@ -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 diff --git a/src/debug.h b/src/debug.h index 415797f43..639ba673d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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 diff --git a/src/mesh_generator_thread.cpp b/src/mesh_generator_thread.cpp index f06bddb57..b69d7f484 100644 --- a/src/mesh_generator_thread.cpp +++ b/src/mesh_generator_thread.cpp @@ -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; diff --git a/src/mesh_generator_thread.h b/src/mesh_generator_thread.h index 77b34a3ce..051a0dc88 100644 --- a/src/mesh_generator_thread.h +++ b/src/mesh_generator_thread.h @@ -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(); diff --git a/src/noise.cpp b/src/noise.cpp index e75fb8278..f67771b88 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -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[] = { diff --git a/src/socket.cpp b/src/socket.cpp index d0ab16cab..0bd2702a1 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -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 diff --git a/src/socket.h b/src/socket.h index 77ce31921..b1f1e0875 100644 --- a/src/socket.h +++ b/src/socket.h @@ -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 diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 8f54fb762..09cc7d836 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -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; |