added LibraryInfo class

This class provides info about build type, isDebugBuild() and version.

 - removed QT_DEBUG/QT_NO_DEBUG and used TINYORM_DEBUG/TINYORM_NO_DEBUG
   instead
This commit is contained in:
silverqx
2021-10-19 16:11:54 +02:00
parent 0b1557bac7
commit 3212fc4d1c
18 changed files with 303 additions and 32 deletions
+5 -1
View File
@@ -186,6 +186,10 @@ target_compile_definitions(${TinyOrm_target}
PROJECT_TINYORM
# Log queries with a time measurement
TINYORM_DEBUG_SQL
# Release build
$<$<NOT:$<CONFIG:Debug>>:TINYORM_NO_DEBUG>
# Debug build
$<$<CONFIG:Debug>:TINYORM_DEBUG>
)
if(BUILD_SHARED_LIBS)
@@ -331,7 +335,7 @@ endif()
if(VERBOSE_CONFIGURE)
if(NOT TINY_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling debug output")
message(STATUS "Disabled debug output and assert")
endif()
feature_summary(WHAT ALL)
+1 -1
View File
@@ -123,7 +123,7 @@ build
set(TINY_RC_FLAGS_BACKUP "")
# Add -nologo to the CMAKE_RC_FLAGS if it does not already contain it
if(NOT CMAKE_RC_FLAGS MATCHES " *[-/]nologo *")
if(MSVC AND NOT CMAKE_RC_FLAGS MATCHES " *[-/]nologo *")
get_property(help_string CACHE CMAKE_RC_FLAGS PROPERTY HELPSTRING)
if(NOT help_string)
set(help_string "Flags for Windows Resource Compiler during all build types.")
+4
View File
@@ -37,8 +37,11 @@ function(tiny_sources out_headers out_sources)
exceptions/runtimeerror.hpp
exceptions/sqlerror.hpp
exceptions/sqltransactionerror.hpp
libraryinfo.hpp
logquery.hpp
macros.hpp
macros/archdetect.hpp
macros/compilerdetect.hpp
macros/systemheader.hpp
mysqlconnection.hpp
ormtypes.hpp
@@ -119,6 +122,7 @@ function(tiny_sources out_headers out_sources)
exceptions/queryerror.cpp
exceptions/runtimeerror.cpp
exceptions/sqlerror.cpp
libraryinfo.cpp
logquery.cpp
mysqlconnection.cpp
ormtypes.cpp
+3
View File
@@ -33,8 +33,11 @@ HEADERS += \
$$PWD/orm/exceptions/runtimeerror.hpp \
$$PWD/orm/exceptions/sqlerror.hpp \
$$PWD/orm/exceptions/sqltransactionerror.hpp \
$$PWD/orm/libraryinfo.hpp \
$$PWD/orm/logquery.hpp \
$$PWD/orm/macros.hpp \
$$PWD/orm/macros/archdetect.hpp \
$$PWD/orm/macros/compilerdetect.hpp \
$$PWD/orm/macros/systemheader.hpp \
$$PWD/orm/mysqlconnection.hpp \
$$PWD/orm/ormtypes.hpp \
+5
View File
@@ -11,4 +11,9 @@ TINY_SYSTEM_HEADER
# define TINYORM_EXTERN_CONSTANTS
#endif
// Debug build
#if !defined(TINYORM_NO_DEBUG) && !defined(TINYORM_DEBUG)
# define TINYORM_DEBUG
#endif
#endif // ORM_CONFIG_HPP
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#ifndef ORM_LIBRARYINFO_H
#define ORM_LIBRARYINFO_H
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
#include <QVersionNumber>
#include "orm/utils/export.hpp"
#ifdef TINYORM_COMMON_NAMESPACE
namespace TINYORM_COMMON_NAMESPACE
{
#endif
namespace Orm
{
class SHAREDLIB_EXPORT LibraryInfo
{
Q_DISABLE_COPY(LibraryInfo)
public:
/*! Deleted DB's default constructor, this is a pure library class. */
LibraryInfo() = delete;
/*! Deleted DB's destructor. */
~LibraryInfo() = delete;
/*! Return a string describing how this version of TinyORM library was built. */
static const char *build() noexcept;
/*! Return true if this build of TinyORM was built with debugging enabled, or
false if it was built in release mode. */
static bool isDebugBuild();
/*! Return the version of the TinyORM library. */
static QVersionNumber version() noexcept Q_DECL_CONST_FUNCTION;
};
} // namespace Orm
#ifdef TINYORM_COMMON_NAMESPACE
} // namespace TINYORM_COMMON_NAMESPACE
#endif
#endif // ORM_LIBRARYINFO_H
+2 -2
View File
@@ -20,14 +20,14 @@ QString parseExecutedQuery(const QSqlQuery &query);
/*! Get pretended query with replaced placeholders ( ideal for logging ). */
QString parseExecutedQueryForPretend(QString query, const QVector<QVariant> &bindings);
#ifdef QT_DEBUG
#if !defined(TINYORM_NO_DEBUG)
/*! Log the last executed query to the debug output. */
[[maybe_unused]]
void logExecutedQuery(const QSqlQuery &query);
#endif
#ifndef LOG_EXECUTED_QUERY
# ifdef QT_DEBUG
# if !defined(TINYORM_NO_DEBUG)
# define LOG_EXECUTED_QUERY(query) logExecutedQuery(query)
# else
# define LOG_EXECUTED_QUERY(query) qt_noop()
+110
View File
@@ -0,0 +1,110 @@
#pragma once
#ifndef ORM_ARCHDETECT_H
#define ORM_ARCHDETECT_H
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
// main part: processor type
#if defined(Q_PROCESSOR_ALPHA)
# define ARCH_PROCESSOR "alpha"
#elif defined(Q_PROCESSOR_ARM_32)
# define ARCH_PROCESSOR "arm"
#elif defined(Q_PROCESSOR_ARM_64)
# define ARCH_PROCESSOR "arm64"
#elif defined(Q_PROCESSOR_AVR32)
# define ARCH_PROCESSOR "avr32"
#elif defined(Q_PROCESSOR_BLACKFIN)
# define ARCH_PROCESSOR "bfin"
#elif defined(Q_PROCESSOR_WASM)
# define ARCH_PROCESSOR "wasm"
#elif defined(Q_PROCESSOR_X86_32)
# define ARCH_PROCESSOR "i386"
#elif defined(Q_PROCESSOR_X86_64)
# define ARCH_PROCESSOR "x86_64"
#elif defined(Q_PROCESSOR_IA64)
# define ARCH_PROCESSOR "ia64"
#elif defined(Q_PROCESSOR_MIPS_64)
# define ARCH_PROCESSOR "mips64"
#elif defined(Q_PROCESSOR_MIPS)
# define ARCH_PROCESSOR "mips"
#elif defined(Q_PROCESSOR_POWER_32)
# define ARCH_PROCESSOR "power"
#elif defined(Q_PROCESSOR_POWER_64)
# define ARCH_PROCESSOR "power64"
#elif defined(Q_PROCESSOR_RISCV_32)
# define ARCH_PROCESSOR "riscv32"
#elif defined(Q_PROCESSOR_RISCV_64)
# define ARCH_PROCESSOR "riscv64"
#elif defined(Q_PROCESSOR_S390_X)
# define ARCH_PROCESSOR "s390x"
#elif defined(Q_PROCESSOR_S390)
# define ARCH_PROCESSOR "s390"
#elif defined(Q_PROCESSOR_SH)
# define ARCH_PROCESSOR "sh"
#elif defined(Q_PROCESSORS_SPARC_64)
# define ARCH_PROCESSOR "sparc64"
#elif defined(Q_PROCESSOR_SPARC_V9)
# define ARCH_PROCESSOR "sparcv9"
#elif defined(Q_PROCESSOR_SPARC)
# define ARCH_PROCESSOR "sparc"
#else
# define ARCH_PROCESSOR "unknown"
#endif
// endianness
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
# define ARCH_ENDIANNESS "little_endian"
#elif Q_BYTE_ORDER == Q_BIG_ENDIAN
# define ARCH_ENDIANNESS "big_endian"
#endif
// pointer type
#if defined(Q_OS_WIN64)
# define ARCH_POINTER "llp64"
#elif defined(__LP64__) || QT_POINTER_SIZE - 0 == 8
# define ARCH_POINTER "lp64"
#else
# define ARCH_POINTER "ilp32"
#endif
// qreal type, if not double (includes the dash)
#ifdef QT_COORD_TYPE_STRING
# define ARCH_COORD_TYPE "-qreal_" QT_COORD_TYPE_STRING
#else
# define ARCH_COORD_TYPE ""
#endif
// secondary: ABI string (includes the dash)
#if defined(__ARM_EABI__) || defined(__mips_eabi)
# define ARCH_ABI1 "-eabi"
#elif defined(_MIPS_SIM)
# if _MIPS_SIM == _ABIO32
# define ARCH_ABI1 "-o32"
# elif _MIPS_SIM == _ABIN32
# define ARCH_ABI1 "-n32"
# elif _MIPS_SIM == _ABI64
# define ARCH_ABI1 "-n64"
# elif _MIPS_SIM == _ABIO64
# define ARCH_ABI1 "-o64"
# endif
#else
# define ARCH_ABI1 ""
#endif
#if defined(__ARM_PCS_VFP) || defined(__mips_hard_float)
// Use "-hardfloat" for platforms that usually have no FPUs
// (and for the platforms which had "-hardfloat" before we established the rule)
# define ARCH_ABI2 "-hardfloat"
#elif defined(_SOFT_FLOAT)
// Use "-softfloat" for architectures that usually have FPUs
# define ARCH_ABI2 "-softfloat"
#else
# define ARCH_ABI2 ""
#endif
#define ARCH_ABI ARCH_ABI1 ARCH_ABI2
#define ARCH_FULL ARCH_PROCESSOR "-" ARCH_ENDIANNESS "-" ARCH_POINTER ARCH_COORD_TYPE \
ARCH_ABI
#endif // ORM_ARCHDETECT_H
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#ifndef ORM_COMPILERDETECT_H
#define ORM_COMPILERDETECT_H
#include "orm/macros/systemheader.hpp"
TINY_SYSTEM_HEADER
// Used compiler
// Must be before GNU, because clang claims to be GNU too
#if defined(__clang__)
// Apple clang has other version numbers
# ifdef __apple_build_version__
# define TINYORM_COMPILER_STRING "Clang " __clang_version__ " (Apple)"
# else
# define TINYORM_COMPILER_STRING "Clang " __clang_version__
# endif
#elif defined(__GNUC__)
# define TINYORM_COMPILER_STRING "GCC " __VERSION__
#elif defined(_MSC_VER)
# if _MSC_VER < 1910
# define TINYORM_COMPILER_STRING "MSVC 2015 (" TINYORM_STRINGIFY(_MSC_VER) ")"
# elif _MSC_VER < 1917
# define TINYORM_COMPILER_STRING "MSVC 2017 (" TINYORM_STRINGIFY(_MSC_VER) ")"
# elif _MSC_VER < 1930
# define TINYORM_COMPILER_STRING "MSVC 2019 (" TINYORM_STRINGIFY(_MSC_VER) ")"
# elif _MSC_VER < 2000
# define TINYORM_COMPILER_STRING "MSVC 2022 (" TINYORM_STRINGIFY(_MSC_VER) ")"
# else
# define TINYORM_COMPILER_STRING "MSVC _MSC_VER " TINYORM_STRINGIFY(_MSC_VER)
# endif
#else
# define TINYORM_COMPILER_STRING "<unknown compiler>"
#endif
#endif // ORM_COMPILERDETECT_H
+3 -1
View File
@@ -108,7 +108,9 @@ namespace Relations {
// BUG cmake MinGW UCRT64 clang static build builds, but cause problem with inline_constants ; shared build with inline_constants cause crashes of 50% of tests, like bug above, this will be MinGW clang or clang bug, on unix it works without problems silverqx
// FUTURE linux, add linker version script https://github.com/sailfishos/qtbase/commit/72ba0079c3967bdfa26acdce78ce6cb98b30c27b?view=parallel https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html https://stackoverflow.com/questions/41061220/where-do-object-file-version-references-come-from silverqx
// TODO Visual Studio memory analyzer https://docs.microsoft.com/en-us/visualstudio/profiling/memory-usage-without-debugging2?view=vs-2019 silverqx
// CUR QLibraryInfo to TinyORM silverqx
// CUR replace all TINYORM_COMMON_NAMESPACE and Orm namespace with macros silverqx
// CUR move export.hpp to macros/ silverqx
// CUR cmake rename TinyQtCommon to TinyCommon silverqx
/*! Base model class. */
template<typename Derived, AllRelationsConcept ...AllRelations>
class Model :
+8 -3
View File
@@ -8,7 +8,7 @@ CONFIG(shared, dll|shared|static|staticlib) | \
CONFIG(dll, dll|shared|static|staticlib): \
# Support override because inline_constants can be used in the shared build too
!inline_constants: \
CONFIG += extern_constants
CONFIG *= extern_constants
# Archive library build
else: \
@@ -18,9 +18,14 @@ else: \
# ---
# Log queries with a time measurement
DEFINES += TINYORM_DEBUG_SQL
DEFINES *= TINYORM_DEBUG_SQL
# Release build
CONFIG(release, debug|release): DEFINES *= TINYORM_NO_DEBUG
# Debug build
CONFIG(debug, debug|release): DEFINES *= TINYORM_DEBUG
# Link with the shared library
CONFIG(shared, dll|shared|static|staticlib) | \
CONFIG(dll, dll|shared|static|staticlib): \
DEFINES += TINYORM_LINKING_SHARED
DEFINES *= TINYORM_LINKING_SHARED
+16 -8
View File
@@ -22,19 +22,27 @@ CONFIG -= c++11 app_bundle
# Disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
#DEFINES += QT_ASCII_CAST_WARNINGS
#DEFINES += QT_NO_CAST_FROM_ASCII
#DEFINES += QT_RESTRICTED_CAST_FROM_ASCII
DEFINES += QT_NO_CAST_TO_ASCII
DEFINES += QT_NO_CAST_FROM_BYTEARRAY
DEFINES += QT_USE_QSTRINGBUILDER
DEFINES += QT_STRICT_ITERATORS
#DEFINES *= QT_ASCII_CAST_WARNINGS
#DEFINES *= QT_NO_CAST_FROM_ASCII
#DEFINES *= QT_RESTRICTED_CAST_FROM_ASCII
DEFINES *= QT_NO_CAST_TO_ASCII
DEFINES *= QT_NO_CAST_FROM_BYTEARRAY
DEFINES *= QT_USE_QSTRINGBUILDER
DEFINES *= QT_STRICT_ITERATORS
# Disable debug output in release mode
CONFIG(release, debug|release): DEFINES += QT_NO_DEBUG_OUTPUT
# TinyORM defines
# ---
# Enable MySQL ping on Orm::MySqlConnection
mysql_ping: DEFINES += TINYORM_MYSQL_PING
mysql_ping: DEFINES *= TINYORM_MYSQL_PING
# Release build
CONFIG(release, debug|release): DEFINES *= TINYORM_NO_DEBUG
# Debug build
CONFIG(debug, debug|release): DEFINES *= TINYORM_DEBUG
# Platform specific configuration
# ---
+3 -3
View File
@@ -13,10 +13,10 @@ IDI_ICON1 ICON "icons/@TinyOrm_target@.ico"
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyOrm_target@>\0"
#ifdef _DEBUG
# define VER_DEBUG VS_FF_DEBUG
#else
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
+55
View File
@@ -0,0 +1,55 @@
#include "orm/libraryinfo.hpp"
#include "orm/macros/archdetect.hpp"
#include "orm/macros/compilerdetect.hpp"
#include "orm/version.hpp"
// Build type release/debug
#ifdef TINYORM_NO_DEBUG
# define DEBUG_STRING " release"
#else
# define DEBUG_STRING " debug"
#endif
// static/shared
#ifdef TINYORM_BUILDING_SHARED
# define SHARED_STRING " shared"
#else
# define SHARED_STRING " static"
#endif
// Full build type string
#define TINYORM_BUILD_STR "TinyORM " TINYORM_VERSION_STR " (" ARCH_FULL SHARED_STRING \
DEBUG_STRING " build; by " TINYORM_COMPILER_STRING ")"
#ifdef TINYORM_COMMON_NAMESPACE
namespace TINYORM_COMMON_NAMESPACE
{
#endif
namespace Orm
{
const char *LibraryInfo::build() noexcept
{
return TINYORM_BUILD_STR;
}
bool LibraryInfo::isDebugBuild()
{
#ifdef TINYORM_NO_DEBUG
return false;
#else
return true;
#endif
}
QVersionNumber LibraryInfo::version() noexcept
{
return QVersionNumber(TINYORM_VERSION_MAJOR, TINYORM_VERSION_MINOR,
TINYORM_VERSION_BUGFIX);
}
} // namespace Orm
#ifdef TINYORM_COMMON_NAMESPACE
} // namespace TINYORM_COMMON_NAMESPACE
#endif
+1
View File
@@ -17,6 +17,7 @@ SOURCES += \
$$PWD/orm/exceptions/queryerror.cpp \
$$PWD/orm/exceptions/runtimeerror.cpp \
$$PWD/orm/exceptions/sqlerror.cpp \
$$PWD/orm/libraryinfo.cpp \
$$PWD/orm/logquery.cpp \
$$PWD/orm/mysqlconnection.cpp \
$$PWD/orm/ormtypes.cpp \
+2 -7
View File
@@ -89,13 +89,8 @@ win32-msvc:CONFIG(debug, debug|release) {
# ---
CONFIG(debug, debug|release):!build_pass: message( "Project is built in DEBUG mode." )
CONFIG(release, debug|release):!build_pass: message( "Project is built in RELEASE mode." )
# Disable debug output in release mode
CONFIG(release, debug|release) {
!build_pass: message( "Disabling debug output." )
DEFINES += QT_NO_DEBUG_OUTPUT
}
CONFIG(release, debug|release):!build_pass: \
message( "Project is built in RELEASE mode (disabled debug output and assert)." )
# User Configuration
# ---
+3 -3
View File
@@ -13,10 +13,10 @@
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyUtils_target@>\0"
#ifdef _DEBUG
# define VER_DEBUG VS_FF_DEBUG
#else
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
+3 -3
View File
@@ -6,10 +6,10 @@
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyTest_target@>\0"
#ifdef _DEBUG
# define VER_DEBUG VS_FF_DEBUG
#else
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO