Mingw cross compilation (#24)

* Fixed icon filename capitalization

* Created mingw cmake toolchain

* Adjusted CMakeLists.txt for compatibility

* Small mingwcc.cmake cleanup

* Added cross-compilation instructions to readme

* Update README.md

Fixed typo

Co-authored-by: Nicola Orlando <nicolaorlando24@gmail.com>
Co-authored-by: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com>
This commit is contained in:
Nixola 2021-10-07 11:53:56 +02:00 committed by GitHub
parent 48721e5811
commit 87e44b700b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 6 deletions

View file

@ -10,8 +10,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
# On Windows, set paths to SDL-devel packages here
if(WIN32)
set(SDL2_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs/SDL2")
set(SDL2_MIXER_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs/SDL2_mixer")
list(APPEND SDL2_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs/SDL2")
list(APPEND SDL2_MIXER_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs/SDL2_mixer")
endif()
# SDL2main is not needed
@ -195,8 +195,14 @@ target_link_libraries(SpaceCadetPinball ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY})
# On Windows, copy DLL to output
if(WIN32)
get_filename_component(SDL2_DLL_PATH ${SDL2_LIBRARY} DIRECTORY)
get_filename_component(SDL2_MIXER_DLL_PATH ${SDL2_MIXER_LIBRARY} DIRECTORY)
list(POP_BACK SDL2_LIBRARY SDL2_DLL_PATH)
list(POP_BACK SDL2_MIXER_LIBRARY 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)
string(REGEX REPLACE "lib$" "bin" SDL2_DLL_PATH ${SDL2_DLL_PATH})
string(REGEX REPLACE "lib$" "bin" SDL2_MIXER_DLL_PATH ${SDL2_MIXER_DLL_PATH})
endif()
message(STATUS "copy paths='${SDL2_DLL_PATH}' '${SDL2_MIXER_DLL_PATH}'")
add_custom_command(TARGET SpaceCadetPinball POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SDL2_DLL_PATH}/SDL2.dll" $<TARGET_FILE_DIR:SpaceCadetPinball>

View file

@ -37,7 +37,8 @@ Compile with Visual Studio; tested with 2019.
On Linux:\
Install devel packages for `SDL2` and `SDL2_mixer`.\
Compile with CMake; tested with GCC 10, Clang 11.
Compile with CMake; tested with GCC 10, Clang 11.\
To cross-compile for Windows, install a 64-bit version of mingw and its `SDL2` and `SDL2_mixer` distributions, then use the `mingwcc.cmake` toolchain.
On macOS:\
**Homebrew**: Install the `SDL2`, `SDL2_mixer` homebrew packages.\

View file

@ -1 +1 @@
ICON_1 ICON "icon_1.ico"
ICON_1 ICON "Icon_1.ico"

25
mingwcc.cmake Normal file
View file

@ -0,0 +1,25 @@
set(TOOLCHAIN_PREFIX "x86_64-w64-mingw32")
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++")
set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}-gcc")
set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}-objcopy")
set(CMAKE_STRIP "${TOOLCHAIN_PREFIX}-strip")
set(CMAKE_SIZE "${TOOLCHAIN_PREFIX}-size")
set(CMAKE_AR "${TOOLCHAIN_PREFIX}-ar")
set(ASSEMBLER "${TOOLCHAIN_PREFIX}-as")
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
# adjust the default behavior of the find commands:
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Add the path to your toolchain version of SDL2
set(SDL2_PATH /usr/${TOOLCHAIN_PREFIX})