0

I have a cmake project which produces several executables. I want to package each executable in seperate Docker containers, so inside the Dockefile, I only built the target that I need:

RUN mkdir build \
    && cd build \
    && cmake /app/project -DCMAKE_BUILD_TYPE=Release
    && make -j 2 myExecutable \
    && make install/fast

This works as expected, but I run into an issue with the conan cmake integration. The installation is done when cmake is called, not during the actual build - this means that no matter which target I want to actually build, all the conan installation calls present in my cmake files are called - so way more packages are installed than necessary.

# for every target
# include conan dependencies (each target has its own conanfile.txt)
conan_cmake_run(CONANFILE conanfile.txt
        BASIC_SETUP CMAKE_TARGETS
        BUILD_TYPE "${CMAKE_BUILD_TYPE}"
        BUILD outdated
        ${update_conan}
        )
conan_target_link_libraries(${PROJECT_NAME})

Is there a way to make the cmake calls dependend on which target I actually want to build?

kutschkem
  • 7,826
  • 3
  • 21
  • 56
  • If I correctly understand the Conan packaging mechanism, then a package needs to be built before one may extract from it the **list of linking libraries** and **include directories**. So it is simply too late for Conan to defer packages building until the user project is built. After CMake project is configured, it should contain complete list of libraries for link and directories for search headers **for every target**, whenever the target will be built or not. – Tsyvarev Feb 20 '19 at 15:48
  • @Tsyvarev Yes, exactly this is the problem. It needs to do this at configuration time. But maybe there is a general cmake way of stating which targets are to be configured in the first place, and making the call conditional on that. Ideally by using some builtin mechanic, not just defining an option. – kutschkem Feb 20 '19 at 16:04

1 Answers1

0

Unfortunately not, the macro conan_cmake_run has no distinction about which target is involved or even it was executed before. You could use CMake options to run or not conan_cmake_run.

Also, you could comment/vote your request thorough the issue https://github.com/conan-io/cmake-conan/issues/105

Regards!

uilianries
  • 3,363
  • 15
  • 28
  • 1
    This is what I ended up doing, I created an option which allows selection of the components to be configured for building. – kutschkem Mar 06 '19 at 07:26