added cmake build 😅💪
@@ -30,6 +30,7 @@ qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
!/resources/TinyOrm.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
# Policies <= CMP0126 default to NEW
|
||||
cmake_minimum_required(VERSION 3.21...3.21 FATAL_ERROR)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonModules"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
|
||||
)
|
||||
|
||||
# Basic project and cmake build setup
|
||||
# ---
|
||||
|
||||
# TODO add support for POSITION_INDEPENDENT_CODE silverqx
|
||||
project(TinyOrm
|
||||
DESCRIPTION "c++ ORM library for Qt framework"
|
||||
HOMEPAGE_URL "https://silverqx.github.io/TinyORM/"
|
||||
LANGUAGES CXX
|
||||
VERSION 0.1.0.0
|
||||
)
|
||||
|
||||
# Specify the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
# Version requirements - older vesions may work, but you are on your own
|
||||
set(minMsvcVersion 19.28)
|
||||
set(minQtVersion 5.15.2)
|
||||
set(minRangeV3Version 0.11.0)
|
||||
|
||||
include(TinyHelpers)
|
||||
# Make minimum toolchain version a requirement
|
||||
tiny_toolchain_requirement(MSVC ${minMsvcVersion})
|
||||
|
||||
# TinyORM build options
|
||||
# ---
|
||||
|
||||
include(FeatureSummary)
|
||||
include(TinyFeatureOptions)
|
||||
|
||||
feature_option(BUILD_SHARED_LIBS
|
||||
"Build using shared libraries" ON)
|
||||
feature_option(BUILD_TESTS
|
||||
"Build Qt tests" OFF)
|
||||
# "Build Qt tests" ON)
|
||||
feature_option(EXPORT_PACKAGE_REGISTRY
|
||||
"Store the current build directory in the CMake User Package Registry" ON)
|
||||
feature_option(MSVC_RUNTIME_DYNAMIC
|
||||
"Use MSVC dynamic runtime library (-MD) instead of static (-MT)" ON)
|
||||
feature_option(PRECOMPILE_HEADERS
|
||||
"Enables support for the use of precompiled headers." ON)
|
||||
feature_option(VERBOSE_CONFIGURE
|
||||
"Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure \
|
||||
output" OFF)
|
||||
|
||||
mark_as_advanced(EXPORT_PACKAGE_REGISTRY)
|
||||
|
||||
# MSVC_PARALLEL option
|
||||
include(TinyMsvcParallel)
|
||||
tiny_msvc_parallel("\
|
||||
Enables /MP flag for parallel builds using MSVC. Specify an \
|
||||
integer value to control the number of threads used (Only \
|
||||
works on some older versions of Visual Studio). Setting to \
|
||||
ON lets the toolchain decide how many threads to use. Set to \
|
||||
OFF to disable /MP completely.")
|
||||
|
||||
# Initialize Tiny and default cmake variables
|
||||
include(TinyInitDefaultVariables)
|
||||
tiny_init_cmake_variables()
|
||||
tiny_init_tiny_variables()
|
||||
|
||||
# TinyORM library header and source files
|
||||
# ---
|
||||
|
||||
include(TinySources)
|
||||
tiny_sources()
|
||||
|
||||
set(TinyOrm_target TinyOrm)
|
||||
add_library(${TinyOrm_target}
|
||||
${headers}
|
||||
${sources}
|
||||
)
|
||||
add_library(TinyOrm::TinyOrm ALIAS ${TinyOrm_target})
|
||||
|
||||
target_compile_features(${TinyOrm_target} PUBLIC cxx_std_20)
|
||||
|
||||
# TinyORM build options - target is needed
|
||||
# ---
|
||||
|
||||
target_optional_compile_definitions(${TinyOrm_target} PUBLIC
|
||||
FEATURE NAME MYSQL_PING DEFAULT OFF
|
||||
DESCRIPTION "Enable MySQL ping on Orm::MySqlConnection"
|
||||
ENABLED TINYORM_MYSQL_PING
|
||||
)
|
||||
|
||||
# Use Precompiled headers (PCH)
|
||||
# ---
|
||||
|
||||
target_precompile_headers(${TinyOrm_target} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:"pch.h">)
|
||||
|
||||
if(PRECOMPILE_HEADERS)
|
||||
target_compile_definitions(${TinyOrm_target} PRIVATE USING_PCH)
|
||||
endif()
|
||||
|
||||
# TinyORM library specific configuration
|
||||
# ---
|
||||
|
||||
set_target_properties(${TinyOrm_target}
|
||||
PROPERTIES
|
||||
C_VISIBILITY_PRESET "hidden"
|
||||
CXX_VISIBILITY_PRESET "hidden"
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION 0
|
||||
EXPORT_NAME TinyOrm
|
||||
)
|
||||
|
||||
# Append a major version number for Windows shared libraries only
|
||||
tiny_init_target_version_ext(${TinyOrm_target})
|
||||
if(${TinyOrm_target}_VERSION_EXT)
|
||||
set_property(
|
||||
TARGET ${TinyOrm_target}
|
||||
PROPERTY OUTPUT_NAME "${TinyOrm_target}${PROJECT_VERSION_MAJOR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(${TinyOrm_target} PUBLIC
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
|
||||
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
# TinyORM defines
|
||||
# ---
|
||||
|
||||
target_compile_definitions(${TinyOrm_target}
|
||||
PUBLIC
|
||||
PROJECT_TINYORM
|
||||
# Log queries with a time measurement
|
||||
TINYORM_DEBUG_SQL
|
||||
)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(${TinyOrm_target}
|
||||
PRIVATE
|
||||
# TODO cmake uses target_EXPORTS, use cmake convention instead silverqx
|
||||
TINYORM_BUILDING_SHARED
|
||||
INTERFACE
|
||||
TINYORM_LINKING_SHARED
|
||||
)
|
||||
endif()
|
||||
|
||||
# Enable code needed by tests, eg. connection overriding in the Model
|
||||
if(BUILD_TESTS)
|
||||
target_compile_definitions(${TinyOrm_target} PUBLIC TINYORM_TESTS_CODE)
|
||||
endif()
|
||||
|
||||
# File version and Windows resource and manifest
|
||||
# ---
|
||||
|
||||
include(TinyFileVersionAndManifest)
|
||||
tiny_file_version_and_manifest(${TinyOrm_target} "include/orm/")
|
||||
|
||||
# Resolve and link dependencies
|
||||
# ---
|
||||
|
||||
# Common configuration as interface library
|
||||
include(TinyQtCommon)
|
||||
set(CommonConfig_target CommonConfig)
|
||||
tiny_qt_common(${CommonConfig_target}
|
||||
NAMESPACE TinyOrm
|
||||
EXPORT NAME CommonConfig
|
||||
)
|
||||
|
||||
# Unconditional dependencies
|
||||
find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core Sql)
|
||||
tiny_find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} CONFIG
|
||||
REQUIRED COMPONENTS Core Sql
|
||||
)
|
||||
tiny_find_package(range-v3 ${minRangeV3Version} CONFIG REQUIRED)
|
||||
|
||||
target_link_libraries(${TinyOrm_target}
|
||||
PUBLIC
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
range-v3::range-v3
|
||||
TinyOrm::CommonConfig
|
||||
)
|
||||
|
||||
# Conditional dependencies
|
||||
if(MYSQL_PING)
|
||||
tiny_find_package(MySQL REQUIRED)
|
||||
target_link_libraries(${TinyOrm_target} PRIVATE MySQL::MySQL)
|
||||
endif()
|
||||
|
||||
# Build auto tests
|
||||
# ---
|
||||
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
find_package(Qt${QT_VERSION_MAJOR} ${minQtVersion} REQUIRED COMPONENTS Test)
|
||||
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# Deployment
|
||||
# ---
|
||||
|
||||
include(TinyDeployment)
|
||||
|
||||
# Generate find_dependency calls for the TinyORM package config file
|
||||
tiny_generate_find_dependency_calls()
|
||||
|
||||
# Create Package Config and Config Package Version files and install the TinyORM Project
|
||||
tiny_install_tinyorm()
|
||||
|
||||
# Create Package Config and Package Config Version files for the Build Tree and export it
|
||||
tiny_export_build_tree()
|
||||
|
||||
# Generate pkg-config file
|
||||
#if (NOT MSVC)
|
||||
# generate_and_install_pkg_config_file(torrent-rasterbar libtorrent-rasterbar)
|
||||
#endif()
|
||||
|
||||
# Some info output
|
||||
# ---
|
||||
|
||||
set_package_properties(Qt${QT_VERSION_MAJOR}
|
||||
PROPERTIES
|
||||
URL "https://doc.qt.io/qt-${QT_VERSION_MAJOR}/"
|
||||
DESCRIPTION "Qt is a full development framework"
|
||||
TYPE REQUIRED
|
||||
PURPOSE "Provides SQL database layer by the QtSql module, QVariant, and QString"
|
||||
)
|
||||
set_package_properties(range-v3
|
||||
PROPERTIES
|
||||
URL "https://ericniebler.github.io/range-v3/"
|
||||
DESCRIPTION "Range algorithms, views, and actions for STL"
|
||||
TYPE REQUIRED
|
||||
PURPOSE "Used to have a nice and clear code"
|
||||
)
|
||||
if(MYSQL_PING)
|
||||
set_package_properties(MySQL
|
||||
PROPERTIES
|
||||
TYPE REQUIRED
|
||||
PURPOSE "Provides MySQL ping, enables MySqlConnection::pingDatabase()"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(VERBOSE_CONFIGURE)
|
||||
# TODO test with CMAKE_CONFIGURATION_TYPES, multi config generators silverqx
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message(STATUS "Disabling debug output")
|
||||
endif()
|
||||
|
||||
feature_summary(WHAT ALL)
|
||||
else()
|
||||
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
|
||||
endif()
|
||||
@@ -1,7 +1,7 @@
|
||||
Todos to check in TinyOrm:
|
||||
--------------------------
|
||||
|
||||
- QueryBuilder::insertGetId() allows insert with empty attributes, also Model::performInsert()
|
||||
- QueryBuilder::insertGetId() allows insert with empty attributes, also Model::performInsert()
|
||||
when incrementing == true, but all other insert methods don't, it's big inconsistency, unify it
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ void deleteModel()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
- check this in cmake build:
|
||||
#include(GenerateExportHeader)
|
||||
#_test_compiler_hidden_visibility()
|
||||
|
||||
|
||||
Todo categories:
|
||||
----------------
|
||||
@@ -117,6 +121,54 @@ Get-ChildItem -Path *.cpp,*.hpp -Recurse | sls -Pattern ' (TODO|NOTE|FIXME|BUG|W
|
||||
Get-Content .\tmp.sql | sls -Pattern '^(Executed prepared query)' | Set-Content executed_queries.sql
|
||||
|
||||
|
||||
cmake build commands:
|
||||
---------------------
|
||||
|
||||
vcvars64.ps1
|
||||
cd E:\c\qMedia\TinyOrm\TinyOrm-builds\build-cmake\
|
||||
cmake.exe -S E:/c/qMedia/TinyOrm/TinyOrm -B E:/c/qMedia/TinyOrm/TinyOrm-builds/build-cmake -GNinja `
|
||||
-DCMAKE_BUILD_TYPE:STRING=Debug `
|
||||
-DCMAKE_TOOLCHAIN_FILE:PATH=E:/c/qMedia/vcpkg/scripts/buildsystems/vcpkg.cmake
|
||||
|
||||
cmake --build . --target all
|
||||
|
||||
- generate Graphviz dependency image:
|
||||
|
||||
cmake.exe -S E:/c/qMedia/TinyOrm/TinyOrm -B E:/c/qMedia/TinyOrm/TinyOrm-builds/build-cmake -GNinja `
|
||||
-DCMAKE_BUILD_TYPE:STRING=Debug `
|
||||
-DCMAKE_TOOLCHAIN_FILE:PATH=E:/c/qMedia/vcpkg/scripts/buildsystems/vcpkg.cmake `
|
||||
--graphviz=E:/c/qMedia/TinyOrm/TinyOrm-builds/build-cmake/graph/graph.dot; `
|
||||
`
|
||||
dot -Tpng -o .\graph\graph.png .\graph\graph.dot; `
|
||||
.\graph\graph.png
|
||||
|
||||
- running ctest
|
||||
|
||||
E:\c\qMedia\TinyOrm\TinyOrm\tests\auto\utils\testdata\dotenv.ps1
|
||||
$env:Path = "E:\c\qMedia\TinyOrm\TinyOrm-builds\build-TinyOrm-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug-cmake;E:\c\qMedia\TinyOrm\TinyOrm-builds\build-TinyOrm-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug-cmake\tests\auto\utils;" + $env:Path
|
||||
ctest
|
||||
ctest --progress
|
||||
|
||||
- some debug output:
|
||||
|
||||
cmake --trace-expand --trace-source=tests/auto/unit/orm/query/mysql_querybuilder/CMakeLists.txt -LA ..
|
||||
cmake -LA .
|
||||
|
||||
- full build command, not needed, I leave it here as a shortcut:
|
||||
|
||||
cmake.exe -S E:/c/qMedia/TinyOrm/TinyOrm -B E:/c/qMedia/TinyOrm/TinyOrm-builds/build-cmake -GNinja `
|
||||
"-DCMAKE_BUILD_TYPE:STRING=Debug" `
|
||||
"-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=E:/Qt/Tools/QtCreator/share/qtcreator/package-manager/auto-setup.cmake" `
|
||||
"-DQT_QMAKE_EXECUTABLE:STRING=E:/Qt/5.15.2/msvc2019_64/bin/qmake.exe" `
|
||||
"-DCMAKE_PREFIX_PATH:STRING=E:/Qt/5.15.2/msvc2019_64" `
|
||||
"-DCMAKE_C_COMPILER:STRING=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/HostX64/x64/cl.exe" `
|
||||
"-DCMAKE_CXX_COMPILER:STRING=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/HostX64/x64/cl.exe" ` "-DCMAKE_TOOLCHAIN_FILE:PATH=E:/c/qMedia/vcpkg/scripts/buildsystems/vcpkg.cmake"
|
||||
|
||||
- system PATH to avoid run config. bug:
|
||||
|
||||
PATH=E:\c\qMedia\TinyOrm\TinyOrm-builds\build-TinyOrm-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug-cmake;E:\c\qMedia\TinyOrm\TinyOrm-builds\build-TinyOrm-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug-cmake\tests\auto\utils;${PATH}
|
||||
|
||||
|
||||
constructor copy/move snippet:
|
||||
------------------------------
|
||||
|
||||
@@ -149,7 +201,7 @@ Torrent &operator=(Torrent &&torrent)
|
||||
conversions:
|
||||
------------
|
||||
|
||||
Makes possible to assign QVector<AttributeItem> to the Model,
|
||||
Makes possible to assign QVector<AttributeItem> to the Model,
|
||||
or implicitly converts a QVector<AttributeItem> to Model:
|
||||
|
||||
Model(const QVector<AttributeItem> &attributes);
|
||||
@@ -163,7 +215,7 @@ Model(std::initializer_list<AttributeItem> attributes)
|
||||
{}
|
||||
|
||||
--
|
||||
Makes possible to assign the Model to the QVector<AttributeItem>,
|
||||
Makes possible to assign the Model to the QVector<AttributeItem>,
|
||||
or converts the Model to the QVector<AttributeItem>:
|
||||
|
||||
operator QVector<AttributeItem>() const;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<h1><img src="https://github.com/silverqx/TinyORM/blob/main/resources/logo-optim.svg" width="34" height="34" alt="TinyORM Logo" align="center"> TinyORM</h1>
|
||||
<h1><img src="https://github.com/silverqx/TinyORM/blob/main/resources/icons/logo-optim.svg" width="34" height="34" alt="TinyORM Logo" align="center"> TinyORM</h1>
|
||||
|
||||
[![silverqx.github.io][docs-badge]][docs]
|
||||
[![License MIT][license-badge]][license]
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Print various internal CMake variables
|
||||
function(cs_system_info)
|
||||
include(CMakePrintSystemInformation)
|
||||
endfunction()
|
||||
|
||||
# Enable verbose output from Makefile builds
|
||||
function(cs_verbose_makefile)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
endfunction()
|
||||
|
||||
# Print all cmake variables
|
||||
function(cs_print_vars)
|
||||
set(exclude_cmake yes)
|
||||
if (ARGC GREATER_EQUAL 1 AND DEFINED ARGV0 AND NOT ARGV0)
|
||||
set(exclude_cmake no)
|
||||
message(STATUS "All variables:")
|
||||
else()
|
||||
message(STATUS "All non-cmake variables:")
|
||||
endif()
|
||||
|
||||
get_cmake_property(variable_names VARIABLES)
|
||||
foreach (variable ${variable_names})
|
||||
if (exclude_cmake AND "${variable}" MATCHES "(^(CMAKE_.*)|^(_.*))")
|
||||
continue()
|
||||
endif ()
|
||||
|
||||
message("${variable}=${${variable}}")
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# Print all env. variables
|
||||
function(cs_print_env_vars)
|
||||
message(STATUS "All environment variables:")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
|
||||
endfunction()
|
||||
|
||||
# Get all propreties that cmake supports
|
||||
if(NOT CMAKE_PROPERTY_LIST)
|
||||
execute_process(
|
||||
COMMAND cmake --help-property-list
|
||||
OUTPUT_VARIABLE CMAKE_PROPERTY_LIST
|
||||
)
|
||||
|
||||
# Convert command output into a CMake list
|
||||
string(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
|
||||
string(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
|
||||
endif()
|
||||
|
||||
# Print all target properties
|
||||
function(print_target_properties target)
|
||||
|
||||
if(NOT TARGET ${target})
|
||||
message(FATAL_ERROR "There is no target named '${target}'")
|
||||
endif()
|
||||
|
||||
message(STATUS "Target properties for '${target}':")
|
||||
foreach(property ${CMAKE_PROPERTY_LIST})
|
||||
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" property ${property})
|
||||
|
||||
if(property STREQUAL "LOCATION" OR property MATCHES "^LOCATION_"
|
||||
OR property MATCHES "_LOCATION$")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
get_property(was_set TARGET ${target} PROPERTY ${property} SET)
|
||||
if(was_set)
|
||||
get_target_property(value ${target} ${property})
|
||||
message("${property} = ${value}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
@@ -0,0 +1,59 @@
|
||||
#.rst:
|
||||
# FindMySQL
|
||||
# ---------
|
||||
#
|
||||
# Try to locate the mysql client library.
|
||||
# If found, this will define the following variables:
|
||||
#
|
||||
# ``MySQL_FOUND``
|
||||
# True if the mysql library is available
|
||||
# ``MySQL_INCLUDE_DIRS``
|
||||
# The mysql include directories
|
||||
# ``MySQL_LIBRARIES``
|
||||
# The mysql libraries for linking
|
||||
#
|
||||
# If ``MySQL_FOUND`` is TRUE, it will also define the following
|
||||
# imported target:
|
||||
#
|
||||
# ``MySQL::MySQL``
|
||||
# The mysql client library
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_check_modules(PC_MySQL QUIET mysqlclient)
|
||||
|
||||
find_path(MySQL_INCLUDE_DIR
|
||||
NAMES mysql.h
|
||||
HINTS ${PC_MySQL_INCLUDEDIR}
|
||||
PATH_SUFFIXES mysql mariadb
|
||||
)
|
||||
|
||||
find_library(MySQL_LIBRARY
|
||||
NAMES libmysql mysql mysqlclient libmariadb mariadb
|
||||
HINTS ${PC_MySQL_LIBDIR}
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(MySQL DEFAULT_MSG MySQL_LIBRARY MySQL_INCLUDE_DIR)
|
||||
|
||||
if(MySQL_FOUND)
|
||||
set(MySQL_INCLUDE_DIRS "${MySQL_INCLUDE_DIR}")
|
||||
set(MySQL_LIBRARIES "${MySQL_LIBRARY}")
|
||||
|
||||
if(NOT TARGET MySQL::MySQL)
|
||||
add_library(MySQL::MySQL UNKNOWN IMPORTED)
|
||||
set_target_properties(MySQL::MySQL
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION "${MySQL_LIBRARIES}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MySQL_INCLUDE_DIRS}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(MySQL_INCLUDE_DIR MySQL_LIBRARY)
|
||||
|
||||
include(FeatureSummary)
|
||||
set_package_properties(MySQL
|
||||
PROPERTIES
|
||||
URL "https://www.mysql.com"
|
||||
DESCRIPTION "MySQL client library"
|
||||
)
|
||||
@@ -0,0 +1,183 @@
|
||||
# This module provides generate_and_install_pkg_config_file() function.
|
||||
# The function takes target name and expects a fully configured project, i.e. with set version and
|
||||
# description. The function extracts interface libraries, include dirs, definitions and options
|
||||
# from the target and generates pkg-config file with install() command
|
||||
# The function expands imported targets and generator expressions
|
||||
|
||||
# save the current file dir for later use in the generate_and_install_pkg_config_file() function
|
||||
set(_GeneratePkGConfigDir "${CMAKE_CURRENT_LIST_DIR}/GeneratePkgConfig")
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
function(_get_target_property_merging_configs _var_name _target_name _propert_name)
|
||||
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name} SET)
|
||||
if (prop_set)
|
||||
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name})
|
||||
else()
|
||||
if (CMAKE_BUILD_TYPE)
|
||||
list(APPEND configs ${CMAKE_BUILD_TYPE})
|
||||
elseif(CMAKE_CONFIGURATION_TYPES)
|
||||
list(APPEND configs ${CMAKE_CONFIGURATION_TYPES})
|
||||
endif()
|
||||
foreach(cfg ${configs})
|
||||
string(TOUPPER "${cfg}" UPPERCFG)
|
||||
get_property(mapped_configs TARGET ${_target_name} PROPERTY "MAP_IMPORTED_CONFIG_${UPPERCFG}")
|
||||
if (mapped_configs)
|
||||
list(GET "${mapped_configs}" 0 target_cfg)
|
||||
else()
|
||||
set(target_cfg "${UPPERCFG}")
|
||||
endif()
|
||||
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg} SET)
|
||||
if (prop_set)
|
||||
get_property(val_for_cfg TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg})
|
||||
list(APPEND vals "$<$<CONFIG:${cfg}>:${val_for_cfg}>")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
if (NOT prop_set)
|
||||
get_property(imported_cfgs TARGET ${_target_name} PROPERTY IMPORTED_CONFIGURATIONS)
|
||||
# CMake docs say we can use any of the imported configs
|
||||
list(GET imported_cfgs 0 imported_config)
|
||||
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name}_${imported_config})
|
||||
# remove config generator expression. Only in this case! Notice we use such expression
|
||||
# ourselves in the loop above
|
||||
string(REPLACE "$<$<CONFIG:${imported_config}>:" "$<1:" vals "${vals}")
|
||||
endif()
|
||||
endif()
|
||||
# HACK for static libraries cmake populates link dependencies as $<LINK_ONLY:lib_name>.
|
||||
# pkg-config does not support special handling for static libraries and as such we will remove
|
||||
# that generator expression
|
||||
string(REPLACE "$<LINK_ONLY:" "$<1:" vals "${vals}")
|
||||
# HACK file(GENERATE), which we use for expanding generator expressions, is BUILD_INTERFACE,
|
||||
# but we need INSTALL_INTERFACE here.
|
||||
# See https://gitlab.kitware.com/cmake/cmake/issues/17984
|
||||
string(REPLACE "$<BUILD_INTERFACE:" "$<0:" vals "${vals}")
|
||||
string(REPLACE "$<INSTALL_INTERFACE:" "@CMAKE_INSTALL_PREFIX@/$<1:" vals "${vals}")
|
||||
set(${_var_name} "${vals}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# This helper function expands imported targets from the provided targets list, collecting their
|
||||
# interface link libraries and imported locations, include directories, compile options and definitions
|
||||
# into the specified variables
|
||||
function(_expand_targets _targets _libraries_var _include_dirs_var _compile_options_var _compile_definitions_var)
|
||||
set(_any_target_was_expanded True)
|
||||
set(_libs "${${_libraries_var}}")
|
||||
set(_includes "${${_include_dirs_var}}")
|
||||
set(_defs "${${_compile_definitions_var}}")
|
||||
set(_options "${${_compile_options_var}}")
|
||||
|
||||
list(APPEND _libs "${_targets}")
|
||||
|
||||
while(_any_target_was_expanded)
|
||||
set(_any_target_was_expanded False)
|
||||
set(_new_libs "")
|
||||
foreach (_dep ${_libs})
|
||||
if (TARGET ${_dep})
|
||||
set(_any_target_was_expanded True)
|
||||
|
||||
get_target_property(_type ${_dep} TYPE)
|
||||
if ("${_type}" STREQUAL "INTERFACE_LIBRARY")
|
||||
# this library may not have IMPORTED_LOCATION property
|
||||
set(_imported_location "")
|
||||
else()
|
||||
_get_target_property_merging_configs(_imported_location ${_dep} IMPORTED_LOCATION)
|
||||
endif()
|
||||
|
||||
_get_target_property_merging_configs(_iface_link_libraries ${_dep} INTERFACE_LINK_LIBRARIES)
|
||||
_get_target_property_merging_configs(_iface_include_dirs ${_dep} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
_get_target_property_merging_configs(_iface_compile_options ${_dep} INTERFACE_COMPILE_OPTIONS)
|
||||
_get_target_property_merging_configs(_iface_definitions ${_dep} INTERFACE_COMPILE_DEFINITIONS)
|
||||
|
||||
if (_imported_location)
|
||||
list(APPEND _new_libs "${_imported_location}")
|
||||
endif()
|
||||
|
||||
if (_iface_link_libraries)
|
||||
list(APPEND _new_libs "${_iface_link_libraries}")
|
||||
endif()
|
||||
|
||||
if(_iface_include_dirs)
|
||||
list(APPEND _includes "${_iface_include_dirs}")
|
||||
endif()
|
||||
|
||||
if(_iface_compile_options)
|
||||
list(APPEND _options "${_iface_compile_options}")
|
||||
endif()
|
||||
|
||||
if(_iface_definitions)
|
||||
list(APPEND _defs "${_iface_definitions}")
|
||||
endif()
|
||||
|
||||
list(REMOVE_DUPLICATES _new_libs)
|
||||
list(REMOVE_DUPLICATES _includes)
|
||||
# Options order is important, thus leave duplicates as they are, skipping duplicates removal
|
||||
list(REMOVE_DUPLICATES _defs)
|
||||
else()
|
||||
list(APPEND _new_libs "${_dep}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(_libs "${_new_libs}")
|
||||
endwhile()
|
||||
set(${_libraries_var} "${_libs}" PARENT_SCOPE)
|
||||
set(${_include_dirs_var} "${_includes}" PARENT_SCOPE)
|
||||
set(${_compile_options_var} "${_options}" PARENT_SCOPE)
|
||||
set(${_compile_definitions_var} "${_defs}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Generates and installs a pkg-config file for a given target
|
||||
function(generate_and_install_pkg_config_file _target _packageName)
|
||||
# collect target properties
|
||||
_expand_targets(${_target}
|
||||
_interface_link_libraries _interface_include_dirs
|
||||
_interface_compile_options _interface_definitions)
|
||||
|
||||
get_target_property(_output_name ${_target} OUTPUT_NAME)
|
||||
if (NOT _output_name)
|
||||
set(_output_name "${_target}")
|
||||
endif()
|
||||
|
||||
set(_package_name "${_packageName}")
|
||||
|
||||
# remove standard include directories
|
||||
foreach(d IN LISTS CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
|
||||
list(REMOVE_ITEM _interface_include_dirs "${d}")
|
||||
endforeach()
|
||||
|
||||
set(_generate_target_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}-pkgconfig")
|
||||
set(_pkg_config_file_template_filename "${_GeneratePkGConfigDir}/pkg-config.cmake.in")
|
||||
|
||||
# Since CMake 3.18 FindThreads may include a generator expression requiring a target, which gets propagated to us through INTERFACE_OPTIONS.
|
||||
# Before CMake 3.19 there's no way to solve this in a general way, so we work around the specific case. See #4956 and CMake bug #21074.
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
|
||||
set(_target_arg TARGET ${_target})
|
||||
else()
|
||||
string(REPLACE "<COMPILE_LANG_AND_ID:CUDA,NVIDIA>" "<COMPILE_LANGUAGE:CUDA>" _interface_compile_options "${_interface_compile_options}")
|
||||
endif()
|
||||
|
||||
# put target and project properties into a file
|
||||
configure_file("${_GeneratePkGConfigDir}/target-compile-settings.cmake.in"
|
||||
"${_generate_target_dir}/compile-settings.cmake" @ONLY)
|
||||
|
||||
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if (NOT _isMultiConfig)
|
||||
set(_variables_file_name "${_generate_target_dir}/compile-settings-expanded.cmake")
|
||||
|
||||
file(GENERATE OUTPUT "${_variables_file_name}" INPUT "${_generate_target_dir}/compile-settings.cmake" ${_target_arg})
|
||||
|
||||
configure_file("${_GeneratePkGConfigDir}/generate-pkg-config.cmake.in"
|
||||
"${_generate_target_dir}/generate-pkg-config.cmake" @ONLY)
|
||||
|
||||
install(SCRIPT "${_generate_target_dir}/generate-pkg-config.cmake")
|
||||
else()
|
||||
foreach(cfg IN LISTS CMAKE_CONFIGURATION_TYPES)
|
||||
set(_variables_file_name "${_generate_target_dir}/${cfg}/compile-settings-expanded.cmake")
|
||||
|
||||
file(GENERATE OUTPUT "${_variables_file_name}" INPUT "${_generate_target_dir}/compile-settings.cmake" CONDITION "$<CONFIG:${cfg}>" ${_target_arg})
|
||||
|
||||
configure_file("${_GeneratePkGConfigDir}/generate-pkg-config.cmake.in"
|
||||
"${_generate_target_dir}/${cfg}/generate-pkg-config.cmake" @ONLY)
|
||||
|
||||
install(SCRIPT "${_generate_target_dir}/${cfg}/generate-pkg-config.cmake")
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,52 @@
|
||||
include("@_variables_file_name@")
|
||||
|
||||
function (cmake_list_to_pkg_config _result _list _prefix)
|
||||
set(_tmp_list "${_list}")
|
||||
list(REMOVE_ITEM _tmp_list "")
|
||||
# remove prefix from prefixed items
|
||||
string(REGEX REPLACE "(^|;)(${_prefix})" "\\1" _tmp_list "${_tmp_list}")
|
||||
# append 'prefix' to each element
|
||||
string(REGEX REPLACE "([^;]+)" "${_prefix}\\1" _tmp_list "${_tmp_list}")
|
||||
# transform cmake list into a space delimited list
|
||||
string(REPLACE ";" " " _tmp_list "${_tmp_list}")
|
||||
set(${_result} "${_tmp_list}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Helper function for splitting full library paths into [dir, name] and merging repetitive dir entries
|
||||
function(split_library_dirs _libraries _base_library_dir _library_dirs_var _library_names_var)
|
||||
set(libdirs "${_base_library_dir}")
|
||||
set(libs "")
|
||||
foreach (l IN LISTS _libraries)
|
||||
get_filename_component(lDir "${l}" DIRECTORY)
|
||||
if (lDir)
|
||||
get_filename_component(lDir "${lDir}" REALPATH)
|
||||
endif()
|
||||
get_filename_component(lFile "${l}" NAME_WE)
|
||||
string(REPLACE "${_SHARED_LIBRARY_PREFIX}" "" lFile "${lFile}")
|
||||
list(APPEND libdirs "${lDir}")
|
||||
list(APPEND libs "${lFile}")
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES libdirs)
|
||||
list(REMOVE_AT libdirs 0) # as it is the base libdir and will be handled separately
|
||||
|
||||
set(${_library_dirs_var} "${libdirs}" PARENT_SCOPE)
|
||||
set(${_library_names_var} "${libs}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
split_library_dirs("${_TARGET_INTERFACE_LINK_LIBRARIES}" "${CMAKE_INSTALL_PREFIX}/${_INSTALL_LIBDIR}" _lib_dirs _library_names)
|
||||
cmake_list_to_pkg_config(_libs "${_library_names}" "-l")
|
||||
list(LENGTH _lib_dirs _additional_libdirs_count)
|
||||
if (_additional_libdirs_count GREATER 0)
|
||||
cmake_list_to_pkg_config(_additional_libdirs "${_lib_dirs}" "-L")
|
||||
set(_interface_link_libraries "${_additional_libdirs} ${_libs}")
|
||||
else()
|
||||
set(_interface_link_libraries "${_libs}")
|
||||
endif()
|
||||
|
||||
cmake_list_to_pkg_config(_interface_definitions "${_TARGET_INTERFACE_DEFINITIONS}" "-D")
|
||||
cmake_list_to_pkg_config(_interface_include_dirs "${_TARGET_INTERFACE_INCLUDE_DIRS}" "-I")
|
||||
set(_interface_compile_options "${_TARGET_INTERFACE_COMPILE_OPTIONS}")
|
||||
string(REPLACE ";" " " _interface_compile_options "${_interface_compile_options}")
|
||||
|
||||
configure_file("@_pkg_config_file_template_filename@" "@_generate_target_dir@/@_package_name@.pc" @ONLY)
|
||||
file(INSTALL "@_generate_target_dir@/@_package_name@.pc" DESTINATION "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/pkgconfig")
|
||||
@@ -0,0 +1,8 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=${prefix}/@_INSTALL_LIBDIR@
|
||||
|
||||
Name: @_PROJECT_NAME@
|
||||
Description: @_PROJECT_DESCRIPTION@
|
||||
Version: @_PROJECT_VERSION@
|
||||
Libs: -L${libdir} -l@_TARGET_OUTPUT_NAME@ @_interface_link_libraries@
|
||||
Cflags: @_interface_compile_options@ @_interface_include_dirs@ @_interface_definitions@
|
||||
@@ -0,0 +1,13 @@
|
||||
set(_TARGET_INTERFACE_LINK_LIBRARIES "@_interface_link_libraries@")
|
||||
set(_TARGET_INTERFACE_COMPILE_OPTIONS "@_interface_compile_options@")
|
||||
set(_TARGET_INTERFACE_INCLUDE_DIRS "@_interface_include_dirs@")
|
||||
set(_TARGET_INTERFACE_DEFINITIONS "@_interface_definitions@")
|
||||
set(_TARGET_OUTPUT_NAME "@_output_name@")
|
||||
|
||||
set(_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
|
||||
set(_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@")
|
||||
set(_SHARED_LIBRARY_PREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@")
|
||||
|
||||
set(_PROJECT_NAME "@PROJECT_NAME@")
|
||||
set(_PROJECT_DESCRIPTION "@PROJECT_DESCRIPTION@")
|
||||
set(_PROJECT_VERSION "@PROJECT_VERSION@")
|
||||
@@ -0,0 +1,23 @@
|
||||
# Helper function for coupling option() and add_feature_info()
|
||||
function(feature_option name description default)
|
||||
|
||||
string(CONCAT desc "${description} (default: ${default})")
|
||||
|
||||
option(${name} "${desc}" "${default}")
|
||||
|
||||
add_feature_info(${name} ${name} "${desc}")
|
||||
|
||||
endfunction()
|
||||
|
||||
include(CMakeDependentOption)
|
||||
# Helper function for coupling cmake_dependent_option() and add_feature_info()
|
||||
macro(feature_option_dependent name description default depends force)
|
||||
|
||||
string(CONCAT desc
|
||||
"${description} (default: ${default}; depends on condition: ${depends})")
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(${name} "${desc}" "${default}" "${depends}" "${force}")
|
||||
|
||||
add_feature_info(${name} ${name} "${desc}")
|
||||
|
||||
endmacro()
|
||||
@@ -0,0 +1,47 @@
|
||||
# Configure file version file and Windows resource and manifest files
|
||||
function(tiny_file_version_and_manifest target version_header_path)
|
||||
|
||||
set(tiny_original_extension)
|
||||
set(tiny_original_filename)
|
||||
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
|
||||
if(target_type STREQUAL "SHARED_LIBRARY")
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(tiny_original_extension "${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
set(tiny_original_extension "${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
endif()
|
||||
elseif(target_type STREQUAL "EXECUTABLE")
|
||||
set(tiny_original_extension "${CMAKE_EXECUTABLE_SUFFIX}")
|
||||
endif()
|
||||
|
||||
# Append a major version number for Windows shared libraries only
|
||||
if(${TinyOrm_target}_VERSION_EXT)
|
||||
set(tiny_original_filename
|
||||
"${target}${PROJECT_VERSION_MAJOR}${tiny_original_extension}")
|
||||
else()
|
||||
set(tiny_original_filename
|
||||
"${target}${tiny_original_extension}")
|
||||
endif()
|
||||
|
||||
configure_file(
|
||||
"${version_header_path}version.hpp.in"
|
||||
# TODO finish, version.hpp to include files? and what about install/export? silverqx
|
||||
"${version_header_path}version.hpp"
|
||||
@ONLY NEWLINE_STYLE LF
|
||||
)
|
||||
|
||||
# TODO are other sources private or public, so they are private, I checked, but anyway check how this whole target_sources() vs add_library()'s sources work, they have to be relative for sure, to be relocable packages, but they are relative to what, include path? silverqx
|
||||
# target_sources(${target} PUBLIC
|
||||
# "${PROJECT_BINARY_DIR}/${version_header_path}version.hpp")
|
||||
target_sources(${target} PRIVATE "${version_header_path}version.hpp")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_sources(${target} PRIVATE
|
||||
"resources/${target}.rc"
|
||||
"resources/${target}${tiny_original_extension}.manifest"
|
||||
)
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,104 @@
|
||||
# Invert a boolean variable value
|
||||
function(tiny_invert_bool variable value)
|
||||
|
||||
if(${value})
|
||||
set(${variable} FALSE PARENT_SCOPE)
|
||||
else()
|
||||
set(${variable} TRUE PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
# Make minimum toolchain version a requirement
|
||||
function(tiny_toolchain_requirement)
|
||||
|
||||
set(singleargs MSVC)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 TINY "" "${singleargs}" "")
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS TINY_MSVC)
|
||||
message(FATAL_ERROR "Minimum required MSVC version was not satisfied, \
|
||||
required version >=${TINY_MSVC}, your version is ${CMAKE_CXX_COMPILER_VERSION}, upgrade \
|
||||
Visual Studio")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
# A helper macro that calls find_package() and appends the package (if found) to the
|
||||
# TINY_PACKAGE_DEPENDENCIES list, which can be used later to generate package config file
|
||||
macro(tiny_find_package package_name)
|
||||
|
||||
find_package(${package_name} ${ARGN})
|
||||
|
||||
if (${package_name}_FOUND)
|
||||
set(args "${package_name}")
|
||||
# These arguments will be forwarded to the find_package() by find_dependency()
|
||||
list(APPEND args "${ARGN}")
|
||||
# REQUIRED and QUIETLY arguments are handled by find_dependency() macro
|
||||
# find_dependency() forwards the correct parameters for QUIET and REQUIRED which
|
||||
# were passed to the original find_package() call
|
||||
list(REMOVE_ITEM args "REQUIRED" "QUIET")
|
||||
# Remove all empty items
|
||||
list(REMOVE_ITEM args "")
|
||||
# Convert to the string
|
||||
string(REPLACE ";" " " args "${args}")
|
||||
|
||||
list(APPEND tiny_package_dependencies "${args}")
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
# Generate find_dependency calls for the TinyORM package config file
|
||||
function(tiny_generate_find_dependency_calls)
|
||||
|
||||
set(find_dependency_calls)
|
||||
|
||||
string(REGEX REPLACE "([^;]+)" "find_dependency(\\1)" find_dependency_calls
|
||||
"${tiny_package_dependencies}")
|
||||
|
||||
string(REPLACE ";" "\n" find_dependency_calls "${find_dependency_calls}")
|
||||
|
||||
set(_find_dependency_calls ${find_dependency_calls} PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
|
||||
# Add a simple build option which controls compile definition(s) for a target.
|
||||
# Synopsis:
|
||||
# target_optional_compile_definitions(<target> [FEATURE]
|
||||
# NAME <name> DESCRIPTION <description> DEFAULT <default_value>
|
||||
# [ENABLED [enabled_compile_definitions...]]
|
||||
# [DISABLED [disabled_compile_defnitions...]]
|
||||
# )
|
||||
# NAME, DESCRIPTION and DEFAULT are passed to option() call
|
||||
# if FEATURE is given, they are passed to add_feature_info()
|
||||
# ENABLED lists compile definitions that will be set on <target> when option is enabled,
|
||||
# DISABLED lists definitions that will be set otherwise
|
||||
function(target_optional_compile_definitions _target _scope)
|
||||
set(options FEATURE)
|
||||
set(oneValueArgs NAME DESCRIPTION DEFAULT)
|
||||
set(multiValueArgs ENABLED DISABLED)
|
||||
cmake_parse_arguments(TOCD ${options} "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
option(${TOCD_NAME} "${TOCD_DESCRIPTION}" ${TOCD_DEFAULT})
|
||||
if (${${TOCD_NAME}})
|
||||
target_compile_definitions(${_target} ${_scope} ${TOCD_ENABLED})
|
||||
else()
|
||||
target_compile_definitions(${_target} ${_scope} ${TOCD_DISABLED})
|
||||
endif()
|
||||
if(${TOCD_FEATURE})
|
||||
add_feature_info(${TOCD_NAME} ${TOCD_NAME} "${TOCD_DESCRIPTION}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Create an empty SQLite database file when does not exist
|
||||
function(create_sqlite_db db_filepath)
|
||||
|
||||
if(EXISTS ${db_filepath})
|
||||
return()
|
||||
endif()
|
||||
|
||||
message(STATUS "Creating SQLite database at '${db_filepath}'")
|
||||
|
||||
file(TOUCH "${db_filepath}")
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,21 @@
|
||||
# Allow per-translation-unit parallel builds when using MSVC
|
||||
function(tiny_msvc_parallel desc)
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "Visual Studio"
|
||||
AND (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel"
|
||||
OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel")
|
||||
)
|
||||
set(MSVC_PARALLEL ON CACHE STRING "${desc}")
|
||||
|
||||
if(MSVC_PARALLEL)
|
||||
if(MSVC_PARALLEL GREATER 0)
|
||||
string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}")
|
||||
string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}")
|
||||
else()
|
||||
string(APPEND CMAKE_C_FLAGS " /MP")
|
||||
string(APPEND CMAKE_CXX_FLAGS " /MP")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,149 @@
|
||||
# Set common variables and create interface-only library target so all other targets
|
||||
# will be able to link to, either directly or transitively, to consume common compile
|
||||
# options/definitions
|
||||
function(tiny_qt_common target alias)
|
||||
|
||||
set(options EXPORT)
|
||||
set(single_args NAMESPACE NAME)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 TINY "${options}" "${single_args}" "")
|
||||
|
||||
add_library(${target} INTERFACE)
|
||||
add_library(${TINY_NAMESPACE}::${TINY_NAME} ALIAS ${target})
|
||||
|
||||
if(TINY_EXPORT)
|
||||
set_target_properties(${target} PROPERTIES EXPORT_NAME ${TINY_NAME})
|
||||
endif()
|
||||
|
||||
# Full C++ 20 support is required
|
||||
target_compile_features(${target} INTERFACE cxx_std_20)
|
||||
|
||||
# Qt defines
|
||||
# ---
|
||||
|
||||
target_compile_definitions(${target} INTERFACE
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
# Disables all the APIs deprecated before Qt 6.0.0
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
|
||||
#QT_NO_CAST_FROM_ASCII
|
||||
#QT_RESTRICTED_CAST_FROM_ASCII
|
||||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_CAST_FROM_BYTEARRAY
|
||||
QT_USE_QSTRINGBUILDER
|
||||
QT_STRICT_ITERATORS
|
||||
|
||||
# Disable debug output in release mode
|
||||
$<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
|
||||
)
|
||||
|
||||
# Platform specific configuration
|
||||
# ---
|
||||
|
||||
# Windows
|
||||
# ---
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_compile_definitions(${target} INTERFACE
|
||||
# Windows 10 1903 "19H1" - 0x0A000007
|
||||
NTDDI_VERSION=0x0A000007
|
||||
# Windows 10 - 0x0A00
|
||||
_WIN32_WINNT=0x0A00
|
||||
_WIN32_IE=0x0A00
|
||||
UNICODE _UNICODE
|
||||
# Exclude unneeded header files
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
)
|
||||
endif()
|
||||
|
||||
# Compiler and Linker options
|
||||
# ---
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(${target} INTERFACE
|
||||
# Suppress banner and info messages
|
||||
/nologo
|
||||
/guard:cf
|
||||
/utf-8
|
||||
# TODO This is by default for msvc c++20, solve when will do clang/gcc build silverqx
|
||||
/permissive-
|
||||
/bigobj
|
||||
# Has to be enabled explicitly
|
||||
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
/Zc:__cplusplus
|
||||
# Standards-conforming behavior
|
||||
/Zc:wchar_t,rvalueCast,inline,strictStrings
|
||||
/Zc:throwingNew,referenceBinding,ternary
|
||||
# /external:anglebrackets /external:W0 /external:templates-
|
||||
# /external:anglebrackets /external:W0
|
||||
# /Wall
|
||||
# /W4 /wd4127
|
||||
/W3 /w34100 /w34189 /w44996 /w44456 /w44457 /w44458 /wd4577 /wd4467
|
||||
)
|
||||
|
||||
target_link_options(${target} INTERFACE
|
||||
/guard:cf
|
||||
$<$<NOT:$<CONFIG:Debug>>:/OPT:REF,ICF=5>
|
||||
# TODO check silverqx
|
||||
# Suppress linking warning due to /INCREMENTAL and /OPT:ICF being both ON
|
||||
$<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>
|
||||
)
|
||||
endif()
|
||||
|
||||
# TODO this is default on MSVC, but check -fexceptions during clang/gcc build tunning silverqx
|
||||
# if(MSVC)
|
||||
# target_compile_options(${target} INTERFACE /EHsc)
|
||||
# else(MSVC)
|
||||
# target_compile_options(${target} INTERFACE -fexceptions)
|
||||
# endif(MSVC)
|
||||
|
||||
# Below is not tested
|
||||
# ---
|
||||
|
||||
# TODO verify silverqx
|
||||
if(MINGW)
|
||||
target_link_options(${target} INTERFACE
|
||||
$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
||||
OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
|
||||
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
|
||||
)
|
||||
target_compile_options(${target} INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-qual
|
||||
-Wcast-align
|
||||
-Winvalid-pch
|
||||
-Woverloaded-virtual
|
||||
-Wold-style-cast
|
||||
-Wnon-virtual-dtor
|
||||
-pedantic
|
||||
-pedantic-errors
|
||||
)
|
||||
|
||||
# Clang 11 still doesn't support -Wstrict-null-sentinel
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
|
||||
if(SNS_SUPPORT)
|
||||
target_compile_options(${target} INTERFACE -Wstrict-null-sentinel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
|
||||
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
|
||||
)
|
||||
target_compile_options(${target} INTERFACE -Wno-range-loop-analysis)
|
||||
endif()
|
||||
|
||||
# Use 64-bit off_t on 32-bit Linux, ensure 64bit offsets are used for filesystem
|
||||
# accesses for 32bit compilation
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
target_compile_definitions(${target} INTERFACE -D_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,108 @@
|
||||
# Create Package Config and Package Config Version files and install the TinyORM Project
|
||||
function(tiny_install_tinyorm)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Install targets from the project and assign them to the export set
|
||||
install(
|
||||
TARGETS ${TinyOrm_target} ${CommonConfig_target}
|
||||
EXPORT TinyOrmTargets
|
||||
LIBRARY ARCHIVE RUNTIME
|
||||
)
|
||||
|
||||
# Install all other files
|
||||
install(DIRECTORY "include/orm" TYPE INCLUDE FILES_MATCHING PATTERN "*.hpp")
|
||||
install(DIRECTORY "${PROJECT_BINARY_DIR}/include/orm" TYPE INCLUDE)
|
||||
file(GLOB tiny_docs "docs/*.mdx")
|
||||
install(FILES ${tiny_docs} DESTINATION "${CMAKE_INSTALL_DOCDIR}/mdx")
|
||||
install(FILES AUTHOR LICENSE TYPE DOC)
|
||||
install(FILES NOTES.txt TYPE DOC RENAME NOTES)
|
||||
install(FILES README.md TYPE DOC RENAME README)
|
||||
if (MSVC)
|
||||
install(FILES "$<TARGET_PDB_FILE:${TinyOrm_target}>" TYPE BIN OPTIONAL)
|
||||
endif()
|
||||
|
||||
# Generate and install a code to import targets from the Install Tree
|
||||
install(
|
||||
EXPORT TinyOrmTargets
|
||||
NAMESPACE TinyOrm::
|
||||
# TODO var. ConfigPackageLocation in libtorrent, also use TinyOrm_target silverqx
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/TinyOrm"
|
||||
)
|
||||
|
||||
# Install destination directories for the Install Tree
|
||||
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/")
|
||||
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/TinyOrm/")
|
||||
set(DOC_INSTALL_DIR "${CMAKE_INSTALL_DOCDIR}/")
|
||||
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/")
|
||||
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/")
|
||||
|
||||
# TODO stackoverflow, scope of includes in functions silverqx
|
||||
include(CMakePackageConfigHelpers)
|
||||
# Configure Package Config file for the Install Tree
|
||||
configure_package_config_file(
|
||||
"cmake/TinyOrmConfig.cmake.in"
|
||||
"cmake/TinyOrmConfig.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/TinyOrm"
|
||||
PATH_VARS
|
||||
BIN_INSTALL_DIR CONFIG_INSTALL_DIR DOC_INSTALL_DIR INCLUDE_INSTALL_DIR
|
||||
LIB_INSTALL_DIR
|
||||
)
|
||||
|
||||
# Compatible Interface Requirement for the project's major version
|
||||
set_property(
|
||||
TARGET ${TinyOrm_target}
|
||||
PROPERTY INTERFACE_TinyOrm_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
|
||||
)
|
||||
set_property(
|
||||
TARGET ${TinyOrm_target} APPEND PROPERTY
|
||||
COMPATIBLE_INTERFACE_STRING TinyOrm_MAJOR_VERSION
|
||||
)
|
||||
|
||||
# Generate the Package Version file for the Package Config file for the Install Tree
|
||||
write_basic_package_version_file(
|
||||
"cmake/TinyOrmConfigVersion.cmake"
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
# Install Package Config and Package Config Verion files
|
||||
install(
|
||||
FILES
|
||||
"${PROJECT_BINARY_DIR}/cmake/TinyOrmConfig.cmake"
|
||||
"${PROJECT_BINARY_DIR}/cmake/TinyOrmConfigVersion.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/TinyOrm"
|
||||
)
|
||||
|
||||
endfunction()
|
||||
|
||||
# Create Package Config and Package Config Version files for the Build Tree and export it
|
||||
function(tiny_export_build_tree)
|
||||
|
||||
# Export Targets from the Build Tree
|
||||
export(
|
||||
EXPORT TinyOrmTargets
|
||||
FILE "cmake/TinyOrmTargets.cmake"
|
||||
NAMESPACE TinyOrm::
|
||||
)
|
||||
|
||||
# Configure Package Config file for the Build Tree
|
||||
configure_package_config_file(
|
||||
"cmake/TinyOrmBuildTreeConfig.cmake.in"
|
||||
"TinyOrmConfig.cmake"
|
||||
# TODO check on unix if "/" is absolute path silverqx
|
||||
# TODO also test how file(RELATIVE_PATH) behaves on unix with "/" and "./" silverqx
|
||||
INSTALL_DESTINATION "./"
|
||||
INSTALL_PREFIX "${PROJECT_BINARY_DIR}"
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
)
|
||||
|
||||
# Generate the Package Version file for the Package Config file for the Build Tree
|
||||
write_basic_package_version_file(
|
||||
"TinyOrmConfigVersion.cmake"
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
# Store the current Build Tree in the CMake User Package Registry
|
||||
export(PACKAGE TinyOrm)
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,59 @@
|
||||
include(TinyHelpers)
|
||||
|
||||
# Initialize CMake default variables by project options
|
||||
function(tiny_init_cmake_variables)
|
||||
|
||||
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
|
||||
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
|
||||
set(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION YES)
|
||||
|
||||
tiny_invert_bool(PRECOMPILE_HEADERS ${PRECOMPILE_HEADERS})
|
||||
set(CMAKE_DISABLE_PRECOMPILE_HEADERS ${PRECOMPILE_HEADERS})
|
||||
|
||||
if (EXPORT_PACKAGE_REGISTRY)
|
||||
set(CMAKE_EXPORT_PACKAGE_REGISTRY YES)
|
||||
endif()
|
||||
|
||||
if(MSVC_RUNTIME_DYNAMIC)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
else()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
endif()
|
||||
|
||||
# TODO test on unix silverqx
|
||||
# set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||
|
||||
# Fix install prefix for the x64 toolchain
|
||||
if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
|
||||
AND CMAKE_SIZEOF_VOID_P EQUAL 8
|
||||
)
|
||||
get_property(intall_prefix_docs CACHE CMAKE_INSTALL_PREFIX PROPERTY HELPSTRING)
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX "C:/Program Files/${PROJECT_NAME}"
|
||||
CACHE PATH "${intall_prefix_docs}" FORCE
|
||||
)
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
# Initialize variable for append a major version number for Windows shared libraries
|
||||
function(tiny_init_target_version_ext target)
|
||||
|
||||
set(result OFF)
|
||||
get_target_property(target_type ${target} TYPE)
|
||||
|
||||
if(WIN32 AND target_type STREQUAL "SHARED_LIBRARY")
|
||||
set(result ON)
|
||||
endif()
|
||||
|
||||
set(${target}_VERSION_EXT ${result} PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
|
||||
# Initialize Tiny variables
|
||||
macro(tiny_init_tiny_variables)
|
||||
|
||||
# List of package dependencies for the package config
|
||||
set(tiny_package_dependencies)
|
||||
|
||||
endmacro()
|
||||
@@ -0,0 +1,148 @@
|
||||
# TinyORM library header and source files
|
||||
# Create header and source files lists and return them
|
||||
function(tiny_sources)
|
||||
|
||||
set(headers
|
||||
basegrammar.hpp
|
||||
concepts.hpp
|
||||
concerns/detectslostconnections.hpp
|
||||
concerns/hasconnectionresolver.hpp
|
||||
configuration.hpp
|
||||
connectioninterface.hpp
|
||||
connectionresolverinterface.hpp
|
||||
connectors/connectionfactory.hpp
|
||||
connectors/connector.hpp
|
||||
connectors/connectorinterface.hpp
|
||||
connectors/mysqlconnector.hpp
|
||||
connectors/postgresconnector.hpp
|
||||
connectors/sqliteconnector.hpp
|
||||
constants.hpp
|
||||
databaseconnection.hpp
|
||||
databasemanager.hpp
|
||||
db.hpp
|
||||
exceptions/domainerror.hpp
|
||||
exceptions/invalidargumenterror.hpp
|
||||
exceptions/invalidformaterror.hpp
|
||||
exceptions/invalidtemplateargumenterror.hpp
|
||||
exceptions/logicerror.hpp
|
||||
exceptions/queryerror.hpp
|
||||
exceptions/runtimeerror.hpp
|
||||
exceptions/sqlerror.hpp
|
||||
exceptions/sqltransactionerror.hpp
|
||||
logquery.hpp
|
||||
macros.hpp
|
||||
mysqlconnection.hpp
|
||||
ormtypes.hpp
|
||||
postgresconnection.hpp
|
||||
query/expression.hpp
|
||||
query/grammars/grammar.hpp
|
||||
query/grammars/mysqlgrammar.hpp
|
||||
query/grammars/postgresgrammar.hpp
|
||||
query/grammars/sqlitegrammar.hpp
|
||||
query/joinclause.hpp
|
||||
query/processors/mysqlprocessor.hpp
|
||||
query/processors/postgresprocessor.hpp
|
||||
query/processors/processor.hpp
|
||||
query/processors/sqliteprocessor.hpp
|
||||
query/querybuilder.hpp
|
||||
schema/grammars/mysqlschemagrammar.hpp
|
||||
schema/grammars/postgresschemagrammar.hpp
|
||||
schema/grammars/schemagrammar.hpp
|
||||
schema/grammars/sqliteschemagrammar.hpp
|
||||
schema/mysqlschemabuilder.hpp
|
||||
schema/postgresschemabuilder.hpp
|
||||
schema/schemabuilder.hpp
|
||||
schema/sqliteschemabuilder.hpp
|
||||
sqliteconnection.hpp
|
||||
support/configurationoptionsparser.hpp
|
||||
tiny/concerns/guardsattributes.hpp
|
||||
tiny/concerns/hasattributes.hpp
|
||||
tiny/concerns/hasrelationstore.hpp
|
||||
tiny/concerns/queriesrelationships.hpp
|
||||
tiny/exceptions/massassignmenterror.hpp
|
||||
tiny/exceptions/modelnotfounderror.hpp
|
||||
tiny/exceptions/relationnotfounderror.hpp
|
||||
tiny/exceptions/relationnotloadederror.hpp
|
||||
tiny/model.hpp
|
||||
tiny/modelproxies.hpp
|
||||
tiny/relations/basepivot.hpp
|
||||
tiny/relations/belongsto.hpp
|
||||
tiny/relations/belongstomany.hpp
|
||||
tiny/relations/concerns/supportsdefaultmodels.hpp
|
||||
tiny/relations/hasmany.hpp
|
||||
tiny/relations/hasone.hpp
|
||||
tiny/relations/hasoneormany.hpp
|
||||
tiny/relations/pivot.hpp
|
||||
tiny/relations/relation.hpp
|
||||
tiny/relations/relationproxies.hpp
|
||||
tiny/tinybuilder.hpp
|
||||
tiny/tinybuilderproxies.hpp
|
||||
tiny/tinytypes.hpp
|
||||
types/log.hpp
|
||||
types/statementscounter.hpp
|
||||
utils/attribute.hpp
|
||||
utils/export.hpp
|
||||
utils/string.hpp
|
||||
utils/type.hpp
|
||||
# version.hpp
|
||||
)
|
||||
|
||||
set(sources
|
||||
basegrammar.cpp
|
||||
concerns/detectslostconnections.cpp
|
||||
concerns/hasconnectionresolver.cpp
|
||||
connectors/connectionfactory.cpp
|
||||
connectors/connector.cpp
|
||||
connectors/mysqlconnector.cpp
|
||||
connectors/postgresconnector.cpp
|
||||
connectors/sqliteconnector.cpp
|
||||
constants.cpp
|
||||
databaseconnection.cpp
|
||||
databasemanager.cpp
|
||||
db.cpp
|
||||
exceptions/logicerror.cpp
|
||||
exceptions/queryerror.cpp
|
||||
exceptions/runtimeerror.cpp
|
||||
exceptions/sqlerror.cpp
|
||||
logquery.cpp
|
||||
mysqlconnection.cpp
|
||||
ormtypes.cpp
|
||||
postgresconnection.cpp
|
||||
query/expression.cpp
|
||||
query/grammars/grammar.cpp
|
||||
query/grammars/mysqlgrammar.cpp
|
||||
query/grammars/postgresgrammar.cpp
|
||||
query/grammars/sqlitegrammar.cpp
|
||||
query/joinclause.cpp
|
||||
query/processors/mysqlprocessor.cpp
|
||||
query/processors/postgresprocessor.cpp
|
||||
query/processors/processor.cpp
|
||||
query/processors/sqliteprocessor.cpp
|
||||
query/querybuilder.cpp
|
||||
schema/grammars/mysqlschemagrammar.cpp
|
||||
schema/grammars/postgresschemagrammar.cpp
|
||||
schema/grammars/schemagrammar.cpp
|
||||
schema/grammars/sqliteschemagrammar.cpp
|
||||
schema/mysqlschemabuilder.cpp
|
||||
schema/postgresschemabuilder.cpp
|
||||
schema/schemabuilder.cpp
|
||||
schema/sqliteschemabuilder.cpp
|
||||
sqliteconnection.cpp
|
||||
support/configurationoptionsparser.cpp
|
||||
tiny/model.cpp
|
||||
tiny/exceptions/modelnotfounderror.cpp
|
||||
tiny/exceptions/relationnotfounderror.cpp
|
||||
tiny/exceptions/relationnotloadederror.cpp
|
||||
tiny/relations/relation.cpp
|
||||
utils/attribute.cpp
|
||||
utils/string.cpp
|
||||
utils/type.cpp
|
||||
)
|
||||
|
||||
list(TRANSFORM headers PREPEND "include/orm/")
|
||||
list(TRANSFORM sources PREPEND "src/orm/")
|
||||
|
||||
set(headers ${headers} PARENT_SCOPE)
|
||||
set(sources ${sources} PARENT_SCOPE)
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,50 @@
|
||||
# Configure passed auto test
|
||||
function(tiny_configure_test name)
|
||||
|
||||
set(options INCLUDE_MODELS)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 TINY "${options}" "" "")
|
||||
|
||||
target_precompile_headers(${name} PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:CXX>:"${CMAKE_SOURCE_DIR}/include/pch.h">
|
||||
)
|
||||
|
||||
set_target_properties(${name}
|
||||
PROPERTIES
|
||||
C_VISIBILITY_PRESET "hidden"
|
||||
CXX_VISIBILITY_PRESET "hidden"
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
)
|
||||
|
||||
target_compile_features(${name} PRIVATE cxx_std_20)
|
||||
|
||||
target_compile_definitions(${name}
|
||||
PRIVATE
|
||||
PROJECT_TINYORM_TEST
|
||||
TINYORM_TESTS_CODE
|
||||
TINYORM_LINKING_SHARED
|
||||
)
|
||||
|
||||
target_include_directories(${name} PRIVATE
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
if(TINY_INCLUDE_MODELS)
|
||||
target_include_directories(${name} PRIVATE
|
||||
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/tests/models>"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${name}
|
||||
PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Sql
|
||||
Qt${QT_VERSION_MAJOR}::Test
|
||||
# TODO do I need this? silverqx
|
||||
# range-v3::range-v3
|
||||
TinyOrm::CommonConfig
|
||||
TinyOrm::TinyUtils
|
||||
TinyOrm::TinyOrm
|
||||
)
|
||||
|
||||
endfunction()
|
||||
@@ -0,0 +1,11 @@
|
||||
# Config file for the @PROJECT_NAME@ package
|
||||
# It defines the TinyOrm::tinyorm target to link against
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
@_find_dependency_calls@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/cmake/TinyOrmTargets.cmake")
|
||||
|
||||
check_required_components(TinyOrm)
|
||||
@@ -0,0 +1,19 @@
|
||||
# Config file for the @PROJECT_NAME@ package
|
||||
# It defines the TinyOrm::tinyorm target to link against
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set_and_check(TinyOrm_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@")
|
||||
set_and_check(TinyOrm_CONFIG_DIR "@PACKAGE_CONFIG_INSTALL_DIR@")
|
||||
set_and_check(TinyOrm_DOC_DIR "@PACKAGE_DOC_INSTALL_DIR@")
|
||||
set_and_check(TinyOrm_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
|
||||
set_and_check(TinyOrm_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
@_find_dependency_calls@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/TinyOrmTargets.cmake")
|
||||
|
||||
check_required_components(TinyOrm)
|
||||
message("|--- PACKAGE_PREFIX_DIR : ${PACKAGE_PREFIX_DIR}")
|
||||
message("|--- CMAKE_CURRENT_LIST_DIR : ${CMAKE_CURRENT_LIST_DIR}")
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
#include <variant>
|
||||
|
||||
#if defined(__clang__) || (defined(_MSC_VER) && _MSC_VER <= 1928)
|
||||
#include <range/v3/algorithm/unique.hpp>
|
||||
#endif
|
||||
|
||||
@@ -83,6 +83,18 @@ namespace Relations {
|
||||
// FEATURE build systems, add docs on how to set up dev. environment and how to run auto tests silverqx
|
||||
// FEATURE build systems, libuv example how it could look like https://github.com/libuv/libuv silverqx
|
||||
// CUR1 reorder all methods in model class silverqx
|
||||
// CUR move testdata to tests/ silverqx
|
||||
// FUTURE cmake can generate export header file by GenerateExportHeader module, find way to use it, because I have own export header file, how to unify this? I don't know now silverqx
|
||||
// CUR omg on unix is visibility of every symbol in dll public 😲, use -fvisibility and -fvisibility-inlines-hidden silverqx
|
||||
// CUR try this clang's UndefinedBehaviorSanitizer at https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html silverqx
|
||||
// CUR try clang-include-fixer at https://clang.llvm.org/extra/clang-include-fixer.html silverqx
|
||||
// CUR try iwyu at https://include-what-you-use.org/ silverqx
|
||||
// CUR enable /W4 on msvc silverqx
|
||||
// CUR constraint Qt min version and also msvc min version silverqx
|
||||
// CUR move testdata to tests/ folder or tests/scripts/ folder silverqx
|
||||
// CUR remove from NOTES.txt 'system PATH to avoid run config. bug' after everything commited and tested on all supported OSes silverqx
|
||||
// CUR unify one version number/file for cmake and qmake silverqx
|
||||
// CUR generate pkg-config file on unix silverqx
|
||||
/*! Base model class. */
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
class Model :
|
||||
@@ -1475,7 +1487,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
Derived
|
||||
Model<Derived, AllRelations...>::newInstance(
|
||||
const QVector<AttributeItem> &attributes, const bool exists)
|
||||
const QVector<AttributeItem> &attributes, const bool exists_)
|
||||
{
|
||||
/* This method just provides a convenient way for us to generate fresh model
|
||||
instances of this current model. It is particularly useful during the
|
||||
@@ -1489,7 +1501,7 @@ namespace Relations {
|
||||
|
||||
model.fill(attributes);
|
||||
|
||||
model.exists = exists;
|
||||
model.exists = exists_;
|
||||
model.setTable(this->model().getTable());
|
||||
|
||||
return model;
|
||||
@@ -1498,7 +1510,7 @@ namespace Relations {
|
||||
template<typename Derived, AllRelationsConcept ...AllRelations>
|
||||
Derived
|
||||
Model<Derived, AllRelations...>::newInstance(
|
||||
QVector<AttributeItem> &&attributes, const bool exists)
|
||||
QVector<AttributeItem> &&attributes, const bool exists_)
|
||||
{
|
||||
/* This method just provides a convenient way for us to generate fresh model
|
||||
instances of this current model. It is particularly useful during the
|
||||
@@ -1512,7 +1524,7 @@ namespace Relations {
|
||||
|
||||
model.fill(std::move(attributes));
|
||||
|
||||
model.exists = exists;
|
||||
model.exists = exists_;
|
||||
model.setTable(this->model().getTable());
|
||||
|
||||
return model;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#ifndef ORMVERSION_HPP
|
||||
#define ORMVERSION_HPP
|
||||
|
||||
#define TINY_VERSION_MAJOR @TinyOrm_VERSION_MAJOR@
|
||||
#define TINY_VERSION_MINOR @TinyOrm_VERSION_MINOR@
|
||||
#define TINY_VERSION_BUGFIX @TinyOrm_VERSION_PATCH@
|
||||
#define TINY_VERSION_BUILD @TinyOrm_VERSION_TWEAK@
|
||||
#define TINY_VERSION_STATUS "" // Should be empty for stable releases!
|
||||
|
||||
#define TINY__STRINGIFY(x) #x
|
||||
#define TINY_STRINGIFY(x) TINY__STRINGIFY(x)
|
||||
|
||||
#if TINY_VERSION_BUILD != 0
|
||||
# define PROJECT_VERSION TINY_STRINGIFY(\
|
||||
TINY_VERSION_MAJOR.TINY_VERSION_MINOR.TINY_VERSION_BUGFIX.TINY_VERSION_BUILD\
|
||||
) TINY_VERSION_STATUS
|
||||
#else
|
||||
# define PROJECT_VERSION TINY_STRINGIFY(\
|
||||
TINY_VERSION_MAJOR.TINY_VERSION_MINOR.TINY_VERSION_BUGFIX) TINY_VERSION_STATUS
|
||||
#endif
|
||||
|
||||
#define TINY_VERSION PROJECT_VERSION
|
||||
#define TINY_VERSION_2 "v" PROJECT_VERSION
|
||||
|
||||
#define TINY_ORIGINAL_FILENAME "@tiny_original_filename@"
|
||||
|
||||
#endif // ORMVERSION_HPP
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
|
||||
<!-- Indicate UAC compliance, with no need for elevated privileges (Win Vista and later) -->
|
||||
<!-- Describes the minimum security permissions required for the application to run on the client computer -->
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<!-- Identifies the security level at which the application requests to be executed -->
|
||||
<!-- Requesting no additional permissions -->
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
<!-- Declare support for various versions of Windows -->
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<asmv3:application>
|
||||
<!-- Enable long paths that exceed MAX_PATH in length -->
|
||||
<asmv3:windowsSettings xmlns:ws16="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
|
||||
<ws16:longPathAware>true</ws16:longPathAware>
|
||||
</asmv3:windowsSettings>
|
||||
|
||||
<!-- Force a process to use UTF-8 as the process code page -->
|
||||
<asmv3:windowsSettings xmlns:ws19="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
|
||||
<ws19:activeCodePage>UTF-8</ws19:activeCodePage>
|
||||
</asmv3:windowsSettings>
|
||||
|
||||
<!-- Segment heap is a modern heap implementation that will generally reduce your overall memory usage -->
|
||||
<asmv3:windowsSettings xmlns:ws20="http://schemas.microsoft.com/SMI/2020/WindowsSettings">
|
||||
<ws20:heapType>SegmentHeap</ws20:heapType>
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma code_page(65001) // UTF-8
|
||||
|
||||
IDI_ICON1 ICON "icons/tinyorm.ico"
|
||||
|
||||
#include <windows.h>
|
||||
#include "orm/version.hpp"
|
||||
|
||||
#define VER_FILEVERSION TINY_VERSION_MAJOR,TINY_VERSION_MINOR,TINY_VERSION_BUGFIX,TINY_VERSION_BUILD
|
||||
#define VER_FILEVERSION_STR TINY_VERSION "\0"
|
||||
|
||||
#define VER_PRODUCTVERSION TINY_VERSION_MAJOR,TINY_VERSION_MINOR,TINY_VERSION_BUGFIX,TINY_VERSION_BUILD
|
||||
#define VER_PRODUCTVERSION_STR TINY_VERSION "\0"
|
||||
|
||||
#define VER_ORIGINALFILENAME_STR TINY_ORIGINAL_FILENAME "\0"
|
||||
|
||||
#ifndef DEBUG
|
||||
# define VER_DEBUG 0
|
||||
#else
|
||||
# define VER_DEBUG VS_FF_DEBUG
|
||||
#endif
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VER_FILEVERSION
|
||||
PRODUCTVERSION VER_PRODUCTVERSION
|
||||
FILEFLAGSMASK VER_DEBUG
|
||||
FILEFLAGS VER_DEBUG
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Crystal Studio\0"
|
||||
VALUE "FileDescription", "TinyORM user-friendly ORM\0"
|
||||
VALUE "FileVersion", VER_FILEVERSION_STR
|
||||
VALUE "InternalName", "tinyorm\0"
|
||||
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
|
||||
VALUE "ProductName", "TinyORM\0"
|
||||
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
|
||||
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
/* End of Version info */
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 35 KiB |
@@ -2,11 +2,13 @@
|
||||
|
||||
#include <QtSql/QSqlDriver>
|
||||
|
||||
//#ifdef _MSC_VER
|
||||
//#include "mysql/mysql.h"
|
||||
//#elif __GNUG__
|
||||
//#include "mysql/mysql.h"
|
||||
//#endif
|
||||
#ifdef TINYORM_MYSQL_PING
|
||||
# ifdef _MSC_VER
|
||||
# include "mysql.h"
|
||||
# elif __GNUG__
|
||||
# include "mysql/mysql.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "orm/query/grammars/mysqlgrammar.hpp"
|
||||
#include "orm/query/processors/mysqlprocessor.hpp"
|
||||
@@ -55,61 +57,72 @@ bool MySqlConnection::isMaria()
|
||||
|
||||
bool MySqlConnection::pingDatabase()
|
||||
{
|
||||
// auto qtConnection = getQtConnection();
|
||||
#ifdef TINYORM_MYSQL_PING
|
||||
auto qtConnection = getQtConnection();
|
||||
|
||||
// const auto getMysqlHandle = [&qtConnection]() -> MYSQL *
|
||||
// {
|
||||
// if (auto driverHandle = qtConnection.driver()->handle();
|
||||
// qstrcmp(driverHandle.typeName(), "MYSQL*") == 0
|
||||
// )
|
||||
// return *static_cast<MYSQL **>(driverHandle.data());
|
||||
const auto getMysqlHandle = [&qtConnection]() -> MYSQL *
|
||||
{
|
||||
if (auto driverHandle = qtConnection.driver()->handle();
|
||||
qstrcmp(driverHandle.typeName(), "MYSQL*") == 0
|
||||
)
|
||||
return *static_cast<MYSQL **>(driverHandle.data());
|
||||
|
||||
// return nullptr;
|
||||
// };
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
// const auto mysqlPing = [getMysqlHandle]() -> bool
|
||||
// {
|
||||
// auto mysqlHandle = getMysqlHandle();
|
||||
// if (mysqlHandle == nullptr)
|
||||
// return false;
|
||||
const auto mysqlPing = [getMysqlHandle]() -> bool
|
||||
{
|
||||
auto mysqlHandle = getMysqlHandle();
|
||||
if (mysqlHandle == nullptr)
|
||||
return false;
|
||||
|
||||
// const auto ping = mysql_ping(mysqlHandle);
|
||||
// const auto errNo = mysql_errno(mysqlHandle);
|
||||
const auto ping = mysql_ping(mysqlHandle);
|
||||
const auto errNo = mysql_errno(mysqlHandle);
|
||||
|
||||
// /* So strange logic, because I want interpret CR_COMMANDS_OUT_OF_SYNC errno as
|
||||
// successful ping. */
|
||||
// if (ping != 0 && errNo == CR_COMMANDS_OUT_OF_SYNC) {
|
||||
// // TODO log to file, how often this happen silverqx
|
||||
// qWarning("mysql_ping() returned : CR_COMMANDS_OUT_OF_SYNC(%ud)", errNo);
|
||||
// return true;
|
||||
// }
|
||||
// else if (ping == 0)
|
||||
// return true;
|
||||
// else if (ping != 0)
|
||||
// return false;
|
||||
// else {
|
||||
// qWarning() << "Unknown behavior during mysql_ping(), this should never "
|
||||
// "happen :/";
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
/* So strange logic, because I want interpret CR_COMMANDS_OUT_OF_SYNC errno as
|
||||
successful ping. */
|
||||
if (ping != 0 && errNo == CR_COMMANDS_OUT_OF_SYNC) {
|
||||
// TODO log to file, how often this happen silverqx
|
||||
qWarning("mysql_ping() returned : CR_COMMANDS_OUT_OF_SYNC(%ud)", errNo);
|
||||
return true;
|
||||
}
|
||||
else if (ping == 0)
|
||||
return true;
|
||||
else if (ping != 0)
|
||||
return false;
|
||||
else {
|
||||
qWarning() << "Unknown behavior during mysql_ping(), this should never "
|
||||
"happen :/";
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// if (qtConnection.isOpen() && mysqlPing()) {
|
||||
// logConnected();
|
||||
// return true;
|
||||
// }
|
||||
if (qtConnection.isOpen() && mysqlPing()) {
|
||||
logConnected();
|
||||
return true;
|
||||
}
|
||||
|
||||
// // The database connection was lost
|
||||
// logDisconnected();
|
||||
// The database connection was lost
|
||||
logDisconnected();
|
||||
|
||||
// // Database connection have to be closed manually
|
||||
// // isOpen() check is called in MySQL driver
|
||||
// qtConnection.close();
|
||||
// Database connection have to be closed manually
|
||||
// isOpen() check is called in MySQL driver
|
||||
qtConnection.close();
|
||||
|
||||
// // Reset in transaction state and the savepoints counter
|
||||
// resetTransactions();
|
||||
// Reset in transaction state and the savepoints counter
|
||||
resetTransactions();
|
||||
|
||||
return false;
|
||||
#else
|
||||
throw Exceptions::RuntimeError(
|
||||
QStringLiteral(
|
||||
"pingDatabase() method was disabled for the '%1' database driver, "
|
||||
"if you want to use MySqlConnection::pingDatabase(), then "
|
||||
"reconfigure the TinyORM project with the MYSQL_PING preprocessor "
|
||||
"macro ( -DMYSQL_PING ) for cmake or with the 'mysql_ping' "
|
||||
"configuration option ( \"CONFIG+=mysql_ping\" ) for qmake.")
|
||||
.arg(driverName()));
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<QueryGrammar> MySqlConnection::getDefaultQueryGrammar() const
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(auto)
|
||||
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(functional)
|
||||
add_subdirectory(unit)
|
||||
add_subdirectory(utils)
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(orm)
|
||||
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(databasemanager)
|
||||
add_subdirectory(query)
|
||||
add_subdirectory(tiny)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(databasemanager
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(databasemanager
|
||||
tst_databasemanager.cpp
|
||||
)
|
||||
|
||||
add_test(NAME databasemanager COMMAND databasemanager)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(databasemanager)
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(querybuilder)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(querybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(querybuilder
|
||||
tst_querybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME querybuilder COMMAND querybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(querybuilder)
|
||||
@@ -0,0 +1,5 @@
|
||||
add_subdirectory(model)
|
||||
add_subdirectory(model_connection_independent)
|
||||
add_subdirectory(model_relations)
|
||||
add_subdirectory(relations_inserting_updating)
|
||||
add_subdirectory(tinybuilder)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(model
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(model
|
||||
tst_model.cpp
|
||||
)
|
||||
|
||||
add_test(NAME model COMMAND model)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(model INCLUDE_MODELS)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(model_connection_independent
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(model_connection_independent
|
||||
tst_model_connection_independent.cpp
|
||||
)
|
||||
|
||||
add_test(NAME model_connection_independent COMMAND model_connection_independent)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(model_connection_independent INCLUDE_MODELS)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(model_relations
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(model_relations
|
||||
tst_model_relations.cpp
|
||||
)
|
||||
|
||||
add_test(NAME model_relations COMMAND model_relations)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(model_relations INCLUDE_MODELS)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(relations_inserting_updating
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(relations_inserting_updating
|
||||
tst_relations_inserting_updating.cpp
|
||||
)
|
||||
|
||||
add_test(NAME relations_inserting_updating COMMAND relations_inserting_updating)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(relations_inserting_updating INCLUDE_MODELS)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(tinybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(tinybuilder
|
||||
tst_tinybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME tinybuilder COMMAND tinybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(tinybuilder INCLUDE_MODELS)
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(orm)
|
||||
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(databaseconnection)
|
||||
add_subdirectory(query)
|
||||
add_subdirectory(tiny)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(databaseconnection
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(databaseconnection
|
||||
tst_databaseconnection.cpp
|
||||
)
|
||||
|
||||
add_test(NAME databaseconnection COMMAND databaseconnection)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(databaseconnection)
|
||||
@@ -51,6 +51,13 @@ void tst_DatabaseConnection::pingDatabase() const
|
||||
QSKIP(QStringLiteral("The '%1' database driver doesn't support ping command.")
|
||||
.arg(driverName).toUtf8().constData(), );
|
||||
|
||||
#ifndef TINYORM_MYSQL_PING
|
||||
QSKIP("mysql_ping feature was disabled, to pass this test reconfigure the TinyORM "
|
||||
"project with the MYSQL_PING preprocessor macro ( -DMYSQL_PING ) for cmake "
|
||||
"or with the 'mysql_ping' configuration option ( \"CONFIG+=mysql_ping\" ) "
|
||||
"for qmake.", );
|
||||
#endif
|
||||
|
||||
const auto result = connection_.pingDatabase();
|
||||
|
||||
QVERIFY2(result, "Ping database failed.");
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
add_subdirectory(mysql_querybuilder)
|
||||
add_subdirectory(postgresql_querybuilder)
|
||||
add_subdirectory(sqlite_querybuilder)
|
||||
@@ -0,0 +1,20 @@
|
||||
project(mysql_querybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(mysql_querybuilder
|
||||
tst_mysql_querybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME mysql_querybuilder COMMAND mysql_querybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(mysql_querybuilder)
|
||||
|
||||
#set(test_env_path "${CMAKE_BINARY_DIR};${CMAKE_BINARY_DIR}/tests/auto/utils;$ENV{PATH}")
|
||||
##message(STATUS "env_path : ${test_env_path}")
|
||||
#string(REPLACE ";" "\;" test_env_path "${test_env_path}")
|
||||
#message(STATUS "env_path : ${test_env_path}")
|
||||
#set_property(TEST mysql_querybuilder APPEND PROPERTY
|
||||
# ENVIRONMENT "PATH=${test_env_path}"
|
||||
#)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(postgresql_querybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(postgresql_querybuilder
|
||||
tst_postgresql_querybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME postgresql_querybuilder COMMAND postgresql_querybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(postgresql_querybuilder)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(sqlite_querybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(sqlite_querybuilder
|
||||
tst_sqlite_querybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME sqlite_querybuilder COMMAND sqlite_querybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(sqlite_querybuilder)
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(mysql_tinybuilder)
|
||||
@@ -0,0 +1,12 @@
|
||||
project(mysql_tinybuilder
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_executable(mysql_tinybuilder
|
||||
tst_mysql_tinybuilder.cpp
|
||||
)
|
||||
|
||||
add_test(NAME mysql_tinybuilder COMMAND mysql_tinybuilder)
|
||||
|
||||
include(TinyTestCommon)
|
||||
tiny_configure_test(mysql_tinybuilder INCLUDE_MODELS)
|
||||
@@ -315,8 +315,6 @@ void tst_MySql_TinyBuilder::hasNested_Basic_OnHasMany() const
|
||||
|
||||
void tst_MySql_TinyBuilder::hasNested_Count_OnHasMany() const
|
||||
{
|
||||
auto builder = createTinyQuery<Torrent>();
|
||||
|
||||
// Single nesting
|
||||
{
|
||||
auto builder = createTinyQuery<Torrent>();
|
||||
@@ -361,8 +359,6 @@ void tst_MySql_TinyBuilder::hasNested_Count_OnHasMany() const
|
||||
|
||||
void tst_MySql_TinyBuilder::hasNested_Count_TinyBuilder_OnHasMany() const
|
||||
{
|
||||
auto builder = createTinyQuery<Torrent>();
|
||||
|
||||
// Single nesting
|
||||
{
|
||||
auto builder = createTinyQuery<Torrent>();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
project(TinyUtils
|
||||
DESCRIPTION "Utils library for TinyORM tests"
|
||||
LANGUAGES CXX
|
||||
VERSION 0.1.0.0
|
||||
)
|
||||
|
||||
add_library(TinyUtils
|
||||
src/databases.hpp
|
||||
src/utils_global.hpp
|
||||
src/databases.cpp
|
||||
)
|
||||
add_library(TinyOrm::TinyUtils ALIAS TinyUtils)
|
||||
|
||||
target_precompile_headers(TinyUtils PRIVATE $<$<COMPILE_LANGUAGE:CXX>:"pch.h">)
|
||||
|
||||
set_target_properties(TinyUtils
|
||||
PROPERTIES
|
||||
C_VISIBILITY_PRESET "hidden"
|
||||
CXX_VISIBILITY_PRESET "hidden"
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION 0
|
||||
)
|
||||
|
||||
# Create an empty SQLite database file when does not exist
|
||||
set(tiny_sqlite_db "${CMAKE_BINARY_DIR}/tests/q_tinyorm_test_1.sqlite3")
|
||||
create_sqlite_db("${tiny_sqlite_db}")
|
||||
|
||||
target_compile_definitions(TinyUtils
|
||||
PRIVATE TINYORM_SQLITE_DATABASE=${tiny_sqlite_db}
|
||||
)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(TinyUtils
|
||||
PRIVATE UTILS_BUILDING_SHARED
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(TinyUtils PUBLIC
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
target_link_libraries(TinyUtils
|
||||
PUBLIC
|
||||
TinyOrm::TinyOrm
|
||||
PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
TinyOrm::CommonConfig
|
||||
)
|
||||
@@ -2,12 +2,23 @@
|
||||
#ifndef UTILS_GLOBAL_H
|
||||
#define UTILS_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
|
||||
|| defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
|
||||
|| defined(__NT__)
|
||||
# define TINY_DECL_EXPORT __declspec(dllexport)
|
||||
# define TINY_DECL_IMPORT __declspec(dllimport)
|
||||
#elif __GNU__ >= 4
|
||||
# define TINY_DECL_EXPORT __attribute__((visibility("default")))
|
||||
# define TINY_DECL_IMPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
# define TINY_DECL_EXPORT
|
||||
# define TINY_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(UTILS_BUILDING_SHARED)
|
||||
# define UTILS_EXPORT Q_DECL_EXPORT
|
||||
# define UTILS_EXPORT TINY_DECL_EXPORT
|
||||
#else
|
||||
# define UTILS_EXPORT Q_DECL_IMPORT
|
||||
# define UTILS_EXPORT TINY_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // UTILS_GLOBAL_H
|
||||
|
||||