Skip to content

Commit 8463d7b

Browse files
committed
Firebird usage in C++ with cmake and vcpkg.
1 parent 6503397 commit 8463d7b

32 files changed

+692
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vcpkg"]
2+
path = vcpkg
3+
url = https://github.com/asfernandes/temp-firebird-vcpkg.git

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Firebird examples
22

33
- [Firebird embedded usage in an Android app using C++](android-cpp/README.md)
4+
- [Firebird client usage in C++ with cmake and vcpkg](cmake-vcpkg/README.md)

cmake-vcpkg/.clang-format

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: WebKit
4+
AccessModifierOffset: -4
5+
AlignAfterOpenBracket: DontAlign
6+
AlignArrayOfStructures: None
7+
AlignConsecutiveMacros: None
8+
AlignConsecutiveAssignments: None
9+
AlignConsecutiveBitFields: None
10+
AlignConsecutiveDeclarations: None
11+
AlignEscapedNewlines: Right
12+
AlignOperands: DontAlign
13+
AlignTrailingComments: false
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Empty
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: Empty
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: Yes
27+
AttributeMacros:
28+
- __capability
29+
BinPackArguments: true
30+
BinPackParameters: true
31+
BraceWrapping:
32+
AfterCaseLabel: false
33+
AfterClass: false
34+
AfterControlStatement: Never
35+
AfterEnum: false
36+
AfterFunction: true
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
AfterExternBlock: false
42+
BeforeCatch: false
43+
BeforeElse: false
44+
BeforeLambdaBody: false
45+
BeforeWhile: false
46+
IndentBraces: false
47+
SplitEmptyFunction: true
48+
SplitEmptyRecord: true
49+
SplitEmptyNamespace: true
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeConceptDeclarations: true
52+
BreakBeforeBraces: Allman
53+
BreakBeforeInheritanceComma: false
54+
BreakInheritanceList: BeforeColon
55+
BreakBeforeTernaryOperators: true
56+
BreakConstructorInitializersBeforeComma: false
57+
BreakConstructorInitializers: BeforeColon
58+
BreakAfterJavaFieldAnnotations: false
59+
BreakStringLiterals: true
60+
ColumnLimit: 120
61+
CommentPragmas: '^ IWYU pragma:'
62+
QualifierAlignment: Leave
63+
CompactNamespaces: false
64+
ConstructorInitializerIndentWidth: 4
65+
ContinuationIndentWidth: 4
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: true
68+
DerivePointerAlignment: false
69+
DisableFormat: false
70+
EmptyLineAfterAccessModifier: Never
71+
EmptyLineBeforeAccessModifier: LogicalBlock
72+
ExperimentalAutoDetectBinPacking: false
73+
PackConstructorInitializers: Never
74+
BasedOnStyle: ''
75+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76+
AllowAllConstructorInitializersOnNextLine: true
77+
FixNamespaceComments: true
78+
ForEachMacros:
79+
- foreach
80+
- Q_FOREACH
81+
- BOOST_FOREACH
82+
IfMacros:
83+
- KJ_IF_MAYBE
84+
IncludeBlocks: Preserve
85+
IncludeCategories:
86+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
87+
Priority: 2
88+
SortPriority: 0
89+
CaseSensitive: false
90+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
91+
Priority: 3
92+
SortPriority: 0
93+
CaseSensitive: false
94+
- Regex: '.*'
95+
Priority: 1
96+
SortPriority: 0
97+
CaseSensitive: false
98+
IncludeIsMainRegex: '(Test)?$'
99+
IncludeIsMainSourceRegex: ''
100+
IndentAccessModifiers: false
101+
IndentCaseLabels: true
102+
IndentCaseBlocks: false
103+
IndentGotoLabels: true
104+
IndentPPDirectives: None
105+
IndentExternBlock: AfterExternBlock
106+
IndentRequires: false
107+
IndentWidth: 4
108+
IndentWrappedFunctionNames: false
109+
InsertTrailingCommas: None
110+
JavaScriptQuotes: Leave
111+
JavaScriptWrapImports: true
112+
KeepEmptyLinesAtTheStartOfBlocks: true
113+
LambdaBodyIndentation: Signature
114+
MacroBlockBegin: ''
115+
MacroBlockEnd: ''
116+
MaxEmptyLinesToKeep: 2
117+
NamespaceIndentation: All
118+
ObjCBinPackProtocolList: Auto
119+
ObjCBlockIndentWidth: 4
120+
ObjCBreakBeforeNestedBlockParam: true
121+
ObjCSpaceAfterProperty: true
122+
ObjCSpaceBeforeProtocolList: true
123+
PenaltyBreakAssignment: 2
124+
PenaltyBreakBeforeFirstCallParameter: 19
125+
PenaltyBreakComment: 300
126+
PenaltyBreakFirstLessLess: 120
127+
PenaltyBreakOpenParenthesis: 0
128+
PenaltyBreakString: 1000
129+
PenaltyBreakTemplateDeclaration: 10
130+
PenaltyExcessCharacter: 1000000
131+
PenaltyReturnTypeOnItsOwnLine: 60
132+
PenaltyIndentedWhitespace: 0
133+
PointerAlignment: Left
134+
PPIndentWidth: -1
135+
ReferenceAlignment: Pointer
136+
ReflowComments: true
137+
RemoveBracesLLVM: false
138+
SeparateDefinitionBlocks: Leave
139+
ShortNamespaceLines: 1
140+
SortIncludes: Never
141+
SortJavaStaticImport: Before
142+
SortUsingDeclarations: true
143+
SpaceAfterCStyleCast: true
144+
SpaceAfterLogicalNot: false
145+
SpaceAfterTemplateKeyword: true
146+
SpaceBeforeAssignmentOperators: true
147+
SpaceBeforeCaseColon: false
148+
SpaceBeforeCpp11BracedList: false
149+
SpaceBeforeCtorInitializerColon: true
150+
SpaceBeforeInheritanceColon: true
151+
SpaceBeforeParens: ControlStatements
152+
SpaceBeforeParensOptions:
153+
AfterControlStatements: true
154+
AfterForeachMacros: true
155+
AfterFunctionDefinitionName: false
156+
AfterFunctionDeclarationName: false
157+
AfterIfMacros: true
158+
AfterOverloadedOperator: false
159+
BeforeNonEmptyParentheses: false
160+
SpaceAroundPointerQualifiers: Default
161+
SpaceBeforeRangeBasedForLoopColon: true
162+
SpaceInEmptyBlock: true
163+
SpaceInEmptyParentheses: false
164+
SpacesBeforeTrailingComments: 2
165+
SpacesInAngles: Never
166+
SpacesInConditionalStatement: false
167+
SpacesInContainerLiterals: true
168+
SpacesInCStyleCastParentheses: false
169+
SpacesInLineCommentPrefix:
170+
Minimum: 1
171+
Maximum: -1
172+
SpacesInParentheses: false
173+
SpacesInSquareBrackets: false
174+
SpaceBeforeSquareBrackets: false
175+
BitFieldColonSpacing: Both
176+
Standard: Latest
177+
StatementAttributeLikeMacros:
178+
- Q_EMIT
179+
StatementMacros:
180+
- Q_UNUSED
181+
- QT_REQUIRE_VERSION
182+
TabWidth: 4
183+
UseCRLF: false
184+
UseTab: AlignWithSpaces
185+
WhitespaceSensitiveMacros:
186+
- STRINGIZE
187+
- PP_STRINGIZE
188+
- BOOST_PP_STRINGIZE
189+
- NS_SWIFT_NAME
190+
- CF_SWIFT_NAME
191+
...

