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

Feature/msvc msbuild #8238

Merged
merged 40 commits into from Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0a6f828
working in msvc new settings
memsharded Dec 10, 2020
27c6fc4
merged develop
memsharded Dec 12, 2020
72f6bee
preliminary support for msvc compiler
memsharded Dec 12, 2020
369143b
fix migration
memsharded Dec 12, 2020
49dad85
adding msvc for msbuild toolchain
memsharded Dec 14, 2020
fb110ba
changing to version 19.1, 19.11, etc
memsharded Dec 15, 2020
ee99a73
merged develop
memsharded Dec 15, 2020
cfc28fe
working on static/dynamic runtime
memsharded Dec 16, 2020
c55072f
Merge branch 'develop' into feature/msvc
memsharded Dec 16, 2020
b245c43
extracting toolchain checkers to use in CMake
memsharded Dec 16, 2020
c363312
removed unused import
memsharded Dec 16, 2020
fb6b57b
adding checks
memsharded Dec 16, 2020
e98d911
adding check
memsharded Dec 16, 2020
ae91af5
Merge branch 'feature/toolchain_checkers' into feature/msvc
memsharded Dec 16, 2020
3c3a7b3
first proposal
memsharded Dec 16, 2020
3bb3e4d
msvc proposal for runtime
memsharded Dec 16, 2020
ef36fd2
fix migration test
memsharded Dec 16, 2020
2000c85
fixing tests
memsharded Dec 16, 2020
640b134
binary compatibility
memsharded Dec 16, 2020
fca3c79
merged develop
memsharded Dec 17, 2020
dc6ecbf
Merge branch 'feature/msvc' into feature/msvc_msbuild
memsharded Dec 19, 2020
1994d1f
command conan new generates files with new toolchains
memsharded Dec 19, 2020
3b71504
removed conanfile
memsharded Dec 19, 2020
e66dbe2
removed files
memsharded Dec 19, 2020
5e8fb4f
Merge branch 'feature/new_v2' into feature/msvc_msbuild
memsharded Dec 20, 2020
b0f86c6
msbuild working for msvc
memsharded Dec 20, 2020
1900ff8
merging develop
memsharded Jan 14, 2021
c0c445c
fixing tests
memsharded Jan 14, 2021
f6528c4
fixing tests
memsharded Jan 14, 2021
da8689f
refactors
memsharded Jan 15, 2021
a311923
Update conan/tools/microsoft/toolchain.py
memsharded Jan 18, 2021
59ed3b0
Update conan/tools/microsoft/toolchain.py
memsharded Jan 18, 2021
ef7053c
Fix #7715, in rpath_flags use host OS instead of build OS to determin…
Erlkoenig90 Jan 14, 2021
b4fd977
modernizing tests (#8340)
memsharded Jan 15, 2021
0f2a416
extracting some common code to base class (#8341)
memsharded Jan 16, 2021
52d5e42
modernizing tests (#8345)
memsharded Jan 18, 2021
07570f8
Fix help message in command remove --outdated (#8350)
danimtb Jan 18, 2021
c8b4897
[test] Add test creating a target without namespaces (CMake) (#8338)
jgsogo Jan 18, 2021
7d81f9d
update tests (#8354)
czoido Jan 18, 2021
7e2beca
added integration test for msbuild
memsharded Jan 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 0 additions & 25 deletions conan/tools/cmake/android.py
Expand Up @@ -19,31 +19,6 @@ class CMakeAndroidToolchain(CMakeToolchainBase):
set(CMAKE_ANDROID_STL_TYPE {{ CMAKE_ANDROID_STL_TYPE }})
set(CMAKE_ANDROID_NDK {{ CMAKE_ANDROID_NDK }})
{% endblock %}

{% block main %}
{{ super() }}

{% if shared_libs -%}
message(STATUS "Conan toolchain: Setting BUILD_SHARED_LIBS= {{ shared_libs }}")
set(BUILD_SHARED_LIBS {{ shared_libs }})
{%- endif %}

{% if parallel -%}
set(CONAN_CXX_FLAGS "${CONAN_CXX_FLAGS} {{ parallel }}")
set(CONAN_C_FLAGS "${CONAN_C_FLAGS} {{ parallel }}")
{%- endif %}

{% if cppstd -%}
message(STATUS "Conan C++ Standard {{ cppstd }} with extensions {{ cppstd_extensions }}}")
set(CMAKE_CXX_STANDARD {{ cppstd }})
set(CMAKE_CXX_EXTENSIONS {{ cppstd_extensions }})
{%- endif %}

set(CMAKE_CXX_FLAGS_INIT "${CONAN_CXX_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_INIT "${CONAN_C_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CONAN_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CONAN_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE)
{% endblock %}
""")

# TODO: fPIC, fPIE
Expand Down
21 changes: 21 additions & 0 deletions conan/tools/cmake/base.py
Expand Up @@ -95,6 +95,27 @@ class CMakeToolchainBase(object):
{%- endif %}
{% endblock %}

{% if shared_libs -%}
message(STATUS "Conan toolchain: Setting BUILD_SHARED_LIBS= {{ shared_libs }}")
set(BUILD_SHARED_LIBS {{ shared_libs }})
{%- endif %}

{% if parallel -%}
set(CONAN_CXX_FLAGS "${CONAN_CXX_FLAGS} {{ parallel }}")
set(CONAN_C_FLAGS "${CONAN_C_FLAGS} {{ parallel }}")
{%- endif %}

{% if cppstd -%}
message(STATUS "Conan C++ Standard {{ cppstd }} with extensions {{ cppstd_extensions }}}")
set(CMAKE_CXX_STANDARD {{ cppstd }})
set(CMAKE_CXX_EXTENSIONS {{ cppstd_extensions }})
{%- endif %}

set(CMAKE_CXX_FLAGS_INIT "${CONAN_CXX_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_INIT "${CONAN_C_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CONAN_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CONAN_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE)

# Variables
{% for it, value in variables.items() %}
set({{ it }} "{{ value }}" CACHE STRING "Variable {{ it }} conan-toolchain defined")
Expand Down
21 changes: 0 additions & 21 deletions conan/tools/cmake/generic.py
Expand Up @@ -68,11 +68,6 @@ class CMakeGenericToolchain(CMakeToolchainBase):
{% block main %}
{{ super() }}

{% if shared_libs -%}
message(STATUS "Conan toolchain: Setting BUILD_SHARED_LIBS= {{ shared_libs }}")
set(BUILD_SHARED_LIBS {{ shared_libs }})
{%- endif %}

{% if fpic -%}
message(STATUS "Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -85,11 +80,6 @@ class CMakeGenericToolchain(CMakeToolchainBase):
set(CMAKE_INSTALL_NAME_DIR "")
{% endif -%}

{% if parallel -%}
set(CONAN_CXX_FLAGS "${CONAN_CXX_FLAGS} {{ parallel }}")
set(CONAN_C_FLAGS "${CONAN_C_FLAGS} {{ parallel }}")
{%- endif %}

{% if architecture -%}
set(CONAN_CXX_FLAGS "${CONAN_CXX_FLAGS} {{ architecture }}")
set(CONAN_C_FLAGS "${CONAN_C_FLAGS} {{ architecture }}")
Expand All @@ -104,12 +94,6 @@ class CMakeGenericToolchain(CMakeToolchainBase):
add_definitions(-D_GLIBCXX_USE_CXX11_ABI={{ glibcxx }})
{%- endif %}

{% if cppstd -%}
message(STATUS "Conan C++ Standard {{ cppstd }} with extensions {{ cppstd_extensions }}")
set(CMAKE_CXX_STANDARD {{ cppstd }})
set(CMAKE_CXX_EXTENSIONS {{ cppstd_extensions }})
{%- endif %}

{% if vs_runtimes %}
{% set genexpr = namespace(str='') %}
{%- for config, value in vs_runtimes.items() -%}
Expand All @@ -118,11 +102,6 @@ class CMakeGenericToolchain(CMakeToolchainBase):
{%- endfor -%}
set(CMAKE_MSVC_RUNTIME_LIBRARY "{{ genexpr.str }}")
{% endif %}

set(CMAKE_CXX_FLAGS_INIT "${CONAN_CXX_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_INIT "${CONAN_C_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CONAN_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CONAN_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE)
{% endblock %}
""")

Expand Down
20 changes: 0 additions & 20 deletions conan/tools/cmake/ios.py
Expand Up @@ -21,26 +21,6 @@ class CMakeiOSToolchain(CMakeToolchainBase):
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "123456789A" CACHE INTERNAL "")
endif()
{% endblock %}
{% block main %}
{{ super() }}
{% if shared_libs -%}
message(STATUS "Conan toolchain: Setting BUILD_SHARED_LIBS= {{ shared_libs }}")
set(BUILD_SHARED_LIBS {{ shared_libs }})
{%- endif %}
{% if parallel -%}
set(CONAN_CXX_FLAGS "${CONAN_CXX_FLAGS} {{ parallel }}")
set(CONAN_C_FLAGS "${CONAN_C_FLAGS} {{ parallel }}")
{%- endif %}
{% if cppstd -%}
message(STATUS "Conan C++ Standard {{ cppstd }} with extensions {{ cppstd_extensions }}}")
set(CMAKE_CXX_STANDARD {{ cppstd }})
set(CMAKE_CXX_EXTENSIONS {{ cppstd_extensions }})
{%- endif %}
set(CMAKE_CXX_FLAGS_INIT "${CONAN_CXX_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_INIT "${CONAN_C_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CONAN_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CONAN_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE)
{% endblock %}
""")

def __init__(self, conanfile, build_type=None, **kwargs):
Expand Down
7 changes: 7 additions & 0 deletions conan/tools/microsoft/msbuild.py
Expand Up @@ -15,8 +15,15 @@ class MSBuild(object):
def __init__(self, conanfile):
self._conanfile = conanfile
self.compiler = conanfile.settings.get_safe("compiler")
# This is assuming this is the Visual Studio IDE version, used for the vcvars
self.version = (conanfile.settings.get_safe("compiler.base.version") or
conanfile.settings.get_safe("compiler.version"))
if self.compiler == "msvc":
version = self.version[:4] # Remove the latest version number 19.1X if existing
_visuals = {'19.0': '14', # TODO: This is common to CMake, refactor
'19.1': '15',
'19.2': '16'}
self.version = _visuals[version]
self.vcvars_arch = vcvars_arch(conanfile)
self.build_type = conanfile.settings.get_safe("build_type")
msvc_arch = {'x86': 'x86',
Expand Down
72 changes: 57 additions & 15 deletions conan/tools/microsoft/toolchain.py
Expand Up @@ -3,7 +3,6 @@
import warnings
from xml.dom import minidom

from conans.client.tools import msvs_toolset
from conans.errors import ConanException
from conans.util.files import save, load

Expand All @@ -17,6 +16,9 @@ def __init__(self, conanfile):
self.preprocessor_definitions = {}
self.compile_options = {}
self.configuration = conanfile.settings.build_type
self.runtime_library = self._runtime_library(conanfile.settings)
self.cppstd = conanfile.settings.get_safe("compiler.cppstd")
self.toolset = self._msvs_toolset(conanfile.settings)

def _name_condition(self, settings):
props = [("Configuration", self.configuration),
Expand Down Expand Up @@ -49,20 +51,59 @@ def generate(self):
self._write_config_toolchain(config_filename)
self._write_main_toolchain(config_filename, condition)

@staticmethod
def _msvs_toolset(settings):
compiler = settings.get_safe("compiler")
compiler_version = settings.get_safe("compiler.version")
if compiler == "msvc":
version = compiler_version[:4] # Remove the latest version number 19.1X if existing
toolsets = {'19.0': 'v140', # TODO: This is common to CMake, refactor
'19.1': 'v141',
'19.2': 'v142'}
return toolsets[version]
if compiler == "intel":
compiler_version = compiler_version if "." in compiler_version else \
"%s.0" % compiler_version
return "Intel C++ Compiler " + compiler_version
if compiler == "Visual Studio":
toolset = settings.get_safe("compiler.toolset")
if not toolset:
toolsets = {"16": "v142",
"15": "v141",
"14": "v140",
"12": "v120",
"11": "v110",
"10": "v100",
"9": "v90",
"8": "v80"}
toolset = toolsets.get(compiler_version)
return toolset or ""

@staticmethod
def _runtime_library(settings):
compiler = settings.compiler
runtime = settings.get_safe("compiler.runtime")
if compiler == "msvc":
build_type = settings.get_safe("build_type")
if build_type != "Debug":
runtime_library = {"static": "MultiThreaded",
"dynamic": "MultiThreadedDLL"}.get(runtime, "")
else:
runtime_library = {"static": "MultiThreadedDebug",
"dynamic": "MultiThreadedDebugDLL"}.get(runtime, "")
else:
runtime_library = {"MT": "MultiThreaded",
"MTd": "MultiThreadedDebug",
"MD": "MultiThreadedDLL",
"MDd": "MultiThreadedDebugDLL"}.get(runtime, "")
return runtime_library

def _write_config_toolchain(self, config_filename):

def format_macro(k, value):
return '%s="%s"' % (k, value) if value is not None else k

runtime = self._conanfile.settings.get_safe("compiler.runtime")
cppstd = self._conanfile.settings.get_safe("compiler.cppstd")
toolset = msvs_toolset(self._conanfile.settings)
runtime_library = {"MT": "MultiThreaded",
"MTd": "MultiThreadedDebug",
"MD": "MultiThreadedDLL",
"MDd": "MultiThreadedDebugDLL"}.get(runtime, "")

content = textwrap.dedent("""\
toolchain_file = textwrap.dedent("""\
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
Expand All @@ -81,17 +122,18 @@ def format_macro(k, value):
""")
preprocessor_definitions = ";".join([format_macro(k, v)
for k, v in self.preprocessor_definitions.items()])
# It is useless to set PlatformToolset in the config file, because the conditional checks it
cppstd = "stdcpp%s" % cppstd if cppstd else ""
toolset = toolset or ""

cppstd = "stdcpp%s" % self.cppstd if self.cppstd else ""
runtime_library = self.runtime_library
toolset = self.toolset
compile_options = self._conanfile.conf["tools.microsoft.msbuildtoolchain"].compile_options
if compile_options is not None:
compile_options = eval(compile_options)
self.compile_options.update(compile_options)
compile_options = "".join("\n <{k}>{v}</{k}>".format(k=k, v=v)
for k, v in self.compile_options.items())
config_props = content.format(preprocessor_definitions, runtime_library, cppstd,
compile_options, toolset)
config_props = toolchain_file.format(preprocessor_definitions, runtime_library, cppstd,
compile_options, toolset)
config_filepath = os.path.abspath(config_filename)
self._conanfile.output.info("MSBuildToolchain created %s" % config_filename)
save(config_filepath, config_props)
Expand Down
2 changes: 1 addition & 1 deletion conans/client/build/compiler_flags.py
Expand Up @@ -28,7 +28,7 @@ def rpath_flags(settings, os_build, lib_paths):
if not os_build:
return []
if compiler in GCC_LIKE:
rpath_separator = "," if is_apple_os(os_build) else "="
rpath_separator = ","
return ['-Wl,-rpath%s"%s"' % (rpath_separator, x.replace("\\", "/"))
for x in lib_paths if x]
return []
Expand Down
2 changes: 1 addition & 1 deletion conans/client/command.py
Expand Up @@ -1091,7 +1091,7 @@ def remove(self, *args):
help="Remove locks")
parser.add_argument("-o", "--outdated", default=False, action="store_true",
help="Remove only outdated from recipe packages. "
"This flag can only be used with a reference")
"This flag can only be used with a pattern or a reference")
parser.add_argument('-p', '--packages', nargs="*", action=Extender,
help="Remove all packages of the specified reference if "
"no specific package ID is provided")
Expand Down
8 changes: 0 additions & 8 deletions conans/client/conf/__init__.py
Expand Up @@ -504,14 +504,6 @@ def full_transitive_package_id(self):
except ConanException:
return None

@property
def msvc_visual_incompatible(self):
try:
visual_comp = self.get_item("general.msvc_visual_incompatible")
return visual_comp.lower() in ("1", "true")
except ConanException:
return False

@property
def short_paths_home(self):
short_paths_home = get_env("CONAN_USER_HOME_SHORT")
Expand Down
3 changes: 2 additions & 1 deletion conans/client/graph/graph_binaries.py
Expand Up @@ -339,7 +339,8 @@ def _compute_package_id(self, node, default_package_id_mode, default_python_requ
python_requires=python_requires,
default_python_requires_id_mode=
default_python_requires_id_mode)
if not self._cache.config.msvc_visual_incompatible:

if not self._cache.new_config["core.package_id"].msvc_visual_incompatible:
msvc_compatible = conanfile.info.msvc_compatible()
if msvc_compatible:
conanfile.compatible_packages.append(msvc_compatible)
Expand Down
3 changes: 2 additions & 1 deletion conans/client/tools/win.py
Expand Up @@ -138,8 +138,9 @@ def msvs_toolset(conanfile):
settings = conanfile
toolset = settings.get_safe("compiler.toolset")
if not toolset:
compiler = settings.get_safe("compiler")
compiler_version = settings.get_safe("compiler.version")
if settings.get_safe("compiler") == "intel":
if compiler == "intel":
compiler_version = compiler_version if "." in compiler_version else \
"%s.0" % compiler_version
toolset = "Intel C++ Compiler " + compiler_version
Expand Down