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

[question] What are the default values and settings for conan v2 and find_pakage on windows? #16271

Open
1 task
mtunjic opened this issue May 16, 2024 · 4 comments
Assignees

Comments

@mtunjic
Copy link

mtunjic commented May 16, 2024

What is your question?

Hi,
I'm currently using conan 2.3.0 with cmake 3.28 on windows 11 and problem is:
in older conan version before 2.x find_package from CMakeLists.txt worked without problems if I didn't set anything in package_info: (conan.py). Now now I get messages that the library does not exist.

        Broken: 
        Default settings without  def package_info(self):  
	
        Works:
	self.cpp_info.set_property("cmake_file_name", "mylib")
        self.cpp_info.set_property("cmake_target_name", f"mylib::{mylib}")
        self.cpp_info.set_property("pkg_config_name",  "mylib")

	Works:
        self.cpp_info.system_libs = ["mylib"]

	Broken:
	self.cpp_info.libs = ["mylib"]

What is needed now and what is the minimum configuration for find_pakcage to work properly?
I apologize if it is documented somewhere, I did not find it.

Thanks,
Marko

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this May 16, 2024
@memsharded
Copy link
Member

Hi @mtunjic

Thanks for your question.

I am not sure where the issue could be. If you check with the default template:

conan new cmake_lib -d name=mypkg -d version=0.1
conan create .

Then you will see that self.cpp_info.libs = ["mypkg"] works fin in package_info() nothing else is needed, definitely not the set_property() or the system_libs.
So it might be something else in your specific CMakeLists.txt. Maybe if you can share a full reproducible example, we could check it.

@mtunjic
Copy link
Author

mtunjic commented May 16, 2024

Thanks @memsharded , here is my old conan.py file adopted to conan v2 which causes the problem and CMakeFile.txt

--- conan.py v2 -----------------

from os import path, getenv
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.files import copy, rmdir 
from conan.tools.scm import Git

required_conan_version = ">=2.0.0"

class MyLibConan(ConanFile):
    name = "mylib"
    license = "MIT"
    package_type = "library"
    author = "Marko"

    description = "MyLib library"
    topics = ("security", "basic", "openssl", "x509")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}
    exports_sources = "*"
    revision_mode = "scm"

    def config_options(self):
        if self.settings.os == "Windows":
            self.options.rm_safe("fPIC")

    
    def configure(self):
        if self.options.shared:
            self.options.rm_safe("fPIC")
        self.settings.rm_safe("compiler.libcxx")
        self.settings.rm_safe("compiler.cppstd")


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

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


    def package(self):
        copy(self, pattern="*.h", dst=path.join(self.package_folder, "include"), src=path.join(self.source_folder, "."))
        copy(self, pattern="*.inl", dst=path.join(self.package_folder, "include"), src=path.join(self.source_folder, "."))
        copy(self, pattern="*.dll", src=self.build_folder, dst=path.join(self.package_folder, "bin"), keep_path=False)
        copy(self, pattern="*.lib", src=self.build_folder, dst=path.join(self.package_folder, "lib"), keep_path=False)
        copy(self, pattern="*.dylib*", src=self.build_folder, dst=path.join(self.package_folder, "lib"), keep_path=False)
        copy(self, pattern="*.so", src=self.build_folder, dst=path.join(self.package_folder, "lib"), keep_path=False)
        copy(self, pattern="*.a", src=self.build_folder, dst=path.join(self.package_folder, "lib"), keep_path=False)


    def package_info(self):
        self.cpp_info.libs = ["mylib"]


    def requirements(self):
        self.requires("cpdk/[~8.0.0]@windows/stable")


    def set_version(self):
        git = Git(self)
        tag = git.run("describe --tags")
        self.version = tag

--- end conan.py v2 ------

---- Consumer app CMakeLists.txt -----

cmake_minimum_required(VERSION 3.15)
project(HelloConan CXX)

find_package(mylib CONFIG REQUIRED)

add_executable(HelloConan src/HelloConan.cpp src/main.cpp)

target_link_libraries(HelloConan fmt::fmt mylib::mylib)

install(TARGETS HelloConan DESTINATION "."
        RUNTIME DESTINATION bin
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        ) 
---- end CMakeLIst.txt -------

and command for create:
$ conan create . --name=mylib --user=windows --channel=stable -tf=  --build=missing

@memsharded
Copy link
Member

Thanks for the feedback.

There are a couple of things that doesn't seem correct:

  • name = "MyLib" is incorrect, as Conan 2 doesn't allow upper case names anymore. It will also conflict with command line --name= argument
  • exports_sources = pattern="*" seems broken too.

The CMakeLists.txt you are sharing seems to be the one for the consumer of mylib, not the one for mylib

I am afraid that I am still missing some information. To have a reproducible example, it would be necessary to provide something that we can actually fully run on our side. As you have the cpdk dependency and I am also missing the files from the mylib repo, it is not possible to reproduce. This is why I was suggesting to start with the conan new cmake_lib template, it is fully working and fully self-contained, so it is very convenient to report things. You can also share a full .zip or a git repo URL with more code that would help to reproduce and understand.

Other feedback:

  • self.requires("cpdk/[~8.0.0]@windows/stable") the windows as "user" seems not recommended. The user shouldn't be used for this, but to identify the organization/team. To model the different os, that is part of the binary model of Conan, packages shouldn't be called after an architecture, os, or any other input "settings"

@mtunjic
Copy link
Author

mtunjic commented May 16, 2024

It was lowercased I made mistake for example. Yes you are right cmake file is from consumer side.
Thanks for the suggestions, I'll try to make a smaller demo and put it in a zip. I think it's best that you can try it.

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

No branches or pull requests

2 participants