diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py index 387653e8101..72c42d7f951 100644 --- a/conans/client/generators/cmake_common.py +++ b/conans/client/generators/cmake_common.py @@ -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}}}) """ @@ -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}}}) """ @@ -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() diff --git a/conans/test/functional/generators/cmake_apple_frameworks_test.py b/conans/test/functional/generators/cmake_apple_frameworks_test.py index c0b03fa9cf4..db89d5a2fad 100644 --- a/conans/test/functional/generators/cmake_apple_frameworks_test.py +++ b/conans/test/functional/generators/cmake_apple_frameworks_test.py @@ -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 @@ -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) @@ -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) @@ -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()