Skip to content

Commit 2e38a29

Browse files
committed
Fix Solaris build
1 parent 68d8667 commit 2e38a29

File tree

1 file changed

+56
-61
lines changed

1 file changed

+56
-61
lines changed

FindMySQL.cmake

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# This program is also distributed with certain software (including
1111
# but not limited to OpenSSL) that is licensed under separate terms,
1212
# as designated in a particular file or component or in included license
13-
# documentation. The authors of MySQL hereby grant you an
13+
# documentation. The authors of MySQL hereby grant you an
1414
# additional permission to link the program and your derivative works
1515
# with the separately licensed software that they have included with
1616
# MySQL.
1717
#
1818
# Without limiting anything contained in the foregoing, this file,
19-
# which is part of MySQL Connector/C++, is also subject to the
19+
# which is part of MySQL Connector/ODBC, is also subject to the
2020
# Universal FOSS Exception, version 1.0, a copy of which can be found at
2121
# http://oss.oracle.com/licenses/universal-foss-exception.
2222
#
@@ -27,7 +27,7 @@
2727
#
2828
# You should have received a copy of the GNU General Public License
2929
# along with this program; if not, write to the Free Software Foundation, Inc.,
30-
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3131

3232
##########################################################################
3333

@@ -118,7 +118,7 @@ set(ENV_OR_OPT_VARS
118118
MYSQL_DIR
119119
MYSQL_INCLUDE_DIR
120120
MYSQL_LIB_DIR
121-
MYSQL_LIB_DIR_RUNTIME
121+
MYSQL_LIB_DIR_LIST
122122
MYSQL_CFLAGS
123123
MYSQL_CXXFLAGS
124124
MYSQL_CONFIG_EXECUTABLE
@@ -129,12 +129,6 @@ set(ENV_OR_OPT_VARS
129129
MYSQL_LINK_FLAGS
130130
)
131131

132-
IF(NOT WIN32)
133-
set(MYSQL_COMPILER_ID
134-
MYSQL_COMPILER_VERSION
135-
)
136-
ENDIF(NOT WIN32)
137-
138132
# Mark the variable names that have values that are paths
139133
set(ENV_OR_OPT_PATH_VARS
140134
MYSQL_DIR
@@ -356,10 +350,10 @@ macro(_mysql_config _var _regex _opt)
356350
_mysql_conf(_mysql_config_output ${_opt})
357351
string(REGEX MATCHALL "${_regex}([^ ]+)" _mysql_config_output "${_mysql_config_output}")
358352
string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output "${_mysql_config_output}")
359-
string(REGEX REPLACE "${_regex}" "" _mysql_config_output "${_mysql_config_output}")
360353
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
361354
string(REGEX REPLACE " -latomic" "" _mysql_config_output "${_mysql_config_output}")
362355
ENDIF()
356+
string(REGEX REPLACE "${_regex}" "" _mysql_config_output "${_mysql_config_output}")
363357
separate_arguments(_mysql_config_output)
364358
set(${_var} ${_mysql_config_output})
365359
endmacro()
@@ -384,11 +378,11 @@ macro(_mysql_config_replace _var _regex1 _replace _regex2 _opt)
384378
_mysql_conf(_mysql_config_output ${_opt})
385379
string(REGEX MATCHALL "${_regex2}([^ ]+)" _mysql_config_output "${_mysql_config_output}")
386380
string(REGEX REPLACE "^[ \t]+" "" _mysql_config_output "${_mysql_config_output}")
387-
string(REGEX REPLACE "${_regex2}" "" _mysql_config_output "${_mysql_config_output}")
388-
string(REGEX REPLACE "${_regex1}" "${_replace}" _mysql_config_output "${_mysql_config_output}")
389381
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
390382
string(REGEX REPLACE " -latomic" "" _mysql_config_output "${_mysql_config_output}")
391383
ENDIF()
384+
string(REGEX REPLACE "${_regex2}" "" _mysql_config_output "${_mysql_config_output}")
385+
string(REGEX REPLACE "${_regex1}" "${_replace}" _mysql_config_output "${_mysql_config_output}")
392386
separate_arguments(_mysql_config_output)
393387
set(${_var} ${_mysql_config_output})
394388
endmacro()
@@ -514,20 +508,9 @@ elseif(MYSQL_CONFIG_EXECUTABLE)
514508
"\"${MYSQL_CONFIG_EXECUTABLE}\"")
515509
endif()
516510

