Conan: cmake_find_package generates invalid *_FOUND varable names

Created on 1 Jul 2018  路  10Comments  路  Source: conan-io/conan

I have just one example. It's OpenSSL

Generated OpenSSL find module has

SET(OpenSSL_FOUND 1)

After this, code like

if(OPENSSL_FOUND)

doesn't work.

If I change it to

if(OpenSSL_FOUND)

it starts working.

So the comparisons are case sensitive and the fully uppercase variant is correct. Official OpenSSL find module also has if(OPENSSL_FOUND)

feature look into

Most helpful comment

CMake's find_package always drives me crazy. it's case-sensitive, and actually package name is case sensitive, as well as variable names are case-sensitive too. so, module is called FindOpenSSL.cmake, while variable are named like OPENSSL_FOUND.
meanwhile, if we take a look at an another package, e.g. boost, then package name is FindBoost.cmake, while variables are named like Boost_FOUND.
there is no logic, and it makes impossible to implement automation of generation of FindXXX.cmake modules properly (each module will require its own quirks, unfortunately).
question to vcpkg users - how does it work for vcpkg? how do they solve this problem?

All 10 comments

I've added replace_in_file("FindOpenSSL.cmake", "OpenSSL_", "OPENSSL_") as a workaround

Oh that was far from enough.. No idea what to do with openssl

Hi @Ri0n !

I think I need more information about what are you trying to do. Are you using the cmake_find_package generator, right? I think the issue is you are trying to use it like the "official" OpenSSL find package script. The cmake_find_package do not pretend to replace any official module, so the variables won't be the same and the usage has to be changed.

oh I see. That's the case. Is it possibe the packages will start providing custom templates for find module generation to be compatible with official?

If you want to use the official you can rely on the cmake_paths generator. It will indicate CMake where to find your libraries using the official one.

CMake's find_package always drives me crazy. it's case-sensitive, and actually package name is case sensitive, as well as variable names are case-sensitive too. so, module is called FindOpenSSL.cmake, while variable are named like OPENSSL_FOUND.
meanwhile, if we take a look at an another package, e.g. boost, then package name is FindBoost.cmake, while variables are named like Boost_FOUND.
there is no logic, and it makes impossible to implement automation of generation of FindXXX.cmake modules properly (each module will require its own quirks, unfortunately).
question to vcpkg users - how does it work for vcpkg? how do they solve this problem?

Agreed. It's now too simple to be really useful. I think that generator should support the following fields to be changed manually by user before generating FindX.cmake:

  • library name - e.g. OpenSSL. Right now we have custom "openssl" Conan package which generates Findopenssl.cmake instead of FindOpenSSL.cmake.

  • library name in variables - in the OpenSSL case we need to set it to "OPENSSL", in Boost case it'll be "Boost", etc. Generator should then set "OPENSSL_FOUND" and "Boost_FOUND" and the other variables. The default should be the library name in uppercase which seems to me most default Find* modules prefer.

It requires a parameter mechanism for the generators, but I agree for this generator is very very useful.

Does it require big API changes? If this is a feature tha will be added on top of existing API, then maybe I may help implement this somehow? :)

It will require some deep analysis, I wouldn't recommend you to implement this one, but many thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Polibif picture Polibif  路  3Comments

uilianries picture uilianries  路  3Comments

Adnn picture Adnn  路  3Comments

tonka3000 picture tonka3000  路  3Comments

mpdelbuono picture mpdelbuono  路  3Comments