Skip to content

Commit

Permalink
[conf] objcpp instead of objcxx (#12635)
Browse files Browse the repository at this point in the history
* objcpp instead of objcxx

* Added UTs
  • Loading branch information
franramirez688 authored Nov 30, 2022
1 parent 5491d4b commit 7395ddd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def context(self):
compilers = {}
# Allowed <LANG> variables (and <LANG>_LAUNCHER)
compilers_mapping = {"c": "C", "cuda": "CUDA", "cpp": "CXX", "objc": "OBJC",
"objcxx": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
"objcpp": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
"hip": "HIP", "ispc": "ISPC"}
for comp, lang in compilers_mapping.items():
# To set CMAKE_<LANG>_COMPILER
Expand Down
2 changes: 1 addition & 1 deletion conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _resolve_apple_flags_and_variables(self, build_env, compilers_by_conf):
self.apple_min_version_flag = [apple_min_version_flag(self._conanfile)]
# Objective C/C++ ones
self.objc = compilers_by_conf.get("objc", "clang")
self.objcpp = compilers_by_conf.get("objcxx", "clang++")
self.objcpp = compilers_by_conf.get("objcpp", "clang++")
self.objc_args = self._get_env_list(build_env.get('OBJCFLAGS', []))
self.objc_link_args = self._get_env_list(build_env.get('LDFLAGS', []))
self.objcpp_args = self._get_env_list(build_env.get('OBJCXXFLAGS', []))
Expand Down
2 changes: 1 addition & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"tools.build:defines": "List of extra definition flags used by different toolchains like CMakeToolchain and AutotoolsToolchain",
"tools.build:sharedlinkflags": "List of extra flags used by CMakeToolchain for CMAKE_SHARED_LINKER_FLAGS_INIT variable",
"tools.build:exelinkflags": "List of extra flags used by CMakeToolchain for CMAKE_EXE_LINKER_FLAGS_INIT variable",
"tools.build:compiler_executables": "Defines a Python dict-like with the compilers path to be used. Allowed keys {'c', 'cpp', 'cuda', 'objc', 'objcxx', 'rc', 'fortran', 'asm', 'hip', 'ispc'}",
"tools.build:compiler_executables": "Defines a Python dict-like with the compilers path to be used. Allowed keys {'c', 'cpp', 'cuda', 'objc', 'objcpp', 'rc', 'fortran', 'asm', 'hip', 'ispc'}",
"tools.microsoft.bash:subsystem": "Set subsystem to use for Windows. Possible values: 'msys2', 'msys', 'cygwin', 'wsl' and 'sfu'",
"tools.microsoft.bash:path": "Path to the shell executable. Default: 'bash'",
"tools.apple:sdk_path": "Path for the sdk location. This value will be passed as SDKROOT or -isysroot depending on the generator used",
Expand Down
15 changes: 15 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,18 @@ def test_variables_types(conanfile):

contents = load(os.path.join(conanfile.generators_folder, "conan_toolchain.cmake"))
assert 'set(FOO ON CACHE BOOL "Variable FOO conan-toolchain defined")' in contents


def test_compilers_block(conanfile):
cmake_mapping = {"c": "C", "cuda": "CUDA", "cpp": "CXX", "objc": "OBJC",
"objcpp": "OBJCXX", "rc": "RC", 'fortran': "Fortran", 'asm': "ASM",
"hip": "HIP", "ispc": "ISPC"}
compilers = {"c": "path_to_c", "cuda": "path_to_cuda", "cpp": "path_to_cpp",
"objc": "path_to_objc", "objcpp": "path_to_objcpp", "rc": "path_to_rc",
'fortran': "path_to_fortran", 'asm': "path_to_asm", "hip": "path_to_hip",
"ispc": "path_to_ispc"}
conanfile.conf.define("tools.build:compiler_executables", compilers)
toolchain = CMakeToolchain(conanfile)
content = toolchain.content
for compiler, lang in cmake_mapping.items():
assert f'set(CMAKE_{lang}_COMPILER "path_to_{compiler}")' in content
18 changes: 18 additions & 0 deletions conans/test/unittests/tools/gnu/autotoolschain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from conan.tools.gnu import AutotoolsToolchain
from conans.errors import ConanException
from conans.model.conf import Conf
from conans.test.utils.mocks import ConanFileMock, MockSettings


Expand Down Expand Up @@ -90,3 +91,20 @@ def test_get_gnu_triplet_for_cross_building_raise_error():
msg = "'compiler' parameter for 'get_gnu_triplet()' is not specified and " \
"needed for os=Windows"
assert msg == str(conan_error.value)


def test_compilers_mapping():
autotools_mapping = {"c": "CC", "cpp": "CXX", "cuda": "NVCC", "fortran": "FC"}
compilers = {"c": "path_to_c", "cpp": "path_to_cpp", "cuda": "path_to_cuda",
"fortran": "path_to_fortran"}
settings = MockSettings({"build_type": "Release",
"os": "Windows",
"arch": "x86_64"})
conanfile = ConanFileMock()
conanfile.conf = Conf()
conanfile.conf.define("tools.build:compiler_executables", compilers)
conanfile.settings = settings
autotoolschain = AutotoolsToolchain(conanfile)
env = autotoolschain.environment().vars(conanfile)
for compiler, env_var in autotools_mapping.items():
assert env[env_var] == f"path_to_{compiler}"

0 comments on commit 7395ddd

Please sign in to comment.