Configure MinGW separately from the toolchain

* Set up the mingw environment in addition to the toolchain rather than
  separately.
* Revert the submodule check to always be done for Windows and MinGW.
* Revert the special link step for MinGW/GCC.
This commit is contained in:
Fabrice de Gans 2024-03-14 12:34:46 -07:00
parent fd2d7c8001
commit 4d074644dc
3 changed files with 49 additions and 18 deletions

View File

@ -46,6 +46,29 @@ if(NOT CMAKE_CXX_COMPILER_LAUNCHER)
endif()
endif()
find_package(Git)
# Make sure we pull in the submodules on windows and mingw.
if(GIT_FOUND AND (WIN32 OR MINGW))
# Win32 deps submodule
set(SUBMODULE_MANUAL_UPDATE FALSE)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
set(SUBMODULE_MANUAL_UPDATE TRUE)
execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule update --init --remote --recursive
RESULT_VARIABLE SUBMODULE_UPDATE_STATUS
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
if(NOT (SUBMODULE_MANUAL_UPDATE AND SUBMODULE_UPDATE_STATUS EQUAL 0))
message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive")
endif()
endif()
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 11)
@ -53,7 +76,6 @@ set(CMAKE_C_STANDARD_REQUIRED True)
project(VBA-M C CXX)
find_package(Git)
find_package(PkgConfig)
if(NOT CMAKE_PREFIX_PATH AND (NOT ("$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")))

View File

@ -1,21 +1,28 @@
if (NOT MINGW)
return()
endif()
# this has to run after the toolchain is initialized.
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-include")
include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
# Win32 deps submodule
set(git_checkout FALSE)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(git_checkout TRUE)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --remote --recursive
RESULT_VARIABLE git_status
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
# link libgcc/libstdc++ statically on GCC/mingw
# and adjust link command when making a static binary
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(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include")
if(NOT (git_checkout AND git_status EQUAL 0))
message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive")
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()
endif()

View File

@ -32,14 +32,16 @@ if(X86_64)
add_compile_definitions(__AMD64__ __X86_64__)
endif()
# Enable ASAN if requested and supported.
include(Toolchain-asan)
# MINGW/MSYS-specific settings.
include(Toolchain-mingw)
# Toolchain-specific settings.
if(MSVC)
# This also includes clang-cl.
include(Toolchain-msvc)
elseif(MINGW)
include(Toolchain-mingw)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
include(Toolchain-gcc-clang)
else()