Skip to content

Commit

Permalink
Add test for #19960 (#16974)
Browse files Browse the repository at this point in the history
  • Loading branch information
czoido authored Sep 11, 2024
1 parent e96a7b0 commit 7244cb7
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from conan.test.utils.test_files import temp_folder
from conan.test.utils.tools import TestClient, TurboTestClient
from conans.util.files import save, load, rmdir
from test.conftest import tools_locations


@pytest.mark.skipif(platform.system() != "Windows", reason="Only for windows")
Expand Down Expand Up @@ -2041,3 +2042,73 @@ def test_cxx_version_not_overriden_if_hardcoded():
tc.run("create . -s=compiler.cppstd=17")
assert "Conan toolchain: C++ Standard 17 with extensions OFF" in tc.out
assert "Warning: Standard CMAKE_CXX_STANDARD value defined in conan_toolchain.cmake to 17 has been modified to 17" not in tc.out


@pytest.mark.tool("cmake", "3.23") # Android complains if <3.19
@pytest.mark.tool("android_ndk")
@pytest.mark.skipif(platform.system() != "Darwin", reason="NDK only installed on MAC")
def test_cmake_toolchain_crossbuild_set_cmake_compiler():
# To reproduce https://github.com/conan-io/conan/issues/16960
# the issue happens when you set CMAKE_CXX_COMPILER and CMAKE_C_COMPILER as cache variables
# and then cross-build
c = TestClient()

ndk_path = tools_locations["android_ndk"]["system"]["path"][platform.system()]
bin_path = ndk_path + (
"/toolchains/llvm/prebuilt/darwin-x86_64/bin" if platform.machine() == "x86_64" else
"/toolchains/llvm/prebuilt/darwin-arm64/bin"
)

android = textwrap.dedent(f"""
[settings]
os=Android
os.api_level=23
arch=x86_64
compiler=clang
compiler.version=12
compiler.libcxx=c++_shared
build_type=Release
[conf]
tools.android:ndk_path={ndk_path}
tools.build:compiler_executables = {{"c": "{bin_path}/x86_64-linux-android23-clang", "cpp": "{bin_path}/x86_64-linux-android23-clang++"}}
""")

conanfile = textwrap.dedent(f"""
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.build import check_min_cppstd
class SDKConan(ConanFile):
name = "sdk"
version = "1.0"
generators = "CMakeDeps", "VirtualBuildEnv"
settings = "os", "compiler", "arch", "build_type"
exports_sources = "CMakeLists.txt"
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["SDK_VERSION"] = str(self.version)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
""")

cmake = textwrap.dedent(f"""
cmake_minimum_required(VERSION 3.23)
project(sdk VERSION ${{SDK_VERSION}}.0)
message("sdk: ${{SDK_VERSION}}.0")
""")

c.save({"android": android,
"conanfile.py": conanfile,
"CMakeLists.txt": cmake,})
# first run works ok
c.run('build . --profile:host=android')
assert 'sdk: 1.0.0' in c.out
# in second run CMake says that you have changed variables that require your cache to be deleted.
# and deletes the cache and fails
c.run('build . --profile:host=android')
assert 'VERSION ".0" format invalid.' not in c.out
assert 'sdk: 1.0.0' in c.out

0 comments on commit 7244cb7

Please sign in to comment.