Skip to content

Modern cmake for linux build #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Builds/Gcc.linux.cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.8)
project(firebird_odbc_driver CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

add_compile_options(
"$<$<CONFIG:DEBUG>:-O0;-g3;-D_DEBUG;-DDEBUG;-DLOGGING;-fexceptions>"
"$<$<CONFIG:RELEASE>:-O3;-DNDEBUG;-ftree-loop-vectorize;-ffast-math>"
)

set(FBODBC_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR})

if(${FBODBC_ARCH} STREQUAL "x86")
add_definitions(-DFBODBC_ARCH_X86)
set(FBODBC_ARCH_X86 1 CACHE BOOL "Arch x86")
message(STATUS "Will compile for ${FBODBC_ARCH} architecture")

elseif(${FBODBC_ARCH} STREQUAL "x86_64")
add_definitions(-DFBODBC_ARCH_X86_64)
set(FBODBC_ARCH_X86_64 1 CACHE BOOL "Arch x86_64")
message(STATUS "Will compile for ${FBODBC_ARCH} architecture")

elseif(${FBODBC_ARCH} STREQUAL "aarch64" OR ${FBODBC_ARCH} STREQUAL "arm64")
add_definitions(-DFBODBC_ARCH_ARM64)
set(FBODBC_ARCH_ARM64 1 CACHE BOOL "Arch ARM64")
message(STATUS "Will compile for ${FBODBC_ARCH} architecture")

else()
add_definitions(-DFBODBC_ARCH_GENERIC)
set(FBODBC_ARCH_GENERIC 1 CACHE BOOL "Arch generic")
message(WARNING "Architecture <${FBODBC_ARCH}> conditionally supported")
endif()

if(FBODBC_ARCH_X86 OR FBODBC_ARCH_X86_64)
add_definitions(-msse4.1)
endif()

find_package(ODBC REQUIRED)

set(ODBCMANAGER "unixODBC")
add_definitions("-D${ODBCMANAGER}")

