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] Binary Conan options should be expressed as an `option()` in CMake when generated with CMakeToolchain

See original GitHub issue

This is common to have True/False options in conanfile.py. For example:

    options = {
        "build_docs": [True, False]
    }

the above is translated by the CMakeToolchain to

set(UNITS_BUILD_DOCS "True" CACHE STRING "Variable UNITS_BUILD_DOCS conan-toolchain defined")

This is seen in a GUI as:

image

However, it would be nicer if those would be generated either as:

set(UNITS_BUILD_DOCS "True" CACHE BOOL "Variable UNITS_BUILD_DOCS conan-toolchain defined")

or

option(UNITS_BUILD_DOCS "Variable UNITS_BUILD_DOCS conan-toolchain defined" ON)

The new behavior better states the purpose of the option and also improves CMake cache variable presentation in GUIs:

image

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
memshardedcommented, Mar 16, 2021

Now I get it, thanks!

What I see is that by the moment you define the tc.variables, the option value is already a string, not a value. All Conan options and settings are converted to strings. So it is not possible to deduce it from the option value, it would require a explicit cast in user code like

tc.variables["UNITS_BUILD_DOCS"] = bool(self.options.build_docs)

this is basically equal to https://github.com/conan-io/conan/issues/8632, but for variables and not preprocessor_definitions

0reactions
mpuszcommented, Mar 16, 2021

But you are right, probably it should be a property of tc.variables.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CMakeToolchain — conan 1.28.2 documentation
The CMakeToolchain will generate 2 files, after a conan install command (or before calling the build() method when the package is being built...
Read more >
FindProtobuf — CMake 3.25.1 Documentation
Locate and configure the Google Protocol Buffers library. New in version 3.6: Support for find_package() version checks. Changed in version 3.6: All input...
Read more >
Cmake Conan - Github Mirror - GitLab - AIMMS
conan_cmake_autodetect(). This function will return the auto-detected settings (things like build_type, compiler or system name) so you can pass ...
Read more >
Frequently Asked Questions - vcpkg - Read the Docs
Can vcpkg create pre-built binary packages? What is the binary ... Can I use my own CMake toolchain file with vcpkg's toolchain file?...
Read more >
Conan Package Manager in Practice - GitHub Pages
can re-run above command from new shell if disconnected ... CMakeToolchain(self).generate() # -> conantoolchain.cmake (variables translated from conan ...
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