• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1                                  _   _ ____  _
2                              ___| | | |  _ \| |
3                             / __| | | | |_) | |
4                            | (__| |_| |  _ <| |___
5                             \___|\___/|_| \_\_____|
6
7                                How To Compile with CMake
8
9# Building with CMake
10
11This document describes how to configure, build and install curl and libcurl
12from source code using the CMake build tool. To build with CMake, you will
13of course have to first install CMake. The minimum required version of CMake
14is specified in the file `CMakeLists.txt` found in the top of the curl
15source tree. Once the correct version of CMake is installed you can follow
16the instructions below for the platform you are building on.
17
18CMake builds can be configured either from the command line, or from one of
19CMake's GUIs.
20
21# Current flaws in the curl CMake build
22
23Missing features in the CMake build:
24
25 - Builds libcurl without large file support
26 - Does not support all SSL libraries (only OpenSSL, Schannel, Secure
27   Transport, and mbedTLS, WolfSSL)
28 - Does not allow different resolver backends (no c-ares build support)
29 - No RTMP support built
30 - Does not allow build curl and libcurl debug enabled
31 - Does not allow a custom CA bundle path
32 - Does not allow you to disable specific protocols from the build
33 - Does not find or use krb4 or GSS
34 - Rebuilds test files too eagerly, but still cannot run the tests
35 - Does not detect the correct `strerror_r` flavor when cross-compiling
36   (issue #1123)
37
38# Configuring
39
40A CMake configuration of curl is similar to the autotools build of curl.
41It consists of the following steps after you have unpacked the source.
42
43## Using `cmake`
44
45You can configure for in source tree builds or for a build tree
46that is apart from the source tree.
47
48 - Build in the source tree.
49
50       $ cmake -B .
51
52 - Build in a separate directory (parallel to the curl source tree in this
53   example). The build directory will be created for you.
54
55       $ cmake -B ../curl-build
56
57### Fallback for CMake before version 3.13
58
59CMake before version 3.13 does not support the `-B` option. In that case,
60you must create the build directory yourself, `cd` to it and run `cmake`
61from there:
62
63    $ mkdir ../curl-build
64    $ cd ../curl-build
65    $ cmake ../curl
66
67If you want to build in the source tree, it is enough to do this:
68
69    $ cmake .
70
71## Using `ccmake`
72
73CMake comes with a curses based interface called `ccmake`. To run `ccmake`
74on a curl use the instructions for the command line cmake, but substitute
75`ccmake` for `cmake`.
76
77This will bring up a curses interface with instructions on the bottom of the
78screen. You can press the "c" key to configure the project, and the "g" key
79to generate the project. After the project is generated, you can run make.
80
81## Using `cmake-gui`
82
83CMake also comes with a Qt based GUI called `cmake-gui`. To configure with
84`cmake-gui`, you run `cmake-gui` and follow these steps:
85
86 1. Fill in the "Where is the source code" combo box with the path to
87    the curl source tree.
88 2. Fill in the "Where to build the binaries" combo box with the path to
89    the directory for your build tree, ideally this should not be the same
90    as the source tree, but a parallel directory called curl-build or
91    something similar.
92 3. Once the source and binary directories are specified, press the
93    "Configure" button.
94 4. Select the native build tool that you want to use.
95 5. At this point you can change any of the options presented in the GUI.
96    Once you have selected all the options you want, click the "Generate"
97    button.
98
99# Building
100
101Build (you have to specify the build directory).
102
103    $ cmake --build ../curl-build
104
105### Fallback for CMake before version 3.13
106
107CMake before version 3.13 does not support the `--build` option. In that
108case, you have to `cd` to the build directory and use the building tool that
109corresponds to the build files that CMake generated for you. This example
110assumes that CMake generates `Makefile`:
111
112    $ cd ../curl-build
113    $ make
114
115# Testing
116
117(The test suite does not yet work with the cmake build)
118
119# Installing
120
121Install to default location (you have to specify the build directory).
122
123    $ cmake --install ../curl-build
124
125### Fallback for CMake before version 3.15
126
127CMake before version 3.15 does not support the `--install` option. In that
128case, you have to `cd` to the build directory and use the building tool that
129corresponds to the build files that CMake generated for you. This example
130assumes that CMake generates `Makefile`:
131
132    $ cd ../curl-build
133    $ make install
134