Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 94 additions & 53 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.30)

set(name ruisapp)
project(${name})
project(ruisapp)

# !!! find_package must go after project() declaration !!!
# Otherwise VCPKG does not set the CMAKE_PREFIX_PATH to find packages.
Expand All @@ -10,27 +9,27 @@ find_package(myci CONFIG REQUIRED)
set(srcs)
myci_add_source_files(srcs
DIRECTORY
../../src/${name}
../../src/${PROJECT_NAME}
RECURSIVE
)

if(IOS)
enable_language(OBJCXX)
list(APPEND srcs ../../src/${name}/glue/ios/glue.mm)
list(APPEND srcs ../../src/${PROJECT_NAME}/glue/ios/glue.mm)

set(ruisapp_build_opengl_variant False)
set(ruisapp_build_opengles_variant True)

set(ruisapp_opengl_install_include_directory) # opengl variant will not be built, no headers to install
set(ruisapp_opengles_install_include_directory ../../src/${name})
set(ruisapp_opengles_install_include_directory ../../src/${PROJECT_NAME})
elseif(APPLE)
enable_language(OBJCXX)
list(APPEND srcs ../../src/${name}/glue/macos/glue.mm)
list(APPEND srcs ../../src/${PROJECT_NAME}/glue/macos/glue.mm)

set(ruisapp_build_opengl_variant True)
set(ruisapp_build_opengles_variant False)

set(ruisapp_opengl_install_include_directory ../../src/${name})
set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME})
set(ruisapp_opengles_install_include_directory) # opengles variant will not be built, no headers to install
elseif(LINUX)
set(ruisapp_build_opengl_variant True)
Expand All @@ -40,12 +39,22 @@ elseif(LINUX)
# the headers are installed by the opengl-xorg variant, see below.
set(ruisapp_opengl_install_include_directory)
set(ruisapp_opengles_install_include_directory)
else()
elseif(WIN32)
set(ruisapp_build_opengl_variant True)
set(ruisapp_build_opengles_variant True)
set(ruisapp_build_vulkan_variant True) # VK_KHR_win32_surface

set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME})
set(ruisapp_opengles_install_include_directory) # opengl variant is also built and will install the headers
set(ruisapp_vulkan_install_include_directory) # opengl variant is also built and will install the headers
elseif(EMSCRIPTEN)
set(ruisapp_build_opengl_variant True)
set(ruisapp_build_opengles_variant True)

set(ruisapp_opengl_install_include_directory ../../src/${name})
set(ruisapp_opengl_install_include_directory ../../src/${PROJECT_NAME})
set(ruisapp_opengles_install_include_directory) # opengl variant is also built and will install the headers
else()
message(FATAL_ERROR "Unknown OS")
endif()

# ====================
Expand Down Expand Up @@ -133,10 +142,10 @@ if(LINUX)

set(install_include_directories)
if(arg_INSTALL_HEADERS)
set(install_include_directories ../../src/${name})
set(install_include_directories ../../src/${PROJECT_NAME})
endif()

