0

It's my first time building a library manually so I just want to verify something. Sometimes, I run Cmake as:

cmake -SOME_SWITCH=ON ..

And this runs fairly quickly. However, after that, I run:

sudo make

Which takes a really long time (30-40 Minutes).

So my question is, if I do after that CMake again with:

cmake -SOME_SWITCH=ON -SWITCH2=ON ..

Do I need to Make again? And if so, is there a way to not have to go through the entire make again (I.e. only compile the new entries?)

Thanks!

AspiringMat
  • 2,161
  • 2
  • 21
  • 33
  • most likely, but depending on the change and how your project is organized it should be faster on subsequent compiles. As for your question on performance, try suggestions at https://stackoverflow.com/q/37327526/7088038 – avigil Mar 13 '18 at 05:49
  • 1
    especially noteworthy: use [ccache](https://github.com/ccache/ccache) – avigil Mar 13 '18 at 05:54
  • @avigil I know this is late, but I just want you to know that I love you. I didn't know about ccache, but it has essentially taken down the build time from 40 minutes to 2 minutes! Thank you! – AspiringMat Mar 14 '18 at 17:04

1 Answers1

3

CMake isn't a build system, it's a build system generator. This is why (to answer your first question), you need to invoke make after running cmake; running cmake generates Makefiles with the appropriate dependencies, flags, blah blah blah, and running make actually uses them.

As to your second question, you shouldn't have to rebuild the entire project again unless something changed that affects the entire project (e.g., you changed cflags or modified a header that everything includes). After you've run cmake, keep the build directory around and you should be able to just run make (it'll detect if a CMakeLists.txt file changed and cmake needs to be invoked again).

Stephen Newell
  • 7,330
  • 1
  • 24
  • 28