From 603c13aaba22ebc5de1c3eb722367320d02cdbd4 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 5 May 2022 22:13:02 +0200 Subject: [PATCH] CMake: Add support for external NanoSVG library --- build/cmake/functions.cmake | 3 +-- build/cmake/lib/CMakeLists.txt | 2 +- build/cmake/lib/core/CMakeLists.txt | 2 +- build/cmake/lib/nanosvg.cmake | 20 ++++++++++++++++++++ build/cmake/options.cmake | 1 + include/wx/features.h | 2 +- src/generic/bmpsvg.cpp | 17 +++++++++++------ 7 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 build/cmake/lib/nanosvg.cmake diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 36a66c43db..32bd959071 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -600,8 +600,7 @@ function(wx_add_thirdparty_library var_name lib_name help_str) if(${var_name} STREQUAL "sys") # If the sys library can not be found use builtin find_package(${lib_name}) - string(TOUPPER ${lib_name} lib_name_upper) - if(NOT ${${lib_name_upper}_FOUND}) + if(NOT ${lib_name}_FOUND) wx_option_force_value(${var_name} builtin) endif() endif() diff --git a/build/cmake/lib/CMakeLists.txt b/build/cmake/lib/CMakeLists.txt index 04f576383c..4b40d7652e 100644 --- a/build/cmake/lib/CMakeLists.txt +++ b/build/cmake/lib/CMakeLists.txt @@ -21,7 +21,7 @@ endif() # Define third party libraries set(LIBS_THIRDPARTY regex zlib expat) if(wxUSE_GUI) - list(APPEND LIBS_THIRDPARTY jpeg png tiff) + list(APPEND LIBS_THIRDPARTY jpeg png tiff nanosvg) endif() foreach(LIB IN LISTS LIBS_THIRDPARTY) include(${LIB}.cmake) diff --git a/build/cmake/lib/core/CMakeLists.txt b/build/cmake/lib/core/CMakeLists.txt index 0f7f22ea6f..b65da760bf 100644 --- a/build/cmake/lib/core/CMakeLists.txt +++ b/build/cmake/lib/core/CMakeLists.txt @@ -56,7 +56,7 @@ elseif(WXQT) endif() wx_add_library(wxcore ${CORE_SRC}) -foreach(lib JPEG PNG TIFF) +foreach(lib JPEG PNG TIFF NANOSVG) if(${lib}_LIBRARIES) wx_lib_link_libraries(wxcore PRIVATE ${${lib}_LIBRARIES}) endif() diff --git a/build/cmake/lib/nanosvg.cmake b/build/cmake/lib/nanosvg.cmake new file mode 100644 index 0000000000..5368714b32 --- /dev/null +++ b/build/cmake/lib/nanosvg.cmake @@ -0,0 +1,20 @@ +############################################################################# +# Name: build/cmake/lib/nanosvg.cmake +# Purpose: Use external or internal nanosvg lib +# Author: Tamas Meszaros, Maarten Bent +# Created: 2022-05-05 +# Copyright: (c) 2022 wxWidgets development team +# Licence: wxWindows licence +############################################################################# + +if(wxUSE_NANOSVG STREQUAL "builtin") + set(wxUSE_NANOSVG_EXTERNAL 0 PARENT_SCOPE) +elseif(wxUSE_NANOSVG) + set(wxUSE_NANOSVG_EXTERNAL 1 PARENT_SCOPE) + + find_package(NanoSVG REQUIRED) + + set(NANOSVG_LIBRARIES NanoSVG::nanosvgrast) + get_target_property(svg_incl_dir NanoSVG::nanosvg INTERFACE_INCLUDE_DIRECTORIES) + set(NANOSVG_INCLUDE_DIRS ${svg_incl_dir}) +endif() diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index 842d057cbc..49c536a07f 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -114,6 +114,7 @@ wx_add_thirdparty_library(wxUSE_EXPAT EXPAT "use expat for XML parsing" DEFAULT_ wx_add_thirdparty_library(wxUSE_LIBJPEG JPEG "use libjpeg (JPEG file format)") wx_add_thirdparty_library(wxUSE_LIBPNG PNG "use libpng (PNG image format)") wx_add_thirdparty_library(wxUSE_LIBTIFF TIFF "use libtiff (TIFF file format)") +wx_add_thirdparty_library(wxUSE_NANOSVG NanoSVG "use NanoSVG for rasterizing SVG") wx_option(wxUSE_LIBLZMA "use LZMA compression" OFF) set(wxTHIRD_PARTY_LIBRARIES ${wxTHIRD_PARTY_LIBRARIES} wxUSE_LIBLZMA "use liblzma for LZMA compression") diff --git a/include/wx/features.h b/include/wx/features.h index e2dd300e58..7465b9fc5b 100644 --- a/include/wx/features.h +++ b/include/wx/features.h @@ -100,7 +100,7 @@ support using wxDC::DrawSpline(), currently we don't do it and so FromSVG() is only available in the ports providing raw bitmap access. */ -#ifdef wxHAS_RAW_BITMAP +#if defined(wxHAS_RAW_BITMAP) && wxUSE_NANOSVG #define wxHAS_SVG #endif diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp index 76f20dce4c..ca8b69fdcc 100644 --- a/src/generic/bmpsvg.cpp +++ b/src/generic/bmpsvg.cpp @@ -19,7 +19,7 @@ // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#ifdef wxHAS_SVG +#if defined(wxHAS_SVG) && !wxUSE_NANOSVG_EXTERNAL // Try to help people updating their sources from Git and forgetting to // initialize new submodules, if possible: if you get this error, it means that @@ -57,11 +57,16 @@ #endif #endif -#define NANOSVG_IMPLEMENTATION -#define NANOSVGRAST_IMPLEMENTATION -#define NANOSVG_ALL_COLOR_KEYWORDS -#include "../../3rdparty/nanosvg/src/nanosvg.h" -#include "../../3rdparty/nanosvg/src/nanosvgrast.h" +#if wxUSE_NANOSVG_EXTERNAL + #include + #include +#else + #define NANOSVG_IMPLEMENTATION + #define NANOSVGRAST_IMPLEMENTATION + #define NANOSVG_ALL_COLOR_KEYWORDS + #include "../../3rdparty/nanosvg/src/nanosvg.h" + #include "../../3rdparty/nanosvg/src/nanosvgrast.h" +#endif #ifdef __VISUALC__ #pragma warning(pop)