(接上篇。。。)
前面的都是前戏,鸡冻人心的时刻到了。。。
一、创建VS工程
MySQL源码中默认并未提供VS的工程文件,我们需要自己去生成,之后才能在VS中打开。
我的VS环境是VS2012,VS2008和VS2010的操作步骤应该是类似的。
首先,需要在C:\MySQLSC\目录下新建一个文件夹:C:\MySQLSC\bld,用来存放生成的工程文件
现在,果断地双击执行【C:\CMake\bin\cmake-gui.exe】,帮我们生成工程文件就全靠它了。
【下面一段是生成工程的关键步骤】
软件启动后的界面是这样的:
需要设置上面的两个参数,如下图所示:
现在点左下角的【Configure】按钮
弹出编译环境配置的窗体:
上面的下拉框可以选择VS版本,下面的四个选项确保选择第一个:【Use default native compilers】
VS版本有很多选择项,稍微解释一下:
Visual Studio 7 对应2003
Visual Studio 8对应2005
Visual Studio 9对应2008
Visual Studio 10对应2010
Visual Studio 11对应2012
此外,后面还有Win64、ARM等修饰,分别对应的是64位版本和版本。
可根据自己的环境及目标选择合适的项,我的环境是VS2012,我要编译64位的MySQL,所以选择的是【Visual Studio 11 Win64】,这个参数你选择的可以和我的不一样,根据你的环境决定即可。
点击【finish】按钮后就可以配置了,这里要花一些时间,具体时间长短取决于你机器的性能,我的配置执行结果如下:
具体输出如下:
============================================================
Running cmake version 2.8.12.2
Configuring with MAX_INDEXES = 64U
The C compiler identification is MSVC 17.0.61030.0
The CXX compiler identification is MSVC 17.0.61030.0
Check for working C compiler using: Visual Studio 11 Win64
Check for working C compiler using: Visual Studio 11 Win64 -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler using: Visual Studio 11 Win64
Check for working CXX compiler using: Visual Studio 11 Win64 -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Performing Test HAVE_GETCURRENTPROCESSORNUMBER
Performing Test HAVE_GETCURRENTPROCESSORNUMBER - Success
Looking for isnan
Looking for isnan - not found
Looking for strcasecmp
Looking for strcasecmp - not found
Looking for strncasecmp
Looking for strncasecmp - not found
Looking for snprintf
Looking for snprintf - not found
Looking for strtok_r
Looking for strtok_r - not found
Looking for strtoull
Looking for strtoull - not found
Looking for vsnprintf
Looking for vsnprintf - found
Looking for stddef.h
Looking for stddef.h - found
Check size of void *
Check size of void * - done
CMake Warning (dev) at CMakeLists.txt:196 (INCLUDE):
Syntax Warning in cmake code at
C:/MySQLSC/cmake/ssl.cmake:252:29
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
MySQL 5.7.3-m13
Packaging as: mysql-5.7.3-m13-winx64
Found Threads: TRUE
Looking for ntohll
Looking for ntohll - not found
Looking for inet_ntop
Looking for inet_ntop - found
Check size of time_t
Check size of time_t - done
Performing Test TIME_T_UNSIGNED
Performing Test TIME_T_UNSIGNED - Failed
Looking for nanosleep
Looking for nanosleep - not found
Using cmake version 2.8.12.2
Not building NDB
Library mysqlclient depends on OSLIBS ws2_32;Secur32
Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://foo.bar.com:80
Library mysqlserver depends on OSLIBS ws2_32
Cannot find wix 3, installer project will not be generated
Configuring done
==============================================================
输出结果中可以看到,有一些Not Found的警告,以及红色字体的一些警告,不用管它,它不会影响我们的编译大计。
现在我们再点【Configure】右边的【Generate】按钮
稍等片刻,工程就生成了:
输出结果如下:
=======================================================
CMake Warning (dev) in libmysql/CMakeLists.txt:
Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link
interface. Run "cmake --help-policy CMP0022" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Target "libmysql" has an INTERFACE_LINK_LIBRARIES property which differs
from its LINK_INTERFACE_LIBRARIES properties.
INTERFACE_LINK_LIBRARIES:
ws2_32;clientlib;dbug;strings;vio;mysys;mysys_ssl;zlib;yassl;taocrypt;auth_win_client
LINK_INTERFACE_LIBRARIES:
This warning is for project developers. Use -Wno-dev to suppress it.
Generating done
======================================================
同样会有红色字体的警告,不用管它。
OK,现在我们的工程已经生成了,源码编译大业已经完成了最重要的一步,现在到C:\MySQLSC\bld目录下看一下我们的成果吧:
可以看到我们熟悉的vcxproj和.sln文件了。
(待续...)