[libmysql/libmariadb] Export unofficial cmake targets (#14290)

* [libmysql/libmariadb] Add vcpkg-cmake-wrapper and usage

* [libmysql] Export target unofficial-libmysql

* [libmariadb] Export target unofficial-libmariadb

* Add conditions

* Remove empty folder

* [libmysql] Enable static build, generate library mysqlclient

* Update ports/libmysql/CONTROL

* [libmysql] Re-write portfile.cmake

* [vcpkg_clean_executables_in_bin] clean up the pdbs

* [libmysql] Fix tools on non-Windows

* [libmysql] Fix tools, fix wrapper

* [libmysql] Add macro libmysql_FOUND

* [vcpkg_clean_executables_in_bin] Revert changes

* [libmysql] Export unofficial-libmysql on both dynamic and static

* Update ports/libmariadb/export-cmake-targets.patch

Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
This commit is contained in:
Jack·Boos·Yu 2020-11-10 09:28:45 -08:00 committed by GitHub
parent 19fe942c13
commit 74844c7546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 233 additions and 36 deletions

View File

@ -1,6 +1,6 @@
Source: libmariadb
Version: 3.1.10
Port-Version: 1
Port-Version: 2
Homepage: https://github.com/MariaDB/mariadb-connector-c
Description: MariaDB Connector/C is used to connect C/C++ applications to MariaDB and MySQL databases
Default-Features: zlib, openssl

View File

@ -0,0 +1,26 @@
diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt
index 083a863..7bc32b4 100644
--- a/libmariadb/CMakeLists.txt
+++ b/libmariadb/CMakeLists.txt
@@ -460,10 +460,21 @@ INSTALL(TARGETS mariadbclient
LIBRARY DESTINATION lib)
INSTALL(TARGETS libmariadb
COMPONENT SharedLibraries
+ EXPORT unofficial-libmariadb-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
+install(EXPORT unofficial-libmariadb-targets DESTINATION share/unofficial-libmariadb)
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/unofficial-libmariadb-config.cmake"
+[[include(CMakeFindDependencyMacro)
+find_dependency(ZLIB)
+find_dependency(OpenSSL)
+include("${CMAKE_CURRENT_LIST_DIR}/unofficial-libmariadb-targets.cmake")
+]])
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unofficial-libmariadb-config.cmake DESTINATION share/unofficial-libmariadb)
IF(0)
# On Windows, install PDB

View File

@ -13,6 +13,7 @@ vcpkg_from_github(
disable-test-build.patch
fix-InstallPath.patch
fix-iconv.patch
export-cmake-targets.patch
)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
@ -38,6 +39,8 @@ vcpkg_configure_cmake(
vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-libmariadb TARGET_PATH share/unofficial-libmariadb)
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
# remove debug header
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

View File

@ -1,5 +1,6 @@
Source: libmysql
Version: 8.0.20
Port-Version: 1
Homepage: https://github.com/mysql/mysql-server
Build-Depends: boost-algorithm, boost-geometry, boost-optional, boost-functional, boost-graph, openssl, icu, libevent, lz4, zlib
Description: A MySQL client library for C development.

View File

@ -0,0 +1,123 @@
diff --git a/cmake/install_macros.cmake b/cmake/install_macros.cmake
index c3a05ec..0d44ef2 100644
--- a/cmake/install_macros.cmake
+++ b/cmake/install_macros.cmake
@@ -100,7 +100,7 @@ ENDFUNCTION()
FUNCTION(MYSQL_INSTALL_TARGETS)
MYSQL_PARSE_ARGUMENTS(ARG
- "DESTINATION;COMPONENT"
+ "DESTINATION;COMPONENT;EXPORT"
""
${ARGN}
)
@@ -115,7 +115,20 @@ FUNCTION(MYSQL_INSTALL_TARGETS)
IF(ARG_COMPONENT)
SET(COMP COMPONENT ${ARG_COMPONENT})
ENDIF()
- INSTALL(TARGETS ${TARGETS} DESTINATION ${ARG_DESTINATION} ${COMP})
+ IF (ARG_EXPORT)
+ FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${ARG_EXPORT}-config.cmake"
+"include(CMakeFindDependencyMacro)
+find_dependency(ZLIB)
+find_dependency(OpenSSL)
+include(\"\${CMAKE_CURRENT_LIST_DIR}/${ARG_EXPORT}-targets.cmake\")
+")
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${ARG_EXPORT}-config.cmake DESTINATION share/${ARG_EXPORT})
+ set(EXPORT_ARGS EXPORT ${ARG_EXPORT}-targets)
+ ENDIF()
+ INSTALL(TARGETS ${TARGETS} ${EXPORT_ARGS} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ${COMP})
+ IF (ARG_EXPORT)
+ INSTALL(${EXPORT_ARGS} DESTINATION share/${ARG_EXPORT})
+ ENDIF()
SET(INSTALL_LOCATION ${ARG_DESTINATION} )
INSTALL_DEBUG_SYMBOLS("${TARGETS}")
SET(INSTALL_LOCATION)
diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake
index 5481fae..3fa58da 100644
--- a/cmake/libutils.cmake
+++ b/cmake/libutils.cmake
@@ -237,7 +237,7 @@ MACRO(MERGE_LIBRARIES_SHARED)
IF(ARG_COMPONENT)
SET(COMP COMPONENT ${ARG_COMPONENT})
ENDIF()
- MYSQL_INSTALL_TARGETS(${TARGET} DESTINATION "${INSTALL_LIBDIR}" ${COMP})
+ MYSQL_INSTALL_TARGETS(${TARGET} EXPORT unofficial-libmysql DESTINATION "${INSTALL_LIBDIR}" ${COMP})
ENDIF()
ENDMACRO()
@@ -372,7 +372,7 @@ MACRO(MERGE_CONVENIENCE_LIBRARIES)
SET(COMP COMPONENT ${ARG_COMPONENT})
ENDIF()
IF(INSTALL_STATIC_LIBRARIES)
- MYSQL_INSTALL_TARGETS(${TARGET} DESTINATION "${INSTALL_LIBDIR}" ${COMP})
+ MYSQL_INSTALL_TARGETS(${TARGET} EXPORT unofficial-libmysql DESTINATION "${INSTALL_LIBDIR}" ${COMP})
ENDIF()
ENDIF()
ENDMACRO()
diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt
index 605288d..c5d0f5d 100644
--- a/libmysql/CMakeLists.txt
+++ b/libmysql/CMakeLists.txt
@@ -245,8 +245,16 @@ ENDIF()
# LDAP authentication SASL client plugin
ADD_SUBDIRECTORY(authentication_ldap)
+IF (BUILD_SHARED_LIBS)
+ set(INSTALL_SHARED )
+ set(INSTALL_STATIC SKIP_INSTALL)
+ELSE()
+ set(INSTALL_SHARED SKIP_INSTALL)
+ set(INSTALL_STATIC )
+ENDIF()
+
# Merge several convenience libraries into one big mysqlclient
-MERGE_CONVENIENCE_LIBRARIES(mysqlclient ${LIBS_TO_MERGE} COMPONENT Development)
+MERGE_CONVENIENCE_LIBRARIES(mysqlclient ${LIBS_TO_MERGE} ${INSTALL_STATIC} COMPONENT Development)
TARGET_LINK_LIBRARIES(mysqlclient PRIVATE ${LIBS_TO_LINK})
# Visual Studio users need debug static library for debug projects
@@ -283,6 +291,7 @@ ENDIF()
# Merge several convenience libraries into one big mysqlclient
# and link them together into shared library.
MERGE_LIBRARIES_SHARED(libmysql ${LIBS_TO_MERGE}
+ ${INSTALL_SHARED}
EXPORTS
${CLIENT_API_FUNCTIONS}
${CLIENT_API_FUNCTIONS_UNDOCUMENTED}
@@ -370,6 +379,7 @@ CONFIGURE_FILE(api_test.c.in ${CMAKE_CURRENT_BINARY_DIR}/api_test.c)
# from @CLIENT_API_FUNCTIONS@ are declared by <mysql.h>. It will fail
# to run if not all of these symbols are exported by the library.
#
+IF (ENABLE_TESTING)
MYSQL_ADD_EXECUTABLE(libmysql_api_test
${CMAKE_CURRENT_BINARY_DIR}/api_test.c
LINK_LIBRARIES libmysql ${LIBRT}
@@ -398,3 +408,4 @@ ADD_CUSTOM_COMMAND(TARGET libmysql_api_test POST_BUILD
COMMAND libmysql_api_test
> ${CMAKE_CURRENT_BINARY_DIR}/libmysql_api_test.out
)
+ENDIF()
\ No newline at end of file
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index a5fa18e..0f2e15c 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -329,13 +329,13 @@ MACRO(EXTRACT_LINK_LIBRARIES target var)
STRING(REGEX REPLACE "^[ ]+" "" ${var} "${${var}}")
STRING(REGEX REPLACE "[ ]+$" "" ${var} "${${var}}")
ENDMACRO()
-
+IF (NOT BUILD_SHARED_LIBS)
EXTRACT_LINK_LIBRARIES(mysqlclient CLIENT_LIBS)
-
-IF(MSVC)
+ENDIF()
+IF(MSVC AND NOT BUILD_SHARED_LIBS)
GET_TARGET_PROPERTY(LIBMYSQL_OS_SHLIB_VERSION mysqlclient VERSION)
GET_TARGET_PROPERTY(LIBMYSQL_OS_OUTPUT_NAME mysqlclient OUTPUT_NAME)
-ELSE()
+ELSEIF(BUILD_SHARED_LIBS)
GET_TARGET_PROPERTY(LIBMYSQL_OS_SHLIB_VERSION libmysql VERSION)
GET_TARGET_PROPERTY(LIBMYSQL_OS_OUTPUT_NAME libmysql OUTPUT_NAME)
ENDIF()

View File

@ -18,6 +18,7 @@ vcpkg_from_github(
ignore-boost-version.patch
system-libs.patch
rename-version.patch
export-cmake-targets.patch
)
file(REMOVE_RECURSE ${SOURCE_PATH}/include/boost_1_70_0)
@ -32,6 +33,9 @@ if(VCPKG_TARGET_IS_WINDOWS)
set(FORCE_UNSUPPORTED_COMPILER 1)
endif()
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC_LIBS)
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" STATIC_CRT_LINKAGE)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
@ -39,22 +43,72 @@ vcpkg_configure_cmake(
-DWITHOUT_SERVER=ON
-DWITH_UNIT_TESTS=OFF
-DENABLED_PROFILING=OFF
-DENABLE_TESTING=OFF
-DWIX_DIR=OFF
${STACK_DIRECTION}
-DIGNORE_BOOST_VERSION=ON
-DWITH_SYSTEMD=OFF
-DWITH_TEST_TRACE_PLUGIN=OFF
-DMYSQL_MAINTAINER_MODE=OFF
-DBUNDLE_RUNTIME_LIBRARIES=OFF
-DDOWNLOAD_BOOST=OFF
-DENABLE_DOWNLOADS=OFF
-DWITH_NDB_TEST=OFF
-DWITH_NDB_NODEJS_DEFAULT=OFF
-DWITH_NDBAPI_EXAMPLES=OFF
-DMYSQLX_ADDITIONAL_TESTS_ENABLE=OFF
-DWITH_SSL=system
-DWITH_ICU=system
-DWITH_LIBEVENT=system
-DWITH_LZ4=system
-DWITH_ZLIB=system
-DFORCE_UNSUPPORTED_COMPILER=${FORCE_UNSUPPORTED_COMPILER}
-DINSTALL_STATIC_LIBRARIES=${BUILD_STATIC_LIBS}
-DLINK_STATIC_RUNTIME_LIBRARIES=${STATIC_CRT_LINKAGE}
)
vcpkg_install_cmake(ADD_BIN_TO_PATH)
# delete debug headers
file(REMOVE_RECURSE
${CURRENT_PACKAGES_DIR}/debug/include)
list(APPEND MYSQL_TOOLS
comp_err
my_print_defaults
mysql
mysql_config_editor
mysql_secure_installation
mysql_ssl_rsa_setup
mysqladmin
mysqlbinlog
mysqlcheck
mysqldump
mysqlimport
mysqlpump
mysqlshow
mysqlslap
mysqltest
perror
zlib_decompress
)
if (VCPKG_TARGET_IS_WINDOWS)
list(APPEND MYSQL_TOOLS
echo
)
else()
list(APPEND MYSQL_TOOLS
mysql_config
)
endif()
vcpkg_copy_tools(TOOL_NAMES ${MYSQL_TOOLS} AUTO_CLEAN)
file(RENAME ${CURRENT_PACKAGES_DIR}/share ${CURRENT_PACKAGES_DIR}/libmysql)
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/share ${CURRENT_PACKAGES_DIR}/debug/libmysql)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/share)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/share)
file(RENAME ${CURRENT_PACKAGES_DIR}/libmysql ${CURRENT_PACKAGES_DIR}/share/libmysql)
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/libmysql ${CURRENT_PACKAGES_DIR}/debug/share/libmysql)
vcpkg_fixup_cmake_targets(CONFIG_PATH share/libmysql/unofficial-libmysql TARGET_PATH share/unofficial-libmysql)
# switch mysql into /mysql
file(RENAME ${CURRENT_PACKAGES_DIR}/include ${CURRENT_PACKAGES_DIR}/include2)
@ -63,52 +117,29 @@ file(RENAME ${CURRENT_PACKAGES_DIR}/include2 ${CURRENT_PACKAGES_DIR}/include/mys
## delete useless vcruntime/scripts/bin/msg file
file(REMOVE_RECURSE
${CURRENT_PACKAGES_DIR}/share
${CURRENT_PACKAGES_DIR}/debug/include
${CURRENT_PACKAGES_DIR}/debug/share
${CURRENT_PACKAGES_DIR}/bin
${CURRENT_PACKAGES_DIR}/debug/bin
${CURRENT_PACKAGES_DIR}/docs
${CURRENT_PACKAGES_DIR}/debug/docs
${CURRENT_PACKAGES_DIR}/lib/debug
${CURRENT_PACKAGES_DIR}/lib/plugin/debug)
${CURRENT_PACKAGES_DIR}/lib/plugin
${CURRENT_PACKAGES_DIR}/lib/plugin/debug
)
## remove misc files
file(REMOVE
${CURRENT_PACKAGES_DIR}/LICENSE
${CURRENT_PACKAGES_DIR}/README
${CURRENT_PACKAGES_DIR}/debug/LICENSE
${CURRENT_PACKAGES_DIR}/debug/README)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE
${CURRENT_PACKAGES_DIR}/lib/libmysql.lib
${CURRENT_PACKAGES_DIR}/lib/libmysql.dll
${CURRENT_PACKAGES_DIR}/lib/libmysql.pdb
${CURRENT_PACKAGES_DIR}/debug/lib/libmysql.lib
${CURRENT_PACKAGES_DIR}/debug/lib/libmysql.dll
${CURRENT_PACKAGES_DIR}/debug/lib/libmysql.pdb)
else()
file(REMOVE
${CURRENT_PACKAGES_DIR}/lib/mysqlclient.lib
${CURRENT_PACKAGES_DIR}/debug/lib/mysqlclient.lib)
# correct the dll directory
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/bin)
file (RENAME ${CURRENT_PACKAGES_DIR}/lib/libmysql.dll ${CURRENT_PACKAGES_DIR}/bin/libmysql.dll)
file (RENAME ${CURRENT_PACKAGES_DIR}/lib/libmysql.pdb ${CURRENT_PACKAGES_DIR}/bin/libmysql.pdb)
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/bin)
file (RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/libmysql.dll ${CURRENT_PACKAGES_DIR}/debug/bin/libmysql.dll)
file (RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/libmysql.pdb ${CURRENT_PACKAGES_DIR}/debug/bin/libmysql.pdb)
endif()
endif()
${CURRENT_PACKAGES_DIR}/debug/README
)
file(READ ${CURRENT_PACKAGES_DIR}/include/mysql/mysql_com.h _contents)
string(REPLACE "#include <mysql/udf_registration_types.h>" "#include \"mysql/udf_registration_types.h\"" _contents "${_contents}")
file(WRITE ${CURRENT_PACKAGES_DIR}/include/mysql/mysql_com.h "${_contents}")
file(INSTALL ${CURRENT_PORT_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
file(INSTALL ${CURRENT_PORT_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
# copy license
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

4
ports/libmysql/usage Normal file
View File

@ -0,0 +1,4 @@
The package libmysql provides CMake targets:
find_package(libmysql REQUIRED)
target_link_libraries(main PRIVATE ${MYSQL_LIBRARIES})

View File

@ -0,0 +1,9 @@
find_package(unofficial-libmysql CONFIG REQUIRED)
if (TARGET mysqlclient)
set(MYSQL_LIBRARY mysqlclient)
elseif (TARGET libmysql)
set(MYSQL_LIBRARY libmysql)
endif()
set(libmysql_FOUND 1)
set(MYSQL_LIBRARIES ${MYSQL_LIBRARY})