conan-io / conan

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

Conan does not detect Visual Studio 2019 #5646

Closed ruipacheco closed 5 years ago

ruipacheco commented 5 years ago

To help us debug your issue please explain:

I've recently uninstalled Visual Studio 2017 and installed 2019 and now I can't build a project that used to work cleanly. The conanfile.py is fairly simple:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Conan file for KVCore, the main KV library.

To install dependencies view https://docs.conan.io/en/latest/howtos/vs2017_cmake.html
"""

from conans import ConanFile, CMake
import os
import shutil
import fnmatch

class KVCoreConan(ConanFile):
    name = "kvcore"
    version = "0.1.0.0"
    description = "Kiwi Core Library"
    topics = ("kv", "core", "C++")
    settings = "os", "arch", "compiler", "build_type"
    options = {"shared": [True, False]}
    default_options = {
        "shared": True,
        "boost:shared": True,
        "boost:header_only": True,
        "boost:system_no_deprecated": True,
        "boost:asio_no_deprecated": True,
        "boost:without_filesystem": True,
        "boost:without_chrono": True,
        "boost:without_thread": True,
        "boost:without_regex": True,
        "boost:without_log": True,
        "boost:without_wave": True,
        "boost:bzip2": False,
        "boost:zlib": False,
        "boost:lzma": False,
        "boost:zstd": False
    }
    generators = "cmake"
    exports_sources = ["src/*", "include/*", "cmake/*", "CMakeLists.txt", "Config.hpp.in", "tests/*"]

    _build_folder = "build/"

    def _configure_cmake(self):
        cmake = CMake(self)
        cmake.configure(build_folder=self._build_folder)
        return cmake

    def requirements(self):
        self.requires("kvapi/0.1.0.0@kiwi/testing")
        self.requires("kvtest/0.1.0.0@kiwi/testing")
        self.requires("kvvideoio/0.1.0.0@kiwi/testing")
        self.requires("opencv/3.4.3@kiwi/testing")
        self.requires("ipp/7.0.4@kiwi/testing")
        self.requires("celero/2.5.0@kiwi/testing")
        self.requires("debugbreak/0.1@kiwi/testing")
        self.requires("freetype/2.9.1@bincrafters/stable")
        self.requires("gtest/1.8.1@bincrafters/stable")
        self.requires("boost/1.70.0@conan/stable")

    def configure(self):
        self.settings.arch = "x86_64"

    def build(self):
        cmake = self._configure_cmake()
        cmake.build()
        cmake.test()

    def package(self):
        cmake = self._configure_cmake()
        cmake.install()
        cmake.patch_config_paths()

        self.copy("*.h", dst="include", src="include")
        self.copy("*.lib", dst="lib", keep_path=False)
        self.copy("*.dll", dst="bin", keep_path=False)

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

But when I try to create the package it defaults the compiler version to 15 and then CMake complains that it can't find Visual Studio 2017. Are these values cached somewhere I'm not aware of? Build output:

λ conan create ../../../ kvcore/0.1.0.0@kiwi/testing -s build_type=Release
[HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'url'. It is recommended to add it as attribute
[HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'license'. It is recommended to add it as attribute
Exporting package recipe
WARN: Failed pylint: [WinError 2] The system cannot find the file specified
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 54 '.hpp' files
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 40 '.cpp' files
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 1 file: clang-format
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 4 '.cmake' files: ClangFormat.cmake, CompileAndEncryptResources.cmake, cotire.cmake, FindWindowsSDK.cmake
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 6 '.txt' files
kvcore/0.1.0.0@kiwi/testing exports_sources: Copied 1 '.in' file: Config.hpp.in
kvcore/0.1.0.0@kiwi/testing: The stored package has not changed
kvcore/0.1.0.0@kiwi/testing: Exported revision: 3360d53dabf6adbafdb390a1cff9c66d
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=15
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

kvcore/0.1.0.0@kiwi/testing: Forced build from source
Installing package: kvcore/0.1.0.0@kiwi/testing
Requirements
    boost/1.70.0@conan/stable from 'conan-center' - Cache
    bzip2/1.0.6@conan/stable from 'conan-center' - Cache
    celero/2.5.0@kiwi/testing from 'genetec' - Cache
    debugbreak/0.1@kiwi/testing from 'genetec' - Cache
    ffmpeg/57.0.0@kiwi/testing from 'genetec' - Cache
    freetype/2.9.1@bincrafters/stable from 'conan-center' - Cache
    gtest/1.8.1@bincrafters/stable from 'conan-center' - Cache
    ipp/7.0.4@kiwi/testing from 'genetec' - Cache
    kvapi/0.1.0.0@kiwi/testing from 'genetec' - Cache
    kvcore/0.1.0.0@kiwi/testing from local cache - Cache
    kvtest/0.1.0.0@kiwi/testing from 'genetec' - Cache
    kvvideoio/0.1.0.0@kiwi/testing from 'genetec' - Cache
    libpng/1.6.37@bincrafters/stable from 'conan-center' - Cache
    opencv/3.4.3@kiwi/testing from 'genetec' - Cache
    zlib/1.2.11@conan/stable from 'conan-center' - Cache
Packages
    boost/1.70.0@conan/stable:524ea35a8120baabdde02483add58d81bf541327 - Cache
    bzip2/1.0.6@conan/stable:5be2b7a2110ec8acdbf9a1cea9de5d60747edb34 - Cache
    celero/2.5.0@kiwi/testing:970e773c5651dc2560f86200a4ea56c23f568ff9 - Cache
    debugbreak/0.1@kiwi/testing:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    ffmpeg/57.0.0@kiwi/testing:ab2e9f86b4109980930cdc685f4a320b359e7bb4 - Cache
    freetype/2.9.1@bincrafters/stable:bc24ecb3030892e9e91d30c72873e53de96982f6 - Cache
    gtest/1.8.1@bincrafters/stable:3f7b6d42d6c995a23d193db1f844ed23ae943226 - Cache
    ipp/7.0.4@kiwi/testing:6cc50b139b9c3d27b3e9042d5f5372d327b3a9f7 - Cache
    kvapi/0.1.0.0@kiwi/testing:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    kvcore/0.1.0.0@kiwi/testing:2aa610711dacff5fd75739ee5d97d9d3cf470e38 - Build
    kvtest/0.1.0.0@kiwi/testing:eee10ac412b895c49314295562e9e3e9230b570c - Cache
    kvvideoio/0.1.0.0@kiwi/testing:636bf32f4340d7f4d0d6b7670d9fd99c45e2561a - Cache
    libpng/1.6.37@bincrafters/stable:606fdb601e335c2001bdf31d478826b644747077 - Cache
    opencv/3.4.3@kiwi/testing:017323a2a5ec0d04ff78bad3afcece97469dacf6 - Cache
    zlib/1.2.11@conan/stable:6cc50b139b9c3d27b3e9042d5f5372d327b3a9f7 - Cache

boost/1.70.0@conan/stable: Already installed!
boost/1.70.0@conan/stable: LIBRARIES: []
boost/1.70.0@conan/stable: Package folder: C:\.conan\570b5e\1
bzip2/1.0.6@conan/stable: Already installed!
celero/2.5.0@kiwi/testing: Already installed!
debugbreak/0.1@kiwi/testing: Already installed!
ffmpeg/57.0.0@kiwi/testing: Already installed!
gtest/1.8.1@bincrafters/stable: Already installed!
ipp/7.0.4@kiwi/testing: Already installed!
kvapi/0.1.0.0@kiwi/testing: Already installed!
opencv/3.4.3@kiwi/testing: Already installed!
zlib/1.2.11@conan/stable: Already installed!
kvtest/0.1.0.0@kiwi/testing: Already installed!
kvvideoio/0.1.0.0@kiwi/testing: Already installed!
libpng/1.6.37@bincrafters/stable: Already installed!
freetype/2.9.1@bincrafters/stable: Already installed!
kvcore/0.1.0.0@kiwi/testing: WARN: Build folder is dirty, removing it: C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\build\2aa610711dacff5fd75739ee5d97d9d3cf470e38
kvcore/0.1.0.0@kiwi/testing: Copying sources to build folder
kvcore/0.1.0.0@kiwi/testing: Building your package in C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\build\2aa610711dacff5fd75739ee5d97d9d3cf470e38
kvcore/0.1.0.0@kiwi/testing: Generator cmake created conanbuildinfo.cmake
kvcore/0.1.0.0@kiwi/testing: Calling build()
CMake Error at CMakeLists.txt:14 (project):
  Generator

    Visual Studio 15 2017 Win64

  could not find any instance of Visual Studio.

-- Configuring incomplete, errors occurred!
See also "C:/Users/RHPACHECO/.conan/data/kvcore/0.1.0.0/kiwi/testing/build/2aa610711dacff5fd75739ee5d97d9d3cf470e38/build/CMakeFiles/CMakeOutput.log".
kvcore/0.1.0.0@kiwi/testing:
kvcore/0.1.0.0@kiwi/testing: ERROR: Package '2aa610711dacff5fd75739ee5d97d9d3cf470e38' build failed
kvcore/0.1.0.0@kiwi/testing: WARN: Build folder C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\build\2aa610711dacff5fd75739ee5d97d9d3cf470e38
ERROR: kvcore/0.1.0.0@kiwi/testing: Error in build() method, line 82
        cmake = self._configure_cmake()
while calling '_configure_cmake', line 62
        cmake.configure(build_folder=self._build_folder)
        ConanException: Error 1 while executing cd C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\build\2aa610711dacff5fd75739ee5d97d9d3cf470e38\build/ && cmake -G "Visual Studio 15 2017 Win64" -DCONAN_LINK_RUNTIME="/MD" -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="15" -DCONAN_CXX_FLAGS="/MP12" -DCONAN_C_FLAGS="/MP12" -DBUILD_SHARED_LIBS="ON" -DCMAKE_INSTALL_PREFIX="C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\package\2aa610711dacff5fd75739ee5d97d9d3cf470e38" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -Wno-dev C:\Users\RHPACHECO\.conan\data\kvcore\0.1.0.0\kiwi\testing\build\2aa610711dacff5fd75739ee5d97d9d3cf470e38

The build will work if I pass the correct compiler.version flag via the command line, ie, 16.

Compiler: Visual Studio 2019 Conan: 1.18.0 OS: Windows 10

lasote commented 5 years ago

You can edit the default profile at ~/.conan/profiles/default to change the default value.

ruipacheco commented 5 years ago

That file doesn't exist. I suspect conan's compiler detector is broken?

lasote commented 5 years ago

Conan only detects the compiler the first time it runs and generates a profiles/default file in the Conan user home. So I think the file must be there.

ruipacheco commented 5 years ago

It is indeed. So the check isn't done every time we run conan?

ruipacheco commented 5 years ago

By check I mean detecting the compiler version.

lasote commented 5 years ago

No, only when the file doesn't exist. This should do also the trick conan profile update settings.compiler.version=16 default In general, it is not recommended to trust the Conan detection of the default profile, especially for companies we recommend to install the needed profiles with the conan config install command.

ruipacheco commented 5 years ago

Thanks!