add test to validate cpp.package works
@@ -224,3 +224,49 @@ def test_imports():
client.save({"conanfile.py": conan_file})
client.run("create . consumer/1.0@ ")
assert "Built and imported!" in client.out
+
+
+def test_cpp_package():
+ client = TestClient()
+
+ conan_hello = textwrap.dedent("""
+ import os
+ from conans import ConanFile
+ from conan.tools.files import save
+ class Pkg(ConanFile):
+ def package(self):
+ save(self, os.path.join(self.package_folder, "foo/include/foo.h"), "")
+ save(self, os.path.join(self.package_folder,"foo/libs/foo.lib"), "")
+
+ def layout(self):
+ self.cpp.package.includedirs = ["foo/include"]
+ self.cpp.package.libdirs = ["foo/libs"]
+ self.cpp.package.libs = ["foo"]
+ """)
+
+ client.save({"conanfile.py": conan_hello})
+ client.run("create . hello/1.0@")
+
+ conan_consumer = textwrap.dedent("""
+ from conans import ConanFile
+ class HelloTestConan(ConanFile):
+ settings = "os", "compiler", "build_type", "arch"
+ requires = "hello/1.0"
+ generators = "CMakeDeps"
+ def generate(self):
+ info = self.dependencies["hello"].cpp_info
+ self.output.warn("**includedirs:{}**".format(info.includedirs))
+ self.output.warn("**libdirs:{}**".format(info.libdirs))
+ self.output.warn("**libs:{}**".format(info.libs))
+ """)
+
+ client.save({"conanfile.py": conan_consumer})
+ client.run("install .")
+ assert "**includedirs:['foo/include']**" in client.out
+ assert "**libdirs:['foo/libs']**" in client.out
+ assert "**libs:['foo']**" in client.out
+ cmake = client.load("hello-release-x86_64-data.cmake")
+
+ assert 'set(hello_INCLUDE_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/include")' in cmake
+ assert 'set(hello_LIB_DIRS_RELEASE "${hello_PACKAGE_FOLDER_RELEASE}/foo/libs")' in cmake
+ assert 'set(hello_LIBS_RELEASE foo)' in cmake
