Bug #68848 Wrong libdir on ppc64
Submitted: 3 Apr 2013 8:21 Modified: 19 Feb 2014 22:48
Reporter: Honza Horak (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.2.4 OS:Linux
Assigned to: Hemant Dangi CPU Architecture:Any

[3 Apr 2013 8:21] Honza Horak
Description:
When building myodbc on some 64bit system other than x86_64 (e.g. ppc64) cmake doesn't recognize that this is 64bit system and incorrectly use lib instead of lib64 as library directory name for installing dynamic library.

How to repeat:
Build myodbc on ppc64:
$ cmake . -G "Unix Makefiles" -DRPM_BUILD=1
$ make
$ make install

Suggested fix:
diff -up mysql-connector-odbc-5.2.4-src/CMakeLists.txt.libdir mysql-connector-odbc-5.2.4-src/CMakeLists.txt
--- mysql-connector-odbc-5.2.4-src/CMakeLists.txt.libdir	2013-04-03 02:18:49.002164793 -0400
+++ mysql-connector-odbc-5.2.4-src/CMakeLists.txt	2013-04-03 03:05:55.840694007 -0400
@@ -228,7 +228,7 @@ SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINA
 SET(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
 
 SET(LIB_SUBDIR "lib")
-IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
+IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|ppc64|ppc64p7|s390x|sparc64)")
   SET(LIB_SUBDIR "lib64")
 ENDIF()
[3 Apr 2013 8:22] Honza Horak
adding aarch64 will be probably necessary in the future
[3 Apr 2013 8:40] Hartmut Holzgraefe
Shouldn't this either test for pointer size

  if( CMAKE_SIZEOF_VOID_P EQUAL 8 )

or for the existence of a 64bit library path?

  get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)

  if (${LIB64} STREQUAL "TRUE")
      set(LIBSUFFIX 64)
  else()
      set(LIBSUFFIX "")
  endif() 

instead of checking for an ever expanding hardcoded list of architectures?
[4 Apr 2013 9:18] Bogdan Degtyariov
Honza, Hartmut,

Thanks for your suggestions.

get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS) is not always reliable on 64-bit platforms: got "FALSE" in my 64-bit Ubuntu.

I think using CMAKE_SIZEOF_VOID_P will give better results.
[9 May 2013 6:47] Bogdan Degtyariov
Finding the right directory is harder in general, as some 64-bit operating system distributions use "lib" others use "lib64". But we could at least
provide a way to let the one building control what location to use.

two things to do

 - Make sure that 64-bit RPMs put the libraries in the correct
   directory

   OR

 - Give the user the option to specify "cmake -DLIBSUBDIR=lib64" or
   similar, so the one building can control the install location
[9 May 2013 8:19] Bogdan Degtyariov
So the approximate patch should look like:

=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2013-05-02 22:34:31 +0000
+++ CMakeLists.txt	2013-05-09 08:10:34 +0000
@@ -228,10 +228,18 @@
 SET(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
 
 SET(LIB_SUBDIR "lib")
-IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
+
+# Make sure /usr/lib64 exists
+IF(RPM_BUILD AND EXISTS "/usr/lib64" AND IS_DIRECTORY "/usr/lib64")
   SET(LIB_SUBDIR "lib64")
 ENDIF()
 
+# Let -DLIBSUBDIR override
+
+IF(LIBSUBDIR)
+  SET(LIB_SUBDIR ${LIBSUBDIR})
+ENDIF(LIBSUBDIR)
+
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
 
 ADD_SUBDIRECTORY(util)
[9 May 2013 8:32] Honza Horak
I'm not really convinced that checking for existence of particular directory should actually decide where to install files. I believe it should depend on architecture only, since having /usr/lib64 directory existing on 32bit system for any reason doesn't seem too weird for me. Either checking for pointer size or checking the arch name as proposed in comments above seem much better for me.
[9 May 2013 8:43] Bogdan Degtyariov
As I have already indicated, some 64-bit platforms (Solaris SPARC 64-bit) don't have lib64 directory, so simple checking for the pointer size would not give us any reliable result.

The architecture is not reliable either because in Solaris x86_64 (maybe somewhere else too) the lib64 directory does not exist.

So far I have not seen any 32-bit system with /usr/lib64, but I am not saying they don't exist or will never appear in the future. Specially for such rare cases there is an option -DLIBSUBDIR to specify any desirable name for the directory.
[7 Feb 2014 2:22] Bogdan Degtyariov
The final decision about the patch for this problem is as following two-stage check:

 1. check if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) to confirm 64-bit
    architecture

 2. look for lib64 directory. If it exists then install ODBC driver in
    there, otherwise in lib directory.
[10 Feb 2014 17:35] Honza Horak
Sounds fine for me.
[19 Feb 2014 10:21] Hemant Dangi
Patch committed to below repos:
rev 1150 in 5.1.14
rev 1222 in 5.2.7
rev 1265 in 5.3.2

Pushed below changes:
-IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
+IF(RPM_BUILD AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|ppc64|ppc64p7|s390x|sparc64)")
[19 Feb 2014 22:48] Daniel So
Added the following entry to the Connector/ODBC 5.3.2, 5.2.7, and 5.1.14 changelog:

"When building Connector/ODBC on some 64-bit systems other than x86_64 (e.g. ppc64), CMake did not recognize that it was a 64-bit system and incorrectly used lib instead of lib64 as directory name for installing the dynamic library. This fix implements a two-step approach, making CMake check for the system architecture by reading the value of CMAKE_SIZEOF_VOID_P and also by checking the existence of the /usr/lib64 folder."