Bug #73502 cmake problems
Submitted: 7 Aug 2014 22:00 Modified: 15 Jan 2015 18:50
Reporter: Alfredo Kojima Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C++ Severity:S3 (Non-critical)
Version:1.1.4 OS:Any
Assigned to: CPU Architecture:Any

[7 Aug 2014 22:00] Alfredo Kojima
Description:
There are a couple problems with the Connector/C++:

1- if you have MySQL installed in a path that contains the characters -m and iuse teh MYSQL_CONFIG_EXECUTABLE option to pass the path to mysql_config, cmake will fail with some error about MYSQL_LIBS not being found. That seems to be because of this bit in FindMySQL.cmake:

    STRING(REGEX MATCHALL "-m([^\r\n]+)" MYSQL_LINK_FLAGS "${_mysql_config_output}")

That will match the -m portion in paths like ~/orig-mysql/ and put a bogus value into MYSQL_LINK_FLAGS

2- If the cmake build dir is not the top source dir, make install will fail with:

Install the project...
-- Install configuration: ""
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/./README
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/./INSTALL
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/./COPYING
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/./Licenses_for_Third-Party_Components.txt
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/./ANNOUNCEMENT
-- Up-to-date: /local/home/mysqldev/linux-res-6.2/cppconn/bld/../../cppconn-gpl/usr/local/include/cppconn/build_config.h
CMake Error at cppconn/cmake_install.cmake:36 (FILE):
  file INSTALL cannot find
  "/local/home/mysqldev/linux-res-6.2/cppconn/cppconn/config.h".

3- seems there's no way to force a dynamic build of connector/c++

How to repeat:
1- install mysql from a tar into /tmp/test-mysql and then cmake -DMYSQL_CONFIG_EXECUTABLE=/tmp/test-mysql/bin/mysql_config

2- cd cppconn-srcdir; mkdir bld; cd bld; cmake ..; make install
[8 Aug 2014 15:43] Hartmut Holzgraefe
this check seems to be supposed to check for architecture dependent gcc options
( "-m..." https://gcc.gnu.org/onlinedocs/gcc/Submodel-Options.html ), assuming that these always are grouped together at the end of the output of "mysql_config --cflags or --cxxflags) ...:

  IF (NOT MYSQL_LINK_FLAGS)
    STRING(REGEX MATCHALL "-m([^\r\n]+)" MYSQL_LINK_FLAGS "${_mysql_config_output}")
  ENDIF (NOT MYSQL_LINK_FLAGS)

I don't understand several things about this though:

* why does it try to extract LINK_FLAGS from the output of "--cflags"?
  (the -m... flags are all about code generation etc, not linking)

* why MATCHALL? --cflags output is on a single line, so there will only be one match for [^\r\n]+ ever anyway ...
  (or does the previous

        EXECUTE_PROCESS(COMMAND ${MYSQL_CONFIG_EXECUTABLE} "--cflags"
            OUTPUT_VARIABLE _mysql_config_output
            )
   split the output at whitespace and puts every "word" on a line
   of its own in OUTPUT_VARIABLE somehow?)

* and most important: why not checking for "-m" either being
  at the beginning of a line or preceded by whitespace, to 
  distinguish actual "-m..." options in the output from other
  in-string occurrences of the letter combination "-" + "m"
  as they may e.g. occur in the file path part of -I options
  in the --cflags output?
[8 Aug 2014 15:47] Hartmut Holzgraefe
(PS: some more comments in this cmake file would be nice,
     CMake code may *look* more readable than autotools,
     but usually ends up being equally un-understandable
     when it comes to implementing tests I'm afraid :(
[14 Aug 2014 18:18] Sveta Smirnova
Thank you for the report.

Verified.

Case 1. cmake finished fine in my case, but make failed with "c++: error: unrecognized command line option ‘-mysql-5.6/include’"

Case 2. In my case build fails with "/usr/local/bin/ar: ../bld/driver/.MYSQL_ARCHIVES/adler32.c.o: No such file or directory" while 

$ ls -la ../bld/driver/.MYSQL_ARCHIVES/adler32.c.o 
-rwxrwxr-x 1 sveta sveta 7600 Aug 14 21:14 ../bld/driver/.MYSQL_ARCHIVES/adler32.c.o
[22 Oct 2014 7:58] Hemant Dangi
Posted by developer:
 
Fixed committed as rev#987.

Removed below line so first case has been fixed.
STRING(REGEX MATCHALL "-m([^\r\n]+)" MYSQL_LINK_FLAGS
"${_mysql_config_output}")
[4 Dec 2014 13:27] Hemant Dangi
Posted by developer:
 
Fix for out of source build:
===========================
=== modified file 'cppconn/CMakeLists.txt'
--- cppconn/CMakeLists.txt	revid:hemant.dangi@oracle.com-20141201101949-52eih37czyv7ywit
+++ cppconn/CMakeLists.txt	2014-12-04 13:19:41 +0000
@@ -53,7 +53,7 @@
 CHECK_FUNCTION_EXISTS(strtoumax HAVE_FUNCTION_STRTOUMAX)
 
 
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cm ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cm ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
 
 
 SET(MYSQLCPPCONN_INSTALL_HEADERS
[16 Dec 2014 10:41] Hemant Dangi
Posted by developer:
 
Make install fail for out of source build.

Committed as revision 1014.
[15 Jan 2015 18:50] Paul DuBois
Noted in 1.1.6 changelog.

Configuration failed if the MYSQL_CONFIG_EXECUTABLE option was
specified and the MySQL installation path contained the characters
-m. Installation failed if the build directory was not in the top
source directory.