set(FBODBC_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")

include_directories("${FBODBC_SRC_DIR}/Headers")
include_directories("${FBODBC_SRC_DIR}/FBClient.Headers")

file(READ "../makefile.sources" ConfigContents)
string(REPLACE "\\\n" "" ConfigContents "${ConfigContents}")
string(REPLACE "\n" ";" ConfigContents "${ConfigContents}")

foreach(NameAndValue ${ConfigContents})
# Strip leading spaces
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
# Find variable name
string(REGEX MATCH "^[^=]+" Name ${NameAndValue})
# Find the value
string(REPLACE "${Name}=" "" Value ${NameAndValue})
# Strip trailing spaces in name
string(REGEX REPLACE "[ ]+" "" Name ${Name})
# Strip tabs & spaces in value and convert it to list
string(REGEX REPLACE "^[ |\t]+" "" Value ${Value})
string(REGEX REPLACE "[\t]+" "" Value ${Value})
string(REGEX REPLACE "[ ]+" ";" Value ${Value})
# Set the variable
set(${Name} ${Value})
endforeach()

list(TRANSFORM ISCDBCSRC PREPEND "${FBODBC_SRC_DIR}/IscDbc/")
list(TRANSFORM ODBCJDBCSRC PREPEND "${FBODBC_SRC_DIR}/")
list(TRANSFORM ODBCJDBCSETUPSRC_LINUX PREPEND "${FBODBC_SRC_DIR}/")

add_library(objlib OBJECT ${ISCDBCSRC} ${ODBCJDBCSRC} ${ODBCJDBCSETUPSRC_LINUX})
set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
target_compile_features(objlib PUBLIC cxx_std_17)

add_library(OdbcFb SHARED $<TARGET_OBJECTS:objlib>)
add_library(OdbcFbStatic STATIC $<TARGET_OBJECTS:objlib>)

target_link_libraries(OdbcFb PRIVATE dl PRIVATE crypt PRIVATE odbcinst)
target_link_libraries(OdbcFbStatic PRIVATE dl PRIVATE crypt PRIVATE odbcinst)
108 changes: 55 additions & 53 deletions IscDbc/IscArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void CAttrArray::loadAttributes ( IscStatement *stmt, const char * nameRelation,
{
ISC_STATUS statusVector [20];
IscConnection * connection = stmt->connection;
isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

if (!connection->GDS->_get_transaction_handle( statusVector, &transactionHandle, stmt->startTransaction() )
&&
Expand Down Expand Up @@ -151,7 +151,7 @@ JString CAttrArray::getFbSqlType()
{
char temp [30];
char name [80];
char * ch = temp;
const char * ch = temp;
char sqlscale = arrDesc.array_desc_scale;
unsigned short sqllen = arrDesc.array_desc_length;

Expand Down Expand Up @@ -245,16 +245,15 @@ JString CAttrArray::getFbSqlType()
ch = "*unknown type*";
}

int len = sprintf (name, "%s[", ch);
ch = name + len;
unsigned len = 0;
len += snprintf (name + len, sizeof(name) - len, "%s[", ch);

for(int i = 0; i < arrDesc.array_desc_dimensions; i++)
{
len = sprintf ( ch , "%d:%d,", arrDesc.array_desc_bounds[i].array_bound_lower
, arrDesc.array_desc_bounds[i].array_bound_upper);
ch += len;
len += snprintf (name + len, sizeof(name) - len, "%d:%d,",
arrDesc.array_desc_bounds[i].array_bound_lower, arrDesc.array_desc_bounds[i].array_bound_upper);
}
*(ch-1) = ']';
*ch = '\0';
len += snprintf (name + len, sizeof(name) - len, "]");

return name;
}
Expand Down Expand Up @@ -372,16 +371,16 @@ void IscArray::getBytesFromArray()
IscConnection * connection = statement->connection;
ISC_LONG lenbuf = arrBufDataSize;

isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

bool ret =
connection->GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
connection->GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
connection->GDS->_array_get_slice(statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf);
connection->GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
connection->GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
connection->GDS->_array_get_slice(statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf);

if ( ret )
THROW_ISC_EXCEPTION_LEGACY (connection, statusVector);
Expand Down Expand Up @@ -471,13 +470,13 @@ void IscArray::fetchArrayToString()
switch(arrTypeElement)
{
case blr_short :
len=sprintf(ptDst,"%i",*(short*)ptSrc);
len=sprintf(ptDst,"%" PRId16,*(int16_t*)ptSrc);
break;
case blr_long :
len=sprintf(ptDst,"%ld",*(int*)ptSrc);
len=sprintf(ptDst,"%" PRId32,*(int32_t*)ptSrc);
break;
case blr_int64 :
len=sprintf(ptDst,"%lld",*(__int64*)ptSrc);
len=sprintf(ptDst,"%" PRId64,*(int64_t*)ptSrc);
break;
case blr_float :
len=sprintf(ptDst,"%.4g",*(float*)ptSrc);
Expand Down Expand Up @@ -510,16 +509,16 @@ void IscArray::writeBlob(char * sqldata)
memset( arrayId, 0, sizeof ( ISC_QUAD ) );
ISC_LONG len = getSegmentLength(0);

isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

bool ret =
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, (char*) Stream::getSegment(0), &len );
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, (char*) Stream::getSegment(0), &len );

if ( ret )
THROW_ISC_EXCEPTION_LEGACY (connection, statusVector);
Expand All @@ -534,16 +533,16 @@ void IscArray::writeBlob(char * sqldata, char *data, ISC_LONG length)
arrayId = (ISC_QUAD*)sqldata;
memset( arrayId, 0, sizeof ( ISC_QUAD ) );

isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

bool ret =
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, data, &length );
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, data, &length );

if ( ret )
THROW_ISC_EXCEPTION_LEGACY (connection, statusVector);
Expand Down Expand Up @@ -715,16 +714,16 @@ void IscArray::writeStringHexToBlob(char * sqldata, char *data, int length)

ISC_LONG lenbuf = arrBufDataSize;

isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

bool ret =
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf );
GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
GDS->_array_put_slice ( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf );

if ( ret )
THROW_ISC_EXCEPTION_LEGACY (connection, statusVector);
Expand All @@ -751,6 +750,9 @@ void IscArray::writeArray(Value * value)
case String:
convStringToArray ( value->data.string.string , (int)strlen( value->data.string.string ) );
break;

default:
break;
} // End switch (value->type)

ISC_STATUS statusVector [20];
Expand All @@ -759,16 +761,16 @@ void IscArray::writeArray(Value * value)

memset( arrayId, 0, sizeof ( ISC_QUAD ));

isc_tr_handle transactionHandle = NULL;
isc_db_handle dbHandle = NULL;
isc_tr_handle transactionHandle = 0;
isc_db_handle dbHandle = 0;

bool ret =
connection->GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
connection->GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
connection->GDS->_array_put_slice( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf);
connection->GDS->_get_transaction_handle( statusVector, &transactionHandle, statement->startTransaction() )
||
connection->GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle )
||
connection->GDS->_array_put_slice( statusVector, &dbHandle, &transactionHandle,
arrayId, &arrDesc, arrBufData, &lenbuf);

if (ret || lenbuf != arrBufDataSize)
THROW_ISC_EXCEPTION_LEGACY (connection, statusVector);
Expand Down
2 changes: 1 addition & 1 deletion IscDbc/IscColumnPrivilegesResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool IscColumnPrivilegesResultSet::nextFetch()
break;
}

char * nullable = sqlda->getVarying (8, len1);
const char * nullable = sqlda->getVarying (8, len1);
if ( *nullable == '1' )
sqlda->updateVarying ( 8, "YES" );
else
Expand Down
4 changes: 2 additions & 2 deletions IscDbc/IscColumnsResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ bool IscColumnsResultSet::nextFetch()
if ( array )
{
int len;
char * relation_name = sqlda->getVarying ( 3, len);
char * relation_name = (char*)sqlda->getVarying ( 3, len);
relation_name[len] = '\0';
char * field_name = sqlda->getVarying ( 4, len);
char * field_name = (char*)sqlda->getVarying ( 4, len);
field_name[len] = '\0';

arrAttr.loadAttributes ( statement, relation_name, field_name, sqlType.subType );
Expand Down
2 changes: 1 addition & 1 deletion IscDbc/IscConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ void IscConnection::openDatabase(const char * dbName, Properties * properties)
{
int len1 = (int)strlen( attachment->userName );
int len2;
char *beg = resultSet.sqlda->getVarying( 5, len2 );
char *beg = (char*)resultSet.sqlda->getVarying( 5, len2 );
char *end = beg + len2;
char *save = end;

Expand Down
16 changes: 10 additions & 6 deletions IscDbc/IscTablesResultSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ void IscTablesResultSet::getTables(const char * catalog, const char * schemaPatt
&& sqlAllParam
&& !(tableNamePattern && *tableNamePattern) )
{
ptSql = "select distinct cast (NULL as varchar(7)) as table_cat,\n" // 1
"cast (tbl.rdb$owner_name as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_schem,\n" // 2
pt = ptSql;
addString(pt, "select distinct cast (NULL as varchar(7)) as table_cat,\n" // 1
"cast (tbl.rdb$owner_name as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_schem,\n" // 2
"cast (NULL as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_name,\n" // 3
"cast (NULL as varchar(13)) as table_type,\n" // 4
"cast (NULL as varchar(255)) as remarks\n" // 5
"from rdb$relations tbl\n";
"from rdb$relations tbl\n");
*pt = '\0';
sqlAllParam = 2; // unique owners
break;
}
Expand All @@ -116,12 +118,14 @@ void IscTablesResultSet::getTables(const char * catalog, const char * schemaPatt
&& sqlAllParam == 2
&& !(tableNamePattern && *tableNamePattern) )
{
ptSql = "select cast (NULL as varchar(7)) as table_cat,\n" // 1
"cast (NULL as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_schem,\n" // 2
pt = ptSql;
addString(pt, "select cast (NULL as varchar(7)) as table_cat,\n" // 1
"cast (NULL as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_schem,\n" // 2
"cast (NULL as varchar(" MACRO_TO_STR(MAX_META_IDENT_LEN) ")) as table_name,\n" // 3
"cast ('SYSTEM TABLE' as varchar(13)) as table_type,\n" // 4
"cast (NULL as varchar(255)) as remarks\n" // 5
"from rdb$database tbl\n";
"from rdb$database tbl\n");
*pt = '\0';
sqlAllParam = 3; // unique table types
break;
}
Expand Down
2 changes: 1 addition & 1 deletion IscDbc/IscUserEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void IscUserEvents::queEvents( void * interfase )
{
ISC_STATUS statusVector[20];

isc_db_handle dbHandle = NULL;
isc_db_handle dbHandle = 0;
connection->GDS->_get_database_handle( statusVector, &dbHandle, connection->databaseHandle );

if ( statusVector [1] )
Expand Down
4 changes: 2 additions & 2 deletions IscDbc/Mlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class MList

int SearchAndInsert(T * key)
{
register int ret = 1, i, l = 0, u = count - 1;
int ret = 1, i, l = 0, u = count - 1;
int size = sizeof(T);
T * buf = ptRoot;

Expand Down Expand Up @@ -206,7 +206,7 @@ class MList

int Search(T * key)
{
register int ret = 1, i, l = 0, u = count - 1;
int ret = 1, i, l = 0, u = count - 1;
int size = sizeof(T);
T * buf = ptRoot;

Expand Down
2 changes: 1 addition & 1 deletion IscDbc/MultibyteConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace IscDbcLibrary {

struct IntlCharsets
{
char *name;
const char *name;
short lengthName;
short code;
short size;
Expand Down
2 changes: 1 addition & 1 deletion IscDbc/ParameterEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ParameterEvent::ParameterEvent( ParameterEvent *next, const char *name, int leng
{
nextParameter = next;
lengthNameEvent = length;
countEvents = ~0lu;
countEvents = ~0u;
changed = false;

nameEvent = new char[lengthNameEvent + 1];
Expand Down
Loading