support emscripten compile

This commit is contained in:
DaniTheSkunk 2022-12-21 14:01:04 +00:00
parent a4ce5bb09e
commit 1fa6361401
7 changed files with 65 additions and 14 deletions

9
em.ini Normal file
View File

@ -0,0 +1,9 @@
[binaries]
c = ['c:/dev/_tools/emsdk/upstream/emscripten/emcc.bat']
ar =['c:/dev/_tools/emsdk/upstream/emscripten/emar.bat']
[host_machine]
system = 'emscripten'
cpu_family = 'wasm'
cpu = 'wasm'
endian = 'little'

View File

@ -1,4 +1,10 @@
project('skunkworks', 'c', default_options: ['buildtype=release'])
project('skunkworks', 'c',
default_options: [
'buildtype=release',
'strip=true',
'debug=false'
]
)
cmake = import('cmake')
@ -20,9 +26,18 @@ opt.add_cmake_defines({
opt.append_compile_args('c', '-I../subprojects/zlib-1.2.13', '-Isubprojects/zlib-1.2.13/__CMake_build')
libpng = cmake.subproject('lpng1639', options: opt).dependency('png_static')
libglfw = cmake.subproject('glfw-3.3.8').dependency('glfw')
opt = cmake.subproject_options()
opt.add_cmake_defines({'GLFW_BUILD_DOCS': false})
if host_machine.system() == 'emscripten'
#libglfw = meson.get_compiler('c').find_library('glfw')
deps = [libz, libpng]
else
libglfw = cmake.subproject('glfw-3.3.8', options: opt).dependency('glfw')
libglew = subproject('glew-2.1.0').get_variable('libglew_dep')
deps = [libz, libpng, libglew, libglfw]
endif
skunk_sources = [
'src/skunkworks.c',
@ -31,4 +46,8 @@ skunk_sources = [
'src/window.c'
]
executable('skunktest', skunk_sources, include_directories: 'include', dependencies: [libz, libpng, libglew, libglfw])
if host_machine.system() == 'emscripten'
executable('skunktest', skunk_sources, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3'], name_suffix: 'html')
else
executable('skunktest', skunk_sources, include_directories: 'include', dependencies: deps)
endif

2
prebuildem.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
meson setup --cross-file=em.ini --prefer-static buildem

View File

@ -3,3 +3,9 @@
#include <GL/glew.h>
#pragma clang diagnostic pop
#include <GLFW/glfw3.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#endif

View File

@ -5,19 +5,30 @@
#include "gl.h"
int main(int argc, char *argv[]) {
struct window *win;
void tick();
int main(int argc, char *argv[]) {
printf("hello world\n");
win = sw_window_create(sw_vec2i(640, 480), "Skunkworks");
png_sig_cmp(0, 0, 0);
glClearColor(0.1f, 0.2f, 0.3f, 1.f);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(tick, 0, 1);
#else
while (!glfwWindowShouldClose(win->_window)) {
tick();
}
#endif
return 0;
}
void tick() {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(win->_window);
glfwPollEvents();
}
return 0;
}

View File

@ -3,6 +3,10 @@ project('glew', 'c')
gl = dependency('gl')
inc = include_directories('include')
c_args = ['-DGLEW_STATIC']
if host_machine.system() == 'emscripten'
lib = static_library('glew', 'src/glew.c', include_directories: inc, c_args: c_args)
else
lib = static_library('glew', 'src/glew.c', include_directories: inc, c_args: c_args, dependencies: gl)
endif
libglew_dep = declare_dependency(include_directories: inc, link_with: lib, compile_args: c_args)

View File

@ -147,10 +147,10 @@ if(MINGW)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
endif(MINGW)
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
#add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
set_target_properties(zlib PROPERTIES SOVERSION 1)
#set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
#set_target_properties(zlib PROPERTIES SOVERSION 1)
if(NOT CYGWIN)
# This property causes shared libraries on Linux to have the full version
@ -160,7 +160,7 @@ if(NOT CYGWIN)
#
# This has no effect with MSVC, on that platform the version info for
# the DLL comes from the resource file win32/zlib1.rc
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
#set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
endif()
if(UNIX)
@ -175,7 +175,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32)
endif()
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
install(TARGETS zlib zlibstatic
install(TARGETS zlibstatic
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )