From 9ee856b9b8952860c6eeca2715c211431e2f6339 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 22 Feb 2019 00:55:22 +0100 Subject: [PATCH] [mlpack] Add new port (#5409) * [mlpack] Add new port Add new port for the http://www.mlpack.org/ library * Tools optional and static build * Info fix * [mlpack] Use PATCHES parameter instead of apply_patches() --- ports/mlpack/CONTROL | 7 + ports/mlpack/cmakelists.patch | 52 +++++++ ports/mlpack/meta_info_extractor.patch | 189 +++++++++++++++++++++++++ ports/mlpack/portfile.cmake | 43 ++++++ 4 files changed, 291 insertions(+) create mode 100644 ports/mlpack/CONTROL create mode 100644 ports/mlpack/cmakelists.patch create mode 100644 ports/mlpack/meta_info_extractor.patch create mode 100644 ports/mlpack/portfile.cmake diff --git a/ports/mlpack/CONTROL b/ports/mlpack/CONTROL new file mode 100644 index 0000000000..457cb769f9 --- /dev/null +++ b/ports/mlpack/CONTROL @@ -0,0 +1,7 @@ +Source: mlpack +Version: 3.0.4 +Description: mlpack is a fast, flexible machine learning library, written in C++, that aims to provide fast, extensible implementations of cutting-edge machine learning algorithms. +Build-Depends: openblas, clapack, boost, armadillo + +Feature: tools +Description: Build command-line executables and tests. diff --git a/ports/mlpack/cmakelists.patch b/ports/mlpack/cmakelists.patch new file mode 100644 index 0000000000..bc251980a0 --- /dev/null +++ b/ports/mlpack/cmakelists.patch @@ -0,0 +1,52 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -252,7 +252,7 @@ + # script Armadillo uses to find these. + if (WIN32) + find_library(LAPACK_LIBRARY +- NAMES lapack liblapack lapack_win32_MT lapack_win32 ++ NAMES clapack lapack liblapack lapack_win32_MT lapack_win32 + PATHS "C:/Program Files/Armadillo" + PATH_SUFFIXES "examples/lib_win32/") + +@@ -261,7 +261,7 @@ + endif () + + find_library(BLAS_LIBRARY +- NAMES blas libblas blas_win32_MT blas_win32 ++ NAMES openblas blas libblas blas_win32_MT blas_win32 + PATHS "C:/Program Files/Armadillo" + PATH_SUFFIXES "examples/lib_win32/") + +@@ -281,6 +281,9 @@ + # Unfortunately this configuration variable is necessary and will need to be + # updated as time goes on and new versions are released. + set(Boost_ADDITIONAL_VERSIONS ++ "1.69.0" "1.69" ++ "1.68.0" "1.68" ++ "1.67.0" "1.67" + "1.66.0" "1.66" + "1.65.1" "1.65.0" "1.65" + "1.64.1" "1.64.0" "1.64" +@@ -307,19 +310,11 @@ + REQUIRED + ) + +-link_directories(${Boost_LIBRARY_DIRS}) +- +-# In Visual Studio, automatic linking is performed, so we don't need to worry +-# about it. Clear the list of libraries to link against and let Visual Studio +-# handle it. +-if (MSVC) +- link_directories(${Boost_LIBRARY_DIRS}) +- set(Boost_LIBRARIES "") +-endif () ++link_directories(${Boost_LIBRARIES}) + + set(MLPACK_INCLUDE_DIRS ${MLPACK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) + set(MLPACK_LIBRARIES ${MLPACK_LIBRARIES} ${Boost_LIBRARIES}) +-set(MLPACK_LIBRARY_DIRS ${MLPACK_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}) ++set(MLPACK_LIBRARY_DIRS ${MLPACK_LIBRARY_DIRS} ${Boost_LIBRARIES}) + + # For Boost testing framework (will have no effect on non-testing executables). + # This specifies to Boost that we are dynamically linking to the Boost test diff --git a/ports/mlpack/meta_info_extractor.patch b/ports/mlpack/meta_info_extractor.patch new file mode 100644 index 0000000000..3a9fa00ddb --- /dev/null +++ b/ports/mlpack/meta_info_extractor.patch @@ -0,0 +1,189 @@ +--- a/src/mlpack/core/cv/meta_info_extractor.hpp ++++ b/src/mlpack/core/cv/meta_info_extractor.hpp +@@ -38,50 +38,142 @@ + bool NumClasses> + struct TrainForm; + +-template +-struct TrainFormBase +-{ +- using PredictionsType = PT; +- using WeightsType = WT; +- +- /* A minimum number of parameters that should be inferred */ +- static const size_t MinNumberOfAdditionalArgs = 1; +- +- template +- using Type = RT(Class::*)(SignatureParams..., Ts...); +-}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; +- +-template +-struct TrainForm : public TrainFormBase {}; ++#if _MSC_VER <= 1916 // Visual Studio 2017 version 15.9 or older. ++ // Due to an internal MSVC compiler bug (MSVC ) we can't use two parameter ++ // packs. So we have to write multiple TrainFormBase forms. ++ template ++ struct TrainFormBase4 ++ { ++ using PredictionsType = PT; ++ using WeightsType = WT; ++ ++ /* A minimum number of parameters that should be inferred */ ++ static const size_t MinNumberOfAdditionalArgs = 1; ++ ++ template ++ using Type = RT(Class::*)(T1, T2, Ts...); ++ }; ++ ++ template ++ struct TrainFormBase5 ++ { ++ using PredictionsType = PT; ++ using WeightsType = WT; ++ ++ /* A minimum number of parameters that should be inferred */ ++ static const size_t MinNumberOfAdditionalArgs = 1; ++ ++ template ++ using Type = RT(Class::*)(T1, T2, T3, Ts...); ++ }; ++ ++ template ++ struct TrainFormBase6 ++ { ++ using PredictionsType = PT; ++ using WeightsType = WT; ++ ++ /* A minimum number of parameters that should be inferred */ ++ static const size_t MinNumberOfAdditionalArgs = 1; ++ ++ template ++ using Type = RT(Class::*)(T1, T2, T3, T4, Ts...); ++ }; ++ ++ template ++ struct TrainFormBase7 ++ { ++ using PredictionsType = PT; ++ using WeightsType = WT; ++ ++ /* A minimum number of parameters that should be inferred */ ++ static const size_t MinNumberOfAdditionalArgs = 1; ++ ++ template ++ using Type = RT(Class::*)(T1, T2, T3, T4, T5, Ts...); ++ }; ++ ++ template ++ struct TrainForm : public TrainFormBase4 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase5 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase5 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase6 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase5 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase6 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase6 {}; ++ ++ template ++ struct TrainForm : public TrainFormBase7 {}; ++#else ++ template ++ struct TrainFormBase ++ { ++ using PredictionsType = PT; ++ using WeightsType = WT; ++ ++ /* A minimum number of parameters that should be inferred */ ++ static const size_t MinNumberOfAdditionalArgs = 1; ++ ++ template ++ using Type = RT(Class::*)(SignatureParams..., Ts...); ++ }; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++ ++ template ++ struct TrainForm : public TrainFormBase {}; ++#endif + + /* A struct for indication that a right method form can't be found */ + struct NotFoundMethodForm diff --git a/ports/mlpack/portfile.cmake b/ports/mlpack/portfile.cmake new file mode 100644 index 0000000000..9bd69ed8b7 --- /dev/null +++ b/ports/mlpack/portfile.cmake @@ -0,0 +1,43 @@ +include(vcpkg_common_functions) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO mlpack/mlpack + REF mlpack-3.0.4 + SHA512 07730a826efb55a41fce2286de8df15421e7a7189b9cdc4699c6a32e3d4b1964a98e3829a60513994ef747640952229e7a3b744ac0ae324f5e5e57f982a86f66 + HEAD_REF master + PATCHES + meta_info_extractor.patch + cmakelists.patch +) + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" MLPACK_SHARED_LIBS) + +set(BUILD_TOOLS OFF) +if("tools" IN_LIST FEATURES) + set(BUILD_TOOLS ON) +endif() + +vcpkg_configure_cmake( + SOURCE_PATH ${SOURCE_PATH} + PREFER_NINJA + OPTIONS + -DBUILD_TESTS=${BUILD_TOOLS} + -DBUILD_CLI_EXECUTABLES=${BUILD_TOOLS} + -DBUILD_SHARED_LIBS=${MLPACK_SHARED_LIBS} +) +vcpkg_install_cmake() +vcpkg_copy_pdbs() + +file(INSTALL ${SOURCE_PATH}/COPYRIGHT.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/mlpack RENAME copyright) + +if(BUILD_TOOLS) + file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools) + file(GLOB MLPACK_TOOLS ${CURRENT_PACKAGES_DIR}/bin/*.exe) + file(COPY ${MLPACK_TOOLS} DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}) + file(REMOVE ${MLPACK_TOOLS}) + file(GLOB MLPACK_TOOLS_DEBUG ${CURRENT_PACKAGES_DIR}/debug/bin/*.exe) + file(REMOVE ${MLPACK_TOOLS_DEBUG}) +endif() + +file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)