Giter Site home page Giter Site logo

Comments (6)

garethsb avatar garethsb commented on July 21, 2024

Ah, maybe Editable Packages help me here?

from cmake-conan.

memsharded avatar memsharded commented on July 21, 2024

Hi @garethsb

Thanks for your question.
This is something that we should have a look. Certainly, this was not the intended use case of cmake-conan, but to provide a relatively simple way to have single projects calling Conan automatically. But mostly it avoids a conan install call.
If the project is more a meta-project, gathering other subprojects, this seems a bit beyond the original scope of this cmake-conan integration, but lets have a look at it and think about it.

Ah, maybe Editable Packages help me here?

Probably not, those are intended to solve a different problem: working simultaneously on different packages. Something to do occasionally, because mainly using packages means that every package should and will be develop in isolation most of the time (otherwise it is not really a package). But if the project is not really componentized into packages, then the editables won't really help much, and specially they will not provide the same integrated development experience in a single IDE project than a real monolith can achieve.

Regarding the approach of having a meta project with several subprojects and each one containing a different conanfile, consider the following: If those subprojects have dependencies to other subprojects, and they are using different versions of dependencies, things will be ugly, with link errors or runtime errors due to discrepancies. Conan cannot detect those discrepancies of versions, because each subproject has a different conanfile, so they install completely independent dependency graphs, but those graphs are not checked against other graphs computed later in another folder, even if it is a sibling folder.

If you need consistency of dependencies across all subprojects, it would be much better to have a single central conanfile declaring all the needed dependencies. Then each subproject can have different find_package() and link only the ones they need.

from cmake-conan.

garethsb avatar garethsb commented on July 21, 2024

Thanks for the thoughtful response. The use case for me is exactly the one you mentioned of the integrated development experience in a single IDE project, by using add_subdirectory, with the option to switch to find_package when the monolith isn't required, since all the same CMake targets are made available either way.

I do understand the concerns about carefully managing dependencies of dependencies, so a central conanfile when using add_subdirectory maybe the workaround even though switching from find_package would become less simple than just toggling a CMake option.

from cmake-conan.

memsharded avatar memsharded commented on July 21, 2024

experience in a single IDE project, by using add_subdirectory, with the option to switch to find_package when the monolith isn't required, since all the same CMake targets are made available either way.

Definitely, being able to modify the CMakeLists.txt to use some conditional logic to use one approach (find_package()) or the other, would help a lot towards that goal. The thing is that often users expect to be able to switch transparently from mono-repo with add_subdirectory() and just using targets defined in sibling sub-projects, to use Conan and magically have things still working, and unfortunately CMake doesn't allow that that easily.

from cmake-conan.

garethsb avatar garethsb commented on July 21, 2024

I use this idiom frequently:

# Find and use FooBar from its installed location or as a subdirectory
set(USE_ADD_SUBDIRECTORY OFF CACHE BOOL "Use add_subdirectory() rather than find_package()")
if(NOT USE_ADD_SUBDIRECTORY)
    message(STATUS "Using find_package(FooBar)")

    # Using find_package() will require FooBar and its dependencies (Baz, Qux, etc.)
    # to be installed and discoverable via a config-file package or find-module
    # Conan is one way of achieving this...

    find_package(FooBar REQUIRED)
else()
    set(FOO_BAR_DIRECTORY "../FooBar" CACHE STRING "Path to FooBar directory")

    message(STATUS "Using add_subdirectory(${FOO_BAR_DIRECTORY})")
    add_subdirectory(${FOO_BAR_DIRECTORY} build-FooBar EXCLUDE_FROM_ALL)
endif()

from cmake-conan.

memsharded avatar memsharded commented on July 21, 2024

I am adding a test here: #623

that shows that the described add_subdirectory() should work too

from cmake-conan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.