diff --git a/ports/fdlibm/CMakeLists.txt b/ports/fdlibm/CMakeLists.txt new file mode 100644 index 00000000000..c31f04ab4a7 --- /dev/null +++ b/ports/fdlibm/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.8) +project(fdlibm C) + +file(GLOB fdlibm_SOURCES "*.c") + +include_directories(".") + +if(WIN32) +set(fdlibm_SOURCES ${fdlibm_SOURCES} libm5.def) +endif() + + +add_library(fdlibm ${fdlibm_SOURCES}) + +install( + TARGETS fdlibm + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib/manual-link + ARCHIVE DESTINATION lib/manual-link +) + +if(NOT DISABLE_INSTALL_HEADERS) + install( + FILES + fdlibm.h + DESTINATION include + ) +endif() diff --git a/ports/fdlibm/CONTROL b/ports/fdlibm/CONTROL new file mode 100644 index 00000000000..e519980bb6a --- /dev/null +++ b/ports/fdlibm/CONTROL @@ -0,0 +1,3 @@ +Source: fdlibm +Version: 5.3-2 +Description: FDLIBM (Freely Distributable LIBM) is a C math library for machines that support IEEE 754 floating-point arithmetic diff --git a/ports/fdlibm/libm5.def b/ports/fdlibm/libm5.def new file mode 100644 index 00000000000..2de0ad485b3 --- /dev/null +++ b/ports/fdlibm/libm5.def @@ -0,0 +1,88 @@ +EXPORTS + __ieee754_acos @ 1 ; + __ieee754_acosh @ 2 ; + __ieee754_asin @ 3 ; + __ieee754_atan2 @ 4 ; + __ieee754_atanh @ 5 ; + __ieee754_cosh @ 6 ; + __ieee754_exp @ 7 ; + __ieee754_fmod @ 8 ; + __ieee754_gamma @ 9 ; + __ieee754_gamma_r @ 10 ; + __ieee754_hypot @ 11 ; + __ieee754_j0 @ 12 ; + __ieee754_j1 @ 13 ; + __ieee754_jn @ 14 ; + __ieee754_lgamma @ 15 ; + __ieee754_lgamma_r @ 16 ; + __ieee754_log @ 17 ; + __ieee754_log10 @ 18 ; + __ieee754_pow @ 19 ; + __ieee754_rem_pio2 @ 20 ; + __ieee754_remainder @ 21 ; + __ieee754_scalb @ 22 ; + __ieee754_sinh @ 23 ; + __ieee754_sqrt @ 24 ; + __ieee754_y0 @ 25 ; + __ieee754_y1 @ 26 ; + __ieee754_yn @ 27 ; + __kernel_cos @ 28 ; + __kernel_rem_pio2 @ 29 ; + __kernel_sin @ 30 ; + __kernel_standard @ 31 ; + __kernel_tan @ 32 ; + _fdlib_version @ 33 DATA ; + acos @ 34 ; + acosh @ 35 ; + asin @ 36 ; + asinh @ 37 ; + atan @ 38 ; + atan2 @ 39 ; + atanh @ 40 ; + cbrt @ 41 ; + ceil @ 42 ; + copysign @ 43 ; + cos @ 44 ; + cosh @ 45 ; + erf @ 46 ; + erfc @ 47 ; + exp @ 48 ; + expm1 @ 49 ; + fabs @ 50 ; + ieee_finite @ 51 ; + floor @ 52 ; + fmod @ 53 ; + frexp @ 54 ; + ieee_gamma @ 55 ; + ieee_gamma_r @ 56 ; + hypot @ 57 ; + ilogb @ 58 ; + ieee_isnan @ 59 ; + j0 @ 60 ; + j1 @ 61 ; + jn @ 62 ; + ldexp @ 63 ; + ieee_lgamma @ 64 ; + ieee_lgamma_r @ 65 ; + log @ 66 ; + log10 @ 67 ; + log1p @ 68 ; + logb @ 69 ; + ieee_matherr @ 70 ; + modf @ 71 ; + nextafter @ 72 ; + pow @ 73 ; + remainder @ 74 ; + rint @ 75 ; + ieee_scalb @ 76 ; + scalbn @ 77 ; + signgam @ 78 DATA ; + ieee_significand @ 79 ; + sin @ 80 ; + sinh @ 81 ; + sqrt @ 82 ; + tan @ 83 ; + tanh @ 84 ; + y0 @ 85 ; + y1 @ 86 ; + yn @ 87 ; diff --git a/ports/fdlibm/portfile.cmake b/ports/fdlibm/portfile.cmake new file mode 100644 index 00000000000..fb616db7b0a --- /dev/null +++ b/ports/fdlibm/portfile.cmake @@ -0,0 +1,24 @@ +include(vcpkg_common_functions) + +vcpkg_from_git( + OUT_SOURCE_PATH SOURCE_PATH + URL https://android.googlesource.com/platform/external/fdlibm + REF 59f7335e4dd8275a7dc2f8aeb4fd00758fde37ac + SHA512 08c16ff7cc6f24d962090bf5ab192d3c8ab33d9f60390ca510898c918cefa1b19572ad6bbf49c327bb09d8a9ab52d8341ec14c44abe169d2d319523567f1300f +) + +file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH}) +file(COPY ${CMAKE_CURRENT_LIST_DIR}/libm5.def DESTINATION ${SOURCE_PATH}) + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA + OPTIONS_DEBUG + -DDISABLE_INSTALL_HEADERS=ON +) + +vcpkg_install_cmake() +vcpkg_copy_pdbs() + +# Handle copyright +configure_file(${SOURCE_PATH}/NOTICE ${CURRENT_PACKAGES_DIR}/share/fdlibm/copyright COPYONLY) diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake index 595ebb00e24..c8b8fa97730 100644 --- a/scripts/cmake/vcpkg_common_functions.cmake +++ b/scripts/cmake/vcpkg_common_functions.cmake @@ -27,4 +27,5 @@ include(vcpkg_get_program_files_32_bit) include(vcpkg_get_program_files_platform_bitness) include(vcpkg_get_windows_sdk) include(vcpkg_replace_string) +include(vcpkg_from_git) include(vcpkg_test_cmake) diff --git a/scripts/cmake/vcpkg_from_git.cmake b/scripts/cmake/vcpkg_from_git.cmake new file mode 100644 index 00000000000..c2965292d04 --- /dev/null +++ b/scripts/cmake/vcpkg_from_git.cmake @@ -0,0 +1,118 @@ +## # vcpkg_from_git +## +## Download and extract a project from git +## +## ## Usage: +## ```cmake +## vcpkg_from_git( +## OUT_SOURCE_PATH +## URL +## [REF <59f7335e4d...>] +## [PATCHES ...] +## ) +## ``` +## +## ## Parameters: +## ### OUT_SOURCE_PATH +## Specifies the out-variable that will contain the extracted location. +## +## This should be set to `SOURCE_PATH` by convention. +## +## ### URL +## The url of the git repository. +## +## ### REF +## The full commit id of the current latest master. +## +## ### PATCHES +## A list of patches to be applied to the extracted sources. +## +## Relative paths are based on the port directory. +## +## ## Notes: +## `REF` and `URL` must be specified. +## +## ## Examples: +## +## * [fdlibm](https://github.com/Microsoft/vcpkg/blob/master/ports/fdlibm/portfile.cmake) + +function(vcpkg_from_git) + set(oneValueArgs OUT_SOURCE_PATH URL REF SHA512) + set(multipleValuesArgs PATCHES) + cmake_parse_arguments(_vdud "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN}) + + if(NOT DEFINED _vdud_OUT_SOURCE_PATH) + message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.") + endif() + + if(NOT DEFINED _vdud_URL) + message(FATAL_ERROR "The git url must be specified") + endif() + + if(NOT DEFINED _vdud_REF) + message(FATAL_ERROR "The git ref must be specified.") + endif() + + if(NOT DEFINED _vdud_SHA512) + message(FATAL_ERROR "vcpkg_from_git requires a SHA512 argument. If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.") + endif() + + string(REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}") + set(TEMP_ARCHIVE "${DOWNLOADS}/temp/${PORT}-${SANITIZED_REF}.zip") + set(ARCHIVE "${DOWNLOADS}/${PORT}-${SANITIZED_REF}.zip") + set(TEMP_SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/${SANITIZED_REF}") + + function(test_hash FILE_PATH FILE_KIND CUSTOM_ERROR_ADVICE) + file(SHA512 ${FILE_PATH} FILE_HASH) + if(NOT FILE_HASH STREQUAL _vdud_SHA512) + message(FATAL_ERROR + "\nFile does not have expected hash:\n" + " File path: [ ${FILE_PATH} ]\n" + " Expected hash: [ ${_vdud_SHA512} ]\n" + " Actual hash: [ ${FILE_HASH} ]\n" + "${CUSTOM_ERROR_ADVICE}\n") + endif() + endfunction() + + if(NOT EXISTS "${ARCHIVE}") + if(_VCPKG_NO_DOWNLOADS) + message(FATAL_ERROR "Downloads are disabled, but '${ARCHIVE}' does not exist.") + endif() + message(STATUS "Fetching ${_vdud_URL}...") + find_program(GIT NAMES git git.cmd) + # Note: git init is safe to run multiple times + vcpkg_execute_required_process( + COMMAND ${GIT} init git-tmp + WORKING_DIRECTORY ${DOWNLOADS} + LOGNAME git-init + ) + vcpkg_execute_required_process( + COMMAND ${GIT} fetch ${_vdud_URL} ${_vdud_REF} --depth 1 -n + WORKING_DIRECTORY ${DOWNLOADS}/git-tmp + LOGNAME git-fetch + ) + file(MAKE_DIRECTORY "${DOWNLOADS}/temp") + vcpkg_execute_required_process( + COMMAND ${GIT} archive FETCH_HEAD -o "${TEMP_ARCHIVE}" + WORKING_DIRECTORY ${DOWNLOADS}/git-tmp + LOGNAME git-archive + ) + test_hash("${TEMP_ARCHIVE}" "downloaded repo" "") + get_filename_component(downloaded_file_dir "${ARCHIVE}" DIRECTORY) + file(MAKE_DIRECTORY "${downloaded_file_dir}") + file(RENAME "${TEMP_ARCHIVE}" "${ARCHIVE}") + else() + message(STATUS "Using cached ${ARCHIVE}") + test_hash("${ARCHIVE}" "cached file" "Please delete the file and retry if this file should be downloaded again.") + endif() + + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${ARCHIVE}" + REF "${SANITIZED_REF}" + PATCHES ${_vdud_PATCHES} + NO_REMOVE_ONE_LEVEL + ) + + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) +endfunction()