From cceeb889489a51b7683b610e46d35887edafdbab Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 21 Dec 2011 23:08:10 +0000 Subject: [PATCH] CMake support for MSVC Use the WIN32 flag for add_executable. --- CMakeLists.txt | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37690a4..694bc2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,15 +120,12 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") endif() set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG -O1") - set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) set(CMAKE_C_FLAGS_DEBUGALL "-g -ggdb -D_DEBUG") - set(CMAKE_CXX_FLAGS_DEBUGALL ${CMAKE_C_FLAGS_DEBUGALL}) set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3 -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO}) set(CMAKE_C_FLAGS_MINSIZEREL "-Os -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") - set(CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL}) + + set(CMAKE_CXX_FLAGS_DEBUGALL ${CMAKE_C_FLAGS_DEBUGALL}) add_definitions(-fno-strict-aliasing) @@ -182,18 +179,27 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") set(ldflags ${ldflags} "-m32") endif() - if (MINGW) - set(ldflags ${ldflags} "-mwindows") - endif() - if (os STREQUAL "linux") set(sys_libs ${sys_libs} dl) endif() endif() +elseif (MSVC) + add_definitions(/W4) + add_definitions(/wd4714) # 'function' marked as __forceinline not inlined + add_definitions(/wd4996) # 'function': was declared deprecated + set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG /Od /Zi") + set(CMAKE_C_FLAGS_RELEASE "/Ox /Oy") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Ox /Oy /Zi") + set(CMAKE_C_FLAGS_MINSIZEREL "/Ox /Oy /Os") else() message(FATAL_ERROR "Unsupported compiler") endif() +set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) +set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO}) +set(CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_C_FLAGS_MINSIZEREL}) + # mingw and msvc if (WIN32) add_definitions(-DWINVER=0x0501) @@ -203,11 +209,16 @@ if (WIN32) dinput8 ksuser dxguid - dxerr8 winmm iphlpapi wsock32 ) + + if (MINGW) + list(APPEND sys_libs dxerr8) + else() + list(APPEND sys_libs dxerr) + endif() endif() message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${os}.${cpu}") @@ -681,7 +692,7 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT MING endif() if (CORE) - add_executable(doom3.${cpu} + add_executable(doom3.${cpu} WIN32 ${src_core} ${src_sys_base} ${src_sys_core} @@ -705,7 +716,7 @@ if (CORE) endif() if (DEDICATED) - add_executable(doom3ded.${cpu} + add_executable(doom3ded.${cpu} WIN32 ${src_core} ${src_stub_openal} ${src_stub_gl}