[ODBC-299] FindIconv.cmake too old to work on MacOS 11 (Big Sur) Created: 2020-12-21  Updated: 2021-08-12  Resolved: 2021-08-12

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: General
Affects Version/s: 3.1.11
Fix Version/s: 3.1.14

Type: Bug Priority: Major
Reporter: Mitchell Blank Jr Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: macos
Environment:

MacOS 11.1
Xcode 12.3



 Description   

When building for homebrew:

$ cmake . -DMARIADB_LINK_DYNAMIC=1 -DWITH_SSL=OPENSSL -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl@1.1 -DWITH_IODBC=0 -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mariadb-connector-odbc/3.1.11 -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk
 
[...]
-- Found ODBC Driver Manager libraries: /usr/local/Cellar/unixodbc/2.3.9/lib
CMake Error at CMakeLists.txt:263 (MESSAGE):
  iconv was not found

This is probably related to MacOS 11's weird way of handling system libraries. Basically the standard libraries like /usr/lib/libiconv.dylib are no longer present on the filesystem but you can link to them.

Most likely you just need to import a newer version of FindIconv.cmake since I'm pretty sure cmake itself can find the package no problem. You seem to have a "frozen in amber" copy of that file.

As a workaround to get homebrew building I am doing this:

@ Formula/mariadb-connector-odbc.rb:26 @ class MariadbConnectorOdbc < Formula
                         "-DWITH_SSL=OPENSSL",
                         "-DOPENSSL_ROOT_DIR=#{Formula["openssl@1.1"].opt_prefix}",
                         "-DWITH_IODBC=0",
                         # Workaround 3.1.11 issues finding system's built-in -liconv
                         "-DICONV_LIBRARIES=" + MacOS.sdk_path + "/usr/lib/libiconv.tbd",
                         "-DICONV_INCLUDE_DIR=/usr/include",
                         *std_cmake_args

see https://github.com/Homebrew/homebrew-core/pull/67348

The ".tbd" files are the linker information for that library. You don't need to pass that to the compiler (just "-liconv" will do) but I needed to find some filename to pass in as the library location so that FindIconv.cmake would be satisfied that it "found" it



 Comments   
Comment by Lawrin Novitsky [ 2021-08-12 ]

The FindIconv coming with cmake 3.21.1 from Homebrew does not solve the problem.

Comment by Mitchell Blank Jr [ 2021-08-12 ]

What results do you get? When I do:

$ cat CMakeLists.txt
project(empty C)
cmake_minimum_required(VERSION 3.0)
find_package(Iconv REQUIRED)

It finds the tbd file without issue:

$ cmake .
-- The C compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Failed
-- Found Iconv: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libiconv.tbd (found version "1.11")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mitch/cmake-test

This is with cmake 3.21.1, direct from Homebrew

Comment by Lawrin Novitsky [ 2021-08-12 ]

The fix is skipping iconv search if MacOS version >= Big Sur. That fixed the build for me. Old FindIconv.cmake has been left in place, as newer version does not help, and we can't make minimal required cmake version higher(FindIconv appears in 3.11) as not all (linux) distributions have it.

Generated at Thu Feb 08 03:27:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.