Repository: conan-io/conan

Issue:
[bug] apple frameworks broken with cmake
When trying to build static version of conan-glib/2.58.3@bincrafters/stable on macos, the test recipe fails to link because [it uses link flags](https://travis-ci.com/bincrafters/conan-glib/jobs/253077883#L5712) `-framework Foundation -framework Foundation -framework Foundation` instead of `-framework Foundation -framework CoreServices -framework CoreFoundation` [as specified in conanfile.py](https://github.com/bincrafters/conan-glib/blob/stable/2.58.3/conanfile.py#L138)

### Environment Details (include every applicable attribute)
  * Operating System+version: Mac OS X 10.14.4
  * Compiler+version: apple clang 10.0
  * Conan version:1.20.2
  * Python version:


### Logs (Executed commands with output) (Include/Attach if Applicable)

[conan 1.19.1: success](https://gist.github.com/ericLemanissier/5a2fcca7faf51f7c4ef69cec0c92eabb)
[conan 1.20.2: failure](https://gist.github.com/ericLemanissier/116fe4d43d642470cdd141508b4ac033)



Discussion:
Looks like this could be a issue related to latest refactor about frameworks with the CMake macro `conan_find_apple_framworks()`

Resolving patch:
diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py
--- 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
--- 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()


Test patch:
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
--- /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
--- 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):
     """