From 184a4eb4209c46f15de026f55902edb9fd73d29a Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Thu, 23 Oct 2025 17:42:13 +0000 Subject: [PATCH] update git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@480 b9cfdab3-6d41-4d17-bbe4-086880011989 --- CMakeLists.txt | 66 ++++++++++++++++++++------------- GNUmakefile | 5 +++ examples/basic/CMakeLists.txt | 9 ++++- examples/vkdemos/CMakeLists.txt | 28 ++++++++++++++ include/Mw/Widget/Vulkan.h | 2 +- src/widget/vulkan.c | 6 +-- 6 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 examples/vkdemos/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a248483..3a6a28e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project( ) 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) else() option(VULKAN "Compile Vulkan widget or not" ON) @@ -102,11 +102,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") PRIVATE USE_GDI ) - target_link_libraries( - Mw - PRIVATE - gdi32 - ) + list(APPEND LIBRARIES gdi32) + + list(APPEND GL_LIBRARIES opengl32 glu32) else() find_package(PkgConfig) pkg_check_modules(X11 REQUIRED x11) @@ -118,35 +116,45 @@ else() PRIVATE 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( Mw PRIVATE 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") - target_link_libraries( - Mw - PRIVATE - dl - ) + 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( + Mw + PRIVATE + ${LIBRARIES} +) + target_compile_definitions( Mw PRIVATE @@ -155,6 +163,12 @@ target_compile_definitions( if(BUILD_EXAMPLES) add_subdirectory(examples/basic) + if(OPENGL) + add_subdirectory(examples/gldemos) + endif() + if(VULKAN) + add_subdirectory(examples/vkdemos) + endif() endif() include(GNUInstallDirs) diff --git a/GNUmakefile b/GNUmakefile index 08273f8..e3e648c 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,6 +21,10 @@ else CFLAGS += -O2 endif +ifeq ($(TARGET),NetBSD) +VULKAN_NO_STRING_HELPER = 1 +endif + ifeq ($(VULKAN_NO_STRING_HELPER),1) VK_STRING_HELPER_DEFINE = 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 UNIX = 1 OPENGL = 1 +VULKAN = 1 FOUND_PLATFORM = 1 endif diff --git a/examples/basic/CMakeLists.txt b/examples/basic/CMakeLists.txt index a5172ac..a9cd769 100644 --- a/examples/basic/CMakeLists.txt +++ b/examples/basic/CMakeLists.txt @@ -1,11 +1,11 @@ # $Id$ file( GLOB - EXAMPLE_BASIC_SOURCES + EXAMPLES_BASIC_SOURCES *.c ) -foreach(PATH IN LISTS EXAMPLE_BASIC_SOURCES) +foreach(PATH IN LISTS EXAMPLES_BASIC_SOURCES) get_filename_component( TARGET ${PATH} @@ -14,6 +14,11 @@ foreach(PATH IN LISTS EXAMPLE_BASIC_SOURCES) add_executable( ${TARGET} ${PATH} ) + target_include_directories( + ${TARGET} + PRIVATE + ${CMAKE_SOURCE_DIR}/include + ) target_link_libraries( ${TARGET} PRIVATE diff --git a/examples/vkdemos/CMakeLists.txt b/examples/vkdemos/CMakeLists.txt new file mode 100644 index 0000000..e1b348b --- /dev/null +++ b/examples/vkdemos/CMakeLists.txt @@ -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() diff --git a/include/Mw/Widget/Vulkan.h b/include/Mw/Widget/Vulkan.h index 69c12a2..7038111 100644 --- a/include/Mw/Widget/Vulkan.h +++ b/include/Mw/Widget/Vulkan.h @@ -12,7 +12,7 @@ #ifndef __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. #endif diff --git a/src/widget/vulkan.c b/src/widget/vulkan.c index 7cf4e33..23e76ea 100644 --- a/src/widget/vulkan.c +++ b/src/widget/vulkan.c @@ -11,13 +11,13 @@ #ifdef _WIN32 #define VK_USE_PLATFORM_WIN32_KHR 1 #endif -#ifdef __linux__ +#ifdef __unix__ #define VK_USE_PLATFORM_XLIB_KHR 1 #endif #include #include -#ifdef __linux__ +#ifdef __unix__ #include #endif @@ -306,7 +306,7 @@ static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o) { VK_CMD(_vkCreateWin32SurfaceKHR(o->vkInstance, &createInfo, NULL, &o->vkSurface)); #endif -#ifdef __linux__ +#ifdef __unix__ LOAD_VK_FUNCTION(vkCreateXlibSurfaceKHR); VkXlibSurfaceCreateInfoKHR createInfo = {