CMake: Add support for external NanoSVG library

This commit is contained in:
Maarten Bent
2022-05-05 22:13:02 +02:00
parent 931370f0ad
commit 603c13aaba
7 changed files with 36 additions and 11 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()

View File

@@ -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()

View File

@@ -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")

View File

@@ -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

View File

@@ -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 <nanosvg.h>
#include <nanosvgrast.h>
#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)