Skip to content

Commit 156f89e

Browse files
committed
cmake: macos build
1 parent 4d4173c commit 156f89e

4 files changed

Lines changed: 94 additions & 59 deletions

File tree

build/cmake/CMakeLists.txt

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ myci_add_source_files(srcs
1414
RECURSIVE
1515
)
1616

17+
enable_language(OBJCXX)
18+
19+
list(APPEND srcs ../../src/${name}/glue/macos/glue.mm)
20+
1721
myci_declare_library(${name}-opengl
1822
SOURCES
1923
${srcs}
@@ -33,34 +37,44 @@ myci_declare_library(${name}-opengl
3337
NO_EXPORT
3438
)
3539

36-
myci_declare_library(${name}-opengles
37-
SOURCES
38-
${srcs}
39-
PUBLIC_INCLUDE_DIRECTORIES
40-
../../src
41-
# header files are installed by ${name}-opengl target
42-
# INSTALL_INCLUDE_DIRECTORIES
43-
# ../../src/${name}
44-
PREPROCESSOR_DEFINITIONS
45-
"RUISAPP_RENDER_OPENGLES"
46-
DEPENDENCIES
47-
nitki
48-
ruis
49-
ruis-render-opengles
50-
LINUX_ONLY_DEPENDENCIES
51-
PkgConfig::gdk-3.0
52-
PkgConfig::x11
53-
PkgConfig::egl
54-
WINDOWS_ONLY_DEPENDENCIES
55-
unofficial-angle/unofficial::angle::libEGL
56-
NO_EXPORT
57-
)
40+
# no opengles build on MACOS for now
41+
if(NOT APPLE)
42+
myci_declare_library(${name}-opengles
43+
SOURCES
44+
${srcs}
45+
PUBLIC_INCLUDE_DIRECTORIES
46+
../../src
47+
# header files are installed by ${name}-opengl target
48+
# INSTALL_INCLUDE_DIRECTORIES
49+
# ../../src/${name}
50+
PREPROCESSOR_DEFINITIONS
51+
"RUISAPP_RENDER_OPENGLES"
52+
DEPENDENCIES
53+
nitki
54+
ruis
55+
ruis-render-opengles
56+
LINUX_ONLY_DEPENDENCIES
57+
PkgConfig::gdk-3.0
58+
PkgConfig::x11
59+
PkgConfig::egl
60+
WINDOWS_ONLY_DEPENDENCIES
61+
unofficial-angle/unofficial::angle::libEGL
62+
NO_EXPORT
63+
)
64+
endif()
5865

59-
myci_export(
60-
TARGETS
61-
${name}-opengl
62-
${name}-opengles
63-
)
66+
if(APPLE)
67+
myci_export(
68+
TARGETS
69+
${name}-opengl
70+
)
71+
else()
72+
myci_export(
73+
TARGETS
74+
${name}-opengl
75+
${name}-opengles
76+
)
77+
endif()
6478

6579
set(app_srcs)
6680
myci_add_source_files(app_srcs
@@ -79,12 +93,23 @@ myci_declare_application(${name}-opengl-test
7993
ruisapp::ruisapp-opengl
8094
)
8195

82-
myci_declare_application(${name}-opengles-test
83-
GUI
84-
SOURCES
85-
${app_srcs}
86-
RESOURCE_DIRECTORY
87-
../../tests/app/res
88-
DEPENDENCIES
89-
ruisapp::ruisapp-opengles
90-
)
96+
if(APPLE)
97+
target_link_libraries(${name}-opengl-test
98+
PRIVATE
99+
# Link the Cocoa framework directly using the -framework flag string.
100+
# The quotes are important so CMake passes it as a single linker argument.
101+
"-framework Cocoa"
102+
)
103+
endif()
104+
105+
if(NOT APPLE)
106+
myci_declare_application(${name}-opengles-test
107+
GUI
108+
SOURCES
109+
${app_srcs}
110+
RESOURCE_DIRECTORY
111+
../../tests/app/res
112+
DEPENDENCIES
113+
ruisapp::ruisapp-opengles
114+
)
115+
endif()

src/ruisapp/glue/macos/application.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "application.hxx"
2323

24+
#include <ruis/render/opengl/context.hpp>
25+
2426
namespace {
2527
ruis::real get_dots_per_inch()
2628
{

src/ruisapp/glue/macos/window.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

2222
#include "window.hxx"
2323

24+
#include <GL/glew.h>
25+
2426
#include "key_code.map.hxx"
2527

2628
namespace {
@@ -577,6 +579,33 @@ void handle_character_input(
577579

578580
@end
579581

582+
native_window::native_window(
583+
const utki::version_duplet& gl_version, //
584+
const ruisapp::window_parameters& window_params,
585+
native_window* shared_gl_context_native_window
586+
) :
587+
cocoa_window(
588+
window_params, //
589+
shared_gl_context_native_window != nullptr
590+
),
591+
opengl_context(
592+
window_params, //
593+
shared_gl_context_native_window ? shared_gl_context_native_window->opengl_context.context
594+
: nullptr // no shared context
595+
),
596+
cur_win_dims(window_params.dims.to<ruis::real>())
597+
{
598+
[this->opengl_context.context setView:[this->cocoa_window.window contentView]];
599+
600+
// if there are no any GL contexts current, then set this one
601+
if ([NSOpenGLContext currentContext] == nil) {
602+
[this->opengl_context.context makeCurrentContext];
603+
}
604+
if (glewInit() != GLEW_OK) {
605+
throw std::runtime_error("GLEW initialization failed");
606+
}
607+
}
608+
580609
void native_window::set_mouse_cursor_visible(bool visible)
581610
{
582611
if (visible) {

src/ruisapp/glue/macos/window.hxx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,10 @@ class native_window : public ruis::render::native_window
212212

213213
public:
214214
native_window(
215-
const utki::version_duplet& gl_version,
215+
const utki::version_duplet& gl_version, //
216216
const ruisapp::window_parameters& window_params,
217217
native_window* shared_gl_context_native_window
218-
) :
219-
cocoa_window(
220-
window_params, //
221-
shared_gl_context_native_window != nullptr
222-
),
223-
opengl_context(
224-
window_params, //
225-
shared_gl_context_native_window ? shared_gl_context_native_window->opengl_context.context
226-
: nullptr // no shared context
227-
),
228-
cur_win_dims(window_params.dims.to<ruis::real>())
229-
{
230-
[this->opengl_context.context setView:[this->cocoa_window.window contentView]];
231-
232-
// if there are no any GL contexts current, then set this one
233-
if ([NSOpenGLContext currentContext] == nil) {
234-
[this->opengl_context.context makeCurrentContext];
235-
}
236-
if (glewInit() != GLEW_OK) {
237-
throw std::runtime_error("GLEW initialization failed");
238-
}
239-
}
218+
);
240219

241220
void set_app_window(app_window* w)
242221
{

0 commit comments

Comments
 (0)