summary refs log tree commit diff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-02-04 20:50:29 +0100
committerMel <einebeere@gmail.com>2024-02-04 20:50:29 +0100
commit44b87e9751f054ed5406042d69bbc130331d660e (patch)
tree1030b4539dcdd96924b3126d52a2b564d6e2eccd /CMakeLists.txt
parentf08eae304a4fe986c9cf91a976e0fdfad9f2a16a (diff)
downloadmeowcraft-44b87e9751f054ed5406042d69bbc130331d660e.tar.zst
meowcraft-44b87e9751f054ed5406042d69bbc130331d660e.zip
Cross-compiling to Windows using MinGW-w64 (fully statically)
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt27
1 files changed, 20 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fffbda..d0c036f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,12 +7,24 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 # Enable assertions for RelWithDebInfo builds.
 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
 
+set(GLEW_USE_STATIC_LIBS ON)
+
 find_package(glfw3 3.3 REQUIRED)
 find_package(GLEW REQUIRED)
+find_package(OpenGL REQUIRED)
+
+# Vendored shared libraries for MinGW-w64
+# for cross-compiling to Windows from macOS
+if (WIN32)
+    set_target_properties(glfw PROPERTIES
+        IMPORTED_IMPLIB_RELEASE "${CMAKE_SOURCE_DIR}/vendor/mingw/libglfw3.a"
+    )
 
-if (LINUX)
-    find_package(OpenGL REQUIRED)
-endif (LINUX)
+    set_target_properties(GLEW::glew_s PROPERTIES
+        IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/vendor/mingw/libglew32.a"
+        INTERFACE_LINK_LIBRARIES "" # Tries importing OpenGL.framework on macOS otherwise
+    )
+endif (WIN32)
 
 add_executable(meowcraft
     src/main.cpp
@@ -68,11 +80,12 @@ add_executable(meowcraft
     src/Common/Casts.hpp
     src/World/VoxelTraversal.hpp
 )
-target_link_libraries(meowcraft glfw GLEW::GLEW)
 
-if (LINUX)
-    target_link_libraries(meowcraft OpenGL)
-endif (LINUX)
+if (WIN32)
+    set(LINK_FLAGS "-static-libgcc -static-libstdc++ -static -mwindows")
+endif (WIN32)
+
+target_link_libraries(meowcraft PRIVATE glfw GLEW::glew_s OpenGL::GL ${LINK_FLAGS})
 
 function(make_includable input_file output_file)
     file(READ ${input_file} content)