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: add support for setting CMAKE_GENERATOR_INSTANCE #16229

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ class GenericSystemBlock(Block):
message(STATUS "Conan toolchain: CMAKE_GENERATOR_TOOLSET={{ toolset }}")
set(CMAKE_GENERATOR_TOOLSET "{{ toolset }}" CACHE STRING "" FORCE)
{% endif %}
{% if generator_instance %}
set(CMAKE_GENERATOR_INSTANCE "{{ generator_instance }}")
{% endif %}
""")

@staticmethod
Expand Down Expand Up @@ -955,14 +958,17 @@ def context(self):
result = self._get_winsdk_version(system_version, generator_platform)
system_version, winsdk_version, gen_platform_sdk_version = result

generator_instance = self._conanfile.conf.get("tools.cmake.cmaketoolchain:generator_instance")

return {"toolset": toolset,
"generator_platform": generator_platform,
"cmake_system_name": system_name,
"cmake_system_version": system_version,
"cmake_system_processor": system_processor,
"cmake_sysroot": cmake_sysroot,
"winsdk_version": winsdk_version,
"gen_platform_sdk_version": gen_platform_sdk_version}
"gen_platform_sdk_version": gen_platform_sdk_version,
"generator_instance": generator_instance}


class OutputDirsBlock(Block):
Expand Down
1 change: 1 addition & 0 deletions conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"tools.build:verbosity": "Verbosity of build systems if set. Possible values are 'quiet' and 'verbose'",
"tools.compilation:verbosity": "Verbosity of compilation tools if set. Possible values are 'quiet' and 'verbose'",
"tools.cmake.cmaketoolchain:generator": "User defined CMake generator to use instead of default",
"tools.cmake.cmaketoolchain:generator_instance": "Define CMAKE_GENERATOR_INSTANCE in CMakeToolchain",
"tools.cmake.cmaketoolchain:find_package_prefer_config": "Argument for the CMAKE_FIND_PACKAGE_PREFER_CONFIG",
"tools.cmake.cmaketoolchain:toolchain_file": "Use other existing file rather than conan_toolchain.cmake one",
"tools.cmake.cmaketoolchain:user_toolchain": "Inject existing user toolchains at the beginning of conan_toolchain.cmake",
Expand Down
29 changes: 29 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,3 +1414,32 @@ def build(self):
})
client.run("export tool")
client.run("create consumer -pr:h host -pr:b build --build=missing")


def test_toolchain_generator_instance():
windows_profile = textwrap.dedent("""
[settings]
os=Windows
arch=x86_64
[conf]
tools.cmake.cmaketoolchain:generator_instance=C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/
""")

client = TestClient(path_with_spaces=False)
client.save({"conanfile.txt": "[generators]\nCMakeToolchain",
"windows": windows_profile})

# Test passing path from profile
client.run("install . --profile:build=windows --profile:host=windows")
toolchain = client.load("conan_toolchain.cmake")
assert 'set(CMAKE_GENERATOR_INSTANCE "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/")' in toolchain

# Test input from command line passing path between doble quotes
client.run('install . --profile:build=windows --profile:host=windows -c tools.cmake.cmaketoolchain:generator_instance="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/"')
toolchain = client.load("conan_toolchain.cmake")
assert 'set(CMAKE_GENERATOR_INSTANCE "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/")' in toolchain

# Test input from command line passing path between simple quotes
client.run('install . --profile:build=windows --profile:host=windows -c tools.cmake.cmaketoolchain:generator_instance=\'C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/\'')
toolchain = client.load("conan_toolchain.cmake")
assert 'set(CMAKE_GENERATOR_INSTANCE "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/")' in toolchain