cpp_n00b cpp_n00b - 5 months ago 65
C++ Question

Build instructions when distributing C++ written in CLion

JetBrains has spoiled me. I'm familiar with the standard UNIX make file and the

make install
routine normally associated with installing software with traditional make files, but I'm not as familiar with cmake since CLion does it all for me.

I want to distribute my code to others and provide simple instructions for building it via cmake so that they have a binary they can execute. The official cmake tutorial shows writing install rules in the CMakeLists.txt file but it isn't clear if this is supported by CLion (or even if it needs to be).

For a simple, single-file (
) application, what would be an example of how to build it using cmake (assuming those it is distributed to don't have CLion nor use another IDE, they just want to build and use it)?

Answer Source

To build code that comes with a CMakeLists.txt file, you run cmake to generate a Makefile (or other build configuration file):

cmake <path_to_CMakeLists.txt>

Then you run

make;make install

as usual. (or as described in the comment, you can type cmake --build . instead of make - useful if you're on a platform with a different build system)

You don't want to check in the Makefile into your source control, though, as it needs to be generated on the computer that will actually be doing the building.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download