cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

A complete new build is always triggered even if built previously and exists in cache

Open starsoup opened this issue 5 years ago • 3 comments

Using conan 1.22.1 @ Ubuntu 18

The application's CMakeLists.txt contains:

...
include(<path>/conan.cmake)
...
conan_cmake_run(REQUIRES <PACKAGE_NAME>
                BASIC_SETUP CMAKE_TARGETS
                GENERATORS cmake_paths deploy
                BUILD <PACKAGE_NAME>
                BUILD missing)

When I build the cmake application:

cmake -DCMAKE_BUILD_TYPE=Release  # conan.cmake invoked -> builds the <PACKAGE_NAME>
cmake --build .  # builds the application

Then if I immediately re-type any of the cmake --build commands it will re-build the whole <PACKAGE_NAME> even if it already exists in the cache? No modifications done there. Why it won't notice that the <PACKAGE_NAME> already exists in the cache?

starsoup avatar Jun 30 '20 09:06 starsoup

Hi @starsoup,

The build policies in conan are additive, so if you add BUILD missing and also BUILD <package_name> it will always rebuild package_name because you are forcing conan to do so. Could you please try to remove the BUILD <PACKAGE_NAME> from the arguments to see if that solves your problem? Thanks a lot, hope this helps!

czoido avatar Jun 30 '20 11:06 czoido

Thanks for the reply @czoido,

yes that does the trick, but there is still something I don't fully grasp about the intended work flow.

If I define it llike this and start the project from scratch

conan_cmake_run(REQUIRES <PACKAGE_NAME>
                BASIC_SETUP CMAKE_TARGETS
                GENERATORS cmake_paths deploy
                BUILD missing)

Conan will attempt to find the <PACKAGE_NAME> from remote(s) first. In my current setup I want to work in offline mode (all remotes are disabled) and the build fails (conan.cmake):

ERROR: Remote '<my-remote-name>' is disabled
CMake Error at <some_work_path>/conan.cmake:402 (message):
  Conan install failed='1'
Call Stack (most recent call first):
  <some_work_path>/conan.cmake:497 (conan_cmake_install)
  CMakeLists.txt:41 (conan_cmake_run)

Interestingly if I enable the remotes (which don't even contain the <PACKAGE_NAME>) the build still fails if I use:

conan_cmake_run(REQUIRES <PACKAGE_NAME>
                BASIC_SETUP CMAKE_TARGETS
                GENERATORS cmake_paths deploy
                BUILD missing)

So in my project I first need to use both "BUILD missing" and "BUILD <PACKAGE_NAME>" and once initial build is done I can remove the "BUILD <PACKAGE_NAME>".

How can I define it so that it won't fail if remotes are disabled and it will build it initially only when missing? I.e. what kind of CMakeLists.txt should I put to VCS so that it will work from scratch without remotes enabled?

starsoup avatar Jul 07 '20 10:07 starsoup

Hi @starsoup, That's happening because the package is associated with the remote, that association is declared in the metadata.json file created in the local cache for the package. With conan remote clean you can remove that association for all the packages and then Conan is not going to try to contact with the server the package comes from. Maybe that helps you.

czoido avatar Jul 09 '20 13:07 czoido