Skip to content

Commit

Permalink
Bugfix: cmake_multi generator used with Xcode CMake generator (#7341)
Browse files Browse the repository at this point in the history
* - fix cmake_multi generator used with Xcode CMake generator

Signed-off-by: SSE4 <tomskside@gmail.com>

* Update cmake_common.py

* Update cmake_common.py

* Update cmake_common.py
  • Loading branch information
SSE4 committed Jul 27, 2020
1 parent d6ae16b commit 7329ee9
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 8 deletions.
19 changes: 12 additions & 7 deletions conans/client/generators/cmake_common.py
Expand Up @@ -34,7 +34,7 @@
set(CONAN_EXE_LINKER_FLAGS_{dep}{build_type}_LIST "{deps.exelinkflags_list}")
# Apple Frameworks
conan_find_apple_frameworks(CONAN_FRAMEWORKS_FOUND_{dep}{build_type} "${{CONAN_FRAMEWORKS_{dep}{build_type}}}" "_{dep}")
conan_find_apple_frameworks(CONAN_FRAMEWORKS_FOUND_{dep}{build_type} "${{CONAN_FRAMEWORKS_{dep}{build_type}}}" "_{dep}" "{build_type}")
# Append to aggregated values variable
set(CONAN_LIBS_{dep}{build_type} ${{CONAN_PKG_LIBS_{dep}{build_type}}} ${{CONAN_SYSTEM_LIBS_{dep}{build_type}}} ${{CONAN_FRAMEWORKS_FOUND_{dep}{build_type}}})
"""
Expand Down Expand Up @@ -115,7 +115,7 @@ def cmake_dependencies(dependencies, build_type=""):
set(CONAN_C_FLAGS{build_type} "{deps.cflags} ${{CONAN_C_FLAGS{build_type}}}")
# Apple Frameworks
conan_find_apple_frameworks(CONAN_FRAMEWORKS_FOUND{build_type} "${{CONAN_FRAMEWORKS{build_type}}}" "")
conan_find_apple_frameworks(CONAN_FRAMEWORKS_FOUND{build_type} "${{CONAN_FRAMEWORKS{build_type}}}" "" "{build_type}")
# Append to aggregated values variable: Use CONAN_LIBS instead of CONAN_PKG_LIBS to include user appended vars
set(CONAN_LIBS{build_type} ${{CONAN_LIBS{build_type}}} ${{CONAN_SYSTEM_LIBS{build_type}}} ${{CONAN_FRAMEWORKS_FOUND{build_type}}})
"""
Expand Down Expand Up @@ -826,19 +826,24 @@ class CMakeCommonMacros:
""")

apple_frameworks_macro = textwrap.dedent("""
macro(conan_find_apple_frameworks FRAMEWORKS_FOUND FRAMEWORKS SUFFIX)
macro(conan_find_apple_frameworks FRAMEWORKS_FOUND FRAMEWORKS SUFFIX BUILD_TYPE)
if(APPLE)
if(CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(_BTYPE ${CMAKE_BUILD_TYPE})
elseif(NOT BUILD_TYPE STREQUAL "")
set(_BTYPE ${BUILD_TYPE})
endif()
if(_BTYPE)
if(${_BTYPE} MATCHES "Debug|_DEBUG")
set(CONAN_FRAMEWORKS${SUFFIX} ${CONAN_FRAMEWORKS${SUFFIX}_DEBUG} ${CONAN_FRAMEWORKS${SUFFIX}})
set(CONAN_FRAMEWORK_DIRS${SUFFIX} ${CONAN_FRAMEWORK_DIRS${SUFFIX}_DEBUG} ${CONAN_FRAMEWORK_DIRS${SUFFIX}})
elseif(${CMAKE_BUILD_TYPE} MATCHES "Release")
elseif(${_BTYPE} MATCHES "Release|_RELEASE")
set(CONAN_FRAMEWORKS${SUFFIX} ${CONAN_FRAMEWORKS${SUFFIX}_RELEASE} ${CONAN_FRAMEWORKS${SUFFIX}})
set(CONAN_FRAMEWORK_DIRS${SUFFIX} ${CONAN_FRAMEWORK_DIRS${SUFFIX}_RELEASE} ${CONAN_FRAMEWORK_DIRS${SUFFIX}})
elseif(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo")
elseif(${_BTYPE} MATCHES "RelWithDebInfo|_RELWITHDEBINFO")
set(CONAN_FRAMEWORKS${SUFFIX} ${CONAN_FRAMEWORKS${SUFFIX}_RELWITHDEBINFO} ${CONAN_FRAMEWORKS${SUFFIX}})
set(CONAN_FRAMEWORK_DIRS${SUFFIX} ${CONAN_FRAMEWORK_DIRS${SUFFIX}_RELWITHDEBINFO} ${CONAN_FRAMEWORK_DIRS${SUFFIX}})
elseif(${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel")
elseif(${_BTYPE} MATCHES "MinSizeRel|_MINSIZEREL")
set(CONAN_FRAMEWORKS${SUFFIX} ${CONAN_FRAMEWORKS${SUFFIX}_MINSIZEREL} ${CONAN_FRAMEWORKS${SUFFIX}})
set(CONAN_FRAMEWORK_DIRS${SUFFIX} ${CONAN_FRAMEWORK_DIRS${SUFFIX}_MINSIZEREL} ${CONAN_FRAMEWORK_DIRS${SUFFIX}})
endif()
Expand Down
90 changes: 89 additions & 1 deletion conans/test/functional/generators/cmake_apple_frameworks_test.py
Expand Up @@ -4,7 +4,7 @@
import unittest

from parameterized import parameterized

from conans.client.tools.env import environment_append
from conans.model.ref import ConanFileReference
from conans.test.utils.tools import TestClient

Expand All @@ -26,6 +26,7 @@ def package_info(self):
class App(ConanFile):
requires = "{}"
generators = "{{generator}}"
settings = "build_type", # cmake_multi doesn't work without build_type
def build(self):
cmake = CMake(self)
Expand Down Expand Up @@ -58,6 +59,43 @@ def test_apple_framework_cmake(self):
self.t.run("build .")
self._check_frameworks_found(str(self.t.out))

def test_apple_framework_cmake_multi(self):
app_cmakelists = textwrap.dedent("""
project(Testing CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
conan_basic_setup()
message(">>> CONAN_FRAMEWORKS_FOUND_LIB_DEBUG: ${CONAN_FRAMEWORKS_FOUND_LIB_DEBUG}")
message(">>> CONAN_FRAMEWORKS_FOUND_LIB_RELEASE: ${CONAN_FRAMEWORKS_FOUND_LIB_RELEASE}")
""")

self.t.save({'conanfile.py': self.app_conanfile.format(generator="cmake_multi"),
'CMakeLists.txt': app_cmakelists})
self.t.run("install . -s build_type=Release")
self.t.run("install . -s build_type=Debug")
self.t.run("build .")
self._check_frameworks_found(str(self.t.out))

def test_apple_framework_cmake_multi_xcode(self):
app_cmakelists = textwrap.dedent("""
project(Testing CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
conan_basic_setup()
message(">>> CONAN_FRAMEWORKS_FOUND_LIB_DEBUG: ${CONAN_FRAMEWORKS_FOUND_LIB_DEBUG}")
message(">>> CONAN_FRAMEWORKS_FOUND_LIB_RELEASE: ${CONAN_FRAMEWORKS_FOUND_LIB_RELEASE}")
""")

self.t.save({'conanfile.py': self.app_conanfile.format(generator="cmake_multi"),
'CMakeLists.txt': app_cmakelists})
with environment_append({"CONAN_CMAKE_GENERATOR": "Xcode"}):
self.t.run("install . -s build_type=Release")
self.t.run("install . -s build_type=Debug")
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)
Expand Down Expand Up @@ -239,6 +277,56 @@ def test(self):
client.run("create .")
self.assertIn("Hello World Release!", client.out)

def test_apple_own_framework_cmake_multi(self):
client = TestClient()

test_cmake = textwrap.dedent("""
project(Testing CXX)
message(STATUS "CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}")
include(${CMAKE_BINARY_DIR}/../../conanbuildinfo_multi.cmake)
conan_basic_setup()
message(">>> CONAN_FRAMEWORKS_FOUND_MYLIBRARY_DEBUG: ${CONAN_FRAMEWORKS_FOUND_MYLIBRARY_DEBUG}")
message(">>> CONAN_FRAMEWORKS_FOUND_MYLIBRARY_RELEASE: ${CONAN_FRAMEWORKS_FOUND_MYLIBRARY_RELEASE}")
add_executable(timer timer.cpp)
target_link_libraries(timer debug ${CONAN_LIBS_DEBUG} optimized ${CONAN_LIBS_RELEASE})
""")

test_conanfile = textwrap.dedent("""
from conans import ConanFile, CMake
class TestPkg(ConanFile):
generators = "cmake_multi"
name = "app"
version = "1.0"
requires = "mylibrary/1.0"
exports_sources = "CMakeLists.txt", "timer.cpp"
settings = "build_type", # cmake_multi doesn't work without build_type
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
self.run("%s/timer" % self.settings.build_type, run_environment=True)
""")
client.save({'conanfile.py': self.conanfile,
"src/CMakeLists.txt": self.cmake,
"src/hello.h": self.hello_h,
"src/hello.cpp": self.hello_cpp,
"src/Info.plist": self.infoplist})
client.run("export . mylibrary/1.0@")
client.run("create . mylibrary/1.0@ -s build_type=Debug")
client.run("create . mylibrary/1.0@ -s build_type=Release")

client.save({"conanfile.py": test_conanfile,
'CMakeLists.txt': test_cmake,
"timer.cpp": self.timer_cpp})
with environment_append({"CONAN_CMAKE_GENERATOR": "Xcode"}):
client.run("install . -s build_type=Debug")
client.run("install . -s build_type=Release")
client.run("test . mylibrary/1.0@")
self.assertIn("Hello World Release!", client.out)
client.run("test . mylibrary/1.0@ -s build_type=Debug")
self.assertIn("Hello World Debug!", client.out)

def test_apple_own_framework_cmake_find_package_multi(self):
client = TestClient()

Expand Down

0 comments on commit 7329ee9

Please sign in to comment.