Warning, /sdk/codevis/thirdparty/soci/cmake/modules/FindODBC.cmake is written in an unsupported language. File is not indexed.
0001 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 0002 # file Copyright.txt or https://cmake.org/licensing for details. 0003 0004 #[=======================================================================[.rst: 0005 FindODBC 0006 -------- 0007 0008 Find the ODBC include directory and library. 0009 0010 Use this module by invoking find_package with the form:: 0011 0012 .. code-block:: cmake 0013 0014 find_package(ODBC 0015 [REQUIRED] # Fail with error if ODBC is not found 0016 ) 0017 0018 On Windows, when building with Visual Studio, this module assumes the ODBC 0019 library is provided by the available Windows SDK. 0020 0021 On Unix, this module allows to search for ODBC library provided by 0022 unixODBC or iODBC implementations of ODBC API. 0023 This module reads hint about location of the config program: 0024 0025 .. variable:: ODBC_CONFIG 0026 0027 Location of odbc_config or iodbc-config program 0028 0029 Otherwise, this module tries to find the config program, 0030 first from unixODBC, then from iODBC. 0031 If no config program found, this module searches for ODBC header 0032 and library in list of known locations. 0033 0034 Imported targets 0035 ^^^^^^^^^^^^^^^^ 0036 0037 This module defines the following :prop_tgt:`IMPORTED` targets: 0038 0039 .. variable:: ODBC::ODBC 0040 0041 Imported target for using the ODBC library, if found. 0042 0043 Result variables 0044 ^^^^^^^^^^^^^^^^ 0045 0046 .. variable:: ODBC_FOUND 0047 0048 Set to true if ODBC library found, otherwise false or undefined. 0049 0050 .. variable:: ODBC_INCLUDE_DIRS 0051 0052 Paths to include directories listed in one variable for use by ODBC client. 0053 May be empty on Windows, where the include directory corresponding to the 0054 expected Windows SDK is already available in the compilation environment. 0055 0056 .. variable:: ODBC_LIBRARIES 0057 0058 Paths to libraries to linked against to use ODBC. 0059 May just a library name on Windows, where the library directory corresponding 0060 to the expected Windows SDK is already available in the compilation environment. 0061 0062 .. variable:: ODBC_CONFIG 0063 0064 Path to unixODBC or iODBC config program, if found or specified. 0065 0066 Cache variables 0067 ^^^^^^^^^^^^^^^ 0068 0069 For users who wish to edit and control the module behavior, this module 0070 reads hints about search locations from the following variables:: 0071 0072 .. variable:: ODBC_INCLUDE_DIR 0073 0074 Path to ODBC include directory with ``sql.h`` header. 0075 0076 .. variable:: ODBC_LIBRARY 0077 0078 Path to ODBC library to be linked. 0079 0080 NOTE: The variables above should not usually be used in CMakeLists.txt files! 0081 0082 Limitations 0083 ^^^^^^^^^^^ 0084 0085 On Windows, this module does not search for iODBC. 0086 On Unix, there is no way to prefer unixODBC over iODBC, or vice versa, 0087 other than providing the config program location using the ``ODBC_CONFIG``. 0088 This module does not allow to search for a specific ODBC driver. 0089 0090 #]=======================================================================] 0091 0092 ### Try Windows Kits ########################################################## 0093 if(WIN32) 0094 # List names of ODBC libraries on Windows 0095 set(ODBC_LIBRARY odbc32.lib) 0096 set(_odbc_lib_names odbc32;) 0097 0098 # List additional libraries required to use ODBC library 0099 if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") 0100 set(_odbc_required_libs_names odbccp32;ws2_32) 0101 elseif(MINGW) 0102 set(_odbc_required_libs_names odbccp32) 0103 endif() 0104 endif() 0105 0106 ### Try unixODBC or iODBC config program ###################################### 0107 if (UNIX AND NOT ODBC_CONFIG) 0108 find_program(ODBC_CONFIG 0109 NAMES odbc_config iodbc-config 0110 DOC "Path to unixODBC or iODBC config program") 0111 endif() 0112 0113 if (UNIX AND ODBC_CONFIG) 0114 # unixODBC and iODBC accept unified command line options 0115 execute_process(COMMAND ${ODBC_CONFIG} --cflags 0116 OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE) 0117 execute_process(COMMAND ${ODBC_CONFIG} --libs 0118 OUTPUT_VARIABLE _libs OUTPUT_STRIP_TRAILING_WHITESPACE) 0119 0120 # Collect paths of include directories from CFLAGS 0121 separate_arguments(_cflags NATIVE_COMMAND "${_cflags}") 0122 foreach(arg IN LISTS _cflags) 0123 if("${arg}" MATCHES "^-I(.*)$") 0124 list(APPEND _odbc_include_paths "${CMAKE_MATCH_1}") 0125 endif() 0126 endforeach() 0127 unset(_cflags) 0128 0129 # Collect paths of library names and directories from LIBS 0130 separate_arguments(_libs NATIVE_COMMAND "${_libs}") 0131 foreach(arg IN LISTS _libs) 0132 if("${arg}" MATCHES "^-L(.*)$") 0133 list(APPEND _odbc_lib_paths "${CMAKE_MATCH_1}") 0134 elseif("${arg}" MATCHES "^-l(.*)$") 0135 set(_lib_name ${CMAKE_MATCH_1}) 0136 string(REGEX MATCH "odbc" _is_odbc ${_lib_name}) 0137 if(_is_odbc) 0138 list(APPEND _odbc_lib_names ${_lib_name}) 0139 else() 0140 list(APPEND _odbc_required_libs_names ${_lib_name}) 0141 endif() 0142 unset(_lib_name) 0143 endif() 0144 endforeach() 0145 unset(_libs) 0146 endif() 0147 0148 ### Try unixODBC or iODBC in include/lib filesystems ########################## 0149 if (UNIX AND NOT ODBC_CONFIG) 0150 # List names of both ODBC libraries, unixODBC and iODBC 0151 set(_odbc_lib_names odbc;iodbc;unixodbc;) 0152 0153 set(_odbc_include_paths 0154 /usr/local/odbc/include) 0155 0156 set(_odbc_lib_paths 0157 /usr/local/odbc/lib) 0158 endif() 0159 0160 # DEBUG 0161 #message("ODBC_CONFIG=${ODBC_CONFIG}") 0162 #message("_odbc_include_hints=${_odbc_include_hints}") 0163 #message("_odbc_include_paths=${_odbc_include_paths}") 0164 #message("_odbc_lib_paths=${_odbc_lib_paths}") 0165 #message("_odbc_lib_names=${_odbc_lib_names}") 0166 0167 ### Find include directories ################################################## 0168 find_path(ODBC_INCLUDE_DIR 0169 NAMES sql.h 0170 HINTS ${_odbc_include_hints} 0171 PATHS ${_odbc_include_paths}) 0172 0173 if(NOT ODBC_INCLUDE_DIR AND WIN32) 0174 set(ODBC_INCLUDE_DIR "") 0175 endif() 0176 0177 ### Find libraries ############################################################ 0178 if(NOT ODBC_LIBRARY) 0179 find_library(ODBC_LIBRARY 0180 NAMES ${_odbc_lib_names} 0181 PATHS ${_odbc_lib_paths} 0182 PATH_SUFFIXES odbc) 0183 0184 foreach(_lib IN LISTS _odbc_required_libs_names) 0185 find_library(_lib_path 0186 NAMES ${_lib} 0187 PATHS ${_odbc_lib_paths} # system parths or collected from ODBC_CONFIG 0188 PATH_SUFFIXES odbc) 0189 if (_lib_path) 0190 list(APPEND _odbc_required_libs_paths ${_lib_path}) 0191 endif() 0192 unset(_lib_path CACHE) 0193 endforeach() 0194 0195 unset(_odbc_lib_names) 0196 unset(_odbc_lib_paths) 0197 unset(_odbc_required_libs_names) 0198 endif() 0199 0200 ### Set result variables ###################################################### 0201 set(REQUIRED_VARS ODBC_LIBRARY) 0202 if(NOT WIN32) 0203 list(APPEND REQUIRED_VARS ODBC_INCLUDE_DIR) 0204 endif() 0205 0206 include(FindPackageHandleStandardArgs) 0207 find_package_handle_standard_args(ODBC DEFAULT_MSG ${REQUIRED_VARS}) 0208 0209 mark_as_advanced(FORCE ODBC_LIBRARY ODBC_INCLUDE_DIR) 0210 0211 if(ODBC_CONFIG) 0212 mark_as_advanced(FORCE ODBC_CONFIG) 0213 endif() 0214 0215 set(ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIR}) 0216 list(APPEND ODBC_LIBRARIES ${ODBC_LIBRARY}) 0217 list(APPEND ODBC_LIBRARIES ${_odbc_required_libs_paths}) 0218 0219 ### Import targets ############################################################ 0220 if(ODBC_FOUND) 0221 if(NOT TARGET ODBC::ODBC) 0222 if(IS_ABSOLUTE "${ODBC_LIBRARY}") 0223 add_library(ODBC::ODBC UNKNOWN IMPORTED) 0224 set_target_properties(ODBC::ODBC PROPERTIES 0225 IMPORTED_LINK_INTERFACE_LANGUAGES "C" 0226 IMPORTED_LOCATION "${ODBC_LIBRARY}") 0227 else() 0228 add_library(ODBC::ODBC INTERFACE IMPORTED) 0229 set_target_properties(ODBC::ODBC PROPERTIES 0230 IMPORTED_LIBNAME "${ODBC_LIBRARY}") 0231 endif() 0232 set_target_properties(ODBC::ODBC PROPERTIES 0233 INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}") 0234 0235 if(_odbc_required_libs_paths) 0236 set_property(TARGET ODBC::ODBC APPEND PROPERTY 0237 INTERFACE_LINK_LIBRARIES "${_odbc_required_libs_paths}") 0238 endif() 0239 endif() 0240 endif() 0241 0242 unset(_odbc_required_libs_paths)