From 69027eca5370d370a1134f778bda1c128181efc3 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Thu, 7 Oct 2021 16:47:07 +0300 Subject: [PATCH] Mingw build: static link, posix g++, SDL2 list order. --- CMakeLists.txt | 9 +++++++-- CMakeModules/FindSDL2.cmake | 2 +- mingwcc.cmake | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db5a714..d729de1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,11 @@ if(WIN32) list(APPEND SDL2_MIXER_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs/SDL2_mixer") endif() +# Link mingw libs static +if(MINGW) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") +endif() + # SDL2main is not needed set(SDL2_BUILDING_LIBRARY ON) @@ -195,8 +200,8 @@ target_link_libraries(SpaceCadetPinball ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY}) # On Windows, copy DLL to output if(WIN32) - list(POP_BACK SDL2_LIBRARY SDL2_DLL_PATH) - list(POP_BACK SDL2_MIXER_LIBRARY SDL2_MIXER_DLL_PATH) + list(GET SDL2_LIBRARY -1 SDL2_DLL_PATH) + list(GET SDL2_MIXER_LIBRARY -1 SDL2_MIXER_DLL_PATH) get_filename_component(SDL2_DLL_PATH ${SDL2_DLL_PATH} DIRECTORY) get_filename_component(SDL2_MIXER_DLL_PATH ${SDL2_MIXER_DLL_PATH} DIRECTORY) if(MINGW) diff --git a/CMakeModules/FindSDL2.cmake b/CMakeModules/FindSDL2.cmake index 652bf43..1e9276f 100644 --- a/CMakeModules/FindSDL2.cmake +++ b/CMakeModules/FindSDL2.cmake @@ -152,7 +152,7 @@ IF(SDL2_LIBRARY_TEMP) # In fact, there seems to be a problem if I used the Threads package # and try using this line, so I'm just skipping it entirely for OS X. IF(NOT APPLE) - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + SET(SDL2_LIBRARY_TEMP ${CMAKE_THREAD_LIBS_INIT} ${SDL2_LIBRARY_TEMP}) ENDIF(NOT APPLE) # For MinGW library diff --git a/mingwcc.cmake b/mingwcc.cmake index 5c26b26..1e61c73 100644 --- a/mingwcc.cmake +++ b/mingwcc.cmake @@ -2,7 +2,8 @@ set(TOOLCHAIN_PREFIX "x86_64-w64-mingw32") set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++") +#posix for std::this_thread, might work with just g++ +set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++-posix") set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}-gcc") set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}-objcopy") set(CMAKE_STRIP "${TOOLCHAIN_PREFIX}-strip")