def test_apple_frameworks(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "Macos" settings.compiler = "apple-clang" settings.compiler.version = "9.1" settings.compiler.libcxx = "libc++" settings.arch = "x86_64" settings.build_type = "Debug" conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) conanfile.settings = settings ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder1") cpp_info.frameworkdirs.extend(["path/to/Frameworks1", "path/to/Frameworks2"]) cpp_info.frameworks = ["OpenGL", "OpenCL"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = CMakeGenerator(conanfile) content = generator.content self.assertIn('find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS' ' ${CONAN_FRAMEWORK_DIRS${SUFFIX}} CMAKE_FIND_ROOT_PATH_BOTH)', content) self.assertIn('set(CONAN_FRAMEWORK_DIRS "dummy_root_folder1/Frameworks"\n' '\t\t\t"dummy_root_folder1/path/to/Frameworks1"\n' '\t\t\t"dummy_root_folder1/path/to/Frameworks2" ' '${CONAN_FRAMEWORK_DIRS})', content) self.assertIn('set(CONAN_LIBS ${CONAN_LIBS} ${CONAN_SYSTEM_LIBS} ' '${CONAN_FRAMEWORKS_FOUND})', content) generator = CMakeFindPackageGenerator(conanfile) content = generator.content content = content['FindMyPkg.cmake'] self.assertIn('conan_find_apple_frameworks(MyPkg_FRAMEWORKS_FOUND "${MyPkg_FRAMEWORKS}"' ' "${MyPkg_FRAMEWORK_DIRS}")', content)
def cmake_find_package_test(self): generator = CMakeFindPackageGenerator(self.conanfile) content = generator.content self.assertIn("Findmy_pkg.cmake", content.keys()) self.assertIn("Findmy_pkg2.cmake", content.keys()) self.assertNotIn("not-a-cmake-module.pc", content["Findmy_pkg2.cmake"]) self.assertIn( 'set(CMAKE_MODULE_PATH "dummy_root_folder1/" ${CMAKE_MODULE_PATH})', content["Findmy_pkg.cmake"]) self.assertIn( 'set(CMAKE_PREFIX_PATH "dummy_root_folder1/" ${CMAKE_PREFIX_PATH})', content["Findmy_pkg.cmake"]) self.assertIn( 'set(CMAKE_MODULE_PATH "dummy_root_folder2/" ${CMAKE_MODULE_PATH})', content["Findmy_pkg2.cmake"]) self.assertIn( 'set(CMAKE_PREFIX_PATH "dummy_root_folder2/" ${CMAKE_PREFIX_PATH})', content["Findmy_pkg2.cmake"]) self.assertIn( 'set(my_pkg_BUILD_MODULES_PATHS "dummy_root_folder1/my-module.cmake")', content["Findmy_pkg.cmake"]) self.assertIn( 'set(my_pkg2_BUILD_MODULES_PATHS "dummy_root_folder2/other-mod.cmake"' '\n\t\t\t"dummy_root_folder2/release-mod.cmake")', content["Findmy_pkg2.cmake"])
def cpp_info_name_cmake_find_package_test(self): """ Test cpp_info.names values are applied instead of the reference name """ conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.name = "MyPkG" conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.name = "MyPkG2" conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = CMakeFindPackageGenerator(conanfile) content = generator.content self.assertIn("FindMyPkG.cmake", content.keys()) self.assertIn("FindMyPkG2.cmake", content.keys()) self.assertNotIn("my_pkg", content["FindMyPkG.cmake"]) self.assertNotIn("MY_PKG", content["FindMyPkG.cmake"]) self.assertNotIn("my_pkg", content["FindMyPkG2.cmake"]) self.assertNotIn("MY_PKG", content["FindMyPkG2.cmake"]) self.assertIn("add_library(MyPkG::MyPkG INTERFACE IMPORTED)", content["FindMyPkG.cmake"]) self.assertIn("add_library(MyPkG2::MyPkG2 INTERFACE IMPORTED)", content["FindMyPkG2.cmake"])
def cmake_find_package_test(self): generator = CMakeFindPackageGenerator(self.conanfile) content = generator.content self.assertIn("FindMyPkG.cmake", content.keys()) self.assertIn("FindMyPkG2.cmake", content.keys()) self.assertNotIn("my_pkg", content["FindMyPkG.cmake"]) self.assertNotIn("MY_PKG", content["FindMyPkG.cmake"]) self.assertNotIn("my_pkg", content["FindMyPkG2.cmake"]) self.assertNotIn("MY_PKG", content["FindMyPkG2.cmake"]) self.assertIn("add_library(MyPkG::MyPkG INTERFACE IMPORTED)", content["FindMyPkG.cmake"]) self.assertIn("add_library(MyPkG2::MyPkG2 INTERFACE IMPORTED)", content["FindMyPkG2.cmake"]) self.assertIn("find_dependency(MyPkG REQUIRED)", content["FindMyPkG2.cmake"])
def cmake_find_package_test(self): generator = CMakeFindPackageGenerator(self.conanfile) content = generator.content self.assertIn("FindMyCMakeFindPackageName.cmake", content.keys()) self.assertIn("FindMyCMakeFindPackageName2.cmake", content.keys()) self.assertNotIn("MyPkG", content["FindMyCMakeFindPackageName.cmake"]) self.assertNotIn("MyPkG2", content["FindMyCMakeFindPackageName2.cmake"]) self.assertIn("add_library(MyCMakeFindPackageName::MyCMakeFindPackageName INTERFACE IMPORTED)", content["FindMyCMakeFindPackageName.cmake"]) self.assertIn("add_library(MyCMakeFindPackageName2::MyCMakeFindPackageName2 INTERFACE IMPORTED)", content["FindMyCMakeFindPackageName2.cmake"]) self.assertIn("find_dependency(MyCMakeFindPackageName REQUIRED)", content["FindMyCMakeFindPackageName2.cmake"])
def apple_frameworks_test(self): settings = Settings.loads(default_settings_yml) settings.os = "Macos" settings.compiler = "apple-clang" settings.compiler.version = "9.1" settings.compiler.libcxx = "libc++" settings.arch = "x86_64" settings.build_type = "Debug" conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.name = ref.name cpp_info.framework_paths.extend( ["path/to/Frameworks1", "path/to/Frameworks2"]) cpp_info.frameworks = ["OpenGL", "OpenCL"] conanfile.deps_cpp_info.update(cpp_info, ref.name) conanfile.settings = settings generator = CMakeGenerator(conanfile) content = generator.content self.assertIn( 'find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS' ' ${CONAN_FRAMEWORK_DIRS})', content) self.assertIn( 'set(CONAN_FRAMEWORK_DIRS "path/to/Frameworks1"\n\t\t\t"path/to/Frameworks2" ' '${CONAN_FRAMEWORK_DIRS})', content) self.assertIn( 'set(CONAN_LIBS ${CONAN_PKG_LIBS} ${CONAN_SYSTEM_LIBS} ' '${CONAN_FRAMEWORKS_FOUND})', content) generator = CMakeFindPackageGenerator(conanfile) content = generator.content content = content['FindMyPkg.cmake'] self.assertIn( 'find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS' ' ${MyPkg_FRAMEWORK_DIRS})', content)