Skip to content

Commit

Permalink
NoGUI: Migrate to new host abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 24, 2022
1 parent 7277d29 commit 6df7d9a
Show file tree
Hide file tree
Showing 30 changed files with 3,471 additions and 1,927 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.16)
project(duckstation C CXX)

message("CMake Version: ${CMAKE_VERSION}")
Expand Down
29 changes: 29 additions & 0 deletions CMakeModules/FindWaylandProtocols.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# from https://github.com/glfw/glfw/blob/master/CMake/modules/FindWaylandProtocols.cmake

find_package(PkgConfig)

pkg_check_modules(WaylandProtocols QUIET wayland-protocols>=${WaylandProtocols_FIND_VERSION})

execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
OUTPUT_VARIABLE WaylandProtocols_PKGDATADIR
RESULT_VARIABLE _pkgconfig_failed)
if (_pkgconfig_failed)
message(FATAL_ERROR "Missing wayland-protocols pkgdatadir")
endif()

string(REGEX REPLACE "[\r\n]" "" WaylandProtocols_PKGDATADIR "${WaylandProtocols_PKGDATADIR}")

find_package_handle_standard_args(WaylandProtocols
FOUND_VAR
WaylandProtocols_FOUND
REQUIRED_VARS
WaylandProtocols_PKGDATADIR
VERSION_VAR
WaylandProtocols_VERSION
HANDLE_COMPONENTS
)

set(WAYLAND_PROTOCOLS_FOUND ${WaylandProtocols_FOUND})
set(WAYLAND_PROTOCOLS_PKGDATADIR ${WaylandProtocols_PKGDATADIR})
set(WAYLAND_PROTOCOLS_VERSION ${WaylandProtocols_VERSION})

38 changes: 38 additions & 0 deletions CMakeModules/FindXKBCommon.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# - Try to find XKBCommon
# Once done, this will define
#
# XKBCOMMON_FOUND - System has XKBCommon
# XKBCOMMON_INCLUDE_DIRS - The XKBCommon include directories
# XKBCOMMON_LIBRARIES - The libraries needed to use XKBCommon
# XKBCOMMON_DEFINITIONS - Compiler switches required for using XKBCommon

find_package(PkgConfig)
pkg_check_modules(PC_XKBCOMMON QUIET xkbcommon)
set(XKBCOMMON_DEFINITIONS ${PC_XKBCOMMON_CFLAGS_OTHER})

find_path(XKBCOMMON_INCLUDE_DIR
NAMES xkbcommon/xkbcommon.h
HINTS ${PC_XKBCOMMON_INCLUDE_DIR} ${PC_XKBCOMMON_INCLUDE_DIRS}
)

find_library(XKBCOMMON_LIBRARY
NAMES xkbcommon
HINTS ${PC_XKBCOMMON_LIBRARY} ${PC_XKBCOMMON_LIBRARY_DIRS}
)

set(XKBCOMMON_LIBRARIES ${XKBCOMMON_LIBRARY})
set(XKBCOMMON_LIBRARY_DIRS ${XKBCOMMON_LIBRARY_DIRS})
set(XKBCOMMON_INCLUDE_DIRS ${XKBCOMMON_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XKBCommon DEFAULT_MSG
XKBCOMMON_LIBRARY
XKBCOMMON_INCLUDE_DIR
)

mark_as_advanced(XKBCOMMON_LIBRARY XKBCOMMON_INCLUDE_DIR)

if (XKBCOMMON_INCLUDE_DIR AND XKBCOMMON_LIBRARY AND NOT TARGET XKBCommon::XKBCommon)
add_library(XKBCommon::XKBCommon UNKNOWN IMPORTED)
set_target_properties(XKBCommon::XKBCommon PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${XKBCOMMON_INCLUDE_DIR}" IMPORTED_LOCATION "${XKBCOMMON_LIBRARY}")
endif()
1 change: 1 addition & 0 deletions duckstation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ Global
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.Debug|x86.Build.0 = Debug|Win32
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugFast|ARM64.ActiveCfg = DebugFast|ARM64
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugFast|x64.ActiveCfg = DebugFast|x64
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugFast|x64.Build.0 = DebugFast|x64
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugFast|x86.ActiveCfg = DebugFast|Win32
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugFast|x86.Build.0 = DebugFast|Win32
{0A172B2E-DC67-49FC-A4C1-975F93C586C4}.DebugUWP|ARM64.ActiveCfg = DebugUWP|ARM64
Expand Down
89 changes: 61 additions & 28 deletions src/duckstation-nogui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,77 @@
add_executable(duckstation-nogui
main.cpp
nogui_host_interface.cpp
nogui_host_interface.h
nogui_host.cpp
nogui_host.h
nogui_platform.h
)

target_link_libraries(duckstation-nogui PRIVATE core common imgui glad frontend-common scmversion)
target_link_libraries(duckstation-nogui PRIVATE core util common imgui glad frontend-common scmversion)

if(USE_SDL2)
target_sources(duckstation-nogui PRIVATE
sdl_host_interface.cpp
sdl_host_interface.h
sdl_key_names.h
if(WIN32)
message(STATUS "Building Win32 NoGUI Platform.")
target_sources(duckstation-nogui PRIVATE
duckstation-nogui.manifest
resource.h
win32_nogui_platform.cpp
win32_nogui_platform.h
)
target_include_directories(duckstation-nogui PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(duckstation-nogui PRIVATE ${SDL2_LIBRARIES})

# We want a Windows subsystem application not console.
set_target_properties(duckstation-nogui PROPERTIES
WIN32_EXECUTABLE TRUE
DEBUG_POSTFIX "-debug")
endif()

if(USE_EVDEV)
target_sources(duckstation-nogui PRIVATE
vty_host_interface.cpp
vty_host_interface.h
if(USE_X11)
message(STATUS "Building X11 NoGUI Platform.")
target_compile_definitions(duckstation-nogui PRIVATE "NOGUI_PLATFORM_X11=1")
target_sources(duckstation-nogui PRIVATE
x11_nogui_platform.cpp
x11_nogui_platform.h
)
target_compile_definitions(duckstation-nogui PRIVATE "-DWITH_VTY=1")
target_compile_definitions(duckstation-nogui PRIVATE "-DUSE_LIBEVDEV=1")
target_include_directories(duckstation-nogui PRIVATE ${LIBEVDEV_INCLUDE_DIRS})
target_link_libraries(duckstation-nogui PRIVATE ${LIBEVDEV_LIBRARIES})
target_include_directories(duckstation-nogui PRIVATE "${X11_INCLUDE_DIR}" "${X11_Xrandr_INCLUDE_PATH}")
target_link_libraries(duckstation-nogui PRIVATE "${X11_LIBRARIES}" "${X11_Xrandr_LIB}")
endif()

if(USE_DRMKMS)
target_compile_definitions(duckstation-nogui PRIVATE "-DWITH_DRMKMS=1")
endif()
if(USE_WAYLAND)
message(STATUS "Building Wayland NoGUI Platform.")
find_package(Wayland REQUIRED Client)
find_package(WaylandScanner REQUIRED)
find_package(WaylandProtocols 1.15 REQUIRED)
find_package(XKBCommon REQUIRED)

if(WIN32)
target_compile_definitions(duckstation-nogui PRIVATE "NOGUI_PLATFORM_WAYLAND=1")
target_sources(duckstation-nogui PRIVATE
duckstation-nogui.manifest
wayland_nogui_platform.cpp
wayland_nogui_platform.h
)

# We want a Windows subsystem application not console.
set_target_properties(duckstation-nogui PROPERTIES
WIN32_EXECUTABLE TRUE
DEBUG_POSTFIX "-debug")
# Generate the xdg-shell and xdg-decoration protocols at build-time.
# Because these are C, not C++, we have to put them in their own library, otherwise
# cmake tries to generate a C PCH as well as the C++ one...
ecm_add_wayland_client_protocol(WAYLAND_PLATFORM_SRCS
PROTOCOL "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml"
BASENAME xdg-shell)
ecm_add_wayland_client_protocol(WAYLAND_PLATFORM_SRCS
PROTOCOL "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
BASENAME xdg-decoration)
add_library(duckstation-nogui-wayland-protocols STATIC ${WAYLAND_PLATFORM_SRCS})
target_include_directories(duckstation-nogui-wayland-protocols PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")

target_link_libraries(duckstation-nogui PRIVATE
duckstation-nogui-wayland-protocols
Wayland::Client
XKBCommon::XKBCommon
)
endif()

if(USE_DRMKMS AND USE_EVDEV)
message(STATUS "Building VTY/DRM/KMS/EVDev NoGUI Platform.")
target_compile_definitions(duckstation-nogui PRIVATE "NOGUI_PLATFORM_VTY=1" "WITH_DRMKMS=1")
target_sources(duckstation-nogui PRIVATE
vty_key_names.h
vty_nogui_platform.cpp
vty_nogui_platform.h
)
target_include_directories(duckstation-nogui PRIVATE ${LIBEVDEV_INCLUDE_DIRS})
target_link_libraries(duckstation-nogui PRIVATE ${LIBEVDEV_LIBRARIES})
endif()
27 changes: 15 additions & 12 deletions src/duckstation-nogui/duckstation-nogui.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\dep\msvc\vsprops\Configurations.props" />
<ItemGroup>
<ClCompile Include="vty_host_interface.cpp">
<ClCompile Include="nogui_host.cpp" />
<ClCompile Include="vty_nogui_platform.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="nogui_host_interface.cpp" />
<ClCompile Include="sdl_host_interface.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="win32_host_interface.cpp" />
<ClCompile Include="wayland_nogui_platform.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="win32_nogui_platform.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="vty_host_interface.h">
<ClInclude Include="nogui_host.h" />
<ClInclude Include="nogui_platform.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="vty_key_names.h">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="evdev_key_names.h">
<ClInclude Include="vty_nogui_platform.h">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="nogui_host_interface.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="sdl_host_interface.h" />
<ClInclude Include="sdl_key_names.h" />
<ClInclude Include="win32_host_interface.h" />
<ClInclude Include="wayland_nogui_platform.h">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="win32_nogui_platform.h" />
</ItemGroup>
<ItemGroup>
<Manifest Include="duckstation-nogui.manifest" />
Expand Down
21 changes: 10 additions & 11 deletions src/duckstation-nogui/duckstation-nogui.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="sdl_host_interface.cpp" />
<ClCompile Include="nogui_host_interface.cpp" />
<ClCompile Include="win32_host_interface.cpp" />
<ClCompile Include="vty_host_interface.cpp" />
<ClCompile Include="nogui_host.cpp" />
<ClCompile Include="win32_nogui_platform.cpp" />
<ClCompile Include="vty_nogui_platform.cpp" />
<ClCompile Include="wayland_nogui_platform.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="sdl_host_interface.h" />
<ClInclude Include="sdl_key_names.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="nogui_host_interface.h" />
<ClInclude Include="win32_host_interface.h" />
<ClInclude Include="evdev_key_names.h" />
<ClInclude Include="vty_host_interface.h" />
<ClInclude Include="nogui_host.h" />
<ClInclude Include="win32_nogui_platform.h" />
<ClInclude Include="vty_nogui_platform.h" />
<ClInclude Include="vty_key_names.h" />
<ClInclude Include="nogui_platform.h" />
<ClInclude Include="wayland_nogui_platform.h" />
</ItemGroup>
<ItemGroup>
<Manifest Include="duckstation-nogui.manifest" />
Expand Down
Loading

0 comments on commit 6df7d9a

Please sign in to comment.