conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

CMake helper requires compiler during package #3011

Closed uilianries closed 6 years ago

uilianries commented 6 years ago

To help us debug your issue please explain:

Hi everyone!

I'm trying give some support to taocpp/PEGTL and I would like to use CMake helper to install the project. The project is header-only, thus it installs the license, headers and pegtl-config.cmake.

However, when the package method runs over Windows, I receive the follow message:

conans.errors.ConanExceptionInUserConanfileMethod: pegtl/2.5.2@taocpp/testing: Error in package() method, line 22
cmake = CMake(self)
ConanException: You must specify compiler, compiler.version and arch in your settings to use a CMake generator. You can also declare the env variable CONAN_CMAKE_GENERATOR.

When I run the same recipe on Linux (Travis CI), I have no problems.

Appveyor error log: https://ci.appveyor.com/project/uilianries/pegtl/build/feature/conan-9/job/tnwvkd69gvkgsb6x#L250

The current PR uses just self.copy, but my intention is revert to follow state, using CMake:

https://github.com/uilianries/PEGTL/blob/dc4011991624faedf67fd390e8f53737f562a897/conanfile.py

Current PR for PEGTL: https://github.com/taocpp/PEGTL/pull/112

I'm curious if CONAN_CMAKE_GENERATOR is required by Conan or is just a CMake limitation.

Conan Version: 1.4.3

danimtb commented 6 years ago

Yes, CMake helper is looking for the generator and first checks CONAN_CMAKE_GENERATOR env var. So this is probably why you find the difference in CI.

We already reviewed this in issue #2758 but seems this could be a missing piece.

However, there is no default cmake generator in Windows so this should be the reason why you have to specify it even for a cmake install command.

pleroux0 commented 6 years ago

Why does conan require that a generator be specified for a package that doesn't depend on a compiler? Why can't you let cmake figure out what to use since it doesn't matter to the package?

On Linux it defaults to "Unix Makefile" and on Windows it tries to detect installed Visual Studio version (Unless otherwise set ). I tested it on a virtual machine with VS2017 Community and it worked as expected. On both linux and windows the following was run:

cmake ..
cmake --build .
memsharded commented 6 years ago

Yes, it seems that cmake works that way: https://stackoverflow.com/questions/6430251/what-is-the-default-generator-for-cmake-in-windows

danimtb commented 6 years ago

looking into this to see if we can avoid the generator check.

BTW @uilianries, you know that you can still include settings in a header only recipe as long as you use self.info.header_only() por package ID, right? (I see you are already doing it, just a reminder)

uilianries commented 6 years ago

@danimtb I just forgot about this! So yeah, I could use CMake Helper + settings to generate the same package id for a header-only project.

I'm just curious about the config.cmake file created by Cmake, if it will be the same for all packages. I'll check this later.

danimtb commented 6 years ago

@uilianries We have disabled the generator check for the CMake build helper. It will be live in next release. Thanks!

uilianries commented 6 years ago

Awesome! Thanks guys, you rock!