CMake Installation and usage (Command Prompt Console and GUI)
As for other posts (see Boost Libraries Installation), this post is actually a sub-post I made while I was writing a larger post where I explain how to download and use MySQL connector C++ libraries (MySQL C++ with mysql-connector).
That post soon became pretty big due to the amount of stuff you need to configure in order to achieve the goal, therefore I decided to split it in smaller posts that on one side are useful on their own and on the other helps in keeping the main post they came from slightly smaller and easier to follow. Because of this I will keep these posts quite short.
If you are interested in this post as well, you can find it there:
For this example I will use MySQL Connector for C++ as a sample to show the usage of CMake to generate Visual Studio solutions.
Let’s start!
CMake (3.0.2) – Download and Install
C:\libs\mysql-connector-c++-1.1.4>cmake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
Usage cmake [options] <path-to-source> cmake [options] <path-to-existing-build> Options -C <initial-cache> = Pre-load a script to populate the cache. -D <var>:<type>=<value> = Create a cmake cache entry. -U <globbing_expr> = Remove matching entries from CMake cache. -G <generator-name> = Specify a build system generator. -T <toolset-name> = Specify toolset name if supported by generator. -Wno-dev = Suppress developer warnings. -Wdev = Enable developer warnings. -E = CMake command mode. -L[A][H] = List non-advanced cached variables. --build <dir> = Build a CMake-generated project binary tree. -N = View mode only. -P <file> = Process script mode. --find-package = Run in pkg-config like mode. --graphviz=[file] = Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more. --system-information [file] = Dump information about this system. --debug-trycompile = Do not delete the try_compile build tree. Only useful on one try_compile at a time. --debug-output = Put cmake in a debug mode. --trace = Put cmake in trace mode. --warn-uninitialized = Warn about uninitialized values. --warn-unused-vars = Warn about unused variables. --no-warn-unused-cli = Don't warn about command line options. --check-system-vars = Find problems with variable usage in system files. --help,-help,-usage,-h,-H,/?= Print usage information and exit. --version,-version,/V [<f>] = Print version number and exit. --help-full [<f>] = Print all help manuals and exit. --help-manual <man> [<f>] = Print one help manual and exit. --help-manual-list [<f>] = List help manuals available and exit. --help-command <cmd> [<f>] = Print help for one command and exit. --help-command-list [<f>] = List commands with help available and exit. --help-commands [<f>] = Print cmake-commands manual and exit. --help-module <mod> [<f>] = Print help for one module and exit. --help-module-list [<f>] = List modules with help available and exit. --help-modules [<f>] = Print cmake-modules manual and exit. --help-policy <cmp> [<f>] = Print help for one policy and exit. --help-policy-list [<f>] = List policies with help available and exit. --help-policies [<f>] = Print cmake-policies manual and exit. --help-property <prop> [<f>]= Print help for one property and exit. --help-property-list [<f>] = List properties with help available and exit. --help-properties [<f>] = Print cmake-properties manual and exit. --help-variable var [<f>] = Print help for one variable and exit. --help-variable-list [<f>] = List variables with help available and exit. --help-variables [<f>] = Print cmake-variables manual and exit. Generators The following generators are available on this platform: Visual Studio 6 = Generates Visual Studio 6 project files. Visual Studio 7 = Generates Visual Studio .NET 2002 project files. Visual Studio 10 2010 = Generates Visual Studio 10 (VS 2010) project files. Visual Studio 11 2012 = Generates Visual Studio 11 (VS 2012) project files. Visual Studio 12 2013 = Generates Visual Studio 12 (VS 2013) project files. Visual Studio 7 .NET 2003 = Generates Visual Studio .NET 2003 project files. Visual Studio 8 2005 = Generates Visual Studio 8 2005 project files. Visual Studio 9 2008 = Generates Visual Studio 9 2008 project files. Borland Makefiles = Generates Borland makefiles. NMake Makefiles = Generates NMake makefiles. NMake Makefiles JOM = Generates JOM makefiles. Watcom WMake = Generates Watcom WMake makefiles. MSYS Makefiles = Generates MSYS makefiles. MinGW Makefiles = Generates a make file for use with mingw32-make. Unix Makefiles = Generates standard UNIX makefiles. Ninja = Generates build.ninja files (experimental). CodeBlocks - MinGW Makefiles= Generates CodeBlocks project files. CodeBlocks - NMake Makefiles= Generates CodeBlocks project files. CodeBlocks - Ninja = Generates CodeBlocks project files. CodeBlocks - Unix Makefiles = Generates CodeBlocks project files. CodeLite - MinGW Makefiles = Generates CodeLite project files. CodeLite - NMake Makefiles = Generates CodeLite project files. CodeLite - Ninja = Generates CodeLite project files. CodeLite - Unix Makefiles = Generates CodeLite project files. Eclipse CDT4 - MinGW Makefiles = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - NMake Makefiles = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files. Eclipse CDT4 - Unix Makefiles = Generates Eclipse CDT 4.0 project files. Kate - MinGW Makefiles = Generates Kate project files. Kate - NMake Makefiles = Generates Kate project files. Kate - Ninja = Generates Kate project files. Kate - Unix Makefiles = Generates Kate project files. Sublime Text 2 - MinGW Makefiles = Generates Sublime Text 2 project files. Sublime Text 2 - NMake Makefiles = Generates Sublime Text 2 project files. Sublime Text 2 - Ninja = Generates Sublime Text 2 project files. Sublime Text 2 - Unix Makefiles = Generates Sublime Text 2 project files. |
We can generate the Visual studio project in two ways:
- Using the GUI
- Using the command line
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
CMake Warning (dev) in CMakeLists.txt: Syntax Warning in cmake code at C:/libs/mysql-connector-c++-1.1.4/CMakeLists.txt:61:24 Argument not separated from preceding token by whitespace. This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) in CMakeLists.txt: Syntax Warning in cmake code at C:/libs/mysql-connector-c++-1.1.4/CMakeLists.txt:61:43 Argument not separated from preceding token by whitespace. This warning is for project developers. Use -Wno-dev to suppress it. -- Environment compile flags: -- Environment link flags: -- Boost version: 1.56.0 -- BOOST_INCLUDE_DIRS=C:/Boost/include/boost-1_56 -- ENV{MYSQL_DIR} = -- MySQL Include dir: C:/Program Files/MySQL/MySQL Connector C 6.1.5/include -- MySQL Library : C:/Program Files/MySQL/MySQL Server 5.6/lib/mysqlclient.lib -- MySQL Library dir: C:/Program Files/MySQL/MySQL Server 5.6/lib -- MySQL CXXFLAGS: -- MySQL Link flags: -- MySQL Include dir: C:/Program Files/MySQL/MySQL Connector C 6.1.5/include -- MySQL Library dir: C:/Program Files/MySQL/MySQL Server 5.6/lib -- MySQL CXXFLAGS: -- MySQL Link flags: -- Installation path is: C:/Program Files/MySQL/ConnectorCPP (overwrite with -DCMAKE_INSTALL_PREFIX=/your/path) -- Looking for include file stdint.h -- Looking for include file stdint.h - found -- Looking for include file inttypes.h -- Looking for include file inttypes.h - not found -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of int8_t -- Check size of int8_t - done -- Check size of uint8_t -- Check size of uint8_t - done -- Check size of int16_t -- Check size of int16_t - done -- Check size of uint16_t -- Check size of uint16_t - done -- Check size of int32_t -- Check size of int32_t - done -- Check size of uint32_t -- Check size of uint32_t - done -- Check size of int64_t -- Check size of int64_t - done -- Check size of uint64_t -- Check size of uint64_t - done -- Check size of __int8 -- Check size of __int8 - done -- Check size of unsigned __int8 -- Check size of unsigned __int8 - done -- Check size of __int16 -- Check size of __int16 - done -- Check size of unsigned __int16 -- Check size of unsigned __int16 - done -- Check size of __int32 -- Check size of __int32 - done -- Check size of unsigned __int32 -- Check size of unsigned __int32 - done -- Check size of __int64 -- Check size of __int64 - done -- Check size of unsigned __int64 -- Check size of unsigned __int64 - done -- Looking for strtold -- Looking for strtold - not found -- Looking for strtol -- Looking for strtol - found -- Looking for strtoll -- Looking for strtoll - not found -- Looking for strtoul -- Looking for strtoul - found -- Looking for strtoull -- Looking for strtoull - not found -- Looking for strtoimax -- Looking for strtoimax - not found -- Looking for strtoumax -- Looking for strtoumax - not found -- BOOST_INCLUDE_DIRS=C:/Boost/include/boost-1_56 -- Using static libmysql binding -- DT_RPATH will not be set -- Configuring driver -- MySQL dynamic load test library: C:/Program Files/MySQL/MySQL Server 5.6/lib/libmysql.dll -- Configuring examples -- Configuring test cases -- Configuring tests framework lib -- Configuring C/J junit tests port -- MySQL dynamic load test library: C:/Program Files/MySQL/MySQL Server 5.6/lib/libmysql.dll -- Configuring unit tests -- Configuring unit tests - examples -- Configuring unit tests - connection -- Configuring unit tests - databasemetadata -- Configuring unit tests - resultsetmetadata -- Configuring unit tests - resultset -- Configuring unit tests - savepoint -- Configuring unit tests - preparedstatement -- Configuring unit tests - parametermetadata -- Configuring unit tests - art_resultset -- Configuring unit tests - statement -- Configuring unit tests - uri -- Configuring performance test - statement -- Configuring bugs test cases - unsorted -- Configuring unit tests - group template_bug -- Configuring done CMake Warning (dev) in driver/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 "mysqlcppconn" has an INTERFACE_LINK_LIBRARIES property which differs from its LINK_INTERFACE_LIBRARIES properties. INTERFACE_LINK_LIBRARIES: mysqlclient;ws2_32 LINK_INTERFACE_LIBRARIES: This warning is for project developers. Use -Wno-dev to suppress it. -- Generating done -- Build files have been written to: C:/libs/mysql-connector-c++-1.1.4 |
Now, if everything went as planned, you should be able to see a solution file (and other files as well) into your connector’s folder:
Супер!!!!