QxOrm入门教程02:编译

官方只在github上提供了源码,官网好像提供了一些东西,但是国内无法访问。目前是自己编译。

环境

  • Windows 10 Pro 22H2
  • Qt 5.15.12
  • Visual Studio 2022

编译

下载最新的代码,使用Qt Creator打开工程文件。

官方提供了pro/CMakeLists.txt格式工程文件,根据需要选择。

点击构建即可,生成的lib/dll不到10MB。

XML支持

之前介绍过,QxOrm支持XML/JSON的序列化和反序列化,默认编译参数是支持JSON读写的,XML需要手动修改参数编译。

boost

QxOrm XML支持需要boost库,Windows下使用vcpkg安装

1
vcpkg install boost

pri

修改QxOrm.pri文件

第59行放开BOOST支持

1
2
# DEFINES += _QX_ENABLE_BOOST
DEFINES += _QX_ENABLE_BOOST

第72行

1
2
# DEFINES += _QX_ENABLE_BOOST_SERIALIZATION
DEFINES += _QX_ENABLE_BOOST_SERIALIZATION BOOST_ARCHIVE_SOURCE BOOST_WARCHIVE_SOURCE

在92行下添加

1
2
3
4
5
6
7
BOOST_INCLUDE = C:\vcpkg\installed\x64-windows\include

BOOST_LIB = C:\vcpkg\installed\x64-windows\debug\lib

BOOST_LIB_SERIALIZATION_DEBUG = boost_serialization-vc142-mt-gd-x64-1_87

BOOST_LIB_SERIALIZATION_RELEASE = boost_serialization-vc142-mt-x64-1_87

修改100行下的变量

1
2
3
4
5
6
7
8
9
10
11
12
contains(DEFINES, _QX_ENABLE_BOOST) {
isEmpty(QX_BOOST_INCLUDE_PATH) { QX_BOOST_INCLUDE_PATH = $$quote($${BOOST_INCLUDE}) }
contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION) {

isEmpty(QX_BOOST_LIB_PATH) { QX_BOOST_LIB_PATH = $$quote($${BOOST_LIB}) }
isEmpty(QX_BOOST_LIB_SERIALIZATION_DEBUG) { QX_BOOST_LIB_SERIALIZATION_DEBUG = "$${BOOST_LIB_SERIALIZATION_DEBUG}" }
isEmpty(QX_BOOST_LIB_SERIALIZATION_RELEASE) { QX_BOOST_LIB_SERIALIZATION_RELEASE = "$${BOOST_LIB_SERIALIZATION_RELEASE}" }
# isEmpty(QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG) { QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG = "$$(BOOST_LIB_WIDE_SERIALIZATION_DEBUG)" }
# isEmpty(QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE) { QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE = "$$(BOOST_LIB_WIDE_SERIALIZATION_RELEASE)" }

} # contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION)
} # contains(DEFINES, _QX_ENABLE_BOOST)

工程文件

可能会用到的完整的工程文件

QxOrm.pri

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#############################################################################
##
## https://www.qxorm.com/
## Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
##
## This file is part of the QxOrm library
##
## This software is provided 'as-is', without any express or implied
## warranty. In no event will the authors be held liable for any
## damages arising from the use of this software
##
## Commercial Usage
## Licensees holding valid commercial QxOrm licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and Lionel Marty
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3.0 as published by the Free Software
## Foundation and appearing in the file 'license.gpl3.txt' included in the
## packaging of this file. Please review the following information to
## ensure the GNU General Public License version 3.0 requirements will be
## met : http://www.gnu.org/copyleft/gpl.html
##
## If you are unsure which license is appropriate for your use, or
## if you have questions regarding the use of this file, please contact :
## contact@qxorm.com
##
#############################################################################

###########################################
# QxOrm library requires a C++11 compiler #
###########################################

# Qt framework requires a C++11 compiler since version Qt 5.7
# So for all previous Qt versions, we need to define CONFIG += c++11
# Please note that QxOrm library doesn't require a full compliant C++11 compiler : for example, QxOrm library can be built and used with MSVC 2012, GCC 4.5 or Clang 3.2

lessThan(QT_MAJOR_VERSION, 5) {
CONFIG += c++11
# QMAKE_CXXFLAGS += -std=c++11
} else {
equals(QT_MAJOR_VERSION, 5) {
lessThan(QT_MINOR_VERSION, 7) {
CONFIG += c++11
} # lessThan(QT_MINOR_VERSION, 7)
} # equals(QT_MAJOR_VERSION, 5)
} # lessThan(QT_MAJOR_VERSION, 5)

###########################################
# Boost Header-Only Dependency (optional) #
###########################################

# Since QxOrm 1.4.4, QxOrm library doesn't depend on boost framework anymore (the boost dependency has been fully removed, replaced by some C++11 features)
# So QxOrm library is now a pure Qt library which depends only on QtCore and QtSql by default
# QxOrm library still supports some boost classes (boost smart-pointers, unordered containers, boost::optional, etc...) : you have to define _QX_ENABLE_BOOST compilation option to enable these features

