diff --git a/.gitignore b/.gitignore index b9192f7..8863231 100644 --- a/.gitignore +++ b/.gitignore @@ -52,7 +52,7 @@ Mkfile.old dkms.conf # Build directory -build/ +build*/ # CCLS cache .ccls-cache/ diff --git a/Makefile b/Makefile index 030828a..6c4833f 100644 --- a/Makefile +++ b/Makefile @@ -22,3 +22,9 @@ compile: debug: @echo "[Makefile] Running debug target..." @./build/sdl2_debug + +# Compile for windows +compile-windows: + @echo "[Makefile] Compile for Windows..." + @cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=`pwd`/toolchain/win-mingw.cmake -B build-win -S src + @cmake --build build-win diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 39952cf..3d7e7da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,9 @@ project(ComputerGraphics # TODO: potentially add bundled SDL2 version # in an `external` directory (maybe submodules) find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) +if (WIN32) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) +endif (WIN32) # Add subdirectories add_subdirectory(core) @@ -20,7 +23,10 @@ add_executable(sdl2_debug WIN32 debug.c) add_executable(render WIN32 render.c) # Obtain libraries -set(SHARED_LIBRARIES SDL2::SDL2) +if (WIN32) + set(SHARED_LIBRARIES mingw32 SDL2::SDL2main) +endif (WIN32) +set(SHARED_LIBRARIES ${SHARED_LIBRARIES} SDL2::SDL2) find_library(math m) if(math) set(SHARED_LIBRARIES ${SHARED_LIBRARIES} ${math}) diff --git a/toolchain/win-mingw.cmake b/toolchain/win-mingw.cmake new file mode 100644 index 0000000..f4aa0e8 --- /dev/null +++ b/toolchain/win-mingw.cmake @@ -0,0 +1,17 @@ +# the name of the target operating system +set(CMAKE_SYSTEM_NAME WIN32) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) + +# where is the target environment located +set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32/) + +# adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# search headers and libraries in the target environment +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)