Skip to content

Commit d7343b6

Browse files
adridonerzhul
authored andcommittedJun 27, 2017
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
1 parent 48cd217 commit d7343b6

10 files changed

+24
-19
lines changed
 

‎misc/winresource.rc

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include <windows.h>
22
#include <commctrl.h>
33
#include <richedit.h>
4+
#ifndef USE_CMAKE_CONFIG_H
45
#define USE_CMAKE_CONFIG_H
6+
#endif
57
#include "config.h"
68
#undef USE_CMAKE_CONFIG_H
79

‎src/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,12 @@ include(CheckCXXCompilerFlag)
703703

704704
if(MSVC)
705705
# Visual Studio
706-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11")
706+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D WIN32_LEAN_AND_MEAN /MP")
707707
# EHa enables SEH exceptions (used for catching segfaults)
708-
set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
708+
set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
709+
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
710+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE")
711+
endif()
709712
#set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
710713
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
711714

@@ -748,6 +751,7 @@ else()
748751

749752
if(MINGW)
750753
set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
754+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32_LEAN_AND_MEAN")
751755
endif()
752756

753757
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")

‎src/database-postgresql.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "database-postgresql.h"
2424

2525
#ifdef _WIN32
26-
#ifndef WIN32_LEAN_AND_MEAN
27-
#define WIN32_LEAN_AND_MEAN
28-
#endif
2926
// Without this some of the network functions are not found on mingw
3027
#ifndef _WIN32_WINNT
3128
#define _WIN32_WINNT 0x0501

‎src/debug.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "gettime.h"
2727
#include "log.h"
2828

29-
#if (defined(WIN32) || defined(_WIN32_WCE))
30-
#define WIN32_LEAN_AND_MEAN
29+
#ifdef _WIN32
3130
#ifndef _WIN32_WINNT
3231
#define _WIN32_WINNT 0x0501
3332
#endif

‎src/mesh_generator_thread.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
223223

224224
data->fillBlockDataBegin(q->p);
225225

226-
int t_now = time(0);
226+
std::time_t t_now = std::time(0);
227227

228228
// Collect data for 3*3*3 blocks from cache
229229
v3s16 dp;

‎src/mesh_generator_thread.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020
#ifndef MESH_GENERATOR_THREAD_HEADER
2121
#define MESH_GENERATOR_THREAD_HEADER
2222

23+
#include <ctime>
2324
#include <mutex>
2425
#include "mapblock_mesh.h"
2526
#include "threading/mutex_auto_lock.h"
@@ -30,7 +31,7 @@ struct CachedMapBlockData
3031
v3s16 p = v3s16(-1337, -1337, -1337);
3132
MapNode *data = nullptr; // A copy of the MapBlock's data member
3233
int refcount_from_queue = 0;
33-
int last_used_timestamp = std::time(0);
34+
std::time_t last_used_timestamp = std::time(0);
3435

3536
CachedMapBlockData() {}
3637
~CachedMapBlockData();

‎src/noise.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ typedef float (*Interp3dFxn)(
4747
float x, float y, float z);
4848

4949
float cos_lookup[16] = {
50-
1.0, 0.9238, 0.7071, 0.3826, 0, -0.3826, -0.7071, -0.9238,
51-
1.0, -0.9238, -0.7071, -0.3826, 0, 0.3826, 0.7071, 0.9238
50+
1.0f, 0.9238f, 0.7071f, 0.3826f, .0f, -0.3826f, -0.7071f, -0.9238f,
51+
1.0f, -0.9238f, -0.7071f, -0.3826f, .0f, 0.3826f, 0.7071f, 0.9238f
5252
};
5353

5454
FlagDesc flagdesc_noiseparams[] = {

‎src/socket.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#include "log.h"
3535

3636
#ifdef _WIN32
37-
#ifndef WIN32_LEAN_AND_MEAN
38-
#define WIN32_LEAN_AND_MEAN
39-
#endif
4037
// Without this some of the network functions are not found on mingw
4138
#ifndef _WIN32_WINNT
4239
#define _WIN32_WINNT 0x0501

‎src/socket.h

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#define SOCKET_HEADER
2222

2323
#ifdef _WIN32
24-
#ifndef WIN32_LEAN_AND_MEAN
25-
#define WIN32_LEAN_AND_MEAN
26-
#endif
2724
#ifndef _WIN32_WINNT
2825
#define _WIN32_WINNT 0x0501
2926
#endif

‎src/threading/thread.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,14 @@ bool Thread::bindToProcessor(unsigned int proc_number)
261261

262262
return false;
263263

264-
#elif USE_WIN_THREADS
264+
#elif _MSC_VER
265265

266266
return SetThreadAffinityMask(getThreadHandle(), 1 << proc_number);
267267

268+
#elif __MINGW32__
269+
270+
return SetThreadAffinityMask(pthread_gethandle(getThreadHandle()), 1 << proc_number);
271+
268272
#elif __FreeBSD_version >= 702106 || defined(__linux__)
269273

270274
cpu_set_t cpuset;
@@ -309,10 +313,14 @@ bool Thread::bindToProcessor(unsigned int proc_number)
309313

310314
bool Thread::setPriority(int prio)
311315
{
312-
#if USE_WIN_THREADS
316+
#ifdef _MSC_VER
313317

314318
return SetThreadPriority(getThreadHandle(), prio);
315319

320+
#elif __MINGW32__
321+
322+
return SetThreadPriority(pthread_gethandle(getThreadHandle()), prio);
323+
316324
#else
317325

318326
struct sched_param sparam;

0 commit comments

Comments
 (0)
Please sign in to comment.