517-
set(_found_mysql_h)
518-
foreach(_incdir ${MYSQL_INCLUDE_DIR})
519-
if(NOT EXISTS "${_incdir}")
520-
message(FATAL_ERROR "Could not find the directory \"${_incdir}\" "
521-
"from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
522-
endif()
523-
if(EXISTS "${_incdir}/mysql.h")
524-
set(_found_mysql_h 1)
525-
endif()
526-
endforeach()
527-
528-
if(NOT _found_mysql_h)
511+
if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
529512
message(FATAL_ERROR "Could not find \"mysql.h\" in \"${MYSQL_INCLUDE_DIR}\" "
530-
"from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
513+
"found from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
531514
endif()
532515

533516
else()
@@ -608,23 +591,31 @@ elseif(MYSQL_CONFIG_EXECUTABLE)
608591
# This code assumes there is just one "-L...." and that
609592
# no space between "-L" and the path
610593
_mysql_config(MYSQL_LIB_DIR "(^| )-L" "--libs")
611-
if(NOT MYSQL_LIB_DIR)
612-
message(FATAL_ERROR "Could not find the library dir from running "
613-
"\"${MYSQL_CONFIG_EXECUTABLE}\"")
614-
endif()
615594

616-
# In case mysql_config returns two paths: (0) runtime and (1) libmysqlclient
595+
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
596+
# This is needed to make Solaris binaries using the default runtime lib path
597+
_mysql_config(DEV_STUDIO_RUNTIME_DIR "(^| )-R" "--libs")
598+
ENDIF()
599+
600+
601+
# In case mysql_config returns several paths: libmysqlclient is last
617602
LIST(LENGTH MYSQL_LIB_DIR n)
618603
IF( ${n} GREATER 1)
619-
LIST(GET MYSQL_LIB_DIR 0 MYSQL_LIB_DIR_RUNTIME)
604+
#copy list of directories
605+
SET(MYSQL_LIB_DIR_LIST ${MYSQL_LIB_DIR})
606+
607+
MATH(EXPR ind "${n}-1")
608+
LIST(GET MYSQL_LIB_DIR ${ind} MYSQL_LIB_DIR)
620609
ENDIF()
610+
if(NOT MYSQL_LIB_DIR)
611+
message(FATAL_ERROR "Could not find the library dir from running "
612+
"\"${MYSQL_CONFIG_EXECUTABLE}\"")
613+
endif()
621614

622-
foreach(_libdir ${MYSQL_LIB_DIR})
623-
if(NOT EXISTS "${_libdir}")
624-
message(FATAL_ERROR "Could not find the directory \"${_libdir}\" "
625-
"from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
626-
endif()
627-
endforeach()
615+
if(NOT EXISTS "${MYSQL_LIB_DIR}")
616+
message(FATAL_ERROR "Could not find the directory \"${MYSQL_LIB_DIR}\" "
617+
"found from running \"${MYSQL_CONFIG_EXECUTABLE}\"")
618+
endif()
628619

629620
# We have the assumed MYSQL_LIB_DIR. The output from "mysql_config"
630621
# might not be correct for static libraries, so we might need to
@@ -655,9 +646,14 @@ elseif(MYSQL_CONFIG_EXECUTABLE)
655646
else()
656647

657648
_mysql_config(MYSQL_LIBRARIES "(^| )-l" "--libs")
658-
649+
FOREACH(__lib IN LISTS MYSQL_LIBRARIES)
650+
string(REGEX MATCH "mysqlclient([^ ]*)" _matched_lib __lib)
651+
IF(_matched_lib)
652+
set(_search_libs ${matched_lib})
653+
ENDIF()
654+
ENDFOREACH()
659655
# First library is assumed to be the client library
660-
list(GET MYSQL_LIBRARIES 0 _search_libs)
656+
# list(GET MYSQL_LIBRARIES 0 _search_libs)
661657
find_library(MYSQL_LIB
662658
NAMES
663659
${_search_libs}
@@ -705,6 +701,19 @@ if(MYSQLCLIENT_STATIC_LINKING AND
705701
list(APPEND MYSQL_LIBRARIES "rt")
706702
endif()
707703

704+
# For dynamic linking use the built-in sys and strings
705+
if(NOT MYSQLCLIENT_STATIC_LINKING)
706+
list(APPEND SYS_LIBRARIES "mysql_sys")
707+
list(APPEND SYS_LIBRARIES "mysql_strings")
708+
list(APPEND SYS_LIBRARIES ${MYSQL_LIBRARIES})
709+
SET(MYSQL_LIBRARIES ${SYS_LIBRARIES})
710+
711+
#if(NOT MYSQLCLIENT_STATIC_LINKING AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
712+
# list(REVERSE MYSQL_LIBRARIES)
713+
#endif()
714+
715+
endif()
716+
708717
if(MYSQL_EXTRA_LIBRARIES)
709718
separate_arguments(MYSQL_EXTRA_LIBRARIES)
710719
list(APPEND MYSQL_LIBRARIES ${MYSQL_EXTRA_LIBRARIES})
@@ -818,24 +827,16 @@ endif()
818827
# set(CMAKE_CXX_FLAGS_${CMAKEBT} "${CMAKE_CXX_FLAGS_${CMAKEBT}} ${MYSQL_CXXFLAGS}")
819828

820829
include_directories("${MYSQL_INCLUDE_DIR}")
821-
link_directories("${MYSQL_LIB_DIR}" "${MYSQL_LIB_DIR_RUNTIME}")
830+
link_directories("${MYSQL_LIB_DIR}")
822831

823-
IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
824-
SET(RPATH " ${RPATH} ${MYSQL_LIB_DIR_RUNTIME}")
832+
MESSAGE(STATUS "MYSQL_LIB_DIR_LIST = ${MYSQL_LIB_DIR_LIST}")
833+
IF(MYSQL_LIB_DIR_LIST)
834+
FOREACH(__libpath IN LISTS MYSQL_LIB_DIR_LIST)
835+
link_directories("${__libpath}")
836+
ENDFOREACH()
825837
ENDIF()
826838

827-
##########################################################################
828-
#
829-
# Get libmysqlclient compiler ID and VERSION
830-
#
831-
##########################################################################
832-
IF(NOT WIN32)
833-
_mysql_conf(MYSQL_COMPILER_VERSION "")
834-
STRING(REGEX MATCH "Compiler:[a-zA-Z0-9\\. ]+" MYSQL_COMPILER_VERSION ${MYSQL_COMPILER_VERSION})
835-
STRING(REGEX REPLACE "Compiler: " "" MYSQL_COMPILER_VERSION ${MYSQL_COMPILER_VERSION})
836-
STRING(REGEX MATCH "[a-zA-Z0-9]+" MYSQL_COMPILER_ID ${MYSQL_COMPILER_VERSION})
837-
STRING(REGEX REPLACE "[a-zA-Z0-9]+ " "" MYSQL_COMPILER_VERSION ${MYSQL_COMPILER_VERSION})
838-
ENDIF(NOT WIN32)
839+
839840

840841
##########################################################################
841842
#
@@ -848,7 +849,6 @@ message(STATUS "MySQL client environment/cmake variables set that the user can o
848849
message(STATUS " MYSQL_DIR : ${MYSQL_DIR}")
849850
message(STATUS " MYSQL_INCLUDE_DIR : ${MYSQL_INCLUDE_DIR}")
850851
message(STATUS " MYSQL_LIB_DIR : ${MYSQL_LIB_DIR}")
851-
message(STATUS " MYSQL_LIB_DIR_RUNTIME : ${MYSQL_LIB_DIR_RUNTIME}")
852852
message(STATUS " MYSQL_CONFIG_EXECUTABLE : ${MYSQL_CONFIG_EXECUTABLE}")
853853
message(STATUS " MYSQL_CXX_LINKAGE : ${MYSQL_CXX_LINKAGE}")
854854
message(STATUS " MYSQL_CFLAGS : ${MYSQL_CFLAGS}")
@@ -867,8 +867,3 @@ message(STATUS " MYSQL_VERSION : ${MYSQL_VERSION}")
867867
message(STATUS " MYSQL_VERSION_ID : ${MYSQL_VERSION_ID}")
868868
message(STATUS " MYSQL_LIB : ${MYSQL_LIB}")
869869
message(STATUS " MYSQL_LIBRARIES : ${MYSQL_LIBRARIES}")
870-
871-
IF(NOT WIN32)
872-
message(STATUS " MYSQL_COMPILER_ID : ${MYSQL_COMPILER_ID}")
873-
message(STATUS " MYSQL_COMPILER_VERSION : ${MYSQL_COMPILER_VERSION}")
874-
ENDIF(NOT WIN32)

0 commit comments

Comments
 (0)