Skip to content

Commit

Permalink
chore(CMake): Add option ENABLE_DATA_SQL_SERVER_BIG_STRINGS, auto-det…
Browse files Browse the repository at this point in the history
…ection of msodbcsql.h on Linux and macOS
  • Loading branch information
matejk committed Oct 18, 2024
1 parent 761c19f commit a120310
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ endif()
if(ODBC_FOUND)
option(ENABLE_DATA "Enable Data" ON)
option(ENABLE_DATA_ODBC "Enable Data ODBC" ON)
option(ENABLE_DATA_SQL_SERVER_BIG_STRINGS "Enable MS SQL Server big strings" ON)
else()
option(ENABLE_DATA "Enable Data" OFF)
option(ENABLE_DATA_ODBC "Enable Data ODBC" OFF)
option(ENABLE_DATA_SQL_SERVER_BIG_STRINGS "Enable MS SQL Server big strings" OFF)
endif()

# Allow enabling and disabling components
Expand Down
38 changes: 38 additions & 0 deletions Data/ODBC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,44 @@ target_include_directories(DataODBC
)
target_compile_definitions(DataODBC PUBLIC THREADSAFE)

# Search for MS ODBC header file which is a pre-requisite to enable
# ENABLE_DATA_SQL_SERVER_BIG_STRINGS
find_file(
_msodbc_h

msodbcsql.h

HINTS

/usr/include
#macOS
/opt/homebrew/include/msodbcsql18
/opt/homebrew/include/msodbcsql17
#Linux
/opt/microsoft/msodbcsql18/include
/opt/microsoft/msodbcsql17/include/
/opt/microsoft/msodbcsql/include/
# Windows?

NO_CACHE
)

if (_msodbc_h)
get_filename_component(MSODBC_DIR ${_msodbc_h} DIRECTORY CACHE)
message(STATUS "ODBC: Found msodbcsql.h in: ${MSODBC_DIR}")
target_include_directories(DataODBC PUBLIC "${MSODBC_DIR}")

if (ENABLE_DATA_SQL_SERVER_BIG_STRINGS)
target_compile_definitions(DataODBC PUBLIC POCO_DATA_SQL_SERVER_BIG_STRINGS=1)
else()
target_compile_definitions(DataODBC PUBLIC POCO_DATA_SQL_SERVER_BIG_STRINGS=0)
endif()
else()
# Disable MS SQL specific setting when msodbcsql.h is not present
set(ENABLE_DATA_SQL_SERVER_BIG_STRINGS OFF CACHE BOOL FORCE "Enable MS SQL Server big strings")
endif()
unset(_msodbc_h)

POCO_INSTALL(DataODBC)
POCO_GENERATE_PACKAGE(DataODBC)

Expand Down
4 changes: 3 additions & 1 deletion Data/ODBC/include/Poco/Data/ODBC/ODBC.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
// affect performance (more memory preallocated
// for prepared statements in order to safely
// accomodate data returned at execution)
#define POCO_DATA_SQL_SERVER_BIG_STRINGS 1
#if !defined(POCO_DATA_SQL_SERVER_BIG_STRINGS)
#define POCO_DATA_SQL_SERVER_BIG_STRINGS 1
#endif
#endif
#endif

Expand Down

0 comments on commit a120310

Please sign in to comment.