Comments (16)
Just an idea:
in my implementation I use something like this once in the beginning of each directory's CMakeLists.txt:
conan_start_dependency_list()
conan_use(XXXXX)
conan_use(YYYYY)
conan_end_dependency_list()
So conan
invocation, conanbuildinfo.cmake
generation and inclusion is done in conan_end_dependency_list()
, and everything is written in CMAKE_CURRENT_BINARY_DIR
. Just need to make sure that conan
home and data dirs are properly locked by CMake's file(LOCK ...)
.
from cmake-conan.
Sorry for my delay. I'll check my case and your suggestions in a couple days and let you know.
from cmake-conan.
@memsharded Yeah. You're right. It's good to me.
Thank you.
from cmake-conan.
You mean, two CMakeListst.txt, in nested folders, like one being the root? The example code to invoke conan, it should be only in the root CMakeLists.txt of the project. Not sure if I understood your issue, please clarify, thanks!
from cmake-conan.
I have that structure:
├── project1
│ └── CMakeLists.txt # has conan dependency
└── project2
└── CMakeLists.txt # has conan dependency
├── CMakeLists.txt # includes project1 and project2
from cmake-conan.
The question is that you can actually build separately project1 and project2, they have their own dedicated build folder, etc, or you have basically one project, with several components, libraries, or apps, called project1, project2, etc.
If you have one project, I would add the conan invocation code in the root CMakeLists.txt, with all the deps.
If you want to be able to run separately both from project1 and project2, and also from the root CMakeLists.txt, I would put the conan invocation cmake code in its separate conan_install.cmake
file, and call it from all three. Then I would use some cmake-fu, to just run the conan install
the first time. Probably just checking for the existence of conanbuildinfo.cmake
before calling conan_cmake_run()
could be enough
from cmake-conan.
Well, the lock is not required, unless conan
is executed during potentially parallel build-time or multiple simultaneous builds, CMake configuring runs in parallel (not sure if CMake supports this at all), or multiple configuring are started simultaneously.
from cmake-conan.
Sure, that sounds also an interesting approach. I don't face those issues that much because I tend to do the opposite, every time I have to write "project management" code, I do it in python, which invokes conan and cmake when necessary. So my project is driven by python scripts, not by cmake scripts, I feel it much more convenient and easy to develop and maintain.
from cmake-conan.
The question is that you can actually build separately project1 and project2
No. They are in one repo. Project2 can have project1 as dependency.
You can think of my repo as boost repo: boost-chrono can't be build without boost-system.
The root cmakelist has only add_directory command to include all projects.
If you have one project, I would add the conan invocation code in the root CMakeLists.txt, with all the deps.
You make me list my dependency in one root CMakeLists.txt. It's work the same as conanfile.txt in the root of a repo.
The better idea presented by @traceon.
# project1/CMakeLists.txt content
...
conan_use(XXXXX)
# project2/CMakeLists.txt content
...
conan_use(XXXXX) # we only check for conflict. Do not install the same library again.
conan_use(YYYYY)
# CMakeLists.txt content
conan_start_dependency_list()
add_subdirectory(project1)
add_subdirectory(project2)
conan_end_dependency_list()
That would be better to not have start and end function at all. I don't know if it is possible.
from cmake-conan.
Rationale behind the start()/end() sections in every CMakeLists.txt is that each dir/project may use same libraries which are built differently, with not-so-compatible settings. This is a rare case, but still...
conan_use(XXXXX) # we only check for conflict. Do not install the same library again.
Do we need to check anything? I think conan
does a good job by eliminating duplicates, etc. Another pleasant surprise about conan
is that it check whether there is a need to (re)build anything very consciously, not just by checking timestamps of config files or full-text hashing. And a run when there is nothing to rebuild is fast enough to even leave one run per conan_use() in CMake configs (although this doesn't seem desirable, due to config variable name clashes.)
from cmake-conan.
Thats true, I think I would add the cmake conan invocation in each sub-project. If the dependency is listed in the other sub-project with the same configuration, it will not be rebuilt, and it will be quite fast. If it uses a different configuration, then, it might need to rebuild or retrieve from remote. But if you have dependencies between subprojects like Boost, it sounds that the dependency tree would have the same configuration, or you might fall into binary compatibility issues.
from cmake-conan.
or you might fall into binary compatibility issues.
That is what I want to avoid.
Is there any way to check that if some targets have the same conan dependency but with different configuration/options?
from cmake-conan.
It is not possible, by definition. Conan dependencies in the same tree will have the same settings and options, or it will be an error:
- If the same dependency is used in different paths of the dependency graph (like a diamond), and some configurations is incompatible, the first one will prevail, and a warning will be issued
- The
--werror
will make such conflicts raise Error instead of warning - It is possible to have different versions of the same package, with different versions, settings and options if the dependencies are "private", which can only be done in some scenarios, like header-only not in public api.
from cmake-conan.
Hi @opilar
Reviewing this issue, I still not sure why just adding the conan invocation in the root CMake wouldn't be enough. With the modern cmake targets syntax, I think that sub-projects could just link to the targets they want.
Did you make any progress on this issue? Thanks!
from cmake-conan.
Look at my test example. Two targets have dependency conflict and no warning is given about it.
from cmake-conan.
From the conan point of view, they are different projects, each one with their own dependencies. Different projects can have different dependencies without any issue, there is no conflict because they are not in the same dependency graph.
from cmake-conan.
Related Issues (20)
- [question] Invalid: 'settings.compiler.runtime' value not defined HOT 21
- Different formatting of msvc runtime value conan_provider.cmake
- Installing only certain packages HOT 8
- [develop2] Question: How stable is the current state HOT 2
- tools.build:compiler_executables breaks build with Autotools and Xcode HOT 3
- [develop2] detect_compiler() detects invalid 'settings.compiler.version' for apple-clang
- [develop2] Can conan_provider.cmake work with add_subdirectory HOT 6
- find_program working when building from command line, but not when using the CLion Conan plugin HOT 11
- [bug] generated settings.yml missing Macos.version "14.2", causes build failures HOT 10
- [develop2, BUG] Unknown arguments specified in conan_provider.cmake:519 HOT 2
- Unable to cross compile openssl/3.x.x on develop2 HOT 6
- Using "build-scripts" package via tool_requires() not working HOT 2
- [develop2] CMAKE_CONFIGURATION_TYPES with custom build types not getting dependencies added properly HOT 3
- ERROR: Invalid setting '6' is not a valid 'settings.compiler.version' value HOT 2
- 【conan install】conan_provider.cmake downloads packages from source because detect_host_profile generates compiler.cppstd=xx in the cmake-build-release/conan_host_profile file with the detect_host_profile method HOT 5
- cmake bootstrapping fails if not on PATH HOT 3
- Not working with conan editable mode HOT 5
- Update readme with more details HOT 1
- MSVC version update HOT 6
- [question] Using layout and -of together Conan 2 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmake-conan.