From 138d1ab021c38dea1606b678e25f53fbd613a5c2 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Fri, 6 May 2022 00:17:05 +0200 Subject: [PATCH] CMake: Support header-only NanoSVG library Check if the NanoSVG target defines any library locations. Add a private compile definition to wxcore, instead of adding another setup.h option. --- build/cmake/lib/core/CMakeLists.txt | 3 +++ build/cmake/lib/nanosvg.cmake | 8 ++++++++ src/generic/bmpsvg.cpp | 9 ++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build/cmake/lib/core/CMakeLists.txt b/build/cmake/lib/core/CMakeLists.txt index b65da760bf..8031cc3730 100644 --- a/build/cmake/lib/core/CMakeLists.txt +++ b/build/cmake/lib/core/CMakeLists.txt @@ -66,6 +66,9 @@ foreach(lib JPEG PNG TIFF NANOSVG) wx_lib_include_directories(wxcore ${${lib}_INCLUDE_DIR}) endif() endforeach() +if(wxUSE_NANOSVG STREQUAL "sys" AND wxUSE_NANOSVG_EXTERNAL_ENABLE_IMPL) + wx_lib_compile_definitions(wxcore wxUSE_NANOSVG_EXTERNAL_ENABLE_IMPL) +endif() if(WIN32) wx_lib_link_libraries(wxcore PRIVATE winmm) diff --git a/build/cmake/lib/nanosvg.cmake b/build/cmake/lib/nanosvg.cmake index 5368714b32..3e59dd9760 100644 --- a/build/cmake/lib/nanosvg.cmake +++ b/build/cmake/lib/nanosvg.cmake @@ -17,4 +17,12 @@ elseif(wxUSE_NANOSVG) set(NANOSVG_LIBRARIES NanoSVG::nanosvgrast) get_target_property(svg_incl_dir NanoSVG::nanosvg INTERFACE_INCLUDE_DIRECTORIES) set(NANOSVG_INCLUDE_DIRS ${svg_incl_dir}) + + get_target_property(svg_lib_d NanoSVG::nanosvgrast IMPORTED_LOCATION_DEBUG) + get_target_property(svg_lib_r NanoSVG::nanosvgrast IMPORTED_LOCATION_RELEASE) + get_target_property(svg_lib NanoSVG::nanosvgrast IMPORTED_LOCATION) + set(wxUSE_NANOSVG_EXTERNAL_ENABLE_IMPL TRUE) + if(svg_lib_d OR svg_lib_r OR svg_lib) + set(wxUSE_NANOSVG_EXTERNAL_ENABLE_IMPL FALSE) + endif() endif() diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp index ca8b69fdcc..738bac2f86 100644 --- a/src/generic/bmpsvg.cpp +++ b/src/generic/bmpsvg.cpp @@ -57,13 +57,16 @@ #endif #endif +#if !wxUSE_NANOSVG_EXTERNAL || defined(wxUSE_NANOSVG_EXTERNAL_ENABLE_IMPL) + #define NANOSVG_IMPLEMENTATION + #define NANOSVGRAST_IMPLEMENTATION + #define NANOSVG_ALL_COLOR_KEYWORDS +#endif + #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