Skip to content

Commit

Permalink
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

(based on cmangos/mangos-wotlk@e94f334)

Signed-off-by: stfx <stfx@hotmail.de>
  • Loading branch information
DomGries committed Sep 2, 2015
1 parent c7c5c82 commit d2a6253
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 deletions.
17 changes: 0 additions & 17 deletions CMakeLists.txt
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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
if ( MSVC )
include(${CMAKE_SOURCE_DIR}/cmake/compiler/msvc/settings.cmake)
endif()

0 comments on commit d2a6253

Please sign in to comment.