From 10577fca9ec4695c9ff0be11a51f0c32a8eedc11 Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Sun, 15 Jan 2023 12:08:15 +0100 Subject: [PATCH] Enabled shared library build, vcpkg update --- .gitignore | 1 + CHANGELOG.md | 2 +- CMakeLists.txt | 28 +++++++++++++++++++++++----- core/generator-config.h | 4 ++-- msdfgen-ext.h | 3 ++- vcpkg.json | 17 ++++++----------- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 8d823762..75c2ceac 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /x64/ .vs/ .vscode/ +.DS_Store *.exe *.zip *.user diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f55990e..1274a087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## Version 1.10 +## Version 1.10 (2023-01-15) - Switched to vcpkg as the primary dependency management system - Switched to libpng as the primary PNG file encoder diff --git a/CMakeLists.txt b/CMakeLists.txt index a5429ffe..6dec9160 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(MSDFGEN_USE_OPENMP "Build with OpenMP support for multithreaded code" OFF option(MSDFGEN_USE_CPP11 "Build with C++11 enabled" ON) option(MSDFGEN_USE_SKIA "Build with the Skia library" ON) option(MSDFGEN_INSTALL "Generate installation target" OFF) +option(BUILD_SHARED_LIBS "Generate dynamic library files instead of static" OFF) if(MSDFGEN_CORE_ONLY AND MSDFGEN_BUILD_STANDALONE) message(WARNING "Option MSDFGEN_CORE_ONLY ignored - extensions are required for standalone executable") @@ -25,6 +26,10 @@ if(NOT MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +if(BUILD_SHARED_LIBS) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() + if(MSDFGEN_USE_VCPKG) # Make sure that vcpkg toolchain file is set if(NOT CMAKE_TOOLCHAIN_FILE) @@ -35,10 +40,10 @@ if(MSDFGEN_USE_VCPKG) endif() endif() # Default to statically linked vcpkg triplet on Windows - if(WIN32 AND NOT VCPKG_TARGET_TRIPLET) - if(${CMAKE_GENERATOR_PLATFORM} MATCHES "64$") + if(WIN32 AND NOT VCPKG_TARGET_TRIPLET AND NOT BUILD_SHARED_LIBS) + if(CMAKE_GENERATOR_PLATFORM MATCHES "64$") set(VCPKG_TARGET_TRIPLET "x64-windows-static") - elseif(${CMAKE_GENERATOR_PLATFORM} MATCHES "32$" OR ${CMAKE_GENERATOR_PLATFORM} STREQUAL "x86") + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "32$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x86") set(VCPKG_TARGET_TRIPLET "x86-windows-static") else() message(WARNING "Vcpkg triplet not explicitly specified and could not be deduced. Recommend using -DVCPKG_TARGET_TRIPLET=x86-windows-static or similar") @@ -100,6 +105,13 @@ if(MSDFGEN_USE_OPENMP) target_link_libraries(msdfgen-core PUBLIC OpenMP::OpenMP_CXX) endif() +if(BUILD_SHARED_LIBS AND WIN32) + target_compile_definitions(msdfgen-core PRIVATE "MSDFGEN_PUBLIC=__declspec(dllexport)") + target_compile_definitions(msdfgen-core INTERFACE "MSDFGEN_PUBLIC=__declspec(dllimport)") +else() + target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_PUBLIC=) +endif() + # Extensions library if(NOT MSDFGEN_CORE_ONLY) if(NOT TARGET Freetype::Freetype) @@ -128,15 +140,21 @@ if(NOT MSDFGEN_CORE_ONLY) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen-ext) if(MSDFGEN_USE_SKIA) + set(MSDFGEN_SKIA_LIB skia) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) if(NOT TARGET skia) - find_package(skia REQUIRED) + if(MSDFGEN_USE_VCPKG) + find_package(unofficial-skia REQUIRED) + set(MSDFGEN_SKIA_LIB unofficial::skia::skia) + else() + find_package(skia REQUIRED) + endif() endif() target_compile_features(msdfgen-ext PUBLIC cxx_std_17) target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_SKIA) - target_link_libraries(msdfgen-ext PRIVATE Threads::Threads skia) + target_link_libraries(msdfgen-ext PRIVATE Threads::Threads ${MSDFGEN_SKIA_LIB}) endif() add_library(msdfgen-full INTERFACE) diff --git a/core/generator-config.h b/core/generator-config.h index ddcad961..4f5c839e 100644 --- a/core/generator-config.h +++ b/core/generator-config.h @@ -9,9 +9,9 @@ namespace msdfgen { /// The configuration of the MSDF error correction pass. struct ErrorCorrectionConfig { /// The default value of minDeviationRatio. - static const double defaultMinDeviationRatio; + static MSDFGEN_PUBLIC const double defaultMinDeviationRatio; /// The default value of minImproveRatio. - static const double defaultMinImproveRatio; + static MSDFGEN_PUBLIC const double defaultMinImproveRatio; /// Mode of operation. enum Mode { diff --git a/msdfgen-ext.h b/msdfgen-ext.h index df35762e..5bbe7177 100644 --- a/msdfgen-ext.h +++ b/msdfgen-ext.h @@ -15,7 +15,8 @@ * (to load input font files) * - TinyXML 2 by Lee Thomason * (to aid in parsing input SVG files) - * - LodePNG by Lode Vandevenne + * - libpng by the PNG Development Group + * - or LodePNG by Lode Vandevenne * (to save output PNG images) * */ diff --git a/vcpkg.json b/vcpkg.json index 9af44c62..77771ce1 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -13,16 +13,11 @@ }, "extensions": { "description": "Extended functionality that depends on external libraries - loading fonts and SVG files, generating PNG images", - "dependencies": [ { - "name": "freetype", - "version>=": "2.12.1#2" - }, { - "name": "tinyxml2", - "version>=": "9.0.0#1" - }, { - "name": "libpng", - "version>=": "1.6.37#19" - } ] + "dependencies": [ + "freetype", + "tinyxml2", + "libpng" + ] }, "geometry-preprocessing": { "description": "Preprocessing of non-compliant vector geometry via the Skia library", @@ -33,7 +28,7 @@ }, { "name": "skia", "default-features": false, - "version>=": "0.36.0" + "version>=": "0.36.0#3" } ] }, "standalone": {