62
62
# In addition, the below CMake variables are set by this include file
63
63
#
64
64
# MYSQL_VERSION - Three position numeric version, like 5.6.41
65
- # MYSQL_NUM_VERSION - Numeric padded version, 5.13.4 => 51304
65
+ # MYSQL_VERSION_ID - Numeric padded version, 5.13.4 => 51304
66
+ # MYSQL_NUM_VERSION - Same as MYSQL_VERSION_ID, for compatibility
66
67
# MYSQL_LIB - Path to the client library
67
68
# MYSQL_LIBRARIES - Library name, might be "-lmysqlclient" while
68
69
# MYSQL_LIB is the path to the library
70
+ # MYSQL_CLIENT_LIBS - Same as MYSQL_LIBRARIES, for compatibility
69
71
#
70
72
# (1) If MYSQL_INCLUDE_DIR or MYSQL_LIB_DIR are given, these are
71
73
# used and an error is reported if can't be used
90
92
# FIXME cache variables, makes them command line args?
91
93
# FIXME really do include_directories() and link_directories()? Likely
92
94
# FIXME add check that if not static, not picked up .a or mysqlclient.lib
93
- # FIXME MYSQL_NUM_VERSION need to take into account Cluster versions
95
+ # FIXME MYSQL_VERSION_ID need to take into account Cluster versions
94
96
# and Connector/C versions
97
+ # FIXME handle MYSQL_VERSION_ID, LIBMYSQL_VERSION and LIBMYSQL_VERSION_ID?
95
98
#
96
99
##########################################################################
97
100
@@ -434,52 +437,7 @@ if(NOT WIN32)
434
437
if (MYSQL_CONFIG_EXECUTABLE )
435
438
message (STATUS "mysql_config was found ${MYSQL_CONFIG_EXECUTABLE} " )
436
439
437
- _mysql_conf (_mysql_version "--version" )
438
-
439
- # Clean up so only numeric, in case of "-alpha" or similar
440
- string (REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${_mysql_version} " )
441
- # To create a fully numeric version, first normalize so N.NN.NN
442
- string (REGEX REPLACE "[.]([0-9])[.]" ".0\\ 1." MYSQL_NUM_VERSION "${MYSQL_VERSION} " )
443
- string (REGEX REPLACE "[.]([0-9])$" ".0\\ 1" MYSQL_NUM_VERSION "${MYSQL_NUM_VERSION} " )
444
- # Finally remove the dot
445
- string (REGEX REPLACE "[.]" "" MYSQL_NUM_VERSION "${MYSQL_NUM_VERSION} " )
446
- endif ()
447
-
448
- endif ()
449
-
450
- ##########################################################################
451
- #
452
- # Try determine if to use C++ linkage, and also find C++ flags
453
- #
454
- ##########################################################################
455
-
456
- if (NOT WIN32 )
457
-
458
- if (MYSQL_CONFIG_EXECUTABLE )
459
-
460
- if (NOT MYSQL_CFLAGS )
461
- _mysql_conf (MYSQL_CFLAGS "--cflags" )
462
- endif ()
463
-
464
- if (NOT MYSQL_CXXFLAGS )
465
- if (MYSQL_CXX_LINKAGE OR MYSQL_NUM_VERSION GREATER 50603 )
466
- _mysql_conf (MYSQL_CXXFLAGS "--cxxflags" )
467
- set (MYSQL_CXX_LINKAGE 1 )
468
- else ()
469
- set (MYSQL_CXXFLAGS "${MYSQL_CFLAGS} " )
470
- endif ()
471
- endif ()
472
-
473
- # FIXME this should not be needed, caller of this module should set
474
- # it's own flags and just use the library on it's on terms
475
- # (change the infe message if enabling this code)
476
- # if(NOT MYSQL_LINK_FLAGS)
477
- # # Find -mcpu -march -mt -m32 -m64 and other flags starting with "-m"
478
- # string(REGEX MATCHALL "(^| )-m([^\r\n ]+)" MYSQL_LINK_FLAGS "${MYSQL_CXXFLAGS}")
479
- # string(REGEX REPLACE "^ " "" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
480
- # string(REGEX REPLACE "; " ";" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
481
- # endif()
482
-
440
+ _mysql_conf (MYSQL_VERSION "--version" )
483
441
endif ()
484
442
485
443
endif ()
@@ -550,9 +508,9 @@ else()
550
508
endif ()
551
509
552
510
# No specific paths, try some common install paths
553
- find_path (MYSQL_INCLUDE_DIR mysql.h ${_include_fallback_path} )
511
+ find_path (MYSQL_INCLUDE_DIR mysql.h ${_include_fallback_path} )
554
512
555
- if (NOT MYSQL_INCLUDE_DIR )
513
+ if (NOT MYSQL_INCLUDE_DIR )
556
514
message (FATAL_ERROR "Could not find \" mysql.h\" from searching "
557
515
"\" ${_pp_include_fallback_path} \" " )
558
516
endif ()
@@ -563,35 +521,6 @@ if(FINDMYSQL_DEBUG)
563
521
message ("DBG: MYSQL_INCLUDE_DIR = \" ${MYSQL_INCLUDE_DIR} \" " )
564
522
endif ()
565
523
566
- if (MYSQL_INCLUDE_DIR AND NOT MYSQL_NUM_VERSION )
567
- try_run (RUN_RESULT_VAR COMPILE_RESULT_VAR
568
- "${CMAKE_BINARY_DIR} "
569
- "${CMAKE_SOURCE_DIR} /cmake/getmysqlversion.c"
570
- CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=${MYSQL_INCLUDE_DIR}
571
- ARGS "${CMAKE_BINARY_DIR} /cmake/mysql_version_info.cmake"
572
- "MYSQL_SERVER_VERSION"
573
- "MYSQL_VERSION_ID"
574
- "LIBMYSQL_VERSION"
575
- "LIBMYSQL_VERSION_ID" )
576
-
577
- if (COMPILE_RESULT_VAR AND RUN_RESULT_VAR )
578
- include (${CMAKE_BINARY_DIR} /cmake/mysql_version_info.cmake )
579
- if (NOT LIBMYSQL_CPP_VERSION STREQUAL "" )
580
- set (MYSQL_VERSION "${LIBMYSQL_CPP_VERSION} " )
581
- elseif (NOT MYSQL_CPP_SERVER_VERSION STREQUAL "" )
582
- set (MYSQL_VERSION "${MYSQL_CPP_SERVER_VERSION} " )
583
- endif (NOT LIBMYSQL_CPP_VERSION STREQUAL "" )
584
- string (REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${MYSQL_VERSION} " )
585
-
586
- if (LIBMYSQL_CPP_VERSION_ID )
587
- set (MYSQL_NUM_VERSION ${LIBMYSQL_CPP_VERSION_ID} )
588
- elseif (MYSQL_CPP_SERVER_VERSION_ID )
589
- set (MYSQL_NUM_VERSION ${MYSQL_CPP_SERVER_VERSION_ID} )
590
- endif (LIBMYSQL_CPP_VERSION_ID )
591
- endif (COMPILE_RESULT_VAR AND RUN_RESULT_VAR )
592
- endif ()
593
-
594
-
595
524
##########################################################################
596
525
#
597
526
# Find MYSQL_LIB_DIR, MYSQL_LIB and MYSQL_LIBRARIES
@@ -612,7 +541,7 @@ if(MYSQL_LIB_DIR)
612
541
NAMES
613
542
${_search_libs}
614
543
PATHS
615
- ${MYSQL_LIB_DIR}
544
+ " ${MYSQL_LIB_DIR} "
616
545
NO_DEFAULT_PATH
617
546
)
618
547
_check_lib_search_error (MYSQL_LIB_DIR MYSQL_LIB "" )
@@ -631,14 +560,14 @@ elseif(MYSQL_DIR AND
631
560
NAMES
632
561
${_search_libs}
633
562
PATHS
634
- ${MYSQL_DIR}
563
+ " ${MYSQL_DIR} "
635
564
PATH_SUFFIXES
636
565
${_lib_subdirs}
637
566
NO_DEFAULT_PATH
638
567
)
639
568
_check_lib_search_error (MYSQL_DIR MYSQL_LIB "in \" ${_pp_lib_subdirs} \" " )
640
- get_filename_component (MYSQL_LIB_DIR ${MYSQL_LIB} PATH )
641
- set (MYSQL_LIBRARIES ${MYSQL_LIB} )
569
+ get_filename_component (MYSQL_LIB_DIR " ${MYSQL_LIB} " PATH )
570
+ set (MYSQL_LIBRARIES " ${MYSQL_LIB} " )
642
571
643
572
elseif (MYSQL_CONFIG_EXECUTABLE )
644
573
@@ -655,7 +584,7 @@ elseif(MYSQL_CONFIG_EXECUTABLE)
655
584
endif ()
656
585
657
586
if (NOT EXISTS "${MYSQL_LIB_DIR} " )
658
- message (FATAL_ERROR "Could not find the directory \" ${MYSQL_INCLUDE_DIR } \" "
587
+ message (FATAL_ERROR "Could not find the directory \" ${MYSQL_LIB_DIR } \" "
659
588
"found from running \" ${MYSQL_CONFIG_EXECUTABLE} \" " )
660
589
endif ()
661
590
@@ -678,7 +607,7 @@ elseif(MYSQL_CONFIG_EXECUTABLE)
678
607
_check_lib_search_error (MYSQL_LIB_DIR MYSQL_LIB "in \" ${_static_subdirs} \" " )
679
608
680
609
# Adjust MYSQL_LIB_DIR in case it changes
681
- get_filename_component (MYSQL_LIB_DIR ${MYSQL_LIB} PATH )
610
+ get_filename_component (MYSQL_LIB_DIR " ${MYSQL_LIB} " PATH )
682
611
683
612
# Replace the current library references with the full path
684
613
# to the library, i.e. the -L will be ignored
@@ -721,7 +650,7 @@ else()
721
650
"\" ${_pp_lib_fallback_path} \" " )
722
651
endif ()
723
652
724
- get_filename_component (MYSQL_LIB_DIR ${MYSQL_LIB} PATH )
653
+ get_filename_component (MYSQL_LIB_DIR " ${MYSQL_LIB} " PATH )
725
654
726
655
endif ()
727
656
@@ -743,18 +672,115 @@ if(MYSQL_EXTRA_LIBRARIES)
743
672
list (APPEND MYSQL_LIBRARIES ${MYSQL_EXTRA_LIBRARIES} )
744
673
endif ()
745
674
675
+ # For compatibility
676
+ SET (MYSQL_CLIENT_LIBS ${MYSQL_LIBRARIES} )
677
+
746
678
##########################################################################
747
679
#
748
- # Add more libraries to MYSQL_LIBRARIES
680
+ # If not found MySQL Serverv version, compile a small client app
681
+ # and let it write a small cmake file with the settings
682
+ #
683
+ ##########################################################################
684
+
685
+ if (MYSQL_INCLUDE_DIR AND NOT MYSQL_VERSION )
686
+
687
+ # Write the C source file that will include the MySQL headers
688
+ set (GETMYSQLVERSION_SOURCEFILE "${CMAKE_CURRENT_BINARY_DIR} /getmysqlversion.c" )
689
+ file (WRITE "${GETMYSQLVERSION_SOURCEFILE} "
690
+ "#include <mysql.h>\n "
691
+ "#include <stdio.h>\n "
692
+ "int main() {\n "
693
+ " printf(\" %s\" , MYSQL_SERVER_VERSION);\n "
694
+ "}\n "
695
+ )
696
+
697
+ # Compile and run the created executable, store output in MYSQL_VERSION
698
+ try_run (_run_result _compile_result
699
+ "${CMAKE_BINARY_DIR} "
700
+ "${GETMYSQLVERSION_SOURCEFILE} "
701
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MYSQL_INCLUDE_DIR} "
702
+ RUN_OUTPUT_VARIABLE MYSQL_VERSION
703
+ )
704
+
705
+ if (FINDMYSQL_DEBUG )
706
+ if (NOT _compile_result )
707
+ message ("DBG: Could not compile \" getmysqlversion.c\" " )
708
+ endif ()
709
+ if (_run_result )
710
+ message ("DBG: Running \" getmysqlversion\" returned ${_run_result} " )
711
+ endif ()
712
+ endif ()
713
+
714
+ endif ()
715
+
716
+ ##########################################################################
717
+ #
718
+ # Clean up MYSQL_VERSION and create MYSQL_VERSION_ID/MYSQL_NUM_VERSION
719
+ #
720
+ ##########################################################################
721
+
722
+ if (NOT MYSQL_VERSION )
723
+ message (FATAL_ERROR "Could not determine the MySQL Server version" )
724
+ endif ()
725
+
726
+ # Clean up so only numeric, in case of "-alpha" or similar
727
+ string (REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${MYSQL_VERSION} " )
728
+ # To create a fully numeric version, first normalize so N.NN.NN
729
+ string (REGEX REPLACE "[.]([0-9])[.]" ".0\\ 1." MYSQL_VERSION_ID "${MYSQL_VERSION} " )
730
+ string (REGEX REPLACE "[.]([0-9])$" ".0\\ 1" MYSQL_VERSION_ID "${MYSQL_VERSION_ID} " )
731
+ # Finally remove the dot
732
+ string (REGEX REPLACE "[.]" "" MYSQL_VERSION_ID "${MYSQL_VERSION_ID} " )
733
+ set (MYSQL_NUM_VERSION ${MYSQL_VERSION_ID} )
734
+
735
+ ##########################################################################
736
+ #
737
+ # Try determine if to use C++ linkage, and also find C++ flags
738
+ #
739
+ ##########################################################################
740
+
741
+ if (NOT WIN32 )
742
+
743
+ if (MYSQL_CONFIG_EXECUTABLE )
744
+
745
+ if (NOT MYSQL_CFLAGS )
746
+ _mysql_conf (MYSQL_CFLAGS "--cflags" )
747
+ endif ()
748
+
749
+ if (NOT MYSQL_CXXFLAGS )
750
+ if (MYSQL_CXX_LINKAGE OR MYSQL_VERSION_ID GREATER 50603 )
751
+ _mysql_conf (MYSQL_CXXFLAGS "--cxxflags" )
752
+ set (MYSQL_CXX_LINKAGE 1 )
753
+ else ()
754
+ set (MYSQL_CXXFLAGS "${MYSQL_CFLAGS} " )
755
+ endif ()
756
+ endif ()
757
+
758
+ # FIXME this should not be needed, caller of this module should set
759
+ # it's own flags and just use the library on it's on terms
760
+ # (change the infe message if enabling this code)
761
+ # if(NOT MYSQL_LINK_FLAGS)
762
+ # # Find -mcpu -march -mt -m32 -m64 and other flags starting with "-m"
763
+ # string(REGEX MATCHALL "(^| )-m([^\r\n ]+)" MYSQL_LINK_FLAGS "${MYSQL_CXXFLAGS}")
764
+ # string(REGEX REPLACE "^ " "" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
765
+ # string(REGEX REPLACE "; " ";" MYSQL_LINK_FLAGS "${MYSQL_LINK_FLAGS}")
766
+ # endif()
767
+
768
+ endif ()
769
+
770
+ endif ()
771
+
772
+ ##########################################################################
773
+ #
774
+ # Inform CMake where to look for headers and libraries
749
775
#
750
776
##########################################################################
751
777
752
778
# string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKEBT)
753
779
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MYSQL_CXXFLAGS}")
754
780
# set(CMAKE_CXX_FLAGS_${CMAKEBT} "${CMAKE_CXX_FLAGS_${CMAKEBT}} ${MYSQL_CXXFLAGS}")
755
781
756
- include_directories (${MYSQL_INCLUDE_DIR} )
757
- link_directories (${MYSQL_LIB_DIR} )
782
+ include_directories (" ${MYSQL_INCLUDE_DIR} " )
783
+ link_directories (" ${MYSQL_LIB_DIR} " )
758
784
759
785
##########################################################################
760
786
#
@@ -782,6 +808,6 @@ message(STATUS " MYSQL_LINK_FLAGS : ${MYSQL_LINK_FLAGS}")
782
808
message (STATUS "MySQL client settings that the user can't override" )
783
809
784
810
message (STATUS " MYSQL_VERSION : ${MYSQL_VERSION} " )
785
- message (STATUS " MYSQL_NUM_VERSION : ${MYSQL_NUM_VERSION } " )
811
+ message (STATUS " MYSQL_VERSION_ID : ${MYSQL_VERSION_ID } " )
786
812
message (STATUS " MYSQL_LIB : ${MYSQL_LIB} " )
787
813
message (STATUS " MYSQL_LIBRARIES : ${MYSQL_LIBRARIES} " )
0 commit comments