From df9c8e260e66713dcf768630cd434caf2c29bbff Mon Sep 17 00:00:00 2001 From: myd7349 Date: Fri, 9 Oct 2020 15:41:42 +0800 Subject: [tinyexpr] Add new port (#13729) --- ports/tinyexpr/CMakeLists.txt | 48 +++++++++++++++++++++++++++++++++++++++ ports/tinyexpr/exports.def | 6 +++++ ports/tinyexpr/fix-issue-34.patch | 16 +++++++++++++ ports/tinyexpr/portfile.cmake | 27 ++++++++++++++++++++++ ports/tinyexpr/vcpkg.json | 7 ++++++ 5 files changed, 104 insertions(+) create mode 100644 ports/tinyexpr/CMakeLists.txt create mode 100644 ports/tinyexpr/exports.def create mode 100644 ports/tinyexpr/fix-issue-34.patch create mode 100644 ports/tinyexpr/portfile.cmake create mode 100644 ports/tinyexpr/vcpkg.json diff --git a/ports/tinyexpr/CMakeLists.txt b/ports/tinyexpr/CMakeLists.txt new file mode 100644 index 000000000..60f38348a --- /dev/null +++ b/ports/tinyexpr/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.14) + +project(tinyexpr LANGUAGES C) + +include(CheckSymbolExists) +include(GNUInstallDirs) + +if(WIN32 AND BUILD_SHARED_LIBS) + add_library(tinyexpr tinyexpr.c exports.def) +else() + add_library(tinyexpr tinyexpr.c) +endif() + +target_include_directories( + tinyexpr + PUBLIC + $ +) + +# https://stackoverflow.com/questions/32816646/can-cmake-detect-if-i-need-to-link-to-libm-when-using-pow-in-c +if(NOT POW_FUNCTION_EXISTS AND NOT NEED_LINKING_AGAINST_LIBM) + check_symbol_exists(pow "math.h" POW_FUNCTION_EXISTS) + if(NOT POW_FUNCTION_EXISTS) + unset(POW_FUNCTION_EXISTS CACHE) + list(APPEND CMAKE_REQUIRED_LIBRARIES m) + check_symbol_exists(pow "math.h" POW_FUNCTION_EXISTS) + if(POW_FUNCTION_EXISTS) + set(NEED_LINKING_AGAINST_LIBM True CACHE BOOL "" FORCE) + else() + message(FATAL_ERROR "Failed making the pow() function available") + endif() + endif() +endif() + +if(NEED_LINKING_AGAINST_LIBM) + target_link_libraries(tinyexpr PUBLIC m) +endif() + +set_target_properties(tinyexpr PROPERTIES PUBLIC_HEADER tinyexpr.h) + +install(TARGETS tinyexpr EXPORT unofficial-tinyexpr-config) + +install( + EXPORT unofficial-tinyexpr-config + NAMESPACE unofficial::tinyexpr:: + DESTINATION share/unofficial-tinyexpr + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +) diff --git a/ports/tinyexpr/exports.def b/ports/tinyexpr/exports.def new file mode 100644 index 000000000..a43f437d2 --- /dev/null +++ b/ports/tinyexpr/exports.def @@ -0,0 +1,6 @@ +EXPORTS + te_compile + te_eval + te_free + te_interp + te_print diff --git a/ports/tinyexpr/fix-issue-34.patch b/ports/tinyexpr/fix-issue-34.patch new file mode 100644 index 000000000..000fea053 --- /dev/null +++ b/ports/tinyexpr/fix-issue-34.patch @@ -0,0 +1,16 @@ +diff --git a/tinyexpr.c b/tinyexpr.c +index 90ed8fc..570f2fd 100755 +--- a/tinyexpr.c ++++ b/tinyexpr.c +@@ -49,6 +49,11 @@ For log = natural log uncomment the next line. */ + #define INFINITY (1.0/0.0) + #endif + ++/* https://github.com/codeplea/tinyexpr/issues/34 */ ++#ifdef _MSC_VER ++#pragma function(ceil) ++#pragma function(floor) ++#endif + + typedef double (*te_fun2)(double, double); + diff --git a/ports/tinyexpr/portfile.cmake b/ports/tinyexpr/portfile.cmake new file mode 100644 index 000000000..480c67a24 --- /dev/null +++ b/ports/tinyexpr/portfile.cmake @@ -0,0 +1,27 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO codeplea/tinyexpr + REF ffb0d41b13e5f8d318db95feb071c220c134fe70 + SHA512 fe4975f8b444a50d7ba8135450a42007a81f1545eebd7775f92307b87b72bc9abee4591e56ddeb76ec9e5aa41f0852ba98c99881d671f47a58caca8bd1ca9999 + HEAD_REF master + PATCHES + fix-issue-34.patch +) + +file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH}) +file(COPY ${CMAKE_CURRENT_LIST_DIR}/exports.def DESTINATION ${SOURCE_PATH}) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA +) + +vcpkg_install_cmake() + +vcpkg_copy_pdbs() + +vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-${PORT} TARGET_PATH share/unofficial-${PORT}) + +file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) + +file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/ports/tinyexpr/vcpkg.json b/ports/tinyexpr/vcpkg.json new file mode 100644 index 000000000..6ed72b483 --- /dev/null +++ b/ports/tinyexpr/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "tinyexpr", + "version-string": "2020-09-25", + "description": "Tiny recursive descent parser and evaluation engine in C", + "homepage": "https://codeplea.com/tinyexpr", + "license": "Zlib" +} -- cgit v1.2.3