CMake: Support external NanoSVG library (PR #22407)

89 views
Skip to first unread message

Maarten

unread,
May 7, 2022, 2:50:55 PM5/7/22
to wx-...@googlegroups.com, Subscribed

Partially based on #22393, but it leaves the other build systems alone.

Support both header-only NanoSVG library, and NanoSVG library that already have the functions implemented.

Since upstream NanoSVG doesn't have CMake support, there is no official target name or namespace to check. Currently it checks for NanoSVG::nanosvg and NanoSVG::nanosvgrast, but this list can easily be extended.

Default CMake build still uses the old method (including ../../3rdparty/nanosvg/src/nanosvg.h), but it can also use external build without implementation using:

    set(wxUSE_NANOSVG_EXTERNAL 1 PARENT_SCOPE)
    set(NANOSVG_LIBRARIES )
    set(NANOSVG_INCLUDE_DIRS "${wxSOURCE_DIR}/3rdparty/nanosvg/src")

You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/22407

Commit Summary

  • fb8e860 CMake: Include third-party library directories when they are defined
  • c8bfd53 CMake: Fix using Windows path separator in wxINSTALL_PREFIX
  • 931370f Add NanoSVG setup options
  • 62628d4 CMake: Add support for external NanoSVG library
  • 3aaeb5a CMake: Enable NanoSVG defines when NanoSVG library is header-only
  • 6d91229 CMake: Check all known NanoSVG target names

File Changes

(17 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407@github.com>

Maarten

unread,
May 7, 2022, 3:40:15 PM5/7/22
to wx-...@googlegroups.com, Push

@MaartenBent pushed 1 commit.

  • 3ee76d7 Add --with-nanosvg option to configure


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/push/9821729576@github.com>

VZ

unread,
May 7, 2022, 5:29:18 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks, this looks good to me, but I think wxUSE_NANOSVG_EXTERNAL and DISABLE_IMPL should be documented in docs/doxygen/mainpages/const_wxusedef.h as they could be useful for people building wx without CMake too.


In build/cmake/functions.cmake:

> @@ -601,7 +601,7 @@ function(wx_add_thirdparty_library var_name lib_name help_str)

         # 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_upper}_FOUND AND NOT ${lib_name}_FOUND)

I just wonder, what is the CMake convention here in general? Is it supposed to always accept both libfoo_FOUND and LIBFOO_FOUND interchangeably?


In configure.in:

> @@ -556,6 +556,7 @@ WX_ARG_WITH(gnomevfs,      [  --with-gnomevfs         use GNOME VFS for associat

 WX_ARG_WITH(libnotify,     [  --with-libnotify        use libnotify for notifications], wxUSE_LIBNOTIFY)

 WX_ARG_WITH(opengl,        [  --with-opengl           use OpenGL (or Mesa)], wxUSE_OPENGL)

 WX_ARG_WITH(xtest,         [  --with-xtest            use XTest extension], wxUSE_XTEST)

+WX_ARG_WITH(nanosvg,       [  --with-nanosvg          use NanoSVG for rasterizing SVG], wxUSE_NANOSVG)

I think this should be

⬇️ Suggested change
-WX_ARG_WITH(nanosvg,       [  --with-nanosvg          use NanoSVG for rasterizing SVG], wxUSE_NANOSVG)

+WX_ARG_WITH(nanosvg,       [  --without-nanosvg          don't use NanoSVG for rasterizing SVG], wxUSE_NANOSVG)

because it is used by default.


In configure.in:

> @@ -2956,6 +2957,14 @@ else

     wxUSE_XML=no

 fi

 

+dnl ------------------------------------------------------------------------

+dnl Check for NanoSVG libraries

⬇️ Suggested change
-dnl Check for NanoSVG libraries

+dnl Use NanoSVG unless explicitly disabled


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965364744@github.com>

Maarten

unread,
May 7, 2022, 5:36:37 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In build/cmake/functions.cmake:

> @@ -601,7 +601,7 @@ function(wx_add_thirdparty_library var_name lib_name help_str)
         # 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_upper}_FOUND AND NOT ${lib_name}_FOUND)

It depends on the package name. For example wxWidgets has wxWidgets_FOUND, and jpeg has JPEG_FOUND.
The packages we used so far all have capitalized names, but NanoSVG probably looks like NanoSVG_FOUND.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965365346@github.com>

VZ

unread,
May 7, 2022, 5:39:09 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In build/cmake/functions.cmake:

> @@ -601,7 +601,7 @@ function(wx_add_thirdparty_library var_name lib_name help_str)
         # 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_upper}_FOUND AND NOT ${lib_name}_FOUND)

So what you're saying is that there is no real standard/convention?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965365504@github.com>

Maarten

unread,
May 7, 2022, 5:39:31 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In configure.in:

> @@ -556,6 +556,7 @@ WX_ARG_WITH(gnomevfs,      [  --with-gnomevfs         use GNOME VFS for associat
 WX_ARG_WITH(libnotify,     [  --with-libnotify        use libnotify for notifications], wxUSE_LIBNOTIFY)
 WX_ARG_WITH(opengl,        [  --with-opengl           use OpenGL (or Mesa)], wxUSE_OPENGL)
 WX_ARG_WITH(xtest,         [  --with-xtest            use XTest extension], wxUSE_XTEST)
+WX_ARG_WITH(nanosvg,       [  --with-nanosvg          use NanoSVG for rasterizing SVG], wxUSE_NANOSVG)

All the external libraries above have --with-lib format, and are enabled / searched for by default. Why not keep this the same?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965365530@github.com>

Maarten

unread,
May 7, 2022, 5:47:39 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In build/cmake/functions.cmake:

> @@ -601,7 +601,7 @@ function(wx_add_thirdparty_library var_name lib_name help_str)
         # 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_upper}_FOUND AND NOT ${lib_name}_FOUND)

I can't find any convention, they use <PackageName>_FOUND found in the documentation.

But I think we could remove ${lib_name_upper}_FOUND since all names are already in the correct capitalization.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965365909@github.com>

VZ

unread,
May 7, 2022, 5:53:26 PM5/7/22
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.


In configure.in:

> @@ -556,6 +556,7 @@ WX_ARG_WITH(gnomevfs,      [  --with-gnomevfs         use GNOME VFS for associat
 WX_ARG_WITH(libnotify,     [  --with-libnotify        use libnotify for notifications], wxUSE_LIBNOTIFY)
 WX_ARG_WITH(opengl,        [  --with-opengl           use OpenGL (or Mesa)], wxUSE_OPENGL)
 WX_ARG_WITH(xtest,         [  --with-xtest            use XTest extension], wxUSE_XTEST)
+WX_ARG_WITH(nanosvg,       [  --with-nanosvg          use NanoSVG for rasterizing SVG], wxUSE_NANOSVG)

My reasoning was that we could fail to find these libraries, so for them this could somewhat make sense, but NanoSVG is always available, so it doesn't seem to be very useful to explicitly enable it.

But maybe you're right and it's better to keep it consistent even if it's a bit different. OTOH we do have --without-gtkprint already. Oh well, I guess we can leave it like this if you prefer it, there is no real consistency here anyhow.

On a tangentially related reason, the behaviour that would make most sense to me would be to have --with-foo require foo and fail if it's not available, --without-foo not use it and default (or some --with-foo=auto) behave as --with-foo does now. But this would almost certainly run into compatibility problems and break builds that worked just fine before because some exotic dependency (like libmspack or something) is not available. So in practice the only thing we could do would be to extend WX_ARG_WITH to allow specifying --with-foo=required.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/965366174@github.com>

Maarten

unread,
May 8, 2022, 3:28:33 PM5/8/22
to wx-...@googlegroups.com, Push

@MaartenBent pushed 2 commits.

  • 6ceab27 CMake: No need to check capitalized package name
  • cbe5e74 Document the NanoSVG options


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/push/9826071262@github.com>

VZ

unread,
May 9, 2022, 8:54:21 AM5/9/22
to wx-...@googlegroups.com, Subscribed

Thanks! Should this be merged now?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1121062413@github.com>

Mark Roszko

unread,
May 9, 2022, 12:32:24 PM5/9/22
to wx-...@googlegroups.com, Subscribed

Can 'unofficial::nanosvg' be added as one of the target candidates? Its what is part of vcpkg now


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1121323054@github.com>

Maarten

unread,
May 9, 2022, 4:56:36 PM5/9/22
to wx-...@googlegroups.com, Subscribed

Yes, I'll add it.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1121572953@github.com>

Maarten

unread,
May 9, 2022, 5:26:19 PM5/9/22
to wx-...@googlegroups.com, Push

@MaartenBent pushed 1 commit.

  • d878165 CMake: Add unofficial::nanosvg target name


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/push/9836408842@github.com>

Maarten

unread,
May 9, 2022, 5:28:02 PM5/9/22
to wx-...@googlegroups.com, Subscribed

Thanks! Should this be merged now?

Yes please, it is ready.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1121600009@github.com>

tamasmeszaros

unread,
May 10, 2022, 2:37:17 AM5/10/22
to wx-...@googlegroups.com, Subscribed

Hello! So NanoSVG now has CMake memononen/nanosvg#209


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1121987340@github.com>

tamasmeszaros

unread,
May 10, 2022, 3:22:58 AM5/10/22
to wx-...@googlegroups.com, Subscribed

@tamasmeszaros commented on this pull request.


In build/cmake/lib/nanosvg.cmake:

> +#############################################################################
+
+if(wxUSE_NANOSVG STREQUAL "builtin")
+    set(wxUSE_NANOSVG_EXTERNAL 0 PARENT_SCOPE)
+elseif(wxUSE_NANOSVG)
+    set(wxUSE_NANOSVG_EXTERNAL 1 PARENT_SCOPE)
+
+    set(NANOSVG_LIBRARIES )
+    set(NANOSVG_INCLUDE_DIRS )
+
+    find_package(NanoSVG REQUIRED)
+
+    set(wxUSE_NANOSVG_EXTERNAL_DISABLE_IMPL FALSE)
+
+    foreach(TARGETNAME NanoSVG::nanosvg NanoSVG::nanosvgrast unofficial::nanosvg)
+        if(NOT TARGETNAME)

This line fails for me but works if I change it to if (NOT TARGET TARGETNAME)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/967291279@github.com>

Maarten

unread,
May 10, 2022, 4:46:49 PM5/10/22
to wx-...@googlegroups.com, Subscribed

@MaartenBent commented on this pull request.


In build/cmake/lib/nanosvg.cmake:

> +#############################################################################
+
+if(wxUSE_NANOSVG STREQUAL "builtin")
+    set(wxUSE_NANOSVG_EXTERNAL 0 PARENT_SCOPE)
+elseif(wxUSE_NANOSVG)
+    set(wxUSE_NANOSVG_EXTERNAL 1 PARENT_SCOPE)
+
+    set(NANOSVG_LIBRARIES )
+    set(NANOSVG_INCLUDE_DIRS )
+
+    find_package(NanoSVG REQUIRED)
+
+    set(wxUSE_NANOSVG_EXTERNAL_DISABLE_IMPL FALSE)
+
+    foreach(TARGETNAME NanoSVG::nanosvg NanoSVG::nanosvgrast unofficial::nanosvg)
+        if(NOT TARGETNAME)

This is indeed the correct syntax, I don't know why the other one works for me too. I'll update the PR.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/968392050@github.com>

Maarten

unread,
May 10, 2022, 5:51:31 PM5/10/22
to wx-...@googlegroups.com, Push

@MaartenBent pushed 5 commits.

  • 5d0428a CMake: Add support for external NanoSVG library
  • 071e936 CMake: Support header-only NanoSVG library
  • 10e3339 CMake: Check all known NanoSVG target names
  • b6e8127 Add --with-nanosvg option to configure
  • 817b060 Document the NanoSVG options


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/push/9847461342@github.com>

Maarten

unread,
May 10, 2022, 7:56:13 PM5/10/22
to wx-...@googlegroups.com, Push

@MaartenBent pushed 5 commits.

  • 603c13a CMake: Add support for external NanoSVG library
  • 138d1ab CMake: Support header-only NanoSVG library
  • 86b3360 CMake: Check all known NanoSVG target names
  • 760bfaa Add --with-nanosvg option to configure
  • ce32faa Document the NanoSVG options


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/push/9848130173@github.com>

Maarten

unread,
May 10, 2022, 8:01:46 PM5/10/22
to wx-...@googlegroups.com, Subscribed

Hello! So nanosvg now has CMake memononen/nanosvg#209

Thanks for your work on this. But it is probably useful to enable NANOSVG_ALL_COLOR_KEYWORDS by default in this CMake build, since users won't have the option anymore.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1123027165@github.com>

VZ

unread,
May 10, 2022, 8:35:16 PM5/10/22
to wx-...@googlegroups.com, Subscribed

Thanks again, I'm finally merging this.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1123048356@github.com>

VZ

unread,
May 10, 2022, 8:38:24 PM5/10/22
to wx-...@googlegroups.com, Subscribed

Merged #22407 into master.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/issue_event/6586016808@github.com>

tamasmeszaros

unread,
May 11, 2022, 3:43:50 AM5/11/22
to wx-...@googlegroups.com, Subscribed

@tamasmeszaros commented on this pull request.


In build/cmake/lib/nanosvg.cmake:

> +#############################################################################
+
+if(wxUSE_NANOSVG STREQUAL "builtin")
+    set(wxUSE_NANOSVG_EXTERNAL 0 PARENT_SCOPE)
+elseif(wxUSE_NANOSVG)
+    set(wxUSE_NANOSVG_EXTERNAL 1 PARENT_SCOPE)
+
+    set(NANOSVG_LIBRARIES )
+    set(NANOSVG_INCLUDE_DIRS )
+
+    find_package(NanoSVG REQUIRED)
+
+    set(wxUSE_NANOSVG_EXTERNAL_DISABLE_IMPL FALSE)
+
+    foreach(TARGETNAME NanoSVG::nanosvg NanoSVG::nanosvgrast unofficial::nanosvg)
+        if(NOT TARGETNAME)

CMake can differ between versions, or who knows :)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/review/968829563@github.com>

Vojtěch Bubník

unread,
May 11, 2022, 5:23:42 AM5/11/22
to wx-...@googlegroups.com, Subscribed

Great, thanks to all involved!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22407/c1123419982@github.com>

Reply all
Reply to author
Forward
0 new messages