Skip to content

Commit

Permalink
move test to functional
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten-klein committed Sep 18, 2023
1 parent 5c4cf44 commit c750d36
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 55 deletions.
3 changes: 2 additions & 1 deletion conan/tools/cmake/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def _configure_preset(conanfile, generator, cache_variables, toolchain_file, mul
if preset_prefix:
name = f"{preset_prefix}-{name}"
if not multiconfig and build_type:
cache_variables["CMAKE_BUILD_TYPE"] = build_type
if not "CMAKE_BUILD_TYPE" in cache_variables:
cache_variables["CMAKE_BUILD_TYPE"] = build_type
ret = {
"name": name,
"displayName": "'{}' config".format(name),
Expand Down
88 changes: 88 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,91 @@ def build(self):
client.run("build . --profile=profile_false")
assert "using FindComandante.cmake" in client.out


@pytest.mark.tool("cmake")
class TestCMakeBuildType:
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(pkg C CXX)
message(STATUS "CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}'")
""")

def test_build_type_single_config_warn(self):
client = TestClient()

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "compiler", "arch"
exports_sources = '*'
generators = "CMakeToolchain"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build(build_type="Release")
""")
client.save({"conanfile.py": conanfile, "CMakeLists.txt":self.cmakelists})
client.run("create . ")
assert "Specifying 'build_type' does not have " + \
"any effect for single-config build systems" in client.out
assert "CMAKE_BUILD_TYPE: ''" in client.out
assert "Created package" in client.out


@pytest.mark.parametrize(
"setting_build_type", [True, False],
)
def test_build_type_enforced(self, setting_build_type):
client = TestClient()

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
if {}:
settings = "os", "compiler", "arch", "build_type"
else:
settings = "os", "compiler", "arch"
exports_sources = '*'
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["CMAKE_BUILD_TYPE"] = "MinSizeRel"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.install()
""").format(setting_build_type)
client.save({"conanfile.py": conanfile, "CMakeLists.txt":self.cmakelists})
client.run("create . -s build_type=Debug")
assert "CMAKE_BUILD_TYPE: 'MinSizeRel'" in client.out
assert 'Created package' in client.out

def test_build_type_setting(self):
client = TestClient()

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "compiler", "arch"
generators = "CMakeToolchain"
exports_sources = '*'
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.install()
""")
client.save({"conanfile.py": conanfile, "CMakeLists.txt":self.cmakelists})
client.run("create . -s build_type=Debug")
assert "CMAKE_BUILD_TYPE: ''" in client.out
assert "Created package" in client.out
54 changes: 0 additions & 54 deletions conans/test/integration/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,3 @@ def run(self, *args, **kwargs):
assert "-something" in client.out
assert "--testverbose" in client.out
assert "-testok" in client.out

def test_build_type_single_config_warn():
client = TestClient()

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "compiler", "arch"
generators = "CMakeToolchain"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build(build_type="Release")
def run(self, *args, **kwargs):
self.output.info("MYRUN: {}".format(*args))
""")
client.save({"conanfile.py": conanfile})
client.run("create . ")
assert "Specifying 'build_type' does not have " + \
"any effect for single-config build systems" in client.out
assert "Created package" in client.out

def test_build_type_empty():
client = TestClient()

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
class Pkg(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "compiler", "arch"
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["CMAKE_BUILD_TYPE"] = "MinSizeRel"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.install()
def run(self, *args, **kwargs):
self.output.info("MYRUN: {}".format(*args))
""")
client.save({"conanfile.py": conanfile})
client.run("create . -s build_type=Debug")
assert '-DCMAKE_BUILD_TYPE="MinSizeRel"' in client.out
assert 'Created package' in client.out

0 comments on commit c750d36

Please sign in to comment.