Skip to content

Commit

Permalink
Fix msvc annoyances (#5963)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adrido authored and nerzhul committed Jun 27, 2017
1 parent 48cd217 commit d7343b6
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions 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

Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions src/database-postgresql.cpp
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/debug.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mesh_generator_thread.cpp
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/mesh_generator_thread.h
Expand Up @@ -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"
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/noise.cpp
Expand Up @@ -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[] = {
Expand Down
3 changes: 0 additions & 3 deletions src/socket.cpp
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/socket.h
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/threading/thread.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d7343b6

Please sign in to comment.