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.

[feature] Clarify how to change location for conan_paths.cmake

See original GitHub issue

As you all know, the typical CMake workflow is cd project && mkdir build && cd build && cmake .. && cmake --build .. In CMakeLists.txt of my projects I always prohibit in-source builds (build without creating build folder, directly in the project root). I used exports_sources approach with:

    def build(self):
        cmake = CMake(self)
        cmake.configure(source_folder=".", build_folder="build")
        cmake.build()

and spent hours trying to make it work because Conan generates cmake_paths.cmake outside of the build directory. Documentation for cmake_paths says:

The folder containing the conan_paths.cmake (self.install_folder when used in a recipe) is also included, so any custom file will be located too. Check cmake_find_package generator generator.

so I tried to adjust self.install_folder without any success. I don’t know if it’s possible at all, is it?

Then I found the layout() method. It says

self.folders.generators: To specify a subfolder where to write the files from the generators and the toolchains. (e.g the xx-config.cmake files from the CMakeDeps)

and suggests this:

     def layout(self):
         self.folders.source = "src"
         build_type = str(self.settings.build_type).lower()
         self.folders.build = "cmake-build-{}".format(build_type)
         self.folders.generators = os.path.join(self.folders.build, "conan")

I copy-pasted it and finally my build works. But I don’t understand how, it makes self.folders.generator to point into something like cmake-build-release/conan. I see no such folder after build and Conan files are located directly in cmake-build-release (otherwise it wouldn’t work because documentation suggests include(${CMAKE_BINARY_DIR}/conan_paths.cmake)). It’s very unclear what’s going on here. Actually, commenting that last line doesn’t break the build…

After all I found the cmake_layout(), now it works and my conanfile.py looks good. Can you please clarify what’s the proper way to do this? I also don’t understand why layout() is experimental if it’s absolutely vital to build canonical CMake projects, is it possible to use some non-experimental feature to achieve my goals? And one more thing, it would be so nice to have in docs a tutorial how to gracefully integrate canonical CMake projects with Conan. I’m now on this path and it’s pretty painful even though I watched all your courses and read the docs…

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
memshardedcommented, Feb 3, 2022

I think that my main fallacy was that I thought Conan is already super-stable and super-integrated with everything because it’s been there for years so I tried to rely on non-experimental approaches 😃

Yes, you are right. The “stable” build system integrations were “frozen” like 4 years ago, and they were lacking features (like transparent integration) and sometimes had some bad defaults. But as they were frozen, they had some difficult to fix things without breaking, so they are stable, but not that good. So we tried to solve all those problems in the new integrations, so we could introduce them without breaking the others, but then the transition and mixing the two approaches is making the whole of it a bit messy and confusing.

We are very focused on 2.0, now in writing the new 2.0 docs, so I think we will better focus on getting that out as soon as possible, I think this one can be closed. Thanks very much for all the feedback! 😃

0reactions
OleksandrKvlcommented, Feb 3, 2022

I think that my main fallacy was that I thought Conan is already super-stable and super-integrated with everything because it’s been there for years so I tried to rely on non-experimental approaches 😃 I will continue to use cmake_layout() for now and will switch to CMakeToolchain in the future. I’m leaving this issue open but since my problem has been resolved feel free to close it if you don’t plan to update related documentation, thanks for you help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake_paths generator — conan 1.4.5 documentation
This generator is especially useful if you are using CMake based only on the find_package feature to locate the dependencies. The cmake_paths generator ......
Read more >
User Interaction Guide — CMake 3.25.1 Documentation
The features and user interfaces described in this manual are available for all ... Setting the default version via the xcode-select command line...
Read more >
What is the difference between using a Makefile and CMake to ...
Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is...
Read more >
How to Use CMake Without the Agonizing Pain - Part 2
The meaning of -Wall changes across compiler versions, ... Well, here's the answer: setting a cache variable at the command line with no ......
Read more >
CMake + Conan: 3 Years Later - Mateusz Pusz - [CppNow 2021]
Boost #Cpp #CppNow Slides: https://cppnow.org/history/2021/talks/CppNow Website: https://cppnow.orgCppNow Twitter: @CppNowStreamed & Edited ...
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