Skip to content

Commit

Permalink
[12912] Add separate cmake file for MSVC compile
Browse files Browse the repository at this point in the history
Also fixes compile on MSVC using PCH

Based on TrinityCore cmake implementation
  • Loading branch information
DomGries committed Aug 30, 2015
1 parent d296ef3 commit e94f334
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 27 deletions.
17 changes: 0 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ if(UNIX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} --no-warnings")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wfatal-errors -Wextra")
elseif(WIN32)
# Disable warnings in Visual Studio 8 and above and add /MP
if(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4996 /wd4355 /wd4244 /wd4267 /MP")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /MP")
endif()
endif()

# if(SQL)
Expand All @@ -269,14 +261,6 @@ endif()
# message(STATUS "Build map/vmap tools : No (default)")
# endif()

# Some small tweaks for Visual Studio 7 and above.
if(MSVC)
# Mark 32 bit executables large address aware so they can use > 2GB address space
if(PLATFORM MATCHES X86)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif()
endif()

# Generate revision-extractor
set(GENREV_SRC
src/tools/genrevision/genrevision.cpp
Expand Down Expand Up @@ -355,7 +339,6 @@ set(DEFINITIONS_DEBUG _DEBUG MANGOS_DEBUG)

if(WIN32)
set(DEFINITIONS ${DEFINITIONS} WIN32 _WIN32)
set(DEFINITIONS_RELEASE ${DEFINITIONS_RELEASE} _CRT_SECURE_NO_WARNINGS)
endif()

if(USE_STD_MALLOC)
Expand Down
44 changes: 44 additions & 0 deletions cmake/compiler/msvc/settings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
if(PLATFORM EQUAL X64)
# This definition is necessary to work around a bug with Intellisense described
# here: http://tinyurl.com/2cb428. Syntax highlighting is important for proper
# debugger functionality.
add_definitions("-D_WIN64")
message(STATUS "MSVC: 64-bit platform, enforced -D_WIN64 parameter")

#Enable extended object support for debug compiles on X64 (not required on X86)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
message(STATUS "MSVC: Enabled extended object-support for debug-compiles")
else()
# mark 32 bit executables large address aware so they can use > 2GB address space
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
message(STATUS "MSVC: Enabled large address awareness")

add_definitions(/arch:SSE2)
message(STATUS "MSVC: Enabled SSE2 support")
endif()

# multithreaded compiling on VS
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")

# Define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES - eliminates the warning by changing the strcpy call to strcpy_s, which prevents buffer overruns
add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
message(STATUS "MSVC: Overloaded standard names")

# Ignore warnings about older, less secure functions
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
message(STATUS "MSVC: Disabled NON-SECURE warnings")

# disable warnings in Visual Studio 8 and above if not wanted
if(NOT WARNINGS)
if(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /wd4619")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996 /wd4355 /wd4244 /wd4985 /wd4267 /wd4619")
message(STATUS "MSVC: Disabled generic compiletime warnings")
endif()
endif()

# Specify the maximum PreCompiled Header memory allocation limit
# Fixes a compiler-problem when using PCH - the /Ym flag is adjusted by the compiler in MSVC2012, hence we need to set an upper limit with /Zm to avoid discrepancies)
# (And yes, this is a verified , unresolved bug with MSVC... *sigh*)
string(REGEX REPLACE "/Zm[0-9]+ *" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zm500" CACHE STRING "" FORCE)
10 changes: 3 additions & 7 deletions cmake/macros/CheckPlatform.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# check what platform we're on (64-bit or 32-bit), and create a simpler test than CMAKE_SIZEOF_VOID_P
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PLATFORM X64)
# This definition is necessary to work around a bug with Intellisense described
# here: http://tinyurl.com/2cb428. Syntax highlighting is important for proper
# debugger functionality.
if(WIN32)
add_definitions("-D_WIN64")
endif()
message(STATUS "Detected 64-bit platform")
else()
set(PLATFORM X86)
message(STATUS "Detected 32-bit platform")
endif()

if(UNIX)
if(WIN32)
include("${CMAKE_SOURCE_DIR}/cmake/platform/win/settings.cmake")
elseif(UNIX)
include("${CMAKE_SOURCE_DIR}/cmake/platform/unix/settings.cmake")
endif()
6 changes: 4 additions & 2 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
option(DEBUG "Debug mode" OFF)
option(DEBUG "Include additional debug-code in core" OFF)
option(WARNINGS "Show all warnings during compile" OFF)
option(TBB_USE_EXTERNAL "Use external TBB" OFF)
option(USE_STD_MALLOC "Use standard malloc instead of TBB" OFF)
option(ACE_USE_EXTERNAL "Use external ACE" OFF)
Expand All @@ -22,7 +23,8 @@ message(
Options that can be used in order to configure the process:
CMAKE_INSTALL_PREFIX Path where the server should be installed to
PCH Use precompiled headers
DEBUG Debug mode
DEBUG Include additional debug-code in core
WARNINGS Show all warnings during compile
INCLUDE_BINDINGS_DIR Include a script library in src/bindings/ with the
defined name. the name must corespond to the name of
the folder and the folder must contain a valid
Expand Down
3 changes: 3 additions & 0 deletions cmake/platform/win/settings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ( MSVC )
include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake)
endif()
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12911"
#define REVISION_NR "12912"
#endif // __REVISION_NR_H__

0 comments on commit e94f334

Please sign in to comment.