milsko/CMakeLists.txt

400 lines
9.7 KiB
Text
Raw Normal View History

cmake_minimum_required(VERSION 3.25)
project(
2026-03-27 17:15:59 -07:00
milsko
)
include(CheckIncludeFiles)
include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
2026-04-15 21:41:16 -07:00
2026-01-12 06:28:43 +09:00
option(MW_CLASSIC_THEME "Use classic theme" OFF)
option(MW_BUILD_EXAMPLES "Build examples" OFF)
option(MW_USE_STB_IMAGE "Use stb_image" ON)
option(MW_USE_STB_TRUETYPE "Use stb_truetype" OFF)
2026-04-15 21:41:16 -07:00
if(${CMAKE_SYSTEM_NAME} MATCHES Retro)
option(MW_BUILD_SHARED "Build a shared library" OFF)
option(MW_BUILD_STATIC "Build a static library" ON)
option(MW_TRY_OPENGL "Try to compile OpenGL widget or not" OFF)
option(MW_TRY_VULKAN "Try to compile Vulkan widget or not" OFF)
else()
option(MW_BUILD_SHARED "Build a shared library" ON)
option(MW_BUILD_STATIC "Build a static library" OFF)
option(MW_TRY_OPENGL "Try to compile OpenGL widget or not" ON)
option(MW_TRY_VULKAN "Try to compile Vulkan widget or not" ON)
endif()
2026-01-12 06:28:43 +09:00
option(MW_INSTALL_HEADERS "Install headers" ON)
2026-04-15 21:41:16 -07:00
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin OR ${CMAKE_SYSTEM_NAME} MATCHES Retro)
option(MW_USE_FREETYPE2 "Use FreeType 2" OFF)
else()
2026-04-15 21:41:16 -07:00
option(MW_USE_FREETYPE2 "Use FreeType 2" ON)
endif()
2026-03-25 14:06:50 -07:00
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
2026-04-15 21:41:16 -07:00
option(MW_USE_WAYLAND "Enable Wayland backend" ON)
2026-03-25 14:06:50 -07:00
endif()
file(
2026-03-27 17:15:59 -07:00
GLOB
SOURCES
2026-03-29 09:42:34 +09:00
external/libz/src/*.c src/*.c src/cursor/*.c src/icon/*.c src/widget/*.c src/text/*.c src/text/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
)
2026-01-12 06:28:43 +09:00
if(NOT MW_USE_STB_IMAGE)
2026-04-15 21:41:16 -07:00
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_image.c")
endif()
2026-01-12 06:28:43 +09:00
if(NOT MW_USE_STB_TRUETYPE)
2026-04-15 21:41:16 -07:00
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/external/stb_truetype.c")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
2026-04-15 21:41:16 -07:00
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/X11R7/include")
list(APPEND CMAKE_REQUIRED_INCLUDES "/usr/pkg/include")
endif()
2026-01-12 06:28:43 +09:00
if(MW_TRY_OPENGL)
2026-04-15 21:41:16 -07:00
find_package(OpenGL)
if(OpenGL_FOUND)
set(MW_BUILD_OPENGL ON)
2026-04-16 23:53:29 +09:00
target_compile_definitions(
Mw
PRIVATE
MW_OPENGL
)
2026-04-15 21:41:16 -07:00
if(APPLE)
list(APPEND SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl_cocoa.m")
2026-03-27 17:15:59 -07:00
endif()
2026-04-15 21:41:16 -07:00
message(STATUS "OpenGL widget has been enabled")
else()
message(WARNING "OpenGL widget has been disabled")
endif()
endif()
2026-01-12 06:28:43 +09:00
if(MW_TRY_VULKAN)
2026-04-15 21:41:16 -07:00
check_include_files(vulkan/vulkan.h HAVE_VULKAN_VULKAN_H)
if(HAVE_VULKAN_VULKAN_H)
set(MW_BUILD_VULKAN ON)
target_compile_definitions(
2026-04-14 20:03:59 -07:00
Mw
PRIVATE
MW_VULKAN
)
2026-04-15 21:41:16 -07:00
message(STATUS "Vulkan widget has been enabled")
else()
message(WARNING "Vulkan widget has been disabled")
endif()
endif()
2026-01-12 06:28:43 +09:00
if(MW_BUILD_STATIC)
2026-04-15 21:41:16 -07:00
message(STATUS "Building Milsko as a static library")
add_library(
2026-03-27 17:15:59 -07:00
Mw
${SOURCES}
2026-01-07 12:30:18 -07:00
)
2026-01-12 06:28:43 +09:00
elseif(MW_BUILD_SHARED)
2026-04-15 21:41:16 -07:00
message(STATUS "Building Milsko as a shared library")
add_library(
2026-03-27 17:15:59 -07:00
Mw
SHARED
${SOURCES}
)
2026-01-07 12:30:18 -07:00
else()
2026-04-15 21:41:16 -07:00
message(ERROR "Must either build a shared library or a static library")
2026-01-07 12:30:18 -07:00
endif()
2026-01-12 06:28:43 +09:00
if(MW_USE_STB_IMAGE)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_STB_IMAGE
)
else()
2026-04-15 21:41:16 -07:00
file(
2026-03-27 17:15:59 -07:00
GLOB
IMAGE_SOURCES
2026-03-29 09:42:34 +09:00
external/libjpeg/src/*.c external/libpng/src/*.c
2026-03-27 17:15:59 -07:00
)
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
${MW_IMAGE_SOURCES}
)
2026-04-15 21:41:16 -07:00
target_include_directories(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
2026-03-29 09:42:34 +09:00
external/libjpeg/include external/libpng/include
2026-03-27 17:15:59 -07:00
)
endif()
2026-01-12 06:28:43 +09:00
if(MW_USE_STB_TRUETYPE)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_STB_TRUETYPE
)
endif()
2026-01-12 06:28:43 +09:00
if(MW_USE_FREETYPE2)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_FREETYPE2
)
2026-04-15 21:41:16 -07:00
find_package(PkgConfig)
pkg_check_modules(FT2 REQUIRED freetype2)
list(APPEND INCLUDE_DIRS ${FT2_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${FT2_LIBRARY_DIRS})
list(APPEND LIBRARIES ${FT2_LIBRARIES})
endif()
2026-03-25 14:06:50 -07:00
if(MW_USE_WAYLAND)
2026-04-15 21:41:16 -07:00
function(scan_wayland_protocol_core)
execute_process(
2026-03-25 14:06:50 -07:00
COMMAND wayland-scanner private-code /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-core-protocol.c
)
2026-04-15 21:41:16 -07:00
execute_process(
2026-03-25 14:06:50 -07:00
COMMAND wayland-scanner client-header /usr/share/wayland/wayland.xml ${CMAKE_CURRENT_SOURCE_DIR}/include/Mw/LowLevel/Wayland/wayland-core-protocol.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
2026-04-15 21:41:16 -07:00
endfunction()
2026-03-25 14:06:50 -07:00
2026-04-15 21:41:16 -07:00
function(scan_wayland_protocol tier proto ver)
SET(proto_c ${CMAKE_CURRENT_SOURCE_DIR}/src/backend/wayland-${proto}-protocol.c)
execute_process(
2026-03-25 14:06:50 -07:00
COMMAND wayland-scanner private-code /usr/share/wayland-protocols/${tier}/${proto}/${proto}${ver}.xml ${proto_c}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
2026-03-25 14:06:50 -07:00
${proto_c}
2026-03-27 17:15:59 -07:00
)
2026-04-15 21:41:16 -07:00
execute_process(
2026-03-25 14:06:50 -07:00
COMMAND wayland-scanner client-header /usr/share/wayland-protocols/${tier}/${proto}/${proto}${ver}.xml ${CMAKE_CURRENT_SOURCE_DIR}/include/Mw/LowLevel/Wayland/${proto}-client-protocol.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_SCANNER_OUTPUT
ERROR_VARIABLE WAYLAND_SCANNER_ERROR
ECHO_OUTPUT_VARIABLE
ECHO_ERROR_VARIABLE
COMMAND_ECHO STDOUT
)
2026-04-15 21:41:16 -07:00
endfunction()
check_include_files(wayland-client.h HAVE_WL_H)
check_include_files(xkbcommon/xkbcommon.h HAVE_XKBCOMMON_H)
check_include_files(cairo/cairo.h HAVE_CAIRO_H)
if(HAVE_WL_H)
if(HAVE_XKBCOMMON_H)
if(HAVE_CAIRO_H)
scan_wayland_protocol_core()
scan_wayland_protocol("stable" "xdg-shell" "")
scan_wayland_protocol("stable" "viewporter" "")
scan_wayland_protocol("stable" "tablet" "-v2")
scan_wayland_protocol("staging" "xdg-toplevel-icon" "-v1")
scan_wayland_protocol("staging" "cursor-shape" "-v1")
scan_wayland_protocol("unstable" "xdg-decoration" "-unstable-v1")
scan_wayland_protocol("unstable" "primary-selection" "-unstable-v1")
scan_wayland_protocol("unstable" "pointer-constraints" "-unstable-v1")
scan_wayland_protocol("unstable" "relative-pointer" "-unstable-v1")
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
src/backend/wayland.c
)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-25 14:06:50 -07:00
Mw
PRIVATE
USE_WAYLAND
)
2026-04-15 21:41:16 -07:00
message(STATUS "Wayland backend has been enabled")
else()
2026-03-27 17:15:59 -07:00
message(WARNING "Wayland backend has been disabled")
2026-04-15 21:41:16 -07:00
endif()
else()
message(WARNING "Wayland backend has been disabled")
2026-03-27 17:15:59 -07:00
endif()
2026-04-15 21:41:16 -07:00
else()
message(WARNING "Wayland backend has been disabled")
endif()
2026-03-25 14:06:50 -07:00
endif()
if(APPLE AND MW_BUILD_OPENGL)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
GL_SILENCE_DEPRECATION
)
endif()
2026-03-29 09:42:34 +09:00
target_include_directories(
Mw
PRIVATE
external/libz/include
)
target_include_directories(
2026-03-27 17:15:59 -07:00
Mw
PUBLIC
include
)
2026-01-12 06:28:43 +09:00
if(MW_CLASSIC_THEME)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_CLASSIC_THEME
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
src/backend/gdi.c
)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_GDI
)
2026-04-15 21:41:16 -07:00
list(APPEND LIBRARIES gdi32)
target_link_options(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
-static-libgcc
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
src/backend/cocoa.m
)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_COCOA
)
2026-04-15 21:41:16 -07:00
list(APPEND LIBRARIES objc)
target_link_options(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
-framework Cocoa
)
2026-04-15 21:41:16 -07:00
elseif(CMAKE_SYSTEM_NAME MATCHES "Retro")
target_sources(
Mw
PRIVATE
src/backend/classicmacos.c
)
if(PLATFORM MATCHES retroppc)
set_target_properties(Mw PROPERTIES COMPILE_FLAGS "-ffunction-sections -mcpu=601 -Os -Wall -Wextra -Wno-unused-parameter")
set_target_properties(Mw PROPERTIES LINK_FLAGS "-Wl,-gc-sections")
endif()
target_compile_definitions(
Mw
PRIVATE
CLASSIC_MAC_OS
)
else()
2026-04-15 21:41:16 -07:00
find_package(PkgConfig)
pkg_check_modules(X11 REQUIRED x11)
pkg_check_modules(XRENDER REQUIRED xrender)
2026-03-27 17:15:59 -07:00
2026-04-15 21:41:16 -07:00
target_sources(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
src/backend/x11.c
)
2026-04-15 21:41:16 -07:00
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
USE_X11
)
2026-04-15 21:41:16 -07:00
list(APPEND INCLUDE_DIRS ${X11_INCLUDE_DIRS} ${XRENDER_INCLUDE_DIRS})
list(APPEND LIBRARY_DIRS ${X11_LIBRARY_DIRS} ${XRENDER_LIBRARY_DIRS})
list(APPEND LIBRARIES ${X11_LIBRARIES} ${XRENDER_LIBRARIES} m)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
endif()
target_include_directories(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
${INCLUDE_DIRS}
)
target_link_directories(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
${LIBRARY_DIRS}
)
target_link_libraries(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
${LIBRARIES}
)
2026-01-12 06:28:43 +09:00
if(MW_BUILD_VULKAN)
2026-04-15 21:41:16 -07:00
check_include_files(vulkan/vk_enum_string_helper.h HAS_VK_ENUM_STRING_HELPER)
if(HAS_VK_ENUM_STRING_HELPER)
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
HAS_VK_ENUM_STRING_HELPER
)
2026-04-15 21:41:16 -07:00
endif()
endif()
target_compile_definitions(
2026-03-27 17:15:59 -07:00
Mw
PRIVATE
_MILSKO
)
install(
2026-03-27 17:15:59 -07:00
TARGETS Mw
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
2026-01-12 06:24:48 +09:00
2026-01-12 06:28:43 +09:00
if(MW_INSTALL_HEADERS)
2026-04-15 21:41:16 -07:00
install(
2026-03-27 17:15:59 -07:00
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
)
2026-01-12 06:24:48 +09:00
endif()
2026-01-12 06:28:43 +09:00
if(MW_BUILD_EXAMPLES)
2026-04-15 21:41:16 -07:00
add_subdirectory(examples)
endif()