diff --git a/CMakeLists.txt b/CMakeLists.txt index 927c8c165a6..6387848584e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) -if(WIN32) +if(WIN32 AND NOT MINGW) # Location of the FreeOrionSDK root set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/..") # Search dependency DLLs inside FreeOrionSDK @@ -142,23 +142,29 @@ add_compile_options( $<$:/EHsc> ) +if(WIN32 AND NOT MINGW) + set_property(DIRECTORY APPEND + PROPERTY COMPILE_DEFINITIONS + # Set minimum Windows target version to WindowsXP + # https://msdn.microsoft.com/en-us/library/aa383745.aspx + $<$:_WIN32_WINNT=_WIN32_WINNT_WINXP> + # Default to unicode variants when using Win32 API + # https://msdn.microsoft.com/en-us/library/dybsewaf.aspx + $<$:_UNICODE> + # Disable "'' was declared deprecated" warning + # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx + $<$:_CRT_SECURE_NO_WARNINGS> + # Disable '': Function call with parameters that may be unsafe" warning + # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx + $<$:_SCL_SECURE_NO_WARNINGS> + # Disable '': The POSIX name for this item is deprecated." warning + # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx + $<$:_CRT_NONSTDC_NO_WARNINGS> + ) +endif() + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS - # Set minimum Windows target version to WindowsXP - # https://msdn.microsoft.com/en-us/library/aa383745.aspx - $<$:_WIN32_WINNT=_WIN32_WINNT_WINXP> - # Default to unicode variants when using Win32 API - # https://msdn.microsoft.com/en-us/library/dybsewaf.aspx - $<$:_UNICODE> - # Disable "'' was declared deprecated" warning - # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx - $<$:_CRT_SECURE_NO_WARNINGS> - # Disable '': Function call with parameters that may be unsafe" warning - # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx - $<$:_SCL_SECURE_NO_WARNINGS> - # Disable '': The POSIX name for this item is deprecated." warning - # https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx - $<$:_CRT_NONSTDC_NO_WARNINGS> # Define platform specific macros $<$:FREEORION_WIN32> @@ -168,6 +174,13 @@ set_property(DIRECTORY APPEND $<$:FREEORION_OPENBSD> ) +if(MINGW) + set_property(DIRECTORY APPEND + PROPERTY COMPILE_DEFINITIONS + FREEORION_MINGW + ) +endif() + if(WIN32 AND MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT") @@ -231,6 +244,13 @@ if(NOT BUILD_HEADLESS) find_package(Vorbis REQUIRED) endif() +if(MINGW) + find_library(WS2_32_LIBRARY ws2_32) + find_library(WSOCK32_LIBRARY wsock32) + find_library(BCRYPT_LIBRARY bcrypt) + find_library(ICONV_LIBRARY iconv) +endif() + if(APPLE) find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) find_library(ICONV_LIBRARY iconv) @@ -253,13 +273,13 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS # Disable Boost auto-linking # http://www.boost.org/doc/libs/1_59_0/libs/config/doc/html/index.html#boost_config.configuring_boost_for_your_platform.user_settable_options - BOOST_ALL_NO_LINK + BOOST_ALL_NO_LIB # Boost iostreams doesn't honor BOOST_ALL_NO_LINK when linking zlib. - # It also tries to link by default to the boost in-source zlib librar, + # It also tries to link by default to the boost in-source zlib library, # which we don't want. # http://www.boost.org/doc/libs/1_59_0/boost/iostreams/detail/config/zlib.hpp - $<$:BOOST_ZLIB_BINARY=zlib.lib> + $<$:BOOST_ZLIB_BINARY=zlib.a> # Link all boost libraries dynamically # http://www.boost.org/doc/libs/1_59_0/libs/config/doc/html/index.html#boost_config.configuring_boost_for_your_platform.user_settable_options @@ -309,8 +329,13 @@ if(Apple) ) endif() +if(NOT MINGW) + add_library(freeorioncommon "") +endif() -add_library(freeorioncommon "") +if(MINGW) + add_library(freeorioncommon STATIC "") +endif() if(WIN32) set_property(TARGET freeorioncommon @@ -361,12 +386,12 @@ target_link_libraries(freeorioncommon ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${ZLIB_LIBRARIES} + ${BCRYPT_LIBRARY} ${CORE_FOUNDATION_LIBRARY} ) add_dependencies(freeorioncommon freeorionversion) - add_library(freeorionparseobj OBJECT "") target_include_directories(freeorionparseobj SYSTEM @@ -380,13 +405,6 @@ set_property(TARGET freeorionparseobj POSITION_INDEPENDENT_CODE ON ) -if(WIN32) - set_property(TARGET freeorionparse - PROPERTY - OUTPUT_NAME Parsers - ) -endif() - target_compile_options(freeorionparseobj PRIVATE $<$:-fvisibility=hidden> @@ -403,8 +421,20 @@ target_compile_definitions(freeorionparseobj -DFREEORION_BUILD_PARSE ) +if(NOT MINGW) + add_library(freeorionparse $) +endif() -add_library(freeorionparse $) +if(MINGW) + add_library(freeorionparse STATIC $) +endif() + +if(WIN32) + set_property(TARGET freeorionparse + PROPERTY + OUTPUT_NAME Parsers + ) +endif() target_compile_options(freeorionparse PRIVATE @@ -467,13 +497,14 @@ target_link_libraries(freeoriond ${Boost_PYTHON_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} + ${WS2_32_LIBRARY} + ${WSOCK32_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ) target_dependencies_copy_to_build(freeoriond) target_dependent_data_symlink_to_build(freeoriond ${PROJECT_SOURCE_DIR}/default) - add_executable(freeorionca "") if(WIN32) @@ -510,6 +541,8 @@ target_link_libraries(freeorionca ${Boost_PYTHON_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} + ${WS2_32_LIBRARY} + ${WSOCK32_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ) @@ -605,6 +638,12 @@ if(NOT BUILD_HEADLESS) ) endif() + if(MINGW) + target_link_libraries(freeorion + mingw32 + ) + endif() + target_link_libraries(freeorion freeorioncommon freeorionparse @@ -616,10 +655,21 @@ if(NOT BUILD_HEADLESS) ${SDL_LIBRARIES} ${OGG_LIBRARIES} ${VORBIS_LIBRARIES} - ${ZLIB_LIBRARIES} + ${Boost_DATE_TIME_LIBRARY} + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_IOSTREAMS_LIBRARY} ${Boost_LOCALE_LIBRARY} ${Boost_LOG_LIBRARY} ${Boost_LOG_SETUP_LIBRARY} + ${Boost_REGEX_LIBRARY} + ${Boost_SERIALIZATION_LIBRARY} + ${Boost_SIGNALS_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${Boost_THREAD_LIBRARY} + ${ZLIB_LIBRARIES} + ${WS2_32_LIBRARY} + ${WSOCK32_LIBRARY} + ${BCRYPT_LIBRARY} ${ICONV_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/client/AI/camain.cpp b/client/AI/camain.cpp index 2c6fb91e629..3c85e2356ca 100644 --- a/client/AI/camain.cpp +++ b/client/AI/camain.cpp @@ -24,7 +24,7 @@ unroll and hide the stack trace, print a message and still crash anyways. */ #define FREEORION_CAMAIN_KEEP_STACKTRACE #endif -#ifndef FREEORION_WIN32 +#if !defined(FREEORION_WIN32) || defined(FREEORION_MINGW) int main(int argc, char* argv[]) { InitDirs(argv[0]); std::vector args; diff --git a/client/human/chmain.cpp b/client/human/chmain.cpp index de38fe20063..4f6288c6d17 100644 --- a/client/human/chmain.cpp +++ b/client/human/chmain.cpp @@ -53,7 +53,7 @@ int mainSetupAndRun(); int mainConfigOptionsSetup(const std::vector& args); -#if defined(FREEORION_LINUX) || defined(FREEORION_FREEBSD) || defined(FREEORION_OPENBSD) +#if defined(FREEORION_LINUX) || defined(FREEORION_FREEBSD) || defined(FREEORION_OPENBSD) || defined(FREEORION_MINGW) int main(int argc, char* argv[]) { // copy command line arguments to vector std::vector args; @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) { return 1; } #endif -#ifdef FREEORION_WIN32 +#if defined(FREEORION_WIN32) && !defined(FREEORION_MINGW) int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { // copy UTF-16 command line arguments to UTF-8 vector std::vector args; diff --git a/server/dmain.cpp b/server/dmain.cpp index d4db90c4c5a..0996a9a6710 100644 --- a/server/dmain.cpp +++ b/server/dmain.cpp @@ -24,7 +24,7 @@ unroll and hide the stack trace, print a message and still crash anyways. */ #define FREEORION_DMAIN_KEEP_STACKTRACE #endif -#ifndef FREEORION_WIN32 +#if !defined(FREEORION_WIN32) || defined(FREEORION_MINGW) int main(int argc, char* argv[]) { InitDirs(argv[0]); std::vector args;