Skip to content

Commit

Permalink
Add windows cross-compile capability
Browse files Browse the repository at this point in the history
  • Loading branch information
CallumDev committed Jun 7, 2024
1 parent 64f1f8d commit 75c5bf6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ set_source_files_properties(${OUTPUT_NAME} PROPERTIES
GENERATED TRUE)
add_custom_target(bittool_lang DEPENDS "${OUTPUT_NAME}")

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(PLATFORM_FILES "win32/resources.rc")
else()
set(PLATFORM_FILES "")
endif()

add_executable(bittool
main.cpp
DroidSansFallback.cpp
Expand All @@ -29,6 +35,7 @@ add_executable(bittool
imgui/imgui_widgets.cpp
imgui/backends/imgui_impl_sdl.cpp
imgui/backends/imgui_impl_opengl3.cpp
${PLATFORM_FILES}
)

set_property(TARGET bittool PROPERTY CXX_STANDARD 14)
Expand All @@ -41,6 +48,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES unix/bittool.svg DESTINATION share/icons/hicolor/scalable/apps)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
set(IS_MINGW_BUILD "Y")
target_link_options(bittool PUBLIC -static-libgcc -static-libstdc++ -static)
endif()

find_package(Freetype)

if(Freetype_FOUND)
Expand All @@ -65,10 +77,14 @@ else()
find_package(SDL2 REQUIRED)
if (TARGET SDL2::SDL2)
message(STATUS "bittool: using TARGET SDL2::SDL2")
target_link_libraries(bittool PRIVATE SDL2::SDL2)
if(${IS_MINGW_BUILD} STREQUAL "Y")
target_link_libraries(bittool PRIVATE SDL2::SDL2main SDL2::SDL2-static)
else()
target_link_libraries(bittool PRIVATE SDL2::SDL2main SDL2::SDL2)
endif()
elseif (TARGET SDL2)
message(STATUS "bittool: using TARGET SDL2")
target_link_libraries(bittool PRIVATE SDL2)
target_link_libraries(bittool PRIVATE SDL2main SDL2)
else()
message(STATUS "bittool: no TARGET SDL2::SDL2, or SDL2, using variables")
target_include_directories(testapp PRIVATE "$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}>")
Expand Down
Binary file added win32/bittool.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions win32/mingw-w64-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Build with x86_64-w64-mingw32 on Ubuntu

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

set(SDL2_DIR /usr/x86_64-w64-mingw32/sys-root/mingw/lib/cmake/SDL2)

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
1 change: 1 addition & 0 deletions win32/resources.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "bittool.ico"

0 comments on commit 75c5bf6

Please sign in to comment.