Skip to content

Commit

Permalink
Setup a windows toolchain for use on linux (#66)
Browse files Browse the repository at this point in the history
Removed some files from the lua build that contained main functions and
a REPL implementation.
  • Loading branch information
LiquidityC authored Aug 19, 2024
1 parent 21a2535 commit 7b6e27c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 32 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,49 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release, Debug]
c_compiler: [gcc, clang, cl]
c_compiler: [gcc, clang, cl, mingw-w64-gcc]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
cmake: '-DSDLMIXER_VENDORED=ON -GNinja'
cmake_args: '-DSDLMIXER_VENDORED=ON'
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
cmake: '-GNinja'
cmake_args: '-GNinja'
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
cmake: '-GNinja'
cmake_args: '-GNinja'
- os: ubuntu-latest
c_compiler: mingw-w64-gcc
cpp_compiler: mingw-w64-g++
cmake_args: >
-DSDL2MIXER_VENDORED=ON
-DSDL2TTF_VENDORED=ON
-DCMAKE_TOOLCHAIN_FILE=build_deps/toolchains/mingw-w64-x86_64.cmake
-GNinja
- os: macos-latest
c_compiler: gcc
cpp_compiler: g++
cmake: '-DSDLMIXER_VENDORED=ON -GNinja'
cmake_args: '-DSDLMIXER_VENDORED=ON -GNinja'
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
cmake: '-DSDLMIXER_VENDORED=ON -GNinja'
cmake_args: '-DSDLMIXER_VENDORED=ON -GNinja'
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: windows-latest
c_compiler: mingw-w64-gcc
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: cl
- os: macos-latest
c_compiler: mingw-w64-gcc

steps:
- uses: actions/checkout@v4
Expand All @@ -73,6 +85,7 @@ jobs:
sudo apt-get update
sudo apt-get -y install \
cmake \
mingw-w64 \
libflac-dev \
libfluidsynth-dev \
libgme-dev \
Expand Down Expand Up @@ -119,6 +132,7 @@ jobs:
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
${{ matrix.cmake_args }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
Expand Down
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ ELSEIF ( WIN32 )
"${CMAKE_C_FLAGS_RELEASE} -mwindows"
)
ENDIF ()
IF ( GCC )
SET (
CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
)
ENDIF ( GCC )
#IF ( GCC )
#SET (
#CMAKE_C_FLAGS_DEBUG
#"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
#)
#ENDIF ( GCC )

if (STEAM)
include_directories(
Expand All @@ -110,7 +110,7 @@ set(SDL_TEST OFF)
add_subdirectory(lib/SDL)
set(SDL2_INCLUDE_DIR lib/SDL/include)
set(SDL2_LIBRARY SDL2-static)
set(SDL2_MAIN SDL2main)
set(SDL2_MAIN_LIBRARY SDL2main)

# Include SDL2_image/mixer/ttf
set(BUILD_SHARED_LIBS OFF)
Expand Down Expand Up @@ -284,7 +284,6 @@ set_source_files_properties(lib/sqlite3/sqlite3.c COMPILE_FLAGS -w)
target_link_libraries(breakhack
${CMAKE_DL_LIBS} # Sqlite needs DL libs
${SDL2_LIBRARY}
${SDL2_MAIN}
${SDL2_IMAGE_LIBRARY}
${SDL2_TTF_LIBRARY}
${SDL2_MIXER_LIBRARY}
Expand All @@ -294,6 +293,12 @@ target_link_libraries(breakhack
checksum
)

if (MSVC OR MINGW)
target_link_libraries(breakhack
${SDL2_MAIN_LIBRARY}
)
endif ()

if (STEAM)
target_link_libraries(breakhack
steamworks_c_wrapper
Expand Down Expand Up @@ -329,7 +334,6 @@ IF (CMOCKA_FOUND AND NOT OSX AND NOT CLANG)
target_link_libraries(test_input
${CMOCKA_LIBRARY}
${SDL2_LIBRARY}
${SDL2MAIN_LIBRARY}
)
#set_target_properties(test_input PROPERTIES
#LINK_FLAGS "-Wl,--wrap,keyboard_direction_press -Wl,--wrap,keyboard_press")
Expand Down
34 changes: 21 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
all:
@make -sC build/debug
@cmake --build build/debug
.PHONY: all

release:
@make -sC build/release
@cmake --build build/release
.PHONY: release

windows:
@cmake --build build/win-release
.PHONY: windows

clean:
@make -sC build/debug clean
@make -sC build/release clean
@cmake --build build/debug --target clean
@cmake --build build/release --target clean
@cmake --build build/win-release --target clean
.PHONY: clean

test:
@make -sC build/debug test
@cmake --build build/debug --target test
.PHONY: test

run: $(all)
Expand All @@ -24,22 +29,25 @@ playtest: $(all)
.PHONY: playtest

lint:
@make -sC build/debug lint
@cmake --build build/debug --target lint
.PHONY: lint

package:
@make -sC build/release package
@cmake --build build/release --target package
.PHONY: package

setup:
@mkdir -p build/debug
@mkdir -p build/release
@cd build/debug/ && \
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=YES ../.. && \
cd -
@cd build/release/ && \
cmake -DCMAKE_BUILD_TYPE=Release ../.. && \
cd -
@mkdir -p build/win-release
@cmake -B build/debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=YES -GNinja
@cmake -B build/release -DCMAKE_BUILD_TYPE=Release -GNinja
@cmake -B build/win-release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=build_deps/toolchains/mingw-w64-x86_64.cmake \
-DSDL2MIXER_VENDORED=ON \
-DSDL2TTF_VENDORED=ON \
-GNinja
@ln -fs build/debug/compile_commands.json
@echo "Setup complete"
.PHONY: setup
Expand Down
16 changes: 16 additions & 0 deletions build_deps/toolchains/mingw-w64-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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})

# 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)
4 changes: 1 addition & 3 deletions lib/lua-5.3.5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(lua_MAJOR_VERSION 5)
set(lua_MINOR_VERSION 3)
set(lua_PATCH_VERSION 5)

if (NOT MSVC)
if (NOT MSVC AND NOT MINGW)
add_definitions(-DLUA_USE_POSIX)
endif ()

Expand Down Expand Up @@ -42,8 +42,6 @@ add_library(lua STATIC
src/ltable.c
src/ltablib.c
src/ltm.c
src/lua.c
src/luac.c
src/lundump.c
src/lutf8lib.c
src/lvm.c
Expand Down
2 changes: 1 addition & 1 deletion src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define SECONDS_PER_HOUR 3600
#define SECONDS_PER_MINUTE 60

#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
#define m_gmtime(time, obj) gmtime_s(obj, time)
#else
#define m_gmtime gmtime_r
Expand Down

0 comments on commit 7b6e27c

Please sign in to comment.