5

I have a library my project depends on, I check out this submodule with git --recursive and then include it in my CMakeLists.txt file:

add_subdirectory(dependencies/library)
add_executable(myExe ...)
add_dependencies(myExe library)
target_link_libraries(myExe library)

The problem:

library is a pretty big library and recompiling it takes an awful lot of time.

I practically NEVER change it so it should be built once, but CMake is recompiling it every time I add a single line to the CMakeLists.txt file and refresh the Visual Studio solution entirely.

How to avoid this horrible behavior and tell CMake NOT to recompile library if nothing changed into it?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Dean
  • 6,610
  • 6
  • 40
  • 90
  • 4
    well, I guess the the library's CMakeLists is written incorrectly. If one of the targets within `dependencies/library/CMakeLists.txt` is considered out-of-date due to whatever reason, you would get this particular behaviour. Please demostrate us that `CMakeLists.txt` and let's speculate what can be wrong with it and what can be fixed. – user3159253 Dec 20 '15 at 23:26
  • I would suspect an improperly described code generation, but the reasons might be much, much weirder. – user3159253 Dec 20 '15 at 23:32
  • Does your `dependencies/library/CMakeLists.txt` also contain a `project()` command? This is just a wild guess, but it could be one reason for this behavior. Generally speaking - for a huge external library - you could think about using [`ExternalProject_Add()`](https://cmake.org/cmake/help/v3.4/module/ExternalProject.html) (see e.g. [here](http://stackoverflow.com/questions/33443164/cmake-share-library-with-multiple-executables)) – Florian Dec 21 '15 at 11:37
  • I'm voting to close because I don't think there's enough info here to answer the question. There's no repro. The SMEs commenting above are all reduced to guessing what could be the problem. – starball Nov 23 '22 at 19:17

0 Answers0