diff --git a/.gitignore b/.gitignore index f9f69301..f3461be1 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ CMakeLists.txt.user.* # Ignore Visual Studio Code files /.vscode + +# Ignore Visual Studio files +/CMakeSettings.json +/.vs diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b96d6b6..44a63de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() ## diff --git a/cmake/FindLibSndFile.cmake b/cmake/FindLibSndFile.cmake index 8666c66f..7a6d32b6 100644 --- a/cmake/FindLibSndFile.cmake +++ b/cmake/FindLibSndFile.cmake @@ -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) diff --git a/cmake/FindPhysFS.cmake b/cmake/FindPhysFS.cmake index fae83786..6d4c93d4 100644 --- a/cmake/FindPhysFS.cmake +++ b/cmake/FindPhysFS.cmake @@ -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) diff --git a/src/CBot/CBotDebug.cpp b/src/CBot/CBotDebug.cpp index 892d1d0e..bef509b0 100644 --- a/src/CBot/CBotDebug.cpp +++ b/src/CBot/CBotDebug.cpp @@ -23,6 +23,7 @@ #include "CBot/CBotInstr/CBotFunction.h" #include "CBot/CBotInstr/CBotInstrCall.h" +#include <functional> #include <sstream> #include <iostream> #include <iomanip> diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index dcb39e1a..a9a83e2e 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e0857506..0a924344 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/common/system/system_windows.cpp b/src/common/system/system_windows.cpp index e459cf00..a20bfcf1 100644 --- a/src/common/system/system_windows.cpp +++ b/src/common/system/system_windows.cpp @@ -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 {