diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py index 647d15897bc..ac5da484625 100644 --- a/conans/client/generators/cmake_common.py +++ b/conans/client/generators/cmake_common.py @@ -617,9 +617,9 @@ def generate_targets_section(dependencies): foreach(_FRAMEWORK ${FRAMEWORKS}) # https://cmake.org/pipermail/cmake-developers/2017-August/030199.html - find_library(CONAN_FRAMEWORK_FOUND NAME ${_FRAMEWORK} PATHS ${CONAN_FRAMEWORK_DIRS}) - if(CONAN_FRAMEWORK_FOUND) - list(APPEND ${FRAMEWORKS_FOUND} ${CONAN_FRAMEWORK_FOUND}) + find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS ${CONAN_FRAMEWORK_DIRS}) + if(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND) + list(APPEND ${FRAMEWORKS_FOUND} ${CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND}) else() message(FATAL_ERROR "Framework library ${_FRAMEWORK} not found in paths: ${CONAN_FRAMEWORK_DIRS}") endif() diff --git a/conans/client/generators/cmake_find_package_common.py b/conans/client/generators/cmake_find_package_common.py index bbd680310b4..6c6a0b0a748 100644 --- a/conans/client/generators/cmake_find_package_common.py +++ b/conans/client/generators/cmake_find_package_common.py @@ -18,9 +18,9 @@ if(APPLE) foreach(_FRAMEWORK ${{{name}_FRAMEWORKS{build_type_suffix}}}) # https://cmake.org/pipermail/cmake-developers/2017-August/030199.html - find_library(CONAN_FRAMEWORK_FOUND NAME ${{_FRAMEWORK}} PATHS ${{{name}_FRAMEWORK_DIRS{build_type_suffix}}}) - if(CONAN_FRAMEWORK_FOUND) - list(APPEND {name}_FRAMEWORKS_FOUND{build_type_suffix} ${{CONAN_FRAMEWORK_FOUND}}) + find_library(CONAN_FRAMEWORK_${{_FRAMEWORK}}_FOUND NAME ${{_FRAMEWORK}} PATHS ${{{name}_FRAMEWORK_DIRS{build_type_suffix}}}) + if(CONAN_FRAMEWORK_${{_FRAMEWORK}}_FOUND) + list(APPEND {name}_FRAMEWORKS_FOUND{build_type_suffix} ${{CONAN_FRAMEWORK_${{_FRAMEWORK}}_FOUND}}) else() message(FATAL_ERROR "Framework library ${{_FRAMEWORK}} not found in paths: ${{{name}_FRAMEWORK_DIRS{build_type_suffix}}}") endif() diff --git a/conans/test/functional/generators/cmake_apple_frameworks_test.py b/conans/test/functional/generators/cmake_apple_frameworks_test.py new file mode 100644 index 00000000000..4ee97b2dd59 --- /dev/null +++ b/conans/test/functional/generators/cmake_apple_frameworks_test.py @@ -0,0 +1,71 @@ +import platform +import textwrap +import unittest + +from conans.model.ref import ConanFileReference +from conans.test.utils.tools import TestClient + + +@unittest.skipUnless(platform.system() == "Darwin", "Only for MacOS") +class CMakeAppleFrameworksTestCase(unittest.TestCase): + lib_ref = ConanFileReference.loads("lib/version") + lib_conanfile = textwrap.dedent(""" + from conans import ConanFile + + class Lib(ConanFile): + def package_info(self): + self.cpp_info.frameworks.extend(['Foundation', 'CoreServices', 'CoreFoundation']) + """) + + app_conanfile = textwrap.dedent(""" + from conans import ConanFile, CMake + + class App(ConanFile): + requires = "{}" + generators = "{{generator}}" + + def build(self): + cmake = CMake(self) + cmake.configure() + """.format(lib_ref)) + + def setUp(self): + self.t = TestClient() + self.t.save({'conanfile.py': self.lib_conanfile}) + self.t.run("create . {}@".format(self.lib_ref)) + + def _check_frameworks_found(self, output): + self.assertIn("/System/Library/Frameworks/Foundation.framework;", output) + self.assertIn("/System/Library/Frameworks/CoreServices.framework;", output) + self.assertIn("/System/Library/Frameworks/CoreFoundation.framework", output) + + def test_apple_framework_cmake(self): + app_cmakelists = textwrap.dedent(""" + project(Testing CXX) + + include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) + conan_basic_setup() + + message(">>> CONAN_FRAMEWORKS_FOUND_LIB: ${CONAN_FRAMEWORKS_FOUND_LIB}") + """) + + self.t.save({'conanfile.py': self.app_conanfile.format(generator="cmake"), + 'CMakeLists.txt': app_cmakelists}) + self.t.run("install .") + self.t.run("build .") + self._check_frameworks_found(str(self.t.out)) + + def test_apple_framework_cmake_find_package(self): + app_cmakelists = textwrap.dedent(""" + project(Testing CXX) + + find_package(lib) + + message(">>> CONAN_FRAMEWORKS_FOUND_LIB: ${lib_FRAMEWORKS_FOUND}") + """) + + self.t.save({'conanfile.py': self.app_conanfile.format(generator="cmake_find_package"), + 'CMakeLists.txt': app_cmakelists}) + self.t.run("install .") + self.t.run("build .") + self._check_frameworks_found(str(self.t.out)) diff --git a/conans/test/unittests/client/generators/cmake_test.py b/conans/test/unittests/client/generators/cmake_test.py index a7cd962e7fb..6acbb10dc4d 100644 --- a/conans/test/unittests/client/generators/cmake_test.py +++ b/conans/test/unittests/client/generators/cmake_test.py @@ -1,9 +1,11 @@ import os +import platform import re +import textwrap import unittest -import six -from mock import patch +import six +from parameterized import parameterized from conans.client.build.cmake_flags import CMakeDefinitionsBuilder from conans.client.conf import default_settings_yml @@ -18,8 +20,9 @@ from conans.model.settings import Settings from conans.test.utils.test_files import temp_folder from conans.test.utils.tools import TestBufferConanOutput +from conans.test.utils.tools import TestClient from conans.util.files import save - +from conans.test.utils.tools import TestClient, GenConanfile class _MockSettings(object): build_type = None @@ -342,13 +345,19 @@ def apple_frameworks_test(self): generator = CMakeGenerator(conanfile) content = generator.content - self.assertIn('find_library(CONAN_FRAMEWORK_FOUND NAME ${_FRAMEWORK} PATHS ' - '${CONAN_FRAMEWORK_DIRS})', 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) + class CMakeCppInfoNameTest(unittest.TestCase): """