Skip to content

Commit

Permalink
runtimes/native: make glfw selectable with a cmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Aug 14, 2024
1 parent 3ba0d05 commit 3590d7e
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions runtimes/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 ()

Expand All @@ -111,28 +126,41 @@ 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}
$<$<BOOL:${MINIFB}>:${MINIFB_SOURCES}>
$<$<BOOL:${GLFW}>:${GLFW_SOURCES}>
$<$<BOOL:${WASM3}>:${WASM3_SOURCES}>
$<$<BOOL:${TOYWASM}>:${TOYWASM_SOURCES}>)
if (TOYWASM)
add_dependencies(wasm4 toywasm)
endif ()

target_include_directories(wasm4 PRIVATE
$<$<BOOL:${GLFW}>:${CMAKE_SOURCE_DIR}/vendor/glad/include>
$<$<BOOL:${WASM3}>:${CMAKE_SOURCE_DIR}/vendor/wasm3/source>
$<$<BOOL:${TOYWASM}>:${toywasm_tmp_install}/include>)
target_link_directories(wasm4 PRIVATE
$<$<BOOL:${TOYWASM}>:${toywasm_tmp_install}/lib>)

target_link_libraries(wasm4 minifb cubeb
target_link_libraries(wasm4 cubeb
$<$<BOOL:${MINIFB}>:minifb>
$<$<BOOL:${GLFW}>:glfw>
$<$<BOOL:${TOYWASM}>:toywasm-core>)
set_target_properties(wasm4 PROPERTIES C_STANDARD 99)
install(TARGETS wasm4)
Expand All @@ -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
#
Expand Down

0 comments on commit 3590d7e

Please sign in to comment.