@@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 3.15)
22
33project (firebird-odbc-driver LANGUAGES CXX C )
44
5+ # ---------------------------------------------------------------------------
6+ # Default build type (single-config generators only, e.g. Unix Makefiles/Ninja)
7+ # ---------------------------------------------------------------------------
8+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
9+ set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE )
10+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel)
11+ endif ()
12+ message (STATUS "Build type: ${CMAKE_BUILD_TYPE } " )
13+
514# Extract version from git tags
615include (cmake/GetVersionFromGit.cmake )
716
@@ -32,7 +41,28 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
3241option (BUILD_SHARED_LIBS "Build shared libraries" ON )
3342option (BUILD_TESTING "Build tests" ON )
3443
35- # Platform-specific settings
44+ # ---------------------------------------------------------------------------
45+ # CPU architecture detection (from PR #248)
46+ # ---------------------------------------------------------------------------
47+ set (FBODBC_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR } )
48+
49+ if (FBODBC_ARCH STREQUAL "x86" OR FBODBC_ARCH STREQUAL "i686" )
50+ add_definitions (-DFBODBC_ARCH_X86 )
51+ message (STATUS "Architecture: ${FBODBC_ARCH} (x86)" )
52+ elseif (FBODBC_ARCH STREQUAL "x86_64" OR FBODBC_ARCH STREQUAL "AMD64" )
53+ add_definitions (-DFBODBC_ARCH_X86_64 )
54+ message (STATUS "Architecture: ${FBODBC_ARCH} (x86_64)" )
55+ elseif (FBODBC_ARCH STREQUAL "aarch64" OR FBODBC_ARCH STREQUAL "arm64" OR FBODBC_ARCH STREQUAL "ARM64" )
56+ add_definitions (-DFBODBC_ARCH_ARM64 )
57+ message (STATUS "Architecture: ${FBODBC_ARCH} (ARM64)" )
58+ else ()
59+ add_definitions (-DFBODBC_ARCH_GENERIC )
60+ message (WARNING "Architecture <${FBODBC_ARCH} > conditionally supported" )
61+ endif ()
62+
63+ # ---------------------------------------------------------------------------
64+ # Platform-specific compiler settings
65+ # ---------------------------------------------------------------------------
3666if (WIN32 )
3767 add_definitions (-DWIN32 -D_WINDOWS -D_USRDLL )
3868 if (MSVC )
@@ -44,20 +74,34 @@ if(WIN32)
4474 endif ()
4575else ()
4676 # Linux/Unix
47- add_definitions (-DUNIX )
77+ add_definitions (-DUNIX -D_REENTRANT -D_PTHREADS -DEXTERNAL )
4878 set (CMAKE_POSITION_INDEPENDENT_CODE ON )
79+
80+ # Compiler optimization flags (from PR #248 / old makefile.linux)
81+ add_compile_options (
82+ "$<$<CONFIG :Debug >:-O0 ;-g3 ;-D_DEBUG ;-DDEBUG ;-DLOGGING ;-fexceptions >"
83+ "$<$<CONFIG :Release >:-O3 ;-DNDEBUG ;-ftree -loop -vectorize >"
84+ "$<$<CONFIG :RelWithDebInfo >:-O2 ;-g ;-DNDEBUG >"
85+ "$<$<CONFIG :MinSizeRel >:-Os ;-DNDEBUG >"
86+ )
87+
88+ # SSE4.1 for x86/x86_64 (from PR #248)
89+ if (FBODBC_ARCH STREQUAL "x86" OR FBODBC_ARCH STREQUAL "i686"
90+ OR FBODBC_ARCH STREQUAL "x86_64" OR FBODBC_ARCH STREQUAL "AMD64" )
91+ add_compile_options (-msse4.1 )
92+ endif ()
4993endif ()
5094
95+ # ---------------------------------------------------------------------------
5196# Find required packages
97+ # ---------------------------------------------------------------------------
5298if (WIN32 )
5399 # On Windows, ODBC is part of the system SDK
54100 set (ODBC_FOUND TRUE )
55101else ()
56102 # On Unix-like systems, find ODBC (unixODBC)
57103 find_package (ODBC REQUIRED )
58- if (ODBC_FOUND)
59- include_directories (${ODBC_INCLUDE_DIRS} )
60- endif ()
104+ add_definitions (-DunixODBC )
61105endif ()
62106
63107# Fetch Firebird public headers from GitHub (replaces vendored FBClient.Headers)
@@ -71,15 +115,21 @@ include_directories(
71115 ${FIREBIRD_INCLUDE_DIR}
72116)
73117
74- # Add IscDbc static library
118+ # ---------------------------------------------------------------------------
119+ # IscDbc — Firebird database connectivity (object library)
120+ # ---------------------------------------------------------------------------
75121add_subdirectory (IscDbc )
76122
123+ # ---------------------------------------------------------------------------
77124# Windows resource file for version info
125+ # ---------------------------------------------------------------------------
78126if (WIN32 )
79127 set (ODBCJDBC_RC OdbcJdbc.rc)
80128endif ()
81129
130+ # ---------------------------------------------------------------------------
82131# Main ODBC driver library sources (from makefile.sources ODBCJDBCSRC)
132+ # ---------------------------------------------------------------------------
83133set (ODBCJDBC_SOURCES
84134 ConnectDialog.cpp
85135 DescRecord.cpp
@@ -94,42 +144,56 @@ set(ODBCJDBC_SOURCES
94144 OdbcError.cpp
95145 OdbcObject.cpp
96146 OdbcStatement.cpp
97- ResourceManagerSink.cpp
98147 SafeEnvThread.cpp
99- TransactionResourceAsync.cpp
100148)
101149
102- # OdbcJdbcSetup sources — built into the same DLL (from makefile.sources ODBCJDBCSETUPSRC)
103- set (ODBCJDBCSETUP_SOURCES
104- OdbcJdbcSetup/CommonUtil.cpp
105- OdbcJdbcSetup/DsnDialog.cpp
106- OdbcJdbcSetup/OdbcJdbcSetup.cpp
107- OdbcJdbcSetup/ServiceClient.cpp
108- OdbcJdbcSetup/ServiceTabBackup.cpp
109- OdbcJdbcSetup/ServiceTabChild.cpp
110- OdbcJdbcSetup/ServiceTabCtrl.cpp
111- OdbcJdbcSetup/ServiceTabRepair.cpp
112- OdbcJdbcSetup/ServiceTabRestore.cpp
113- OdbcJdbcSetup/ServiceTabStatistics.cpp
114- OdbcJdbcSetup/ServiceTabUsers.cpp
115- OdbcJdbcSetup/Setup.cpp
116- OdbcJdbcSetup/UserDialog.cpp
117- OdbcJdbcSetup/UsersTabChild.cpp
118- OdbcJdbcSetup/UsersTabMemberShips.cpp
119- OdbcJdbcSetup/UsersTabRoles.cpp
120- OdbcJdbcSetup/UsersTabUsers.cpp
121- )
150+ # Windows-only sources (ATL-based DTC support, wrapped in #ifdef _WINDOWS)
151+ if (WIN32 )
152+ list (APPEND ODBCJDBC_SOURCES
153+ ResourceManagerSink.cpp
154+ TransactionResourceAsync.cpp
155+ )
156+ endif ()
122157
123- # Linux-only setup source
124- if (NOT WIN32 )
125- list (APPEND ODBCJDBCSETUP_SOURCES OdbcInstGetProp.cpp)
158+ # ---------------------------------------------------------------------------
159+ # OdbcJdbcSetup sources — platform-specific (from makefile.sources)
160+ # ---------------------------------------------------------------------------
161+ if (WIN32 )
162+ # Windows: full GUI setup (ODBCJDBCSETUPSRC)
163+ set (ODBCJDBCSETUP_SOURCES
164+ OdbcJdbcSetup/CommonUtil.cpp
165+ OdbcJdbcSetup/DsnDialog.cpp
166+ OdbcJdbcSetup/OdbcJdbcSetup.cpp
167+ OdbcJdbcSetup/ServiceClient.cpp
168+ OdbcJdbcSetup/ServiceTabBackup.cpp
169+ OdbcJdbcSetup/ServiceTabChild.cpp
170+ OdbcJdbcSetup/ServiceTabCtrl.cpp
171+ OdbcJdbcSetup/ServiceTabRepair.cpp
172+ OdbcJdbcSetup/ServiceTabRestore.cpp
173+ OdbcJdbcSetup/ServiceTabStatistics.cpp
174+ OdbcJdbcSetup/ServiceTabUsers.cpp
175+ OdbcJdbcSetup/Setup.cpp
176+ OdbcJdbcSetup/UserDialog.cpp
177+ OdbcJdbcSetup/UsersTabChild.cpp
178+ OdbcJdbcSetup/UsersTabMemberShips.cpp
179+ OdbcJdbcSetup/UsersTabRoles.cpp
180+ OdbcJdbcSetup/UsersTabUsers.cpp
181+ )
182+ else ()
183+ # Linux: only OdbcInstGetProp (ODBCJDBCSETUPSRC_LINUX)
184+ set (ODBCJDBCSETUP_SOURCES
185+ OdbcInstGetProp.cpp
186+ )
126187endif ()
127188
189+ # ---------------------------------------------------------------------------
128190# Create the main ODBC driver library
191+ # ---------------------------------------------------------------------------
129192add_library (OdbcFb
130193 ${ODBCJDBC_SOURCES}
131194 ${ODBCJDBCSETUP_SOURCES}
132195 ${ODBCJDBC_RC}
196+ $<TARGET_OBJECTS :IscDbc >
133197)
134198
135199# Set library output name
@@ -139,11 +203,11 @@ else()
139203 set_target_properties (OdbcFb PROPERTIES OUTPUT_NAME "OdbcFb" )
140204endif ()
141205
142- # Link with IscDbc library
143- target_link_libraries (OdbcFb PRIVATE IscDbc )
144-
145- # Platform-specific linking (matching the .vcxproj AdditionalDependencies)
206+ # ---------------------------------------------------------------------------
207+ # Linking
208+ # ---------------------------------------------------------------------------
146209if (WIN32 )
210+ # Match the .vcxproj AdditionalDependencies
147211 target_link_libraries (OdbcFb PRIVATE
148212 odbccp32
149213 version
@@ -153,15 +217,13 @@ if(WIN32)
153217 legacy_stdio_wide_specifiers
154218 )
155219
156- # Set the .def file for exports (matching the .vcxproj ModuleDefinitionFile)
157- # Disable automatic manifest generation — the .rc file already embeds one.
158- # Add explicit exports matching the .vcxproj /EXPORT: flags
220+ # .def file for exports + disable duplicate manifest + extra exports
159221 set_target_properties (OdbcFb PROPERTIES
160222 LINK_FLAGS "/DEF:${CMAKE_CURRENT_SOURCE_DIR } /OdbcJdbc.def /MANIFEST:NO /EXPORT:ConfigDSN /EXPORT:ConfigDriver,PRIVATE /EXPORT:DllRegisterServer,PRIVATE /EXPORT:DllUnregisterServer,PRIVATE /EXPORT:DllInstall,PRIVATE"
161223 )
162224else ()
163225 target_link_libraries (OdbcFb PRIVATE
164- ${ODBC_LIBRARIES}
226+ ODBC::ODBC
165227 odbcinst
166228 dl
167229 pthread
@@ -174,13 +236,17 @@ target_compile_definitions(OdbcFb PRIVATE
174236 $<$<CONFIG :Debug >:LOGGING >
175237)
176238
239+ # ---------------------------------------------------------------------------
177240# Testing
241+ # ---------------------------------------------------------------------------
178242if (BUILD_TESTING)
179243 enable_testing ()
180244 add_subdirectory (tests )
181245endif ()
182246
183- # Installation rules
247+ # ---------------------------------------------------------------------------
248+ # Installation
249+ # ---------------------------------------------------------------------------
184250install (TARGETS OdbcFb
185251 RUNTIME DESTINATION bin
186252 LIBRARY DESTINATION lib
0 commit comments