Skip to content

Commit

Permalink
[soci] Fix dependencies in, intern, out (microsoft#34327)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt authored Oct 11, 2023
1 parent dfc21e3 commit 64c330e
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 73 deletions.
100 changes: 100 additions & 0 deletions ports/soci/dependencies.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
diff --git a/cmake/dependencies/Boost.cmake b/cmake/dependencies/Boost.cmake
index 366d32b..7ff041b 100644
--- a/cmake/dependencies/Boost.cmake
+++ b/cmake/dependencies/Boost.cmake
@@ -10,4 +10,6 @@ endif()
set(Boost_RELEASE_VERSION
"${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")

+set(BOOST_FOUND "${Boost_FOUND}")
+set(BOOST_LIBRARIES "${Boost_LIBRARIES}")
boost_external_report(Boost RELEASE_VERSION INCLUDE_DIR LIBRARIES)
diff --git a/cmake/dependencies/MySQL.cmake b/cmake/dependencies/MySQL.cmake
index 5599b08..0a4ce0f 100644
--- a/cmake/dependencies/MySQL.cmake
+++ b/cmake/dependencies/MySQL.cmake
@@ -1,5 +1,9 @@
set(MySQL_FIND_QUIETLY TRUE)

-find_package(MySQL)
+find_package(MYSQL NAMES unofficial-libmysql REQUIRED)
+set(MYSQL_LIBRARIES "$<TARGET_NAME:libmysql>")
+if(TARGET mysqlclient AND NOT TARGET libmysql)
+ set(MYSQL_LIBRARIES "$<TARGET_NAME:mysqlclient>")
+endif()

boost_external_report(MySQL INCLUDE_DIR LIBRARIES)
diff --git a/cmake/dependencies/PostgreSQL.cmake b/cmake/dependencies/PostgreSQL.cmake
index c6f2154..ef6bfcd 100644
--- a/cmake/dependencies/PostgreSQL.cmake
+++ b/cmake/dependencies/PostgreSQL.cmake
@@ -1,5 +1,8 @@
set(PostgreSQL_FIND_QUIETLY TRUE)

-find_package(PostgreSQL)
+find_package(PostgreSQL REQUIRED)
+set(POSTGRESQL_FOUND TRUE)
+set(POSTGRESQL_INCLUDE_DIRS "${PostgreSQL_INCLUDE_DIRS}")
+set(POSTGRESQL_LIBRARIES "${PostgreSQL_LIBRARIES}")

boost_external_report(PostgreSQL INCLUDE_DIRS LIBRARIES VERSION)
diff --git a/cmake/dependencies/SQLite3.cmake b/cmake/dependencies/SQLite3.cmake
index 0daa9a5..17775da 100644
--- a/cmake/dependencies/SQLite3.cmake
+++ b/cmake/dependencies/SQLite3.cmake
@@ -1,5 +1,6 @@
set(SQLITE3_FIND_QUIETLY TRUE)

-find_package(SQLite3)
+find_package(SQLITE3 NAMES unofficial-sqlite3 CONFIG REQUIRED)
+set(SQLITE3_LIBRARIES unofficial::sqlite3::sqlite3)

boost_external_report(SQLite3 INCLUDE_DIR LIBRARIES)
diff --git a/cmake/resources/SOCIConfig.cmake.in b/cmake/resources/SOCIConfig.cmake.in
index 8096a3c..354c18b 100644
--- a/cmake/resources/SOCIConfig.cmake.in
+++ b/cmake/resources/SOCIConfig.cmake.in
@@ -1,3 +1,11 @@
@PACKAGE_INIT@

+include(CMakeFindDependencyMacro)
+if("@WITH_MYSQL@")
+ find_dependency(unofficial-libmysql)
+endif()
+if("@WITH_SQLITE3@")
+ find_dependency(unofficial-sqlite3)
+endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/SOCITargets.cmake)
diff --git a/include/soci/mysql/soci-mysql.h b/include/soci/mysql/soci-mysql.h
index 376bb7e..fbe48fa 100644
--- a/include/soci/mysql/soci-mysql.h
+++ b/include/soci/mysql/soci-mysql.h
@@ -21,8 +21,8 @@
#ifdef _WIN32
#include <winsock.h> // SOCKET
#endif // _WIN32
-#include <mysql.h> // MySQL Client
-#include <errmsg.h> // MySQL Error codes
+#include <mysql/mysql.h> // MySQL Client
+#include <mysql/errmsg.h> // MySQL Error codes
#include <vector>


diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt
index 871e151..3cffc80 100644
--- a/src/backends/CMakeLists.txt
+++ b/src/backends/CMakeLists.txt
@@ -14,9 +14,9 @@ colormsg(_HIBLUE_ "Configuring SOCI backend libraries:")
foreach(dep ${SOCI_BACKENDS_DB_DEPENDENCIES})
string(TOUPPER ${dep} depUP)
if (WITH_${depUP})
- find_package(${dep})
- endif()
- if(${dep}_FOUND OR ${depUP}_FOUND)
+ if(NOT (${dep}_FOUND OR ${depUP}_FOUND))
+ message(FATAL_ERROR "${depUP} not found, check SociDependencies.cmake")
+ endif()
set(${depUP}_FOUND ON)
else()
set(${depUP}_FOUND OFF)
14 changes: 0 additions & 14 deletions ports/soci/fix-dependency-libmysql.patch

This file was deleted.

12 changes: 0 additions & 12 deletions ports/soci/fix-mysql-feature-error.patch

This file was deleted.

69 changes: 37 additions & 32 deletions ports/soci/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,62 @@ vcpkg_from_github(
SHA512 d501f55e7e7408e46b4823fd8a97d6ef587f5db0f5b98434be8dfc5693c91b8c3b84a24454279c83142ab1cd1fa139c6e54d6d9a67397b2ead61650fcc88bcdb
HEAD_REF master
PATCHES
fix-dependency-libmysql.patch
export-include-dirs.patch
fix-mysql-feature-error.patch # https://bugs.mysql.com/bug.php?id=85131
dependencies.diff
usage-requirements.diff
)
file(REMOVE
"${SOURCE_PATH}/cmake/modules/FindPostgreSQL.cmake"
)

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" SOCI_DYNAMIC)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" SOCI_STATIC)

# Handle features
set(_COMPONENT_FLAGS "")
foreach(_feature IN LISTS ALL_FEATURES)
# Uppercase the feature name and replace "-" with "_"
string(TOUPPER "${_feature}" _FEATURE)
string(REPLACE "-" "_" _FEATURE "${_FEATURE}")

# Turn "-DWITH_*=" ON or OFF depending on whether the feature
# is in the list.
if(_feature IN_LIST FEATURES)
list(APPEND _COMPONENT_FLAGS "-DWITH_${_FEATURE}=ON")
else()
list(APPEND _COMPONENT_FLAGS "-DWITH_${_FEATURE}=OFF")
endif()

if(_feature MATCHES "mysql")
set(MYSQL_OPT "-DMYSQL_INCLUDE_DIR=${CURRENT_INSTALLED_DIR}/include/mysql")
endif()
endforeach()
vcpkg_check_features(OUT_FEATURE_OPTIONS options
FEATURES
boost WITH_BOOST
boost CMAKE_REQUIRE_FIND_PACKAGE_Boost
empty SOCI_EMPTY
mysql WITH_MYSQL
odbc WITH_ODBC
odbc CMAKE_REQUIRE_FIND_PACKAGE_ODBC
postgresql WITH_POSTGRESQL
sqlite3 WITH_SQLITE3
INVERTED_FEATURES
core WITH_DB2
core WITH_FIREBIRD
core WITH_ORACLE
core WITH_VALGRIND
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DSOCI_TESTS=OFF
-DSOCI_CXX11=ON
-DSOCI_STATIC=${SOCI_STATIC}
-DSOCI_SHARED=${SOCI_DYNAMIC}
${_COMPONENT_FLAGS}
${MYSQL_OPT}
-DSOCI_STATIC=${SOCI_STATIC}
-DSOCI_TESTS=OFF
${options}
MAYBE_UNUSED_VARIABLES
CMAKE_REQUIRE_FIND_PACKAGE_Boost
CMAKE_REQUIRE_FIND_PACKAGE_ODBC
)

vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/SOCI)

if ("mysql" IN_LIST FEATURES)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/SOCIConfig.cmake"
"# Create imported target SOCI::soci_mysql"
"\ninclude(CMakeFindDependencyMacro)\nfind_dependency(libmysql)\n# Create imported target SOCI::soci_mysql"
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/soci/soci-platform.h" "ifdef SOCI_DLL" "if 1")
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

# Handle copyright
set(backends ${FEATURES})
list(REMOVE_ITEM backends core boost)
if(backends STREQUAL "")
message(STATUS "Attention:\n\nThis soci build doesn't include any backends.\n")
set(backends "none")
endif()
configure_file("${CURRENT_PORT_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" @ONLY)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE_1_0.txt")
7 changes: 7 additions & 0 deletions ports/soci/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
soci provides CMake targets:

find_package(soci CONFIG REQUIRED)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_core>,SOCI::soci_core,SOCI::soci_core_static>)

# Linking specific backends (enabled: @backends@)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_<BACKEND>,SOCI::soci_<BACKEND>,SOCI::soci_<BACKEND>_static>)
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
diff --git a/cmake/SociBackend.cmake b/cmake/SociBackend.cmake
index 5d4ef0d..bb0edf2 100644
index 5d4ef0d..279cb75 100644
--- a/cmake/SociBackend.cmake
+++ b/cmake/SociBackend.cmake
@@ -159,8 +159,14 @@ macro(soci_backend NAME)
@@ -159,8 +159,13 @@ macro(soci_backend NAME)
${THIS_BACKEND_HEADERS})

