diff --git a/CMakeLists.txt b/CMakeLists.txt index 01c44c7b..526c9e89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,10 @@ if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Debug") endif() +if(NOT ENV{MSYSTEM_PREFIX} STREQUAL "") + set(MSYS ON) +endif() + include(CTest) if(BUILD_TESTING) enable_testing() @@ -216,7 +220,11 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg") endif() endif() -set(VBAM_SDL2_LIBS SDL2::SDL2 ${SDL2_LIBRARY_TEMP}) +if(VBAM_STATIC) + set(VBAM_SDL2_LIBS SDL2::SDL2-static ${SDL2_LIBRARY_TEMP}) +else() + set(VBAM_SDL2_LIBS SDL2::SDL2 ${SDL2_LIBRARY_TEMP}) +endif() set(VBAM_GENERATED_DIR ${CMAKE_BINARY_DIR}/generated) diff --git a/cmake/Toolchain-gcc-clang.cmake b/cmake/Toolchain-gcc-clang.cmake index f1ba3686..8ab25f3d 100644 --- a/cmake/Toolchain-gcc-clang.cmake +++ b/cmake/Toolchain-gcc-clang.cmake @@ -49,3 +49,7 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) include_directories(/usr/local/include) endif() + +if(VBAM_STATIC) + add_link_options("-static-libgcc" "-static-libstdc++") +endif() diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 2b1f8cc1..5c72b17a 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -286,7 +286,7 @@ endif() # OpenAL. find_package(OpenAL REQUIRED) -if(OPENAL_STATIC OR (WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe))) +if(OPENAL_STATIC) target_compile_definitions(visualboyadvance-m PRIVATE AL_LIBTYPE_STATIC) endif() target_include_directories(visualboyadvance-m PRIVATE ${OPENAL_INCLUDE_DIR}) @@ -334,6 +334,20 @@ if(NOT wxWidgets_FOUND) target_compile_definitions(visualboyadvance-m PRIVATE NO_OGL) endif() +# Workaround of static liblzma not being found on MSYS2. +if(VBAM_STATIC AND MSYS) + unset(cleaned_up_wx_libs) + foreach(lib ${wxWidgets_LIBRARIES}) + if(lib STREQUAL "-llzma") + set(lib "liblzma.a") + endif() + + list(APPEND cleaned_up_wx_libs "${lib}") + endforeach() + + set(wxWidgets_LIBRARIES "${cleaned_up_wx_libs}") +endif() + target_link_libraries(visualboyadvance-m ${wxWidgets_LIBRARIES}) target_include_directories(visualboyadvance-m PRIVATE ${wxWidgets_INCLUDE_DIRS}) target_compile_options(visualboyadvance-m PRIVATE ${wxWidgets_CXX_FLAGS})