diff --git a/runtimes/native/CMakeLists.txt b/runtimes/native/CMakeLists.txt index 23459ad8..cf4a7908 100644 --- a/runtimes/native/CMakeLists.txt +++ b/runtimes/native/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.7) project(WASM4) set(WASM_BACKEND "wasm3" CACHE STRING "webassembly runtime") +set(WINDOW_BACKEND "minifb" CACHE STRING "window backend") set (WASM3 OFF) set (TOYWASM OFF) @@ -13,6 +14,16 @@ else () message (FATAL_ERROR "Unrecognized WASM_BACKEND value: ${WASM_BACKEND}") endif () +set (MINIFB OFF) +set (GLFW OFF) +if (WINDOW_BACKEND STREQUAL "minifb") +set (MINIFB ON) +elseif (WINDOW_BACKEND STREQUAL "glfw") +set (GLFW ON) +else () +message (FATAL_ERROR "Unrecognized WINDOW_BACKEND value: ${WINDOW_BACKEND}") +endif () + # Prevent BUILD_SHARED_LIBS and other options from being cleared by vendor CMakeLists # https://stackoverflow.com/a/66342383 set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) @@ -94,8 +105,12 @@ if (LIBRETRO) endif () if (NOT LIBRETRO) -# add_subdirectory(vendor/glfw) +if (GLFW) +add_subdirectory(vendor/glfw) +endif () +if (MINIFB) add_subdirectory(vendor/minifb) +endif () add_subdirectory(vendor/cubeb) endif () @@ -111,15 +126,25 @@ endif () if (NOT LIBRETRO) # -# Desktop (minifb + cubeb) backend +# Desktop ([minifb|glfw] + cubeb) backend # -set(MINIFB_SOURCES +set(MAIN_SOURCES src/backend/main.c +) + +set(MINIFB_SOURCES src/backend/window_minifb.c ) -add_executable(wasm4 ${COMMON_SOURCES} ${MINIFB_SOURCES} +set(GLFW_SOURCES + src/backend/window_glfw.c + vendor/glad/src/glad.c +) + +add_executable(wasm4 ${COMMON_SOURCES} ${MAIN_SOURCES} + $<$:${MINIFB_SOURCES}> + $<$:${GLFW_SOURCES}> $<$:${WASM3_SOURCES}> $<$:${TOYWASM_SOURCES}>) if (TOYWASM) @@ -127,12 +152,15 @@ add_dependencies(wasm4 toywasm) endif () target_include_directories(wasm4 PRIVATE + $<$:${CMAKE_SOURCE_DIR}/vendor/glad/include> $<$:${CMAKE_SOURCE_DIR}/vendor/wasm3/source> $<$:${toywasm_tmp_install}/include>) target_link_directories(wasm4 PRIVATE $<$:${toywasm_tmp_install}/lib>) -target_link_libraries(wasm4 minifb cubeb +target_link_libraries(wasm4 cubeb + $<$:minifb> + $<$:glfw> $<$:toywasm-core>) set_target_properties(wasm4 PROPERTIES C_STANDARD 99) install(TARGETS wasm4) @@ -153,24 +181,6 @@ if (WASMER_DIR) install(TARGETS wasm4_wasmer) endif () -# # -# # Desktop (glfw + cubeb) backend -# # -# -# set(GLFW_SOURCES -# src/backend/main.c -# src/backend/wasm_wasm3.c -# src/backend/window_glfw.c -# vendor/glad/src/glad.c -# ) -# add_executable(wasm4_glfw) -# target_sources(wasm4_glfw PRIVATE ${COMMON_SOURCES} ${GLFW_SOURCES} ${M3_SOURCES}) -# target_include_directories(wasm4_glfw PRIVATE "${CMAKE_SOURCE_DIR}/vendor/wasm3/source") -# target_include_directories(wasm4_glfw PRIVATE "${CMAKE_SOURCE_DIR}/vendor/glad/include") -# target_link_libraries(wasm4_glfw glfw cubeb) -# set_target_properties(wasm4_glfw PROPERTIES C_STANDARD 99) -# install(TARGETS wasm4_glfw) - # # Libretro backend #