initial cmake support

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@477 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-23 17:04:35 +00:00
parent 06807b6779
commit 49ddd969a7
5 changed files with 184 additions and 3 deletions

155
CMakeLists.txt Normal file
View File

@@ -0,0 +1,155 @@
# $Id$
cmake_minimum_required(VERSION 3.25)
project(
milsko
VERSION 0.0
DESCRIPTION "Milsko GUI Toolkit"
)
option(OPENGL "Compile OpenGL widget or not" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
option(VULKAN "Compile Vulkan widget or not" OFF)
else()
option(VULKAN "Compile Vulkan widget or not" ON)
endif()
option(CLASSIC "Use classic theme" OFF)
option(USE_STB_IMAGE "Use stb_image" ON)
option(USE_STB_TRUETYPE "Use stb_truetype" ON)
file(
GLOB
SOURCES
src/*.c src/cursor/*.c src/icon/*.c src/text/*.c src/widget/*.c external/*.c
)
if(NOT OPENGL)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")
endif()
if(NOT VULKAN)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
endif()
if(NOT USE_STB_IMAGE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.c")
endif()
if(NOT USE_STB_TRUETYPE)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_truetype.c")
endif()
add_library(
Mw
SHARED
${SOURCES}
)
if(USE_STB_IMAGE)
target_compile_definitions(
Mw
PRIVATE
USE_STB_IMAGE
)
else()
file(
GLOB
IMAGE_SOURCES
external/libz/src/*.c external/libjpeg/src/*.c external/libpng/src/*.c
)
target_sources(
Mw
PRIVATE
${IMAGE_SOURCES}
)
target_include_directories(
Mw
PRIVATE
external/libz/include external/libjpeg/include external/libpng/include
)
endif()
if(USE_STB_TRUETYPE)
target_compile_definitions(
Mw
PRIVATE
USE_STB_TRUETYPE
)
endif()
target_include_directories(
Mw
PRIVATE
include
)
if(CLASSIC)
target_compile_definitions(
Mw
PRIVATE
MW_CLASSIC_THEME
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(
Mw
PRIVATE
src/backend/gdi.c
)
target_compile_definitions(
Mw
PRIVATE
USE_GDI
)
target_link_libraries(
Mw
PRIVATE
gdi32
)
else()
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
pkg_check_modules(XRENDER REQUIRED xrender)
pkg_check_modules(XCURSOR REQUIRED xcursor)
target_sources(
Mw
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
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(
Mw
PRIVATE
dl
)
endif()
endif()
target_compile_definitions(
Mw
PRIVATE
_MILSKO
)
add_subdirectory(examples/basic)

View File

@@ -0,0 +1,22 @@
# $Id$
file(
GLOB
EXAMPLE_BASIC_SOURCES
*.c
)
foreach(PATH IN LISTS EXAMPLE_BASIC_SOURCES)
get_filename_component(
TARGET
${PATH}
NAME_WE
)
add_executable(
${TARGET} ${PATH}
)
target_link_libraries(
${TARGET}
PRIVATE
Mw
)
endforeach()

View File

@@ -12,6 +12,10 @@ int main() {
MwLLPixmap px2 = MwLoadImage(window, "examples/picture.jpg");
MwLLPixmap px3 = MwLoadImage(window, "resource/logo.png");
if(px == NULL)px = MwLoadImage(window, "../examples/picture.png");
if(px2 == NULL)px2 = MwLoadImage(window, "../examples/picture.jpg");
if(px3 == NULL)px3 = MwLoadImage(window, "../resource/logo.png");
MwVaApply(window,
MwNiconPixmap, px,
NULL);

View File

@@ -253,6 +253,6 @@ void MwFontFree(void* handle) {
free(ttf->data);
free(ttf);
#else
(void)font;
(void)handle;
#endif
}

View File

@@ -147,7 +147,7 @@ static void click(MwWidget handle) {
static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point) {
int i, w = 0, h = 0;
#ifdef UNIX
#ifdef USE_X11
XSetWindowAttributes xswa;
Atom wndtype = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE", False);
Atom wndmenu = XInternAtom(handle->lowlevel->display, "_NET_WM_WINDOW_TYPE_MENU", False);
@@ -162,7 +162,7 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point) {
MwLLDetach(handle->lowlevel, point);
#ifdef _WIN32
#ifdef USE_GDI
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_STYLE, (LPARAM)0);
SetWindowLongPtr(handle->lowlevel->hWnd, GWL_EXSTYLE, (LPARAM)WS_EX_TOOLWINDOW);
#endif