drivers initial cmake build

This commit is contained in:
silverqx
2023-12-16 20:42:54 +01:00
parent 43b70d43ba
commit 7990791ed0
15 changed files with 719 additions and 10 deletions

View File

@@ -91,6 +91,20 @@ feature_option(BUILD_TESTS
"Build TinyORM unit tests" OFF
)
# TinyDrivers options
feature_option(BUILD_DRIVERS
"Build TinyORM database drivers that replaces QtSql module" OFF
)
feature_string_option_dependent(DRIVERS_TYPE
"Shared;Loadable;Static"
"Build TinyDrivers database driver (core/common code)" Shared
"BUILD_DRIVERS AND BUILD_SHARED_LIBS" ${TINY_DRIVERS_TYPE_FORCE}
)
feature_option_dependent(BUILD_MYSQL_DRIVER
"Build TinyORM MySQL database driver" ON
"BUILD_DRIVERS" OFF
)
# Depends on tiny_init_cmake_variables_pre() call
feature_option_dependent(MATCH_EQUAL_EXPORTED_BUILDTREE
"Exported package configuration from the build tree is considered to match only \
@@ -281,6 +295,13 @@ else()
target_compile_definitions(${TinyOrm_target} PUBLIC TINYORM_INLINE_CONSTANTS)
endif()
# Using the TinyDrivers instead of QtSql drivers
if(BUILD_DRIVERS)
target_compile_definitions(${TinyOrm_target} PUBLIC TINYORM_USING_TINYDRIVERS)
else()
target_compile_definitions(${TinyOrm_target} PUBLIC TINYORM_USING_QTSQLDRIVERS)
endif()
# Enable code needed by tests, eg. connection overriding in the Model or
# MySqlConnection::setConfigVersion()
if(BUILD_TESTS)
@@ -410,6 +431,13 @@ if(TOM)
target_link_libraries(${TinyOrm_target} PUBLIC tabulate::tabulate)
endif()
# Build TinyDrivers
# ---
if(BUILD_DRIVERS)
add_subdirectory(drivers)
endif()
# Build auto tests
# ---

View File

@@ -43,3 +43,73 @@ macro(feature_option_dependent name description default depends force)
add_feature_info(${name} ${name} "${desc}")
endmacro()
# Macro to provide a STRING type option dependent on other options.
# This macro works the same and as the cmake_dependent_option() but it's for the STRING
# type options instead of BOOL option-s.
# It also sets the set_property(CACHE <option> PROPERTY STRINGS <strings>) to populate
# drop-down combo box for CMake GUI-s.
macro(tiny_dependent_string_option option strings doc default depends force)
set(${option}_AVAILABLE YES)
# Determine whether the given option should be provided and visible (using the full
# Condition Syntax (CMP0127 implementation))
foreach(depend ${depends})
# Don't use the if(NOT ${depend}) without else() block here, the ${depend} can
# contain complex condition and it can break meaning of this condition
cmake_language(EVAL CODE "
if(${depend})
else()
set(${option}_AVAILABLE NO)
endif()"
)
endforeach()
if(${option}_AVAILABLE)
# Restore the previous option value from the INTERNAL cache variable saved earlier
if(DEFINED CACHE{${option}})
set(${option} "${${option}}" CACHE STRING "${doc}" FORCE)
# Use the given <default> value if there is no INTERNAL cache variable defined
else()
set(${option} "${default}" CACHE STRING "${doc}" FORCE)
endif()
# Populate drop-down combo box for CMake GUI-s
set_property(CACHE ${option} PROPERTY STRINGS ${strings})
else()
# Save the current option value to restore it later (if defined) and
# hide the option from a user using the INTERNAL cache variable
if(DEFINED CACHE{${option}})
set(${option} "${${option}}" CACHE INTERNAL "${doc}")
endif()
# Set option value to the <force> value until the option is hidden
set(${option} "${force}")
endif()
unset(${option}_AVAILABLE)
endmacro()
# Helper function for coupling tiny_dependent_string_option() and add_feature_info()
macro(feature_string_option_dependent name strings description default depends force)
set(allowedValues)
string(JOIN ", " allowedValues ${strings})
string(CONCAT desc
"${description} (allowed values: ${allowedValues}; default: ${default}; \
depends on condition: ${depends})")
tiny_dependent_string_option(
${name} "${strings}" "${desc}" "${default}" "${depends}" "${force}"
)
add_feature_info(${name} ${name} "${desc}")
unset(desc)
unset(allowedValues)
endmacro()

View File

@@ -0,0 +1,76 @@
# Initialize TinyDrivers CMake internal cache variables, early initialization
function(tiny_init_driver_types_pre)
set(driversTypeForce DRIVERS_TYPE-NOTFOUND)
# Build the TinyDrivers library as a static archive if the TinyOrm library is built
# as a static archive; also, the DRIVERS_TYPE option will be hidden in this case
# because it can't have any other value
if(BUILD_DRIVERS AND NOT BUILD_SHARED_LIBS)
set(driversTypeForce Static)
endif()
set(TINY_DRIVERS_TYPE_FORCE ${driversTypeForce} CACHE INTERNAL
"Specifies value for the 'force' parameter \
for the feature_string_option_dependent(DRIVERS_TYPE) function")
endfunction()
# Initialize TinyDrivers build types CMake internal cache variables (for nicer if()-s)
function(tiny_init_driver_types)
# Initialize to undefined values instead of OFF if TinyDrivers are not built
if(NOT BUILD_DRIVERS)
set(driversShared TINY_BUILD_SHARED_DRIVERS-NOTFOUND)
set(driversStatic TINY_BUILD_STATIC_DRIVERS-NOTFOUND)
set(driversLoadable TINY_BUILD_LOADABLE_DRIVERS-NOTFOUND)
set(driversLibraryType TINY_BUILD_LOADABLE_DRIVERS-NOTFOUND)
else()
set(driversShared OFF)
set(driversStatic OFF)
set(driversLoadable OFF)
# TinyDrivers library type for the add_library() CMake function
string(TOUPPER "${DRIVERS_TYPE}" driversLibraryType)
# For case-insensitive comparisons
string(TOLOWER "${DRIVERS_TYPE}" driversTypeLower)
# Build as one TinyDrivers shared library with all enabled SQL drivers inside
if(driversTypeLower STREQUAL "shared")
set(driversShared ON)
# Build TinyDrivers as a static archive library (will be linked into the TinyOrm
# shared or static libary)
elseif(driversTypeLower STREQUAL "static")
set(driversStatic ON)
# Build all enabled SQL drivers as loadable shared libraries which will be loaded
# at runtime by the TinyDrivers shared library
elseif(driversTypeLower STREQUAL "loadable")
set(driversLoadable ON)
# TinyDrivers library must be of the SHARED type if building SQL drivers
# as loadable shared libraries
set(driversLibraryType "SHARED")
else()
message(FATAL_ERROR "Unsupported value '${DRIVERS_TYPE}' for
the DRIVERS_TYPE CMake option for ${TinyDrivers_target} library, allowed values are \
Shared, Static, or Loadable (case-insensitive).")
endif()
message(VERBOSE "Building ${TinyDrivers_target} ${driversTypeLower} library")
endif()
set(TINY_BUILD_SHARED_DRIVERS ${driversShared} CACHE INTERNAL
"Determine whether ${TinyDrivers_target} library will be built as a shared \
library with all enabled SQL drivers inside")
set(TINY_BUILD_STATIC_DRIVERS ${driversStatic} CACHE INTERNAL
"Determine whether ${TinyDrivers_target} library will be built as a static \
library that will be linked into the ${TinyOrm_target} shared or static library")
set(TINY_BUILD_LOADABLE_DRIVERS ${driversLoadable} CACHE INTERNAL
"Determine whether all enabled SQL drivers will be built as loadable shared \
libraries which will be loaded at runtime by the ${TinyDrivers_target} shared library")
set(TINY_DRIVERS_LIBRARY_TYPE ${driversLibraryType} CACHE INTERNAL
"Specifies ${TinyDrivers_target} library type for the add_library() CMake \
function")
endfunction()

View File

@@ -1,3 +1,4 @@
include(TinyDrivers)
include(TinyHelpers)
# Initialize default CMake variables on which CMake options depend
@@ -161,12 +162,16 @@ macro(tiny_init_tiny_variables_pre)
# Top level project name, used for alias namespaces, CMAKE_MESSAGE_CONTEXT, or as
# the main package name
set(TinyDrivers_ns TinyDrivers)
set(TinyMySql_ns TinyMySql)
set(TinyOrm_ns TinyOrm)
set(TinyUtils_ns TinyUtils)
set(TomExample_ns tom)
set(TomTestData_ns tom_testdata)
# Target names
set(CommonConfig_target CommonConfig)
set(TinyDrivers_target TinyDrivers)
set(TinyMySql_target TinyMySql)
set(TinyOrm_target TinyOrm)
set(TinyUtils_target TinyUtils)
set(TomExample_target tom)
@@ -211,6 +216,9 @@ macro(tiny_init_tiny_variables_pre)
"Change the default triplet for CMake Integration.")
endif()
# Initialize TinyDrivers CMake internal cache variables, early initialization
tiny_init_driver_types_pre()
endmacro()
# Initialize Tiny variables
@@ -278,6 +286,9 @@ $<SHELL_PATH:${${TinyOrm_ns}_BINARY_DIR}/tests/${TinyUtils_ns}>${TINY_PATH_SEPAR
constants")
unset(tinyExternConstants)
# Specifies which TinyDrivers build type is currently being built (for nicer if()-s)
tiny_init_driver_types()
endmacro()
# Initialize the default database paths for the make:migration/model/seeder commands

View File

@@ -1,3 +1,149 @@
# TinyDrivers library header and source files
# Create header and source files lists and return them
function(tinydrivers_sources out_headers_private out_headers out_sources)
# Private Header files section
set(headers_private)
if(TINY_EXTERN_CONSTANTS)
list(APPEND headers_private constants_extern_p.hpp)
else()
list(APPEND headers_private constants_inline_p.hpp)
endif()
list(APPEND headers_private
constants_p.hpp
macros/declaresqldriverprivate_p.hpp
sqldatabase_p.hpp
sqldriver_p.hpp
sqlresult_p.hpp
support/connectionshash_p.hpp
utils/helpers_p.hpp
utils/type_p.hpp
)
# Header files section
set(headers)
list(APPEND headers
driverstypes.hpp
macros/export.hpp
sqldatabase.hpp
sqldatabasemanager.hpp
sqldriver.hpp
sqldrivererror.hpp
sqlfield.hpp
sqlquery1.hpp
sqlrecord.hpp
sqlresult.hpp
utils/notnull.hpp
version.hpp
)
# Source files section
set(sources)
if(TINY_EXTERN_CONSTANTS)
list(APPEND sources constants_extern_p.cpp)
endif()
list(APPEND sources
sqldatabase.cpp
sqldatabase_p.cpp
sqldatabasemanager.cpp
sqldriver.cpp
sqldrivererror.cpp
sqlfield.cpp
sqlquery1.cpp
sqlrecord.cpp
sqlresult.cpp
sqlresult_p.cpp
utils/type_p.cpp
)
list(SORT headers_private)
list(SORT headers)
list(SORT sources)
set(sourceDir "${${TinyDrivers_ns}_SOURCE_DIR}")
set(suffixDir "orm/drivers/")
list(TRANSFORM headers_private PREPEND "${sourceDir}/include_private/${suffixDir}")
list(TRANSFORM headers PREPEND "${sourceDir}/include/${suffixDir}")
list(TRANSFORM sources PREPEND "${sourceDir}/src/${suffixDir}")
set(${out_headers_private} ${headers_private} PARENT_SCOPE)
set(${out_headers} ${headers} PARENT_SCOPE)
set(${out_sources} ${sources} PARENT_SCOPE)
endfunction()
# TinyMySql library header and source files
# Create header and source files lists and return them
function(tinymysqldriver_sources out_headers_private out_headers out_sources)
# Private Header files section
set(headers_private)
if(TINY_EXTERN_CONSTANTS)
list(APPEND headers_private mysqlconstants_extern_p.hpp)
else()
list(APPEND headers_private mysqlconstants_inline_p.hpp)
endif()
list(APPEND headers_private
macros/includemysqlh_p.hpp
mysqlconstants_p.hpp
mysqldriver_p.hpp
mysqlresult_p.hpp
mysqlutils_p.hpp
)
# Header files section
set(headers)
list(APPEND headers
mysqldriver.hpp
mysqlresult.hpp
version.hpp
)
# Source files section
set(sources)
if(TINY_EXTERN_CONSTANTS)
list(APPEND sources mysqlconstants_extern_p.cpp)
endif()
if(TINY_BUILD_LOADABLE_DRIVERS)
list(APPEND sources main.cpp)
endif()
list(APPEND sources
mysqldriver.cpp
mysqldriver_p.cpp
mysqlresult.cpp
mysqlresult_p.cpp
mysqlutils_p.cpp
)
list(SORT headers_private)
list(SORT headers)
list(SORT sources)
set(sourceDir "${${TinyOrm_ns}_SOURCE_DIR}/drivers/mysql")
set(suffixDir "orm/drivers/mysql/")
list(TRANSFORM headers_private PREPEND "${sourceDir}/include_private/${suffixDir}")
list(TRANSFORM headers PREPEND "${sourceDir}/include/${suffixDir}")
list(TRANSFORM sources PREPEND "${sourceDir}/src/${suffixDir}")
set(${out_headers_private} ${headers_private} PARENT_SCOPE)
set(${out_headers} ${headers} PARENT_SCOPE)
set(${out_sources} ${sources} PARENT_SCOPE)
endfunction()
# TinyORM library header and source files
# Create header and source files lists and return them
function(tinyorm_sources out_headers out_sources)

View File

@@ -4,7 +4,7 @@ include(TinySources)
# Configure a passed auto test
function(tiny_configure_test name)
set(options INCLUDE_MIGRATIONS INCLUDE_MODELS INCLUDE_PROJECT_SOURCE_DIR)
set(options INCLUDE_MIGRATIONS INCLUDE_MODELS INCLUDE_PROJECT_SOURCE_DIR LINK_DRIVERS)
cmake_parse_arguments(PARSE_ARGV 1 TINY "${options}" "" "")
if(DEFINED TINY_UNPARSED_ARGUMENTS)
@@ -95,6 +95,11 @@ ${TINY_UNPARSED_ARGUMENTS}")
${TinyOrm_ns}::${TinyOrm_target}
)
# Explicitly link against the TinyDrivers library
if(TINY_LINK_DRIVERS)
target_link_libraries(${name} PRIVATE ${TinyDrivers_ns}::${TinyDrivers_target})
endif()
# Windows resource and manifest files
# ---

8
drivers/CMakeLists.txt Normal file
View File

@@ -0,0 +1,8 @@
# TinyDrivers database drivers
# ---
add_subdirectory(common)
if(TINY_BUILD_LOADABLE_DRIVERS AND BUILD_MYSQL_DRIVER)
add_subdirectory(mysql)
endif()

View File

@@ -0,0 +1,201 @@
# TinyDrivers database drivers - core/common code
# ---
# Initialize Project Version
# ---
include(TinyHelpers)
tiny_read_version(TINY_VERSION
TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK
VERSION_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/orm/drivers/version.hpp"
PREFIX TINYDRIVERS
HEADER_FOR "${TinyDrivers_ns}"
)
# Basic project
# ---
project(${TinyDrivers_ns}
DESCRIPTION "Database drivers for TinyORM library"
HOMEPAGE_URL "https://www.tinyorm.org"
LANGUAGES CXX
VERSION ${TINY_VERSION}
)
# TinyDrivers library
# ---
add_library(${TinyDrivers_target} ${TINY_DRIVERS_LIBRARY_TYPE})
add_library(${TinyDrivers_ns}::${TinyDrivers_target} ALIAS ${TinyDrivers_target})
# TinyDrivers library header and source files
# ---
include(TinySources)
tinydrivers_sources(
${TinyDrivers_target}_headers_private
${TinyDrivers_target}_headers
${TinyDrivers_target}_sources
)
target_sources(${TinyDrivers_target} PRIVATE
${${TinyDrivers_target}_headers_private}
${${TinyDrivers_target}_headers}
${${TinyDrivers_target}_sources}
)
# Using source files directly to avoid unnecessary static library build and linking
if(NOT TINY_BUILD_LOADABLE_DRIVERS AND BUILD_MYSQL_DRIVER)
tinymysqldriver_sources(
${TinyMySql_target}_headers_private
${TinyMySql_target}_headers
${TinyMySql_target}_sources
)
target_sources(${TinyDrivers_target} PRIVATE
${${TinyMySql_target}_headers_private}
${${TinyMySql_target}_headers}
${${TinyMySql_target}_sources}
)
endif()
# Use Precompiled headers (PCH)
# ---
target_precompile_headers(${TinyDrivers_target}
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:"pch.h">
)
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_compile_definitions(${TinyDrivers_target} PRIVATE TINYDRIVERS_USING_PCH)
endif()
# TinyDrivers library specific configuration
# ---
set_target_properties(${TinyDrivers_target}
PROPERTIES
C_VISIBILITY_PRESET "hidden"
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN YES
VERSION ${PROJECT_VERSION}
SOVERSION 0
EXPORT_NAME ${TinyDrivers_ns}
)
# Append a major version number for shared or static library (Windows/MinGW only)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# TODO use a new CMAKE_DLL_NAME_WITH_SOVERSION in CMake v3.27 silverqx
set_property(
TARGET ${TinyDrivers_target}
PROPERTY OUTPUT_NAME "${TinyDrivers_target}${PROJECT_VERSION_MAJOR}"
)
endif()
target_include_directories(${TinyDrivers_target}
PUBLIC
"$<BUILD_INTERFACE:${${TinyOrm_ns}_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
PRIVATE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include_private>"
)
if(NOT TINY_BUILD_LOADABLE_DRIVERS AND BUILD_MYSQL_DRIVER)
target_include_directories(${TinyDrivers_target}
PRIVATE
"$<BUILD_INTERFACE:${${TinyOrm_ns}_SOURCE_DIR}/drivers/mysql/include>"
"$<BUILD_INTERFACE:${${TinyOrm_ns}_SOURCE_DIR}/drivers/mysql/include_private>"
)
endif()
# TinyDrivers defines
# ---
# No need to set these _NO/_DEBUG macros as PUBLIC because they are used in cpp files only
target_compile_definitions(${TinyDrivers_target}
PUBLIC
PROJECT_TINYDRIVERS
PRIVATE
# Release build
$<$<NOT:$<CONFIG:Debug>>:TINYDRIVERS_NO_DEBUG>
# Debug build
$<$<CONFIG:Debug>:TINYDRIVERS_DEBUG>
# TinyDrivers support these strict Qt macros
QT_ASCII_CAST_WARNINGS
QT_NO_CAST_FROM_ASCII
)
if(TINY_BUILD_SHARED_DRIVERS OR TINY_BUILD_LOADABLE_DRIVERS)
target_compile_definitions(${TinyDrivers_target}
PRIVATE
# TODO cmake uses target_EXPORTS, use cmake convention instead silverqx
TINYDRIVERS_BUILDING_SHARED
INTERFACE
TINYDRIVERS_LINKING_SHARED
)
endif()
# Specifies which global constant types will be used
if(TINY_EXTERN_CONSTANTS)
target_compile_definitions(${TinyDrivers_target} PRIVATE TINYDRIVERS_EXTERN_CONSTANTS)
else()
target_compile_definitions(${TinyDrivers_target} PRIVATE TINYDRIVERS_INLINE_CONSTANTS)
endif()
if(TINY_BUILD_LOADABLE_DRIVERS AND BUILD_MYSQL_DRIVER)
target_compile_definitions(${TinyDrivers_target}
PRIVATE
TINYDRIVERS_MYSQL_LOADABLE_LIBRARY
# Don't user quotes around the path here
TINYDRIVERS_MYSQL_PATH=${CMAKE_BINARY_DIR}/drivers/mysql/
)
endif()
# Enable code needed by tests (not used)
if(BUILD_TESTS)
target_compile_definitions(${TinyDrivers_target} PRIVATE TINYDRIVERS_TESTS_CODE)
endif()
# Windows resource and manifest files
# ---
# Find icons, orm/version.hpp, and Windows manifest file for MinGW
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
tiny_set_rc_flags("-I \"${PROJECT_SOURCE_DIR}/resources\"")
endif()
include(TinyResourceAndManifest)
tiny_resource_and_manifest(${TinyDrivers_target}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
)
# Resolve and link dependencies
# ---
# Must be before the TinyCommon, to exclude WINVER for the MSYS2 Qt6 builds to avoid:
# 'WINVER' macro redefined [-Wmacro-redefined]
# Look also to the TinyCommon for conditional WINVER definition
find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
tiny_find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} CONFIG
REQUIRED COMPONENTS Core
)
# Unconditional dependencies
target_link_libraries(${TinyDrivers_target} PUBLIC Qt${QT_VERSION_MAJOR}::Core)
# Conditional dependencies
if(STRICT_MODE)
target_link_libraries(${TinyDrivers_target}
PUBLIC ${TinyOrm_ns}::${CommonConfig_target}
)
else()
target_link_libraries(${TinyDrivers_target}
PRIVATE ${TinyOrm_ns}::${CommonConfig_target}
)
endif()
# The PRIVATE MySQL dependency is propagated for TinyDrivers library static build
if(NOT TINY_BUILD_LOADABLE_DRIVERS AND BUILD_MYSQL_DRIVER)
tiny_find_package(MySQL REQUIRED)
target_link_libraries(${TinyDrivers_target} PRIVATE MySQL::MySQL)
endif()

