Add support for VS CMake/vcpkg compilation ()

* Add support for VS CMake/vcpkg compilation

* Fix system_windows.cpp compilation

* Add optimization and hidden console to MSVC release builds
1008-fix
Mateusz Przybył 2018-06-04 09:17:51 +02:00 committed by krzys_h
parent 073191d1ea
commit abb7d54ef5
8 changed files with 76 additions and 10 deletions

4
.gitignore vendored
View File

@ -38,3 +38,7 @@ CMakeLists.txt.user.*
# Ignore Visual Studio Code files
/.vscode
# Ignore Visual Studio files
/CMakeSettings.json
/.vs

View File

@ -124,6 +124,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Include cmake directory with some additional scripts
set(CMAKE_MODULE_PATH "${colobot_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# MSVC needs different flags if linking statically
option(MSVC_STATIC "Link statically when using MSVC" OFF)
# Compiler detection
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
@ -160,14 +163,19 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "Detected MSVC compiler")
set(NORMAL_CXX_FLAGS "/wd\"4244\" /wd\"4309\" /wd\"4800\" /wd\"4996\" /wd\"4351\" /EHsc") # disable some useless warnings
set(RELEASE_CXX_FLAGS "/MD")
set(DEBUG_CXX_FLAGS "/MDd /ZI")
if(MSVC_STATIC)
set(RELEASE_CXX_FLAGS "/MT /Ox")
set(DEBUG_CXX_FLAGS "/MTd /ZI")
else(MSVC_STATIC)
set(RELEASE_CXX_FLAGS "/MD /Ox")
set(DEBUG_CXX_FLAGS "/MDd /ZI")
endif()
set(TEST_CXX_FLAGS "")
add_definitions(-DNOEXCEPT= -DHAS_MSVC_EXCEPTION_BUG)
# Needed for Debug information (it's set to "No" by default for some reason)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
else()
message(FATAL_ERROR "Your C++ compiler doesn't seem to be supported.")
endif()
@ -315,6 +323,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(CBOT_STATIC 1) # only this works for some reason
set(WINGETOPT 1) # use wingetopt library
# Hide console in release builds
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_WIN32_EXECUTABLE 1)
endif()
endif()
##

View File

@ -5,7 +5,7 @@
FIND_PATH(LIBSNDFILE_INCLUDE_DIR sndfile.h)
SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile)
SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile libsndfile-1)
FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES} PATH)
IF(LIBSNDFILE_INCLUDE_DIR AND LIBSNDFILE_LIBRARY)

View File

@ -7,7 +7,7 @@ IF (WIN32)
FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h
DOC "The directory where physfs.h resides")
FIND_LIBRARY( PHYSFS_LIBRARY
NAMES physfs
NAMES physfs physfs-static
PATHS /mingw/lib
DOC "The PhysFS library")
ELSE (WIN32)

View File

@ -23,6 +23,7 @@
#include "CBot/CBotInstr/CBotFunction.h"
#include "CBot/CBotInstr/CBotInstrCall.h"
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>

View File

@ -151,7 +151,12 @@ set(LOCAL_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/..
)
set(SYSTEM_INCLUDES
${Boost_INCLUDE_DIRS}
)
include_directories(${LOCAL_INCLUDES})
include_directories(SYSTEM ${SYSTEM_INCLUDES})
if(CBOT_STATIC)

View File

@ -44,8 +44,51 @@ if(MXE) # MXE requires special treatment
elseif(PLATFORM_WINDOWS)
# because it isn't included in standard linking libraries
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
find_library(LIBINTL_LIBRARY NAMES intl.lib)
set(PLATFORM_LIBS ${LIBINTL_LIBRARY})
find_library(LIBINTL_LIBRARY NAMES intl.lib libintl)
if(${MSVC_STATIC})
if (${OPENAL_SOUND})
find_library(FLAC_LIBRARY NAMES flac.lib)
find_library(VORBIS_LIBRARY NAMES vorbis.lib)
find_library(VORBISENC_LIBRARY NAMES vorbisenc.lib)
find_library(OGG_LIBRARY NAMES ogg.lib)
set(OPENAL_MSVC_LIBS
${FLAC_LIBRARY}
${VORBIS_LIBRARY}
${VORBISENC_LIBRARY}
${OGG_LIBRARY}
)
endif()
find_library(BZ2_LIBRARY NAMES bz2.lib)
find_library(JPEG_LIBRARY NAMES jpeg.lib)
find_library(TIFF_LIBRARY NAMES tiff.lib)
find_library(WEBP_LIBRARY NAMES webp.lib)
find_library(LZMA_LIBRARY NAMES lzma.lib)
find_library(FREETYPE_LIBRARY NAMES freetype.lib)
set(MSVC_LIBS
${LIBINTL_LIBRARY}
${OPENAL_MSVC_LIBS}
${JPEG_LIBRARY}
${TIFF_LIBRARY}
${BZ2_LIBRARY}
${WEBP_LIBRARY}
${LZMA_LIBRARY}
${FREETYPE_LIBRARY}
winmm.lib
dxguid.lib
imm32.lib
ole32.lib
oleaut32.lib
version.lib
wsock32.lib
ws2_32.lib
)
else(${MSVC_STATIC})
set(MSVC_LIBS ${LIBINTL_LIBRARY})
endif()
set(PLATFORM_LIBS ${MSVC_LIBS})
else()
set(PLATFORM_LIBS "-lintl")
endif()

View File

@ -111,7 +111,7 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str)
std::string CSystemUtilsWindows::GetSaveDir()
{
#if PORTABLE_SAVES || DEV_BUILD
return "./saves";
return CSystemUtils::GetSaveDir();
#else
std::string savegameDir;
@ -119,7 +119,7 @@ std::string CSystemUtilsWindows::GetSaveDir()
if (envUSERPROFILE == nullptr)
{
GetLogger()->Warn("Unable to find directory for saves - using current directory");
savegameDir = CSystemUtils::GetSaveDir(false);
savegameDir = "./saves";
}
else
{