Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] OPENSSL_FOUND and similar variables aren't defined #10829

Closed
computerquip-work opened this issue Mar 18, 2022 · 5 comments
Closed

[bug] OPENSSL_FOUND and similar variables aren't defined #10829

computerquip-work opened this issue Mar 18, 2022 · 5 comments

Comments

@computerquip-work
Copy link

External code often relies on the variable OPENSSL_FOUND being defined. I see code in the OpenSSL package recipe to handle this but I'm a bit confused as to how this is supposed to work. Provided is a test case showing that OPENSSL_FOUND is not defined but OpenSSL_FOUND is defined by default.

Environment Details (include every applicable attribute)

  • OS: Arch LInux
  • Compiler: GCC 11.2.0
  • Conan version: 1.46.0
  • Python version: 3.10.2

Steps to reproduce

Test Case: https://github.com/computerquip-work/conan-openssl-fail-case

From source:

mkdir -p build;
cd build;
conan install ..;
conan build ..;
@computerquip-work
Copy link
Author

computerquip-work commented Mar 18, 2022

I really don't understand this. If I minimize the example (note the use of OpenSSL 3.0):

from conans import ConanFile, RunEnvironment, tools
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps

class FailConan(ConanFile):
    name = "fail-test-case"
    version = "0.0.1"
    license = "Apache-2.0"
    requires = ("openssl/3.0.1")
    settings = "os", "compiler", "build_type", "arch"
    description = ""

    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()

        deps = CMakeDeps(self)
        deps.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

I get the output:

<snip>
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Component target declared 'OpenSSL::Crypto'
-- Conan: Component target declared 'OpenSSL::SSL'
-- Conan: Target declared 'openssl::openssl'
-- Conan: Target declared 'ZLIB::ZLIB'
-- Conan: Including build module from '/home/zlund/.conan/data/openssl/3.0.1/_/_/package/b88c434d8110e892fcfb7bbb4f76234f590822f1/lib/cmake/conan-official-openssl-variables.cmake'
-- Conan: Including build module from '/home/zlund/.conan/data/openssl/3.0.1/_/_/package/b88c434d8110e892fcfb7bbb4f76234f590822f1/lib/cmake/conan-official-openssl-variables.cmake'
-- 2 The newer OpenSSL OpenSSL_FOUND is defined.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/<snip>/Projects/<snip>/applications/openssl-conan-fail/build

Looking at that cmake module, it contains:

if(DEFINED OpenSSL_FOUND)
    set(OPENSSL_FOUND ${OpenSSL_FOUND})
endif()
if(DEFINED OpenSSL_INCLUDE_DIR)
    set(OPENSSL_INCLUDE_DIR ${OpenSSL_INCLUDE_DIR})
endif()
if(DEFINED OpenSSL_Crypto_LIBS)
    set(OPENSSL_CRYPTO_LIBRARY ${OpenSSL_Crypto_LIBS})
    set(OPENSSL_CRYPTO_LIBRARIES ${OpenSSL_Crypto_LIBS}
                                 ${OpenSSL_Crypto_DEPENDENCIES}
                                 ${OpenSSL_Crypto_FRAMEWORKS}
                                 ${OpenSSL_Crypto_SYSTEM_LIBS})
endif()
if(DEFINED OpenSSL_SSL_LIBS)
    set(OPENSSL_SSL_LIBRARY ${OpenSSL_SSL_LIBS})
    set(OPENSSL_SSL_LIBRARIES ${OpenSSL_SSL_LIBS}
                              ${OpenSSL_SSL_DEPENDENCIES}
                              ${OpenSSL_SSL_FRAMEWORKS}
                              ${OpenSSL_SSL_SYSTEM_LIBS})
endif()
if(DEFINED OpenSSL_LIBRARIES)
    set(OPENSSL_LIBRARIES ${OpenSSL_LIBRARIES})
endif()
if(DEFINED OpenSSL_VERSION)
    set(OPENSSL_VERSION ${OpenSSL_VERSION})
endif()

It seems like it should be set. I can modify that file to output markers. The file is definitely included but in that context if (DEFINED OpenSSL_FOUND) fails. So this seems to me that the *Config.cmake files don't implement _FOUND for some reason (does this work elsewhere?).

EDIT: After looking at some documentation, CMake automatically sets _FOUND but appears to be after the config module has finished running. So unfortunately, this particular use-case seems broken.

@computerquip-work computerquip-work changed the title [question] OPENSSL_FOUND and similar variables aren't defined [bug] OPENSSL_FOUND and similar variables aren't defined Mar 18, 2022
@computerquip-work
Copy link
Author

I also found this related issue from a few years back: #3148

Seems that in combination with that and #10387, there's no obvious way to work around this.

After delving the source code a bit, I realized there's the concept of "blocks" described in CMakeToolchain. One of those is "find_paths" which apparently controls CMAKE_FIND_PACKAGE_PREFER_CONFIG, but unfortunately doesn't document how. This is what ultimately "fixes" the problem for me:

    def generate(self):
        tc = CMakeToolchain(self)
        tc.blocks["find_paths"].values["find_package_prefer_config"]=False
        tc.generate()

        deps = CMakeDeps(self)
        deps.generate()

Since the OpenSSL package generates a FindOpenSSL.cmake module that works (as it explicitly sets OpenSSL_FOUND before the standard variables cmake script is called), this is "good enough".

I'm leaving this open because this experience frankly sucked however.

@jngrb
Copy link

jngrb commented Nov 25, 2022

I found that conan-io/conan-center-index#12838 only fixed this for the 1.x.x recipe versions.

I made the similar fix for the 3.x.x recipe versions in conan-io/conan-center-index#14426

@hchechao2
Copy link

tc.blocks["find_paths"].values["find_package_prefer_config"]=False works for me !!!

@memsharded
Copy link
Member

The PRs above should have taken care of this issue (in the conan-center-index repo, sorry this wasn't followed up back then) time ago.

@hchechao2 It is also possible to control the files that CMakeDeps generate via .set_property(...., "cmake_find_mode", ) property, to control specifically the files generated for each dependency if you need.

I am closing this ticket as solved time ago, please create new tickets if you have any further question, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants