Logcxx-521 (#59)
* Link cleanly with ODBC on Linux
diff --git a/.github/workflows/log4cxx.yml b/.github/workflows/log4cxx.yml
index ac725c0..1233d19 100644
--- a/.github/workflows/log4cxx.yml
+++ b/.github/workflows/log4cxx.yml
@@ -53,8 +53,6 @@
run: |
sudo apt-get update
sudo apt-get install -y libapr1-dev libaprutil1-dev
- # note: sqlext.h exists on github VM, purge for now as we don't link correctly...
- sudo apt-get purge unixodbc-dev
- name: 'Restore Prebuilt Dependencies - Windows'
id: restore-vcpkg-cache
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 283283c..b60e54f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,9 +5,15 @@
target_include_directories(log4cxx INTERFACE $<INSTALL_INTERFACE:include> PRIVATE ${APR_INCLUDE_DIR} ${APR_UTIL_INCLUDE_DIR})
target_link_libraries(log4cxx PRIVATE ${APR_UTIL_LIBRARIES} EXPAT::EXPAT ${APR_LIBRARIES} ${APR_SYSTEM_LIBS})
if(WIN32)
-# The ODBC appender is always enabled in the Windows configuration
-target_link_libraries(log4cxx PRIVATE odbc32.lib)
-option(LOG4CXX_INSTALL_PDB "Install .pdb files (if generated)" ON)
+ # The ODBC appender is always enabled in the Windows configuration
+ target_link_libraries(log4cxx PRIVATE odbc32.lib)
+ option(LOG4CXX_INSTALL_PDB "Install .pdb files (if generated)" ON)
+else()
+ if(${odbc_FOUND})
+ target_include_directories(log4cxx PRIVATE ${odbc_INCLUDE_DIRS})
+ target_link_directories( log4cxx PRIVATE ${odbc_LIBRARY_DIRS})
+ target_link_libraries( log4cxx PRIVATE ${odbc_LIBRARIES})
+ endif(${odbc_FOUND})
endif()
if(BUILD_TESTING)
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index 5659f2a..a596d4b 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -68,8 +68,18 @@
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
+if(WIN32)
+ CHECK_INCLUDE_FILES(sqlext.h HAS_ODBC)
+else()
+ include(FindPkgConfig)
+
+ pkg_check_modules( odbc QUIET odbc )
+ if(${odbc_FOUND})
+ set(HAS_ODBC 1)
+ endif(${odbc_FOUND})
+endif(WIN32)
+
CHECK_INCLUDE_FILE_CXX(locale HAS_STD_LOCALE)
-CHECK_INCLUDE_FILES(sqlext.h HAS_ODBC)
CHECK_FUNCTION_EXISTS(mbsrtowcs HAS_MBSRTOWCS)
CHECK_FUNCTION_EXISTS(wcstombs HAS_WCSTOMBS)
CHECK_FUNCTION_EXISTS(fwide HAS_FWIDE)