question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Understanding exports_sources and CMake's add_subdirectory

See original GitHub issue

Hello Kings of the swamp,

My understanding is that when I have something like:

    exports_sources = "CMakeLists.txt", "src/*", "tools/*", "tests/*", "include/*"

conan create would take all of these and place it in the .conan/... (aka the recipe). I also realized, though I’m not sure, that if code in tests/CMakeLists.txt need some package to link with, e.g. boost but the rest of the tree does not need it, since I have it in exports_sources it is as if the entire package needs boost.

Now, I also figured out that add_subdirectory() need to match the above exports_sources list. In other words, if I have add_subdirectory(tests) and I remove tests/* from the above list, I have an error:

CMake Error at CMakeLists.txt:43 (add_subdirectory):
  add_subdirectory given source "tests" which is not an existing directory.
...
ERROR: foo/1.1.1: Error in build() method, line 41
	cmake.configure()
	ConanException: Error 1 while executing cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=..."

But I don’t want tests/*. I don’t need it in the recipe. I don’t need the dependencies. How do I remove tests/* without the above error. Surely there is a way.

Thanks! Kobi

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kobi-cacommented, Oct 29, 2021

thank you @memsharded !!

1reaction
memshardedcommented, Oct 29, 2021

I think it might be related to the nature of build_requires, not intended to be used via ``find_package(), and this also depends on if you are using the “build” and “host” profiles. The direction should be:

  • Put boost as self.requires("boost...", force_host_context=True) inside requirements(), this indicates this dep is in the “host” context.
  • That should handle the transitive dependencies too (using the new CMakeDeps integrations.
  • Recommended to use the --profile:build explicitly, to start opting-in in what will be the default behavior in 2.0 and in ConanCenter soon too.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing and Exporting Guide — CMake 3.25.1 Documentation
This guide and the complete example source code can be found in the Help/guide/importing-exporting directory of the CMake source code tree. Importing Targets¶....
Read more >
Explanation of CMake variable scope , add_subdirectory vs ...
Conclusion. CMake variable has a concept of scope like variables in other programming languages. Some CMake directives, commands like add_ ...
Read more >
CMake: How to build multiple projects exported for ...
MyLibrary and MyDependentLibrary are both set up with install and build directory exports to be compatible with the find_package() command. So ...
Read more >
Enhanced source file handling with target_sources() - Crascit -
In all but trivial CMake projects, it is common to find targets built from a large number of source files. These files may...
Read more >
Exporting and importing CMake packages with find_package
This syntax tells CMake to use a directory inside the source tree when building the package and use the directory under the installation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found