myci_declare_library(${name}-${renderer}-${backend}
myci_declare_library(${PROJECT_NAME}-${renderer}-${backend}
SOURCES
${srcs}
PUBLIC_INCLUDE_DIRECTORIES
Expand All @@ -163,7 +172,7 @@ if(LINUX)
if(backend STREQUAL "wayland")
# the generated xdg-shell client protocol source is added after the library
# declaration, so that it is not picked up by the format targets
target_sources(${name}-${renderer}-${backend}
target_sources(${PROJECT_NAME}-${renderer}-${backend}
PRIVATE
${wayland_xdg_shell_protocol_source}
)
Expand All @@ -182,14 +191,14 @@ if(LINUX)
# Compatibility aliases: for now ruisapp-opengl / ruisapp-opengles refer to the xorg variants.
# Note: the namespaced alias refers to the plain (non-namespaced) target, the same
# convention that myci_declare_library() uses for the ${PROJECT_NAME}::<name> alias.
add_library(${name}-opengl ALIAS ${name}-opengl-xorg)
add_library(${PROJECT_NAME}::${name}-opengl ALIAS ${name}-opengl-xorg)
add_library(${name}-opengles ALIAS ${name}-opengles-xorg)
add_library(${PROJECT_NAME}::${name}-opengles ALIAS ${name}-opengles-xorg)
add_library(${PROJECT_NAME}-opengl ALIAS ${PROJECT_NAME}-opengl-xorg)
add_library(${PROJECT_NAME}::${PROJECT_NAME}-opengl ALIAS ${PROJECT_NAME}-opengl-xorg)
add_library(${PROJECT_NAME}-opengles ALIAS ${PROJECT_NAME}-opengles-xorg)
add_library(${PROJECT_NAME}::${PROJECT_NAME}-opengles ALIAS ${PROJECT_NAME}-opengles-xorg)

else()
if(ruisapp_build_opengl_variant)
myci_declare_library(${name}-opengl
myci_declare_library(${PROJECT_NAME}-opengl
SOURCES
${srcs}
PUBLIC_INCLUDE_DIRECTORIES
Expand All @@ -213,23 +222,23 @@ else()

if(APPLE)
# link to Cocoa framework
target_link_libraries(${name}-opengl
target_link_libraries(${PROJECT_NAME}-opengl
PRIVATE
# Link the Cocoa framework directly using the -framework flag string.
# The quotes are important so CMake passes it as a single linker argument.
"-framework Cocoa"
)

# TODO: Define the GL_SILENCE_DEPRECATION macro to silence OpenGL deprecation warnings on Apple platforms. Need to move to Metal eventually.
target_compile_definitions(${name}-opengl PRIVATE GL_SILENCE_DEPRECATION)
target_compile_definitions(${PROJECT_NAME}-opengl PRIVATE GL_SILENCE_DEPRECATION)

# TODO: some stuff (e.g. NSOpenGLContext) is deprecated on MacOS, so suppress the warnings for now. Need to use new APIs eventually.
target_compile_options(${name}-opengl PRIVATE -Wno-deprecated-declarations)
target_compile_options(${PROJECT_NAME}-opengl PRIVATE -Wno-deprecated-declarations)
endif()
endif()

if(ruisapp_build_opengles_variant)
myci_declare_library(${name}-opengles
myci_declare_library(${PROJECT_NAME}-opengles
SOURCES
${srcs}
PUBLIC_INCLUDE_DIRECTORIES
Expand All @@ -255,7 +264,7 @@ else()
)

if(IOS)
target_link_libraries(${name}-opengles
target_link_libraries(${PROJECT_NAME}-opengles
PRIVATE
# Link the iOS frameworks directly using the -framework flag string.
# The quotes are important so CMake passes it as a single linker argument.
Expand All @@ -265,12 +274,33 @@ else()
)

# TODO: Define the GLES_SILENCE_DEPRECATION macro to silence OpenGL ES deprecation warnings on Apple platforms. Need to move to Metal eventually.
target_compile_definitions(${name}-opengles PRIVATE GLES_SILENCE_DEPRECATION)
target_compile_definitions(${PROJECT_NAME}-opengles PRIVATE GLES_SILENCE_DEPRECATION)

# TODO: some stuff (e.g. UI_USER_INTERFACE_IDIOM) is deprecated on iOS, so suppress the warnings for now. Need to use new APIs eventually.
target_compile_options(${name}-opengles PRIVATE -Wno-deprecated-declarations)
target_compile_options(${PROJECT_NAME}-opengles PRIVATE -Wno-deprecated-declarations)
endif()
endif()

if(ruisapp_build_vulkan_variant)
myci_declare_library(${PROJECT_NAME}-vulkan
SOURCES
${srcs}
PUBLIC_INCLUDE_DIRECTORIES
../../src
INSTALL_INCLUDE_DIRECTORIES
${ruisapp_vulkan_install_include_directory}
PREPROCESSOR_DEFINITIONS
"RUISAPP_RENDER_VULKAN"
DEPENDENCIES
nitki
ruis
ruis-render-vulkan
opros
setka
tml
NO_EXPORT
)
endif()
endif()

# ====================
Expand All @@ -279,30 +309,29 @@ endif()
if(LINUX)
myci_export(
TARGETS
${name}-opengl-xorg
${name}-opengles-xorg
${name}-opengl-wayland
${name}-opengles-wayland
${name}-opengl-sdl
${name}-opengles-sdl
${name}-vulkan-xorg
${name}-vulkan-wayland
${PROJECT_NAME}-opengl-xorg
${PROJECT_NAME}-opengles-xorg
${PROJECT_NAME}-opengl-wayland
${PROJECT_NAME}-opengles-wayland
${PROJECT_NAME}-opengl-sdl
${PROJECT_NAME}-opengles-sdl
${PROJECT_NAME}-vulkan-xorg
${PROJECT_NAME}-vulkan-wayland
)
elseif(ruisapp_build_opengl_variant AND ruisapp_build_opengles_variant)
myci_export(
TARGETS
${name}-opengl
${name}-opengles
)
elseif(ruisapp_build_opengl_variant)
myci_export(
TARGETS
${name}-opengl
)
elseif(ruisapp_build_opengles_variant)
else()
set(ruisapp_export_targets)
if(ruisapp_build_opengl_variant)
list(APPEND ruisapp_export_targets ${PROJECT_NAME}-opengl)
endif()
if(ruisapp_build_opengles_variant)
list(APPEND ruisapp_export_targets ${PROJECT_NAME}-opengles)
endif()
if(ruisapp_build_vulkan_variant)
list(APPEND ruisapp_export_targets ${PROJECT_NAME}-vulkan)
endif()
myci_export(
TARGETS
${name}-opengles
${ruisapp_export_targets}
)
endif()

Expand All @@ -317,15 +346,15 @@ myci_add_source_files(app_srcs
)
# Declare a GUI test app for the given ruisapp-<renderer>-<backend> library variant.
function(ruisapp_declare_test_app renderer backend)
set(test_app_name "${name}-${renderer}-${backend}-test")
set(test_app_name "${PROJECT_NAME}-${renderer}-${backend}-test")
myci_declare_application(${test_app_name}
GUI
SOURCES
${app_srcs}
RESOURCE_DIRECTORY
../../tests/app/res
DEPENDENCIES
${PROJECT_NAME}::${name}-${renderer}-${backend}
${PROJECT_NAME}::${PROJECT_NAME}-${renderer}-${backend}
)
endfunction()

Expand All @@ -341,7 +370,7 @@ if(LINUX)
ruisapp_declare_test_app(vulkan wayland)
else()
if(ruisapp_build_opengl_variant)
myci_declare_application(${name}-opengl-test
myci_declare_application(${PROJECT_NAME}-opengl-test
GUI
SOURCES
${app_srcs}
Expand All @@ -352,14 +381,14 @@ else()
)

if(APPLE)
set_target_properties(${name}-opengl-test PROPERTIES
set_target_properties(${PROJECT_NAME}-opengl-test PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.ruisapp-opengl-test"
)
endif()
endif()

if(ruisapp_build_opengles_variant)
myci_declare_application(${name}-opengles-test
myci_declare_application(${PROJECT_NAME}-opengles-test
GUI
SOURCES
${app_srcs}
Expand All @@ -370,12 +399,24 @@ else()
)

if(APPLE)
set_target_properties(${name}-opengles-test PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.github.cppfw.${name}-opengles-test"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.${name}-opengles-test"
set_target_properties(${PROJECT_NAME}-opengles-test PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.github.cppfw.${PROJECT_NAME}-opengles-test"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "io.github.cppfw.${PROJECT_NAME}-opengles-test"
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "948FQ58W9M"
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Automatic"
)
endif()
endif()

if(ruisapp_build_vulkan_variant)
myci_declare_application(${PROJECT_NAME}-vulkan-test
GUI
SOURCES
${app_srcs}
RESOURCE_DIRECTORY
../../tests/app/res
DEPENDENCIES
ruisapp::${PROJECT_NAME}-vulkan
)
endif()
endif()
49 changes: 43 additions & 6 deletions src/ruisapp/glue/windows/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ruisapp::application::directories get_application_directories(std::string_view a

application_glue::application_glue(const utki::version_duplet& gl_version) :
gl_version(gl_version),
#ifndef RUISAPP_RENDER_VULKAN
shared_gl_context_native_window(utki::make_shared<native_window>(
this->display,
this->gl_version,
Expand All @@ -110,18 +111,29 @@ application_glue::application_glue(const utki::version_duplet& gl_version) :
},
nullptr // no shared gl context
)),
#endif
#ifdef RUISAPP_RENDER_VULKAN
device(make_vulkan_device()),
#endif
render_factory([&]() {
#ifdef RUISAPP_RENDER_VULKAN
// Vulkan has no "current context" — a null surface is sufficient for the factory (resource creation)
return utki::make_shared<ruis::render::vulkan::factory>(
utki::make_shared<ruis::render::vulkan::surface>(this->device.get(), VK_NULL_HANDLE)
);
#else
utki::logcat_debug("application_glue::application_glue(): creating shared gl context", '\n');
#ifdef RUISAPP_RENDER_OPENGL
# ifdef RUISAPP_RENDER_OPENGL
using factory_type = ruis::render::opengl::factory;
#elif defined(RUISAPP_RENDER_OPENGLES)
# elif defined(RUISAPP_RENDER_OPENGLES)
using factory_type = ruis::render::opengles::factory;
#else
# error "Unknown graphics API"
#endif
# else
# error "Unknown graphics API"
# endif
auto c = utki::make_shared<factory_type>(this->shared_gl_context_native_window);
utki::logcat_debug("application_glue::application_glue(): shared gl context created", '\n');
return c;
#endif
}()),
common_shaders(this->render_factory.get().make_shaders()),
common_render_objects(utki::make_shared<ruis::render::renderer::objects>(this->render_factory.get())),
Expand Down Expand Up @@ -180,12 +192,16 @@ app_window* application_glue::get_window(native_window::window_id_type id)

ruisapp::window& application_glue::make_window(ruisapp::window_parameters window_params)
{
#ifdef RUISAPP_RENDER_VULKAN
auto ruis_native_window = utki::make_shared<native_window>(this->display, window_params);
#else
auto ruis_native_window = utki::make_shared<native_window>(
this->display,
this->gl_version,
window_params,
&this->shared_gl_context_native_window.get()
);
#endif

auto ruis_context = utki::make_shared<ruis::context>(ruis::context::parameters{
.post_to_ui_thread_function =
Expand All @@ -194,7 +210,28 @@ ruisapp::window& application_glue::make_window(ruisapp::window_parameters window
},
.updater = this->updater,
.renderer = utki::make_shared<ruis::render::renderer>(
#ifdef RUISAPP_RENDER_OPENGL
#ifdef RUISAPP_RENDER_VULKAN
utki::make_shared<ruis::render::vulkan::context>(
ruis_native_window,
[&]() {
// Create a VK_KHR_win32_surface from the window handle. The surface is owned
// by the surface provider (destroyed together with the render context).
VkWin32SurfaceCreateInfoKHR sci{};
sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
sci.hinstance = GetModuleHandle(nullptr);
sci.hwnd = ruis_native_window.get().get_hwnd();
VkSurfaceKHR vk_surface = VK_NULL_HANDLE;
vkCreateWin32SurfaceKHR(
this->device.get().get_instance(), //
&sci,
nullptr,
&vk_surface
);
return utki::make_shared<const ruis::render::vulkan::surface>(this->device.get(), vk_surface);
}(),
this->render_factory
),
#elif defined(RUISAPP_RENDER_OPENGL)
utki::make_shared<ruis::render::opengl::context>(ruis_native_window, this->render_factory),
#elif defined(RUISAPP_RENDER_OPENGLES)
utki::make_shared<ruis::render::opengles::context>(ruis_native_window, this->render_factory),
Expand Down
Loading
Loading