DEFINES += _QX_ENABLE_BOOST

############################################################
# Boost Serialization Shared Library Dependency (optional) #
############################################################

# By default, QxOrm library doesn't depend on boost::serialization shared library, but it is possible to enable it defining the compilation option : _QX_ENABLE_BOOST_SERIALIZATION
# Without this compilation option, QxOrm is a much lighter library, generated binaries based on QxOrm are smaller, and QxOrm depends only on Qt binaries (and boost header files)
# But in this case, serialization features are limited (based on QDataStream and QJson engines) : limited qx::clone, no XML serialization, limited binary serialization, limited QxService module (network transactions), etc...
# If you define _QX_ENABLE_BOOST_SERIALIZATION compilation option, then boost serialization is enabled with XML and binary engine by default (see _QX_ENABLE_BOOST_SERIALIZATION_BINARY and _QX_ENABLE_BOOST_SERIALIZATION_XML for more details)
# Note : if you are not using serialization functions in projects based on QxOrm library, then you can define or not _QX_ENABLE_BOOST_SERIALIZATION compilation option without changing any line of your source code
# Other note : to persist containers in database (not relationships, for example : std::vector<int>), without _QX_ENABLE_BOOST_SERIALIZATION it is stored as QByteArray (based on QDataStream engine), with _QX_ENABLE_BOOST_SERIALIZATION it is stored as XML (based on boost serialization XML engine) => so be careful, in this case it is not compatible

DEFINES += _QX_ENABLE_BOOST_SERIALIZATION BOOST_ARCHIVE_SOURCE BOOST_WARCHIVE_SOURCE

contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION) {
!contains(DEFINES, _QX_ENABLE_BOOST) {
DEFINES += _QX_ENABLE_BOOST
} # !contains(DEFINES, _QX_ENABLE_BOOST)
} # contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION)

######################################
# Boost Library Configuration / Path #
######################################

# In this section, it's necessary to specify boost directories (lib + include) and boost serialization module name (debug + release) :
# - QX_BOOST_INCLUDE_PATH (required) : your boost include path (by default, environment variable named BOOST_INCLUDE)
# - QX_BOOST_LIB_PATH (optional) : your boost lib path (by default, environment variable named BOOST_LIB)
# - QX_BOOST_LIB_SERIALIZATION_DEBUG (optional) : your boost serialization module name in debug mode (by default, environment variable named BOOST_LIB_SERIALIZATION_DEBUG)
# - QX_BOOST_LIB_SERIALIZATION_RELEASE (optional) : your boost serialization module name in release mode (by default, environment variable named BOOST_LIB_SERIALIZATION_RELEASE)
# - QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG (optional) : your boost wide serialization module name in debug mode (default is empty)
# - QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE (optional) : your boost wide serialization module name in release mode (default is empty)
# Note : if _QX_ENABLE_BOOST_SERIALIZATION is not defined, then the only option used is QX_BOOST_INCLUDE_PATH (other options are ignored, QxOrm just needs to know how to find boost header files)

BOOST_INCLUDE = C:\vcpkg\installed\x64-windows\include

BOOST_LIB = C:\vcpkg\installed\x64-windows\debug\lib

BOOST_LIB_SERIALIZATION_DEBUG = boost_serialization-vc142-mt-gd-x64-1_87

BOOST_LIB_SERIALIZATION_RELEASE = boost_serialization-vc142-mt-x64-1_87

contains(DEFINES, _QX_ENABLE_BOOST) {
isEmpty(QX_BOOST_INCLUDE_PATH) { QX_BOOST_INCLUDE_PATH = $$quote($${BOOST_INCLUDE}) }
contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION) {

isEmpty(QX_BOOST_LIB_PATH) { QX_BOOST_LIB_PATH = $$quote($${BOOST_LIB}) }
isEmpty(QX_BOOST_LIB_SERIALIZATION_DEBUG) { QX_BOOST_LIB_SERIALIZATION_DEBUG = "$${BOOST_LIB_SERIALIZATION_DEBUG}" }
isEmpty(QX_BOOST_LIB_SERIALIZATION_RELEASE) { QX_BOOST_LIB_SERIALIZATION_RELEASE = "$${BOOST_LIB_SERIALIZATION_RELEASE}" }
# isEmpty(QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG) { QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG = "$$(BOOST_LIB_WIDE_SERIALIZATION_DEBUG)" }
# isEmpty(QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE) { QX_BOOST_LIB_WIDE_SERIALIZATION_RELEASE = "$$(BOOST_LIB_WIDE_SERIALIZATION_RELEASE)" }

} # contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION)
} # contains(DEFINES, _QX_ENABLE_BOOST)

####################################
# Check Boost Configuration / Path #
####################################
...

QxOrm入门教程02:编译
https://blog.jackeylea.com/qxorm/how-to-build-qxorm/
作者
JackeyLea
发布于
2025年4月25日
许可协议