From 72c4037ca78c580dc28cab6d58453fff8f8c9053 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 27 Sep 2023 10:22:44 +0200 Subject: [PATCH] [lmdb] Update, refresh (#33967) * [lmdb] Update, refresh * Use getopt-win32 --- ports/lmdb/cmake/CMakeLists.txt | 111 ++++++++---------- ports/lmdb/cmake/cmake/package-config.cmakein | 14 +-- ports/lmdb/cmake/cmake/runtest.cmake | 6 +- ports/lmdb/cmake/lmdb.def | 2 +- ports/lmdb/cmake/lmdbd.def | 58 --------- ports/lmdb/getopt-win32.diff | 50 ++++++++ ports/lmdb/lmdb-config.cmake | 14 +++ ports/lmdb/portfile.cmake | 32 ++++- ports/lmdb/usage | 4 + ports/lmdb/vcpkg.json | 17 ++- versions/baseline.json | 4 +- versions/l-/lmdb.json | 5 + 12 files changed, 172 insertions(+), 145 deletions(-) delete mode 100644 ports/lmdb/cmake/lmdbd.def create mode 100644 ports/lmdb/getopt-win32.diff create mode 100644 ports/lmdb/lmdb-config.cmake create mode 100644 ports/lmdb/usage diff --git a/ports/lmdb/cmake/CMakeLists.txt b/ports/lmdb/cmake/CMakeLists.txt index babddef004e598..1388328a188eef 100644 --- a/ports/lmdb/cmake/CMakeLists.txt +++ b/ports/lmdb/cmake/CMakeLists.txt @@ -1,81 +1,72 @@ -cmake_minimum_required(VERSION 2.8) - -file(READ "${CMAKE_CURRENT_SOURCE_DIR}/lmdb.h" VERSION_HEADER) -string(REGEX MATCH ".*MDB_VERSION_MAJOR[ \t]+([0-9])" MAJOR_VERSION_MATCH "${VERSION_HEADER}") -set(LMDB_MAJOR_VERSION ${CMAKE_MATCH_1}) -string(REGEX MATCH ".*MDB_VERSION_MINOR[ \t]+([0-9])" MINOR_VERSION_MATCH "${VERSION_HEADER}") -set(LMDB_MINOR_VERSION ${CMAKE_MATCH_1}) -string(REGEX MATCH ".*MDB_VERSION_PATCH[ \t]+([0-9]+)" PATCH_VERSION_MATCH "${VERSION_HEADER}") -set(LMDB_PATCH_VERSION ${CMAKE_MATCH_1}) - -set(LMDB_VERSION "${LMDB_MAJOR_VERSION}.${LMDB_MINOR_VERSION}.${LMDB_PATCH_VERSION}") +cmake_minimum_required(VERSION 3.27) project(lmdb) option(LMDB_BUILD_TOOLS "Build lmdb tools" OFF) option(LMDB_BUILD_TESTS "Build lmdb tests" OFF) option(LMDB_INSTALL_HEADERS "Install LMDB header files" ON) -set(LMDB_INCLUDE_INSTALL_DIR include CACHE PATH "Install directory for headers") -set(LMDB_LIBRARY_INSTALL_DIR lib CACHE PATH "Install directory for library") -set(LMDB_RUNTIME_INSTALL_DIR bin CACHE PATH "Install directory for binaries/dlls") -set(LMDB_CONFIG_INSTALL_DIR share/lmdb CACHE PATH "Install directory for cmake config files") - -if(MSVC AND BUILD_SHARED_LIBS) -set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/lmdbd.def\"") -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /DEF:\"${CMAKE_CURRENT_SOURCE_DIR}/lmdb.def\"") -endif() -set(SRCS lmdb mdb.c lmdb.h midl.c midl.h ) -add_library(lmdb ${SRCS}) +include(GNUInstallDirs) -if (WIN32) - target_link_libraries(lmdb PRIVATE ntdll.lib) +add_library(lmdb mdb.c lmdb.h midl.c midl.h) +if(WIN32 AND BUILD_SHARED_LIBS) + target_sources(lmdb PRIVATE lmdb.def) endif() -install(TARGETS lmdb DESTINATION lib - EXPORT lmdb-targets - RUNTIME DESTINATION ${LMDB_RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION ${LMDB_LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${LMDB_LIBRARY_INSTALL_DIR} - ) +set(THREADS_PREFER_PTHREAD_FLAG 1) +find_package(Threads REQUIRED) +target_link_libraries(lmdb PRIVATE Threads::Threads) + +install(TARGETS lmdb + EXPORT unofficial-lmdb-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) if(LMDB_INSTALL_HEADERS) - install(FILES lmdb.h midl.h DESTINATION ${LMDB_INCLUDE_INSTALL_DIR}) + install(FILES lmdb.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") endif() +target_include_directories(lmdb INTERFACE "$") include(CMakePackageConfigHelpers) - -set(INSTALL_INCLUDE_DIR ${LMDB_INCLUDE_INSTALL_DIR}) -configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/package-config.cmakein ${CMAKE_CURRENT_BINARY_DIR}/lmdb-config.cmake - INSTALL_DESTINATION ${LMDB_CONFIG_INSTALL_DIR} - PATH_VARS INSTALL_INCLUDE_DIR - ) - -write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/lmdb-config-version.cmake VERSION ${LMDB_VERSION} COMPATIBILITY SameMajorVersion ) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lmdb-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/lmdb-config-version.cmake - DESTINATION ${LMDB_CONFIG_INSTALL_DIR} ) - - -install(EXPORT lmdb-targets DESTINATION ${LMDB_CONFIG_INSTALL_DIR}) +configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/package-config.cmakein" "${CMAKE_CURRENT_BINARY_DIR}/unofficial-lmdb-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/lmdb" +) +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/unofficial-lmdb-config-version.cmake" + VERSION "${LMDB_VERSION}" + COMPATIBILITY SameMajorVersion +) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/unofficial-lmdb-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/unofficial-lmdb-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-lmdb" +) +install(EXPORT unofficial-lmdb-targets + NAMESPACE unofficial::lmdb:: + DESTINATION "${CMAKE_INSTALL_DATADIR}/unofficial-lmdb" +) if(LMDB_BUILD_TOOLS) - # don't build mdb_dump/load/stat since they will - # not build on windows - foreach(_tool mdb_copy) - add_executable(${_tool} ${_tool}.c) - target_link_libraries(${_tool} lmdb) - endforeach() + set(getopt_libs "") + if(WIN32 AND NOT MINGW) + find_package(unofficial-getopt-win32 REQUIRED) + set(getopt_libs "unofficial::getopt-win32::getopt") + endif() + foreach(tool IN ITEMS mdb_copy mdb_dump mdb_load mdb_stat) + add_executable(${tool} ${tool}.c) + target_link_libraries(${tool} lmdb ${getopt_libs}) + install(TARGETS ${tool} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) + endforeach() endif() if(LMDB_BUILD_TESTS) - enable_testing() - # don't use mtest6 since it will only build in static - # build - foreach(_test mtest mtest2 mtest3 mtest4 mtest5) - add_executable(${_test} ${_test}.c) - target_link_libraries(${_test} lmdb) - add_test(NAME ${_test} - COMMAND ${CMAKE_COMMAND} -DTEST=$ + #include + #include ++#ifdef _MSC_VER ++#include ++#else + #include ++#endif + #include + #include "lmdb.h" + +diff --git a/libraries/liblmdb/mdb_load.c b/libraries/liblmdb/mdb_load.c +index d2a3cec..f050286 100644 +--- a/libraries/liblmdb/mdb_load.c ++++ b/libraries/liblmdb/mdb_load.c +@@ -16,7 +16,11 @@ + #include + #include + #include ++#ifdef _MSC_VER ++#include ++#else + #include ++#endif + #include "lmdb.h" + + #define PRINT 1 +diff --git a/libraries/liblmdb/mdb_stat.c b/libraries/liblmdb/mdb_stat.c +index 3a81175..f1f4a75 100644 +--- a/libraries/liblmdb/mdb_stat.c ++++ b/libraries/liblmdb/mdb_stat.c +@@ -14,7 +14,13 @@ + #include + #include + #include ++#ifdef _MSC_VER ++#include ++#include ++typedef SSIZE_T ssize_t; ++#else + #include ++#endif + #include "lmdb.h" + + #ifdef _WIN32 diff --git a/ports/lmdb/lmdb-config.cmake b/ports/lmdb/lmdb-config.cmake new file mode 100644 index 00000000000000..50b92707f12242 --- /dev/null +++ b/ports/lmdb/lmdb-config.cmake @@ -0,0 +1,14 @@ +file(READ "${CMAKE_CURRENT_LIST_DIR}/../lmdb/usage" usage) +message(WARNING "find_package(lmdb) is deprecated.\n${usage}") + +include(CMakeFindDependencyMacro) +find_dependency(unofficial-lmdb ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION}) + +set(${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") +set(${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIRS "${${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIR}") +set(${CMAKE_FIND_PACKAGE_NAME}_LIBRARIES lmdb) + +string(TOUPPER "${CMAKE_FIND_PACKAGE_NAME}" UPPER_PACKAGE_NAME) +set(${UPPER_PACKAGE_NAME}_INCLUDE_DIR "${${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIR}") +set(${UPPER_PACKAGE_NAME}_INCLUDE_DIRS "${${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIR}") +set(${UPPER_PACKAGE_NAME}_LIBRARIES lmdb) diff --git a/ports/lmdb/portfile.cmake b/ports/lmdb/portfile.cmake index 263966bbd32ac6..2e32aca98934be 100644 --- a/ports/lmdb/portfile.cmake +++ b/ports/lmdb/portfile.cmake @@ -1,23 +1,43 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO LMDB/lmdb - REF 8ad7be2510414b9506ec9f9e24f24d04d9b04a1a # LMDB_0.9.29 - SHA512 a18b6217761bdfcc5964d9817addd2d0c6c735d02a823717eb7ae1561a48110da0708a3290e21297d481e4d8eeb5d92a4a6860ff44888bf2da665cd9f167513c + REF "LMDB_${VERSION}" + SHA512 a5763ff94af0b5bbc2406c52890797e6232e77593bacdb240441ed30c8634e4e6de6eba206880475544e21561ccd0be2dee16733d6ec35483eb1dbbb81913a8d HEAD_REF master + PATCHES + getopt-win32.diff ) - file(COPY "${CMAKE_CURRENT_LIST_DIR}/cmake/" DESTINATION "${SOURCE_PATH}/libraries/liblmdb") +vcpkg_check_features(OUT_FEATURE_OPTIONS options_release + FEATURES + tools LMDB_BUILD_TOOLS +) + vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}/libraries/liblmdb" + OPTIONS + "-DLMDB_VERSION=${VERSION}" + OPTIONS_RELEASE + ${options_release} OPTIONS_DEBUG -DLMDB_INSTALL_HEADERS=OFF ) vcpkg_cmake_install() +vcpkg_copy_pdbs() +vcpkg_cmake_config_fixup(PACKAGE_NAME unofficial-lmdb) -file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") +if(LMDB_BUILD_TOOLS) + vcpkg_copy_tools(TOOL_NAMES mdb_copy mdb_dump mdb_load mdb_stat AUTO_CLEAN) +endif() -file(INSTALL "${SOURCE_PATH}/libraries/liblmdb/COPYRIGHT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/lmdb" RENAME copyright) +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") -vcpkg_copy_pdbs() +file(COPY "${CURRENT_PORT_DIR}/lmdb-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +file(COPY "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright( + FILE_LIST + "${SOURCE_PATH}/libraries/liblmdb/COPYRIGHT" + "${SOURCE_PATH}/libraries/liblmdb/LICENSE" +) diff --git a/ports/lmdb/usage b/ports/lmdb/usage new file mode 100644 index 00000000000000..ef273ae521f37e --- /dev/null +++ b/ports/lmdb/usage @@ -0,0 +1,4 @@ +lmdb provides CMake targets: + + find_package(unofficial-lmdb CONFIG REQUIRED) + target_link_libraries(main PRIVATE unofficial::lmdb::lmdb) diff --git a/ports/lmdb/vcpkg.json b/ports/lmdb/vcpkg.json index 210c776d13ada1..f743855b266896 100644 --- a/ports/lmdb/vcpkg.json +++ b/ports/lmdb/vcpkg.json @@ -1,11 +1,9 @@ { "name": "lmdb", - "version": "0.9.29", - "port-version": 2, + "version": "0.9.31", "description": "LMDB is an extraordinarily fast, memory-efficient database", "homepage": "https://github.com/LMDB/lmdb", - "license": null, - "supports": "!(arm & windows)", + "license": "OLDAP-2.8", "dependencies": [ { "name": "vcpkg-cmake", @@ -15,5 +13,14 @@ "name": "vcpkg-cmake-config", "host": true } - ] + ], + "features": { + "tools": { + "description": "Build tools", + "supports": "!uwp", + "dependencies": [ + "getopt" + ] + } + } } diff --git a/versions/baseline.json b/versions/baseline.json index 42baf5f48df7d4..695eb2281d0376 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5081,8 +5081,8 @@ "port-version": 6 }, "lmdb": { - "baseline": "0.9.29", - "port-version": 2 + "baseline": "0.9.31", + "port-version": 0 }, "lockpp": { "baseline": "1.0.2", diff --git a/versions/l-/lmdb.json b/versions/l-/lmdb.json index d150fa7f195cd8..0c9880b1d4d785 100644 --- a/versions/l-/lmdb.json +++ b/versions/l-/lmdb.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "3a13501d369f479e4b9a5e14c3f75022c07a18dd", + "version": "0.9.31", + "port-version": 0 + }, { "git-tree": "1c94e6b90d91bc39a4307502116b20d7b38de413", "version": "0.9.29",