0

JetBrains has spoiled me. I'm familiar with the standard UNIX make file and the make, 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 (main.cpp) 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)?

cpp_n00b
  • 27
  • 1
  • 7
  • you just run `cmake ` then the usual make;make install – xaxxon Sep 25 '17 at 04:17
  • @xaxxon should that be run before uploading to a repo so folks can just do normal install? Or are they expected to run cmake themselves? – cpp_n00b Sep 25 '17 at 04:19
  • you need to run cmake on the computer doing the build so it can tell exactly the environment that it is building on to create a correct makefile for that computer. – xaxxon Sep 25 '17 at 04:20
  • 1
    @xaxxon makes sense. I'll accept if you post as answer. I'll upvote too but my votes don't count yet because my rep is too low. – cpp_n00b Sep 25 '17 at 04:23
  • answered. Thanks. – xaxxon Sep 25 '17 at 04:39
  • FYI, the install rules are used to configure how your package should be deployed onto the target system. (e.g. copy header files to /usr/include, libraries to /usr/lib, or whatever) There is also CPack which is CMake's package building system so that you can build debian packages or Windows Installer packages or what have you for distributing a package that installs your files. However, if you expect people to compile your stuff from source you don't need install rules or packaging rules. It will then be up to them to copy the build products (library, executable, whatever). – legalize Sep 29 '17 at 00:20
  • @legalize I had never heard of CPack before, very cool! I think I like it better than Open Build Service based on what I'm seeing so far. – cpp_n00b Sep 29 '17 at 03:12

1 Answers1

3

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.

xaxxon
  • 19,189
  • 5
  • 50
  • 80