Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Fix issue with apple framewords and CMake cached variables #6042

Merged
merged 6 commits into from Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions conans/client/generators/cmake_common.py
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions conans/client/generators/cmake_find_package_common.py
Expand Up @@ -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()
Expand Down
71 changes: 71 additions & 0 deletions 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))
19 changes: 14 additions & 5 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down