build: fix build on MINGW{64,32}/UCRT64 on MSYS2
Pass -Wno-deprecated-copy only for C++, gcc gives a warning for C. Pass -Wno-unused-command-line-argument for clang only, gcc gives a warning about it. Add a failsafe for gcc/clang static link flags if libstdc++ or libpthread is not available as a static library. Move link command adjustment script invocations to src/wx, the target is not yet defined in the toolchain. Add -lws2_32 to the end of the link command for gcc on Windows because of link order issues with those symbols. Disable LTO for gcc on Windows, as it is broken. Don't install extra-cmake-modules on MINGW32, that package is not available there. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
f57cad67c4
commit
d9432ebb14
|
@ -49,7 +49,7 @@ endif()
|
||||||
find_package(Git)
|
find_package(Git)
|
||||||
|
|
||||||
# Make sure we pull in the submodules on windows and mingw.
|
# Make sure we pull in the submodules on windows and mingw.
|
||||||
if(GIT_FOUND AND (WIN32 OR MINGW))
|
if(GIT_FOUND AND WIN32)
|
||||||
# Win32 deps submodule
|
# Win32 deps submodule
|
||||||
set(SUBMODULE_MANUAL_UPDATE FALSE)
|
set(SUBMODULE_MANUAL_UPDATE FALSE)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build w
|
||||||
set(VBAM_STATIC_DEFAULT OFF)
|
set(VBAM_STATIC_DEFAULT OFF)
|
||||||
if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static")
|
if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static")
|
||||||
set(VBAM_STATIC_DEFAULT ON)
|
set(VBAM_STATIC_DEFAULT ON)
|
||||||
elseif(MINGW OR (NOT "$ENV{MSYSTEM_PREFIX}" STREQUAL ""))
|
elseif(MINGW OR MSYS)
|
||||||
# Default to static builds on MinGW and all MSYS2 envs.
|
# Default to static builds on MinGW and all MSYS2 envs.
|
||||||
set(VBAM_STATIC_DEFAULT ON)
|
set(VBAM_STATIC_DEFAULT ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -13,14 +13,17 @@ endif()
|
||||||
# Common flags.
|
# Common flags.
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
-pipe
|
-pipe
|
||||||
-Wno-unused-command-line-argument
|
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-copy>
|
||||||
-Wno-deprecated-copy
|
|
||||||
-Wformat
|
-Wformat
|
||||||
-Wformat-security
|
-Wformat-security
|
||||||
-feliminate-unused-debug-types
|
-feliminate-unused-debug-types
|
||||||
-fdiagnostics-color=always
|
-fdiagnostics-color=always
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
|
add_compile_options(-Wno-unused-command-line-argument)
|
||||||
|
endif()
|
||||||
|
|
||||||
# check if ssp flags are supported.
|
# check if ssp flags are supported.
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL Debug)
|
if(CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||||
check_cxx_compiler_flag(-fstack-protector-strong STACK_PROTECTOR_SUPPORTED)
|
check_cxx_compiler_flag(-fstack-protector-strong STACK_PROTECTOR_SUPPORTED)
|
||||||
|
@ -51,5 +54,5 @@ if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(VBAM_STATIC)
|
if(VBAM_STATIC)
|
||||||
add_link_options("-static-libgcc" "-static-libstdc++")
|
add_link_options("-static-libgcc" "-static-libstdc++" "-Wl,-Bstatic" "-lstdc++" "-lpthread")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -6,23 +6,5 @@ endif()
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
|
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
|
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
|
||||||
|
|
||||||
# link libgcc/libstdc++ statically on GCC/mingw
|
# Add Winsock as the last library linked because of broken link precedence.
|
||||||
# and adjust link command when making a static binary
|
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lws2_32")
|
||||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND VBAM_STATIC)
|
|
||||||
# some dists don't have a static libpthread
|
|
||||||
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread ")
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
add_custom_command(
|
|
||||||
TARGET visualboyadvance-m PRE_LINK
|
|
||||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/msys-link-static.cmake
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
add_custom_command(
|
|
||||||
TARGET visualboyadvance-m PRE_LINK
|
|
||||||
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/link-static.cmake
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
|
@ -4,10 +4,16 @@ include(CheckCXXCompilerFlag)
|
||||||
include(ProcessorCount)
|
include(ProcessorCount)
|
||||||
ProcessorCount(num_cpus)
|
ProcessorCount(num_cpus)
|
||||||
|
|
||||||
if (ENABLE_LTO)
|
if(ENABLE_LTO)
|
||||||
include(CheckIPOSupported)
|
include(CheckIPOSupported)
|
||||||
check_ipo_supported(RESULT LTO_SUPPORTED)
|
check_ipo_supported(RESULT LTO_SUPPORTED)
|
||||||
if (LTO_SUPPORTED)
|
|
||||||
|
# MINGW64 on x64 does not support LTO
|
||||||
|
if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
set(LTO_SUPPORTED FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LTO_SUPPORTED)
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
else()
|
else()
|
||||||
message(WARNING "LTO is not supported by the compiler, diasabling LTO")
|
message(WARNING "LTO is not supported by the compiler, diasabling LTO")
|
||||||
|
|
|
@ -1152,7 +1152,13 @@ windows_installdeps() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
pkgs="$pkgs SDL2 sfml FAudio wxWidgets3.2 zlib binutils cmake crt-git extra-cmake-modules headers-git make pkgconf tools-git windows-default-manifest libmangle-git ninja gdb ccache"
|
pkgs="$pkgs SDL2 sfml FAudio wxWidgets3.2 zlib binutils cmake crt-git headers-git make pkgconf tools-git windows-default-manifest libmangle-git ninja gdb ccache"
|
||||||
|
|
||||||
|
case "$target" in
|
||||||
|
*x86_64)
|
||||||
|
pkgs="$pkgs extra-cmake-modules"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
[ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs openal"
|
[ -n "$ENABLE_OPENAL" ] && pkgs="$pkgs openal"
|
||||||
[ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg"
|
[ -n "$ENABLE_FFMPEG" ] && pkgs="$pkgs ffmpeg"
|
||||||
|
|
|
@ -197,6 +197,23 @@ target_link_libraries(
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# adjust link command when making a static binary for gcc
|
||||||
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND VBAM_STATIC)
|
||||||
|
if(MSYS)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET visualboyadvance-m PRE_LINK
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/msys-link-static.cmake
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_custom_command(
|
||||||
|
TARGET visualboyadvance-m PRE_LINK
|
||||||
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/link-static.cmake
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
add_dependencies(visualboyadvance-m translations-zip)
|
add_dependencies(visualboyadvance-m translations-zip)
|
||||||
|
|
||||||
# on unix we have to check for X11 before we overwrite all the compile/link
|
# on unix we have to check for X11 before we overwrite all the compile/link
|
||||||
|
|
Loading…
Reference in New Issue