View File

@@ -80,7 +80,7 @@ namespace Orm::Drivers::Support
ConnectionsHash::at_ts(const key_type &key)
{
// Shared/read lock
std::shared_lock lock(m_mutex);
const std::shared_lock lock(m_mutex);
return m_data.at(key);
}
@@ -89,7 +89,7 @@ namespace Orm::Drivers::Support
ConnectionsHash::at_ts(const key_type &key) const
{
// Shared/read lock
std::shared_lock lock(m_mutex);
const std::shared_lock lock(m_mutex);
return m_data.at(key);
}
@@ -102,7 +102,7 @@ namespace Orm::Drivers::Support
bool ConnectionsHash::contains_ts(const key_type &key) const
{
// Shared/read lock
std::shared_lock lock(m_mutex);
const std::shared_lock lock(m_mutex);
return m_data.contains(key);
}
@@ -110,10 +110,10 @@ namespace Orm::Drivers::Support
QStringList ConnectionsHash::keys_ts() const
{
// Shared/read lock
std::shared_lock lock(m_mutex);
const std::shared_lock lock(m_mutex);
QStringList result;
result.reserve(m_data.size());
result.reserve(static_cast<QStringList::size_type>(m_data.size()));
for (const auto &[key, _] : m_data)
result << key;

View File

@@ -0,0 +1,159 @@
# TinyMySql database driver
# ---
# All include and link dependencies can be PRIVATE because the TinyMySql library will be
# only used as a loadable shared library (aka. add_library(MODULE)), so we don't need to
# propagate these dependencies anywhere
# Initialize Project Version
# ---
include(TinyHelpers)
tiny_read_version(TINY_VERSION
TINY_VERSION_MAJOR TINY_VERSION_MINOR TINY_VERSION_PATCH TINY_VERSION_TWEAK
VERSION_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/orm/drivers/mysql/version.hpp"
PREFIX TINYMYSQL
HEADER_FOR "${TinyMySql_ns}"
)
# Basic project
# ---
project(${TinyMySql_ns}
DESCRIPTION "MySQL driver for TinyORM library"
HOMEPAGE_URL "https://www.tinyorm.org"
LANGUAGES CXX
VERSION ${TINY_VERSION}
)
# TinyMySql library
# ---
add_library(${TinyMySql_target} MODULE)
add_library(${TinyMySql_ns}::${TinyMySql_target} ALIAS ${TinyMySql_target})
# TinyMySql library header and source files
# ---
include(TinySources)
tinymysqldriver_sources(
${TinyMySql_target}_headers_private
${TinyMySql_target}_headers
${TinyMySql_target}_sources
)
target_sources(${TinyMySql_target} PRIVATE
${${TinyMySql_target}_headers_private}
${${TinyMySql_target}_headers}
${${TinyMySql_target}_sources}
)
# Use Precompiled headers (PCH)
# ---
target_precompile_headers(${TinyMySql_target}
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:"pch.h">
)
if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_compile_definitions(${TinyMySql_target} PRIVATE TINYMYSQL_USING_PCH)
endif()
# TinyMySql library specific configuration
# ---
set_target_properties(${TinyMySql_target}
PROPERTIES
C_VISIBILITY_PRESET "hidden"
CXX_VISIBILITY_PRESET "hidden"
VISIBILITY_INLINES_HIDDEN YES
VERSION ${PROJECT_VERSION}
SOVERSION 0
EXPORT_NAME ${TinyMySql_ns}
)
# Append a major version number for shared or static library (Windows/MinGW only)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# TODO use a new CMAKE_DLL_NAME_WITH_SOVERSION in CMake v3.27 silverqx
set_property(
TARGET ${TinyMySql_target}
PROPERTY OUTPUT_NAME "${TinyMySql_target}${PROJECT_VERSION_MAJOR}"
)
endif()
target_include_directories(${TinyMySql_target}
PRIVATE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include_private>"
"$<BUILD_INTERFACE:${${TinyOrm_ns}_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${${TinyOrm_ns}_SOURCE_DIR}/drivers/common/include_private>"
)
# TinyMySql defines
# ---
target_compile_definitions(${TinyMySql_target}
PUBLIC
PROJECT_TINYMYSQL
PRIVATE
# Release build
$<$<NOT:$<CONFIG:Debug>>:TINYDRIVERS_NO_DEBUG>
# Debug build
$<$<CONFIG:Debug>:TINYDRIVERS_DEBUG>
# TinyMySql support these strict Qt macros
QT_ASCII_CAST_WARNINGS
QT_NO_CAST_FROM_ASCII
# TinyMySql defines
TINYDRIVERS_MYSQL_LOADABLE_LIBRARY
)
target_compile_definitions(${TinyMySql_target}
PRIVATE
# TODO cmake uses target_EXPORTS, use cmake convention instead silverqx
TINYDRIVERS_BUILDING_SHARED
)
# Specifies which global constant types will be used
if(TINY_EXTERN_CONSTANTS)
target_compile_definitions(${TinyMySql_target} PRIVATE TINYDRIVERS_EXTERN_CONSTANTS)
else()
target_compile_definitions(${TinyMySql_target} PRIVATE TINYDRIVERS_INLINE_CONSTANTS)
endif()
# Enable code needed by tests (not used)
if(BUILD_TESTS)
target_compile_definitions(${TinyMySql_target} PRIVATE TINYDRIVERS_TESTS_CODE)
endif()
# Windows resource and manifest files
# ---
# Find icons, orm/version.hpp, and Windows manifest file for MinGW
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
tiny_set_rc_flags("-I \"${PROJECT_SOURCE_DIR}/resources\"")
endif()
include(TinyResourceAndManifest)
tiny_resource_and_manifest(${TinyMySql_target}
OUTPUT_DIR "${TINY_BUILD_GENDIR}/tmp/"
)
# Resolve and link dependencies
# ---
# Must be before the TinyCommon, to exclude WINVER for the MSYS2 Qt6 builds to avoid:
# 'WINVER' macro redefined [-Wmacro-redefined]
# Look also to the TinyCommon for conditional WINVER definition
find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
tiny_find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} CONFIG
REQUIRED COMPONENTS Core
)
tiny_find_package(MySQL REQUIRED)
# Unconditional dependencies
target_link_libraries(${TinyMySql_target}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
MySQL::MySQL
${TinyOrm_ns}::${CommonConfig_target}
${TinyDrivers_ns}::${TinyDrivers_target}
)

