From 5571f4a03d10d590c0d0d0e64b9e210d0752a44e Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 7 Oct 2023 09:34:00 +0800 Subject: Start migrating cairo for emsripten. --- .editorconfig | 6 +++++- CMakeLists.txt | 3 ++- scripts/cmake/cairo.cmake | 22 ++++++++++----------- src/platform/CMakeLists.txt | 1 + src/platform/graphics/cairo/CMakeLists.txt | 31 ++++++++++++++++++------------ 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/.editorconfig b/.editorconfig index 345d6884..5fb29bf4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,6 +16,10 @@ indent_size = 2 indent_style = space indent_size = 2 -[*.cmake, CMakeLists.txt] +[*.cmake] +indent_style = tab +indent_size = 4 + +[CMakeLists.txt] indent_style = tab indent_size = 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b777728..ca73ada3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,10 @@ function(target_add_resources target res_dir) endforeach(RES_FILE) endfunction() +include(scripts/cmake/cairo.cmake) + add_subdirectory(src) add_subdirectory(test) add_subdirectory(demos) -include(scripts/cmake/cairo.cmake) diff --git a/scripts/cmake/cairo.cmake b/scripts/cmake/cairo.cmake index 64de7318..88836222 100644 --- a/scripts/cmake/cairo.cmake +++ b/scripts/cmake/cairo.cmake @@ -7,19 +7,19 @@ set(CAIRO_INSTALL_DIR ${CMAKE_BINARY_DIR}/cairo/install) set(CAIRO_MESON_SETUP meson setup ${CAIRO_BUILD_DIR} --prefix=${CAIRO_INSTALL_DIR}) if(EMSCRIPTEN) - cmake_path(GET CMAKE_C_COMPILER PARENT_PATH EMSCRIPTEN_TOOLCHAIN) - set(EMSCRIPTEN_CROSS_FILE_TEMPLATE ${PROJECT_SOURCE_DIR}/scripts/meson-emscripten.ini.in) - set(EMSCRIPTEN_CROSS_FILE ${CAIRO_BUILD_DIR}/emscripten.ini) - configure_file(${EMSCRIPTEN_CROSS_FILE_TEMPLATE} ${EMSCRIPTEN_CROSS_FILE}) - set(CAIRO_MESON_SETUP ${CAIRO_MESON_SETUP} --cross-file ${EMSCRIPTEN_CROSS_FILE}) + cmake_path(GET CMAKE_C_COMPILER PARENT_PATH EMSCRIPTEN_TOOLCHAIN) + set(EMSCRIPTEN_CROSS_FILE_TEMPLATE ${PROJECT_SOURCE_DIR}/scripts/meson-emscripten.ini.in) + set(EMSCRIPTEN_CROSS_FILE ${CAIRO_BUILD_DIR}/emscripten.ini) + configure_file(${EMSCRIPTEN_CROSS_FILE_TEMPLATE} ${EMSCRIPTEN_CROSS_FILE}) + set(CAIRO_MESON_SETUP ${CAIRO_MESON_SETUP} --cross-file ${EMSCRIPTEN_CROSS_FILE}) endif() add_custom_target( - cairo-build - COMMAND mkdir -p ${CAIRO_BUILD_DIR} ${CAIRO_INSTALL_DIR} - COMMAND ${CAIRO_MESON_SETUP} - COMMAND ninja -C ${CAIRO_BUILD_DIR} - COMMAND ninja -C ${CAIRO_BUILD_DIR} install - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/cairo + cairo-build + COMMAND mkdir -p ${CAIRO_BUILD_DIR} ${CAIRO_INSTALL_DIR} + COMMAND ${CAIRO_MESON_SETUP} + COMMAND ninja -C ${CAIRO_BUILD_DIR} + COMMAND ninja -C ${CAIRO_BUILD_DIR} install + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/lib/cairo ) diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 0a94a26e..c1b08c2f 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -20,6 +20,7 @@ elseif (APPLE) add_subdirectory(gui/osx) elseif (EMSCRIPTEN) add_subdirectory(web) + add_subdirectory(graphics/cairo) add_subdirectory(graphics/web_canvas) endif() diff --git a/src/platform/graphics/cairo/CMakeLists.txt b/src/platform/graphics/cairo/CMakeLists.txt index 5879e01c..73b18499 100644 --- a/src/platform/graphics/cairo/CMakeLists.txt +++ b/src/platform/graphics/cairo/CMakeLists.txt @@ -1,3 +1,16 @@ +add_library(CruPlatformGraphicsCairo + Base.cpp + CairoBrush.cpp + CairoGeometry.cpp + CairoGraphicsFactory.cpp + CairoImage.cpp + CairoImageFactory.cpp + CairoPainter.cpp + CairoResource.cpp + PangoFont.cpp + PangoTextLayout.cpp +) + if (UNIX AND NOT EMSCRIPTEN) # It's so great to see emscripten is somewhat UNIX! foreach(PP IN LISTS CMAKE_SYSTEM_PREFIX_PATH) cmake_path(APPEND PP "lib" ${CMAKE_LIBRARY_ARCHITECTURE}) @@ -16,19 +29,13 @@ if (UNIX AND NOT EMSCRIPTEN) # It's so great to see emscripten is somewhat UNIX! find_library(LIB_PNG png REQUIRED) - add_library(CruPlatformGraphicsCairo - Base.cpp - CairoBrush.cpp - CairoGeometry.cpp - CairoGraphicsFactory.cpp - CairoImage.cpp - CairoImageFactory.cpp - CairoPainter.cpp - CairoResource.cpp - PangoFont.cpp - PangoTextLayout.cpp - ) target_compile_definitions(CruPlatformGraphicsCairo PRIVATE CRU_PLATFORM_GRAPHICS_CAIRO_EXPORT_API) target_link_libraries(CruPlatformGraphicsCairo PUBLIC CruPlatformGraphics PUBLIC ${LIB_GOBJECT} ${LIB_CAIRO} ${LIB_PANGO} ${LIB_PANGOCAIRO} ${LIB_PNG}) target_include_directories(CruPlatformGraphicsCairo PUBLIC ${CAIRO_HEADER_DIR} ${GLIB_HEADER_DIR} ${GLIBCONFIG_HEADER_DIR} ${HARFBUZZ_HEADER_DIR} ${PANGO_HEADER_DIR}) endif() + +if (EMSCRIPTEN) + add_dependencies(CruPlatformGraphicsCairo cairo-build) + target_link_libraries(CruPlatformGraphicsCairo PUBLIC CruPlatformGraphics PUBLIC ${CAIRO_INSTALL_DIR}/lib/libcairo.a) + target_include_directories(CruPlatformGraphicsCairo PUBLIC ${CAIRO_INSTALL_DIR}/include) +endif() -- cgit v1.2.3