cmake-vcpkg/.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
charset = utf-8
3+
insert_final_newline = true
4+
trim_trailing_whitespace = true
5+
6+
[*]
7+
indent_style = tab
8+
indent_size = 4
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.json]
15+
indent_style = space
16+
indent_size = 2

cmake-vcpkg/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
vcpkg_installed/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"cppStandard": "c++17",
10+
"intelliSenseMode": "linux-gcc-x64",
11+
"compileCommands": "${workspaceFolder}/build/vs2022-x64/compile_commands.json",
12+
"configurationProvider": "ms-vscode.cmake-tools"
13+
},
14+
{
15+
"name": "Win32",
16+
"includePath": [
17+
"${workspaceFolder}/**"
18+
],
19+
"defines": [],
20+
"cppStandard": "c++17",
21+
"intelliSenseMode": "windows-msvc-x64",
22+
"browse": {
23+
"path": ["${workspaceFolder}"]
24+
}
25+
}
26+
],
27+
"version": 4
28+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode.cmake-tools",
4+
"xaver.clang-format"
5+
]
6+
}

cmake-vcpkg/.vscode/settings.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"files.exclude": {
3+
"build": true,
4+
"vcpkg": true
5+
},
6+
"cmake.sourceDirectory": "${workspaceFolder}",
7+
"cmake.buildDirectory": "${workspaceFolder}/build/${buildType}",
8+
"cmake.generator": "Ninja",
9+
"cmake.configureSettings": {
10+
"CMAKE_VERBOSE_MAKEFILE": "ON",
11+
"CMAKE_BUILD_TYPE": "${buildType}",
12+
"CMAKE_CXX_COMPILER": "${buildKitTriple}"
13+
},
14+
"files.associations": {
15+
"/usr/include/c++/**": "cpp"
16+
},
17+
"[cpp]": {
18+
"editor.formatOnSave": true,
19+
"editor.defaultFormatter": "xaver.clang-format"
20+
},
21+
}