View File

@@ -1,6 +1,10 @@
add_subdirectory(orm)
add_subdirectory(others)
if(BUILD_DRIVERS)
add_subdirectory(drivers)
endif()
if(TOM)
add_subdirectory(tom)
endif()

View File

@@ -1 +1,2 @@
add_subdirectory(sqlquery_normal)
add_subdirectory(sqlquery_prepared)

View File

@@ -9,4 +9,4 @@ add_executable(sqlquery_normal
add_test(NAME sqlquery_normal COMMAND sqlquery_normal)
include(TinyTestCommon)
tiny_configure_test(sqlquery_normal)
tiny_configure_test(sqlquery_normal LINK_DRIVERS)

View File

@@ -9,4 +9,4 @@ add_executable(sqlquery_prepared
add_test(NAME sqlquery_prepared COMMAND sqlquery_prepared)
include(TinyTestCommon)
tiny_configure_test(sqlquery_prepared)
tiny_configure_test(sqlquery_prepared LINK_DRIVERS)

View File

@@ -12,9 +12,9 @@ Param(
[string] $TodoKeywordsPattern = ' (TODO|NOTE|FIXME|BUG|WARNING|CUR|FEATURE|TEST|FUTURE|CUR1|TMP|SEC) ',
[Parameter(HelpMessage = 'Specifies subfolders to search. The pattern value is used ' +
'in regular expression, eg. (examples|include|src|tests|tom).')]
'in regular expression, eg. (drivers|examples|include|src|tests|tom).')]
[AllowEmptyString()]
[string] $InSubFoldersPattern = '(examples|include|src|tests|tom)'
[string] $InSubFoldersPattern = '(drivers|examples|include|src|tests|tom)'
)
Set-StrictMode -Version 3.0