build: fix static linking on MSYS2 CLANG64

Bring back setting the MSYS variable under MSYS2, it's still being used
in a few places.

Link the SDL2::SDL2-static target for static builds.

Add -static-libgcc and -static-libstdc++ to the gcc/clang toolchain for
static builds.

Edit wxWidgets_LIBRARIES under MSYS2 to specify liblzma.a explicitly
because for some reason it's not being linked statically by default for
static builds.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2024-03-30 18:06:25 +00:00
parent ce7cc4e223
commit f57cad67c4
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
3 changed files with 28 additions and 2 deletions

View File

@ -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()
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)

View File

@ -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()

View File

@ -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})