cmake-vcpkg/CMakeLists.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
set(VCPKG_ROOT "../vcpkg")
4+
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
5+
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
11+
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
12+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
13+
14+
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15+
16+
if(WIN32)
17+
set(DYNLIB_DIRECTORY bin)
18+
else()
19+
set(DYNLIB_DIRECTORY lib)
20+
endif()
21+
22+
if(IS_MULTI_CONFIG)
23+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/bin)
24+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIG>/lib)
25+
set(INSTALL_SUFFIX $<CONFIG>)
26+
else()
27+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
28+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
29+
set(INSTALL_SUFFIX .)
30+
endif()
31+
32+
# Avoid copy of only fbclient.dll in Windows.
33+
option(VCPKG_APPLOCAL_DEPS OFF)
34+
35+
36+
project(firebird-vcpkg-example)
37+
38+
enable_language(CXX)
39+
40+
if(MSVC)
41+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
42+
endif()
43+
44+
if(MSVC)
45+
add_compile_options(/W3)
46+
else()
47+
add_compile_options(-Wall)
48+
endif()
49+
50+
find_package(firebird CONFIG REQUIRED)
51+
52+
add_executable(${PROJECT_NAME}
53+
src/main.cpp
54+
)
55+
56+
set_property(TARGET ${PROJECT_NAME} PROPERTY
57+
VS_DEBUGGER_ENVIRONMENT "PATH=${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin"
58+
)
59+
60+
target_link_libraries(${PROJECT_NAME}
61+
PRIVATE firebird
62+
)
63+
64+
65+
install(
66+
TARGETS ${PROJECT_NAME}
67+
RUNTIME
68+
DESTINATION ${INSTALL_SUFFIX}/bin
69+
)
70+
71+
install(
72+
DIRECTORY
73+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/${DYNLIB_DIRECTORY}"
74+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/plugins"
75+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share"
76+
USE_SOURCE_PERMISSIONS
77+
CONFIGURATIONS Release
78+
DESTINATION ${CMAKE_INSTALL_PREFIX}/${INSTALL_SUFFIX}
79+
PATTERN "*.cmake" EXCLUDE
80+
PATTERN "vcpkg*" EXCLUDE
81+
)
82+
83+
install(
84+
DIRECTORY
85+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/${DYNLIB_DIRECTORY}"
86+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/plugins"
87+
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/share"
88+
USE_SOURCE_PERMISSIONS
89+
CONFIGURATIONS Debug
90+
DESTINATION ${CMAKE_INSTALL_PREFIX}/${INSTALL_SUFFIX}
91+
PATTERN "*.cmake" EXCLUDE
92+
PATTERN "vcpkg*" EXCLUDE
93+
)

0 commit comments

Comments
 (0)