target_link_libraries(${THIS_BACKEND_TARGET}
+ PUBLIC
${SOCI_CORE_TARGET}
${THIS_BACKEND_DEPENDS_LIBRARIES})
+
+ target_include_directories(${THIS_BACKEND_TARGET}
+ PUBLIC
+ ${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}
+ )

if(WIN32)
set_target_properties(${THIS_BACKEND_TARGET}
@@ -197,9 +203,15 @@ macro(soci_backend NAME)
@@ -197,8 +202,14 @@ macro(soci_backend NAME)

# Still need to link the libraries for tests to work
target_link_libraries (${THIS_BACKEND_TARGET_STATIC}
+ PUBLIC
+ ${SOCI_CORE_TARGET}_static
${THIS_BACKEND_DEPENDS_LIBRARIES}
)
-
+
+ target_include_directories(${THIS_BACKEND_TARGET_STATIC}
+ PUBLIC
+ ${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}
+ )
+

set_target_properties(${THIS_BACKEND_TARGET_STATIC}
PROPERTIES
OUTPUT_NAME ${THIS_BACKEND_OUTPUT_NAME}
27 changes: 21 additions & 6 deletions ports/soci/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "soci",
"version": "4.0.3",
"port-version": 1,
"description": "SOCI database access library",
"homepage": "https://github.com/SOCI/soci",
"port-version": 2,
"description": "SOCI - The C++ Database Access Library",
"homepage": "https://soci.sourceforge.net/",
"license": "BSL-1.0",
"dependencies": [
{
Expand All @@ -26,6 +26,9 @@
"boost-tuple"
]
},
"empty": {
"description": "Build the backend skeleton for new backends development"
},
"mysql": {
"description": "Build mysql backend",
"dependencies": [
Expand All @@ -34,18 +37,30 @@
},
"odbc": {
"description": "Build odbc backend",
"supports": "!uwp"
"supports": "!uwp",
"dependencies": [
{
"name": "unixodbc",
"platform": "!windows"
}
]
},
"postgresql": {
"description": "Build postgresql backend",
"dependencies": [
"libpq"
{
"name": "libpq",
"default-features": false
}
]
},
"sqlite3": {
"description": "Build sqlite3 backend",
"dependencies": [
"sqlite3"
{
"name": "sqlite3",
"default-features": false
}
]
}
}
Expand Down
5 changes: 5 additions & 0 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,11 @@ vcpkg-ci-paraview:x64-windows-static-md=pass
vcpkg-ci-paraview:x64-windows-static=pass
vcpkg-ci-paraview:x64-windows=pass
vcpkg-ci-paraview:x86-windows=pass
vcpkg-ci-soci:x64-linux=pass
vcpkg-ci-soci:x64-osx=pass
vcpkg-ci-soci:x64-windows=pass
vcpkg-ci-soci:x64-windows-static=pass
vcpkg-ci-soci:x64-windows-static-md=pass
vcpkg-ci-wxwidgets:arm64-windows=pass
vcpkg-ci-wxwidgets:x64-linux=pass
vcpkg-ci-wxwidgets:x64-osx=pass
Expand Down
4 changes: 4 additions & 0 deletions scripts/test_ports/vcpkg-ci-soci/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

vcpkg_cmake_configure(SOURCE_PATH "${CURRENT_PORT_DIR}/project")
vcpkg_cmake_build()
13 changes: 13 additions & 0 deletions scripts/test_ports/vcpkg-ci-soci/project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.7)
project(soci-test CXX)

if(APPLE)
set(CMAKE_CXX_STANDARD 11)
endif()

add_executable(main main.cpp)

find_package(SOCI CONFIG REQUIRED)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_mysql>,SOCI::soci_mysql,SOCI::soci_mysql_static>)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_postgresql>,SOCI::soci_postgresql,SOCI::soci_postgresql_static>)
target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:SOCI::soci_sqlite3>,SOCI::soci_sqlite3,SOCI::soci_sqlite3_static>)
11 changes: 11 additions & 0 deletions scripts/test_ports/vcpkg-ci-soci/project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <soci/soci.h>
#include <soci/mysql/soci-mysql.h>
#include <soci/postgresql/soci-postgresql.h>
#include <soci/sqlite3/soci-sqlite3.h>

int main()
{
soci::session mysql_db(soci::mysql, "test:mysql");
soci::session pgsql_db(soci::postgresql, "test:postgresql");
soci::session sqlite3_db(soci::sqlite3, "test.db");
}
20 changes: 20 additions & 0 deletions scripts/test_ports/vcpkg-ci-soci/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "vcpkg-ci-soci",
"version-string": "ci",
"description": "Validates soci",
"supports": "x64 & (linux | osx | windows) & !uwp",
"dependencies": [
{
"name": "soci",
"features": [
"mysql",
"postgresql",
"sqlite3"
]
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}
Loading

0 comments on commit 64c330e

Please sign in to comment.