git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@480 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-23 17:42:13 +00:00
parent 841ea75f37
commit 184a4eb420
6 changed files with 84 additions and 32 deletions

View File

@@ -7,7 +7,7 @@ project(
) )
option(OPENGL "Compile OpenGL widget or not" ON) option(OPENGL "Compile OpenGL widget or not" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
option(VULKAN "Compile Vulkan widget or not" OFF) option(VULKAN "Compile Vulkan widget or not" OFF)
else() else()
option(VULKAN "Compile Vulkan widget or not" ON) option(VULKAN "Compile Vulkan widget or not" ON)
@@ -102,11 +102,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
PRIVATE PRIVATE
USE_GDI USE_GDI
) )
target_link_libraries( list(APPEND LIBRARIES gdi32)
Mw
PRIVATE list(APPEND GL_LIBRARIES opengl32 glu32)
gdi32
)
else() else()
find_package(PkgConfig) find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11) pkg_check_modules(X11 REQUIRED x11)
@@ -118,34 +116,44 @@ else()
PRIVATE PRIVATE
src/backend/x11.c src/backend/x11.c
) )
target_include_directories(
Mw
PRIVATE
${X11_INCLUDE_DIRS} ${XRENDER_INCLUDE_DIRS} ${XCURSOR_INCLUDE_DIRS}
)
target_link_directories(
Mw
PRIVATE
${X11_LIBRARY_DIRS} ${XRENDER_LIBRARY_DIRS} ${XCURSOR_LIBRARY_DIRS}
)
target_link_libraries(
Mw
PRIVATE
${X11_LIBRARIES} ${XRENDER_LIBRARIES} ${XCURSOR_LIBRARIES} m
)
target_compile_definitions( target_compile_definitions(
Mw Mw
PRIVATE PRIVATE
USE_X11 USE_X11
) )
list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS} ${XRENDER_INCLUDE_DIRS} ${XCURSOR_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${X11_LIBRARY_DIRS} ${XRENDER_LIBRARY_DIRS} ${XCURSOR_LIBRARY_DIRS})
list(APPEND LIBRARIES ${X11_LIBRARIES} ${XRENDER_LIBRARIES} ${XCURSOR_LIBRARIES} m)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD" AND VULKAN)
list(APPEND INCLUDE_DIRS /usr/pkg/include)
endif()
list(APPEND GL_INCLUDE_DIRS ${INCLUDE_DIRS})
list(APPEND GL_LIBRARY_DIRS ${LIBRARY_DIRS})
list(APPEND GL_LIBRARIES GL GLU)
list(APPEND VK_INCLUDE_DIRS ${INCLUDE_DIRS})
list(APPEND VK_LIBRARY_DIRS ${LIBRARY_DIRS})
endif()
target_include_directories(
Mw
PRIVATE
${INCLUDE_DIRS}
)
target_link_directories(
Mw
PRIVATE
${LIBRARY_DIRS}
)
target_link_libraries( target_link_libraries(
Mw Mw
PRIVATE PRIVATE
dl ${LIBRARIES}
) )
endif()
endif()
target_compile_definitions( target_compile_definitions(
Mw Mw
@@ -155,6 +163,12 @@ target_compile_definitions(
if(BUILD_EXAMPLES) if(BUILD_EXAMPLES)
add_subdirectory(examples/basic) add_subdirectory(examples/basic)
if(OPENGL)
add_subdirectory(examples/gldemos)
endif()
if(VULKAN)
add_subdirectory(examples/vkdemos)
endif()
endif() endif()
include(GNUInstallDirs) include(GNUInstallDirs)

View File

@@ -21,6 +21,10 @@ else
CFLAGS += -O2 CFLAGS += -O2
endif endif
ifeq ($(TARGET),NetBSD)
VULKAN_NO_STRING_HELPER = 1
endif
ifeq ($(VULKAN_NO_STRING_HELPER),1) ifeq ($(VULKAN_NO_STRING_HELPER),1)
VK_STRING_HELPER_DEFINE = VK_STRING_HELPER_DEFINE =
else else
@@ -50,6 +54,7 @@ CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include
LDFLAGS += -L/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/X11R7/lib -Wl,-R/usr/pkg/lib LDFLAGS += -L/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/X11R7/lib -Wl,-R/usr/pkg/lib
UNIX = 1 UNIX = 1
OPENGL = 1 OPENGL = 1
VULKAN = 1
FOUND_PLATFORM = 1 FOUND_PLATFORM = 1
endif endif

View File

@@ -1,11 +1,11 @@
# $Id$ # $Id$
file( file(
GLOB GLOB
EXAMPLE_BASIC_SOURCES EXAMPLES_BASIC_SOURCES
*.c *.c
) )
foreach(PATH IN LISTS EXAMPLE_BASIC_SOURCES) foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES)
get_filename_component( get_filename_component(
TARGET TARGET
${PATH} ${PATH}
@@ -14,6 +14,11 @@ foreach(PATH IN LISTS EXAMPLE_BASIC_SOURCES)
add_executable( add_executable(
${TARGET} ${PATH} ${TARGET} ${PATH}
) )
target_include_directories(
${TARGET}
PRIVATE
${CMAKE_SOURCE_DIR}/include
)
target_link_libraries( target_link_libraries(
${TARGET} ${TARGET}
PRIVATE PRIVATE

View File

@@ -0,0 +1,28 @@
# $Id$
file(
GLOB
EXAMPLES_VKDEMOS_SOURCES
*.c
)
foreach(PATH IN LISTS EXAMPLES_VKDEMOS_SOURCES)
get_filename_component(
TARGET
${PATH}
NAME_WE
)
add_executable(
${TARGET} ${PATH}
)
target_include_directories(
${TARGET}
PRIVATE
${VK_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include
)
target_link_libraries(
${TARGET}
PRIVATE
Mw
)
endforeach()

View File

@@ -12,7 +12,7 @@
#ifndef __MW_WIDGET_VULKAN_H__ #ifndef __MW_WIDGET_VULKAN_H__
#define __MW_WIDGET_VULKAN_H__ #define __MW_WIDGET_VULKAN_H__
#if !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) #if !defined(_WIN32) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#error Vulkan is unsupported on the requested platform. #error Vulkan is unsupported on the requested platform.
#endif #endif

View File

@@ -11,13 +11,13 @@
#ifdef _WIN32 #ifdef _WIN32
#define VK_USE_PLATFORM_WIN32_KHR 1 #define VK_USE_PLATFORM_WIN32_KHR 1
#endif #endif
#ifdef __linux__ #ifdef __unix__
#define VK_USE_PLATFORM_XLIB_KHR 1 #define VK_USE_PLATFORM_XLIB_KHR 1
#endif #endif
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
#ifdef __linux__ #ifdef __unix__
#include <vulkan/vulkan_xlib.h> #include <vulkan/vulkan_xlib.h>
#endif #endif
@@ -306,7 +306,7 @@ static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) {
VK_CMD(_vkCreateWin32SurfaceKHR(o->vkInstance, &createInfo, NULL, VK_CMD(_vkCreateWin32SurfaceKHR(o->vkInstance, &createInfo, NULL,
&o->vkSurface)); &o->vkSurface));
#endif #endif
#ifdef __linux__ #ifdef __unix__
LOAD_VK_FUNCTION(vkCreateXlibSurfaceKHR); LOAD_VK_FUNCTION(vkCreateXlibSurfaceKHR);
VkXlibSurfaceCreateInfoKHR createInfo = { VkXlibSurfaceCreateInfoKHR createInfo = {