From 1688e04a48ebafb1d9b1bd0b436072a81d606946 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 16:13:00 +0100 Subject: [PATCH 1/9] use target without namespace --- conans/model/build_info.py | 14 ++- .../cmake_find_package_multi_test.py | 115 ++++++++++++++++++ 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/conans/model/build_info.py b/conans/model/build_info.py index 98d24ea369b..5efff753daa 100644 --- a/conans/model/build_info.py +++ b/conans/model/build_info.py @@ -2,6 +2,8 @@ from collections import OrderedDict from copy import copy +import six + from conans.errors import ConanException from conans.util.conan_v2_mode import conan_v2_behavior @@ -82,6 +84,7 @@ def dict_to_abs_paths(the_dict, rootpath): def merge_dicts(d1, d2): def merge_lists(seq1, seq2): return [s for s in seq1 if s not in seq2] + seq2 + result = d1.copy() for k, v in d2.items(): if k not in d1.keys(): @@ -145,7 +148,12 @@ def _filter_paths(self, paths): @property def build_modules_paths(self): if self._build_modules_paths is None: - if isinstance(self.build_modules, list): # FIXME: This should be just a plain dict + # FIXME: This should be just a plain dict + if isinstance(self.build_modules, six.string_types): + conan_v2_behavior("Use 'self.cpp_info.build_modules[\"\"] = " + "{the_list}' instead".format(the_list=[self.build_modules, ])) + self.build_modules = BuildModulesDict.from_list([self.build_modules, ]) + if isinstance(self.build_modules, list): conan_v2_behavior("Use 'self.cpp_info.build_modules[\"\"] = " "{the_list}' instead".format(the_list=self.build_modules)) self.build_modules = BuildModulesDict.from_list(self.build_modules) @@ -346,7 +354,8 @@ def _check_components_requires_instersection(comp_requires): reason = None if comp_require not in pkg_requires: reason = "not defined as a recipe requirement" - elif package_requires[comp_require].private and package_requires[comp_require].override: + elif package_requires[comp_require].private and package_requires[ + comp_require].override: reason = "it was defined as an overridden private recipe requirement" elif package_requires[comp_require].private: reason = "it was defined as a private recipe requirement" @@ -380,7 +389,6 @@ def __init__(self): super(_BaseDepsCppInfo, self).__init__() def update(self, dep_cpp_info): - def merge_lists(seq1, seq2): return [s for s in seq1 if s not in seq2] + seq2 diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index 9278cc0e5ed..4c3210d334d 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -526,3 +526,118 @@ def build(self): self.assertIn("component libs: $<$:;>;$<$:;>;" "$<$:;>;$<$:system_lib_component;", t.out) + + +@pytest.mark.tool_cmake +class TestNoNamespaceTarget: + """ This test case uses build-modules feature to create a target without a namespace. This + target uses targets create by Conan (build_modules are included after Conan targets) + """ + + conanfile = textwrap.dedent(""" + import os + from conans import ConanFile, CMake + + class Recipe(ConanFile): + settings = "os", "compiler", "arch" + exports_sources = ["src/*", "build-module.cmake"] + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure(source_folder="src") + cmake.build() + + def package(self): + self.copy("*.h", dst="include", src="src") + self.copy("*.lib", dst="lib", keep_path=False) + self.copy("*.dll", dst="bin", keep_path=False) + self.copy("*.dylib*", dst="lib", keep_path=False) + self.copy("*.so", dst="lib", keep_path=False) + self.copy("*.a", dst="lib", keep_path=False) + self.copy("build-module.cmake", dst="share/cmake") + + def package_info(self): + self.cpp_info.libs = ["library"] + module = os.path.join("share", "cmake", "build-module.cmake") + self.cpp_info.build_modules = module + """) + + build_module = textwrap.dedent(""" + message(">> Build-module is included") + + if(NOT TARGET nonamespace) + add_library(nonamespace INTERFACE IMPORTED) + target_link_libraries(nonamespace INTERFACE library::library) + endif() + """) + + consumer = textwrap.dedent(""" + cmake_minimum_required(VERSION 3.0) + set(CMAKE_CXX_COMPILER_WORKS 1) + set(CMAKE_CXX_ABI_COMPILED 1) + project(consumer) + + find_package(library) + + get_target_property(LIBS1 library::library INTERFACE_LINK_LIBRARIES) + message(">> library::library libs: ${LIBS1}") + + get_target_property(LIBS2 nonamespace INTERFACE_LINK_LIBRARIES) + message(">> nonamespace libs: ${LIBS2}") + + add_executable(consumer main.cpp) + target_link_libraries(consumer library::library) + """) + + main = textwrap.dedent(""" + #include "library.h" + + int main() { + library(); + } + """) + + @classmethod + def setup_class(cls): + cls.t = t = TestClient() + t.current_folder = '/private/var/folders/fc/6mvcrc952dqcjfhl4c7c11ph0000gn/T/tmpiq_fqfmfconans/path with spaces' + # Create a library providing a build-module + t.run('new library/version -s') + t.save({'conanfile.py': cls.conanfile, + 'build-module.cmake': cls.build_module}) + t.run('create conanfile.py library/version@') + # Prepare project to consume the targets + t.save({'CMakeLists.txt': cls.consumer, 'main.cpp': cls.main}, clean_first=True) + + def test_non_multi_generator(self): + t = self.t + with t.chdir('not_multi'): + t.run('install library/version@ -g cmake_find_package -s build_type=Release') + t.run_command('cmake .. -DCMAKE_MODULE_PATH="{}"'.format(t.current_folder)) + assert str(t.out).count('>> Build-module is included') == 1 + assert '>> nonamespace libs: library::library' in t.out + t.run_command('cmake --build .') # Compiles and links. + + @pytest.mark.skipif(platform.system() != "Windows", reason="Only windows") + def test_multi_generator_windows(self): + t = self.t + with t.chdir('multi_macos'): + t.run('install library/version@ -g cmake_find_package_multi -s build_type=Release') + t.run('install library/version@ -g cmake_find_package_multi -s build_type=Debug') + generator = '-G "Visual Studio 15 2017" -A "x64"' + t.run_command('cmake .. {} -DCMAKE_PREFIX_PATH="{}"'.format(generator, t.current_folder)) + assert str(t.out).count('>> Build-module is included') == 2 # FIXME: Known bug + assert '>> nonamespace libs: library::library' in t.out + t.run_command('cmake --build . --config Release') # Compiles and links. + + @pytest.mark.skipif(platform.system() != "Darwin", reason="Requires Macos") + def test_multi_generator_macos(self): + t = self.t + with t.chdir('multi_macos'): + t.run('install library/version@ -g cmake_find_package_multi -s build_type=Release') + t.run('install library/version@ -g cmake_find_package_multi -s build_type=Debug') + t.run_command('cmake .. -G Xcode -DCMAKE_PREFIX_PATH="{}"'.format(t.current_folder)) + assert str(t.out).count('>> Build-module is included') == 2 # FIXME: Known bug + assert '>> nonamespace libs: library::library' in t.out + t.run_command('cmake --build . --config Release') # Compiles and links. From 40a54bbaaf300599f0ce8ee7b2332268f6d4ba3e Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 16:26:27 +0100 Subject: [PATCH 2/9] add marks --- .../functional/generators/cmake_find_package_multi_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index 4c3210d334d..f73bf26421f 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -610,6 +610,7 @@ def setup_class(cls): # Prepare project to consume the targets t.save({'CMakeLists.txt': cls.consumer, 'main.cpp': cls.main}, clean_first=True) + @pytest.mark.tool_compiler def test_non_multi_generator(self): t = self.t with t.chdir('not_multi'): @@ -620,6 +621,7 @@ def test_non_multi_generator(self): t.run_command('cmake --build .') # Compiles and links. @pytest.mark.skipif(platform.system() != "Windows", reason="Only windows") + @pytest.mark.tool_visual_studio def test_multi_generator_windows(self): t = self.t with t.chdir('multi_macos'): @@ -632,6 +634,7 @@ def test_multi_generator_windows(self): t.run_command('cmake --build . --config Release') # Compiles and links. @pytest.mark.skipif(platform.system() != "Darwin", reason="Requires Macos") + @pytest.mark.tool_xcode def test_multi_generator_macos(self): t = self.t with t.chdir('multi_macos'): From 2b1905c1ed187f21e95ee39c0f99d40ec2c0a147 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 16:28:14 +0100 Subject: [PATCH 3/9] use target from the build-module --- .../test/functional/generators/cmake_find_package_multi_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index f73bf26421f..e24c545d92e 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -587,7 +587,7 @@ def package_info(self): message(">> nonamespace libs: ${LIBS2}") add_executable(consumer main.cpp) - target_link_libraries(consumer library::library) + target_link_libraries(consumer nonamespace) """) main = textwrap.dedent(""" From 8bb5d3ca3e453958705787c24f921f206c5e44f9 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 16:56:35 +0100 Subject: [PATCH 4/9] remove line --- .../test/functional/generators/cmake_find_package_multi_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index e24c545d92e..08b6f941daf 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -601,7 +601,6 @@ def package_info(self): @classmethod def setup_class(cls): cls.t = t = TestClient() - t.current_folder = '/private/var/folders/fc/6mvcrc952dqcjfhl4c7c11ph0000gn/T/tmpiq_fqfmfconans/path with spaces' # Create a library providing a build-module t.run('new library/version -s') t.save({'conanfile.py': cls.conanfile, From f2163c6c30037c0476aa48733a58e060bda65b82 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 17:06:13 +0100 Subject: [PATCH 5/9] build-module per generator --- .../functional/generators/cmake_find_package_multi_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index 08b6f941daf..f6b21a39c02 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -560,7 +560,8 @@ def package(self): def package_info(self): self.cpp_info.libs = ["library"] module = os.path.join("share", "cmake", "build-module.cmake") - self.cpp_info.build_modules = module + self.cpp_info.build_modules['cmake_find_package'] = [module, ] + self.cpp_info.build_modules['cmake_find_package_multi'] = [module, ] """) build_module = textwrap.dedent(""" From 6ef885aba6b985877838bb2869bda360afd847ff Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 17:06:51 +0100 Subject: [PATCH 6/9] revert changes in build_info --- conans/model/build_info.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/conans/model/build_info.py b/conans/model/build_info.py index 5efff753daa..98d24ea369b 100644 --- a/conans/model/build_info.py +++ b/conans/model/build_info.py @@ -2,8 +2,6 @@ from collections import OrderedDict from copy import copy -import six - from conans.errors import ConanException from conans.util.conan_v2_mode import conan_v2_behavior @@ -84,7 +82,6 @@ def dict_to_abs_paths(the_dict, rootpath): def merge_dicts(d1, d2): def merge_lists(seq1, seq2): return [s for s in seq1 if s not in seq2] + seq2 - result = d1.copy() for k, v in d2.items(): if k not in d1.keys(): @@ -148,12 +145,7 @@ def _filter_paths(self, paths): @property def build_modules_paths(self): if self._build_modules_paths is None: - # FIXME: This should be just a plain dict - if isinstance(self.build_modules, six.string_types): - conan_v2_behavior("Use 'self.cpp_info.build_modules[\"\"] = " - "{the_list}' instead".format(the_list=[self.build_modules, ])) - self.build_modules = BuildModulesDict.from_list([self.build_modules, ]) - if isinstance(self.build_modules, list): + if isinstance(self.build_modules, list): # FIXME: This should be just a plain dict conan_v2_behavior("Use 'self.cpp_info.build_modules[\"\"] = " "{the_list}' instead".format(the_list=self.build_modules)) self.build_modules = BuildModulesDict.from_list(self.build_modules) @@ -354,8 +346,7 @@ def _check_components_requires_instersection(comp_requires): reason = None if comp_require not in pkg_requires: reason = "not defined as a recipe requirement" - elif package_requires[comp_require].private and package_requires[ - comp_require].override: + elif package_requires[comp_require].private and package_requires[comp_require].override: reason = "it was defined as an overridden private recipe requirement" elif package_requires[comp_require].private: reason = "it was defined as a private recipe requirement" @@ -389,6 +380,7 @@ def __init__(self): super(_BaseDepsCppInfo, self).__init__() def update(self, dep_cpp_info): + def merge_lists(seq1, seq2): return [s for s in seq1 if s not in seq2] + seq2 From e2afa59c9a2caf037210772f98f3acab7b76505a Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 17:42:19 +0100 Subject: [PATCH 7/9] make it explicit it is PATH --- .../generators/cmake_find_package_multi_test.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index f6b21a39c02..10311780d3a 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -615,20 +615,21 @@ def test_non_multi_generator(self): t = self.t with t.chdir('not_multi'): t.run('install library/version@ -g cmake_find_package -s build_type=Release') - t.run_command('cmake .. -DCMAKE_MODULE_PATH="{}"'.format(t.current_folder)) + t.run_command('cmake .. -DCMAKE_MODULE_PATH:PATH="{}"'.format(t.current_folder)) assert str(t.out).count('>> Build-module is included') == 1 assert '>> nonamespace libs: library::library' in t.out - t.run_command('cmake --build .') # Compiles and links. + t.run_command('cmake --build .') # Compiles and links. @pytest.mark.skipif(platform.system() != "Windows", reason="Only windows") @pytest.mark.tool_visual_studio def test_multi_generator_windows(self): t = self.t - with t.chdir('multi_macos'): + with t.chdir('multi_windows'): t.run('install library/version@ -g cmake_find_package_multi -s build_type=Release') t.run('install library/version@ -g cmake_find_package_multi -s build_type=Debug') generator = '-G "Visual Studio 15 2017" -A "x64"' - t.run_command('cmake .. {} -DCMAKE_PREFIX_PATH="{}"'.format(generator, t.current_folder)) + t.run_command( + 'cmake .. {} -DCMAKE_PREFIX_PATH:PATH="{}"'.format(generator, t.current_folder)) assert str(t.out).count('>> Build-module is included') == 2 # FIXME: Known bug assert '>> nonamespace libs: library::library' in t.out t.run_command('cmake --build . --config Release') # Compiles and links. @@ -640,7 +641,7 @@ def test_multi_generator_macos(self): with t.chdir('multi_macos'): t.run('install library/version@ -g cmake_find_package_multi -s build_type=Release') t.run('install library/version@ -g cmake_find_package_multi -s build_type=Debug') - t.run_command('cmake .. -G Xcode -DCMAKE_PREFIX_PATH="{}"'.format(t.current_folder)) + t.run_command('cmake .. -G Xcode -DCMAKE_PREFIX_PATH:PATH="{}"'.format(t.current_folder)) assert str(t.out).count('>> Build-module is included') == 2 # FIXME: Known bug assert '>> nonamespace libs: library::library' in t.out t.run_command('cmake --build . --config Release') # Compiles and links. From e5e010986cb4e4c7e862a3c0547bc3ca3f5c3942 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Thu, 14 Jan 2021 19:20:22 +0100 Subject: [PATCH 8/9] even without build-type, compiler.runtime is different for Release/Debug --- .../functional/generators/cmake_find_package_multi_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index 10311780d3a..7feac9eee19 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -539,7 +539,7 @@ class TestNoNamespaceTarget: from conans import ConanFile, CMake class Recipe(ConanFile): - settings = "os", "compiler", "arch" + settings = "os", "compiler", "arch", "build_type" exports_sources = ["src/*", "build-module.cmake"] generators = "cmake" @@ -606,7 +606,8 @@ def setup_class(cls): t.run('new library/version -s') t.save({'conanfile.py': cls.conanfile, 'build-module.cmake': cls.build_module}) - t.run('create conanfile.py library/version@') + t.run('create conanfile.py library/version@ -s build_type=Debug') + t.run('create conanfile.py library/version@ -s build_type=Release') # Prepare project to consume the targets t.save({'CMakeLists.txt': cls.consumer, 'main.cpp': cls.main}, clean_first=True) @@ -627,7 +628,7 @@ def test_multi_generator_windows(self): with t.chdir('multi_windows'): t.run('install library/version@ -g cmake_find_package_multi -s build_type=Release') t.run('install library/version@ -g cmake_find_package_multi -s build_type=Debug') - generator = '-G "Visual Studio 15 2017" -A "x64"' + generator = '-G "Visual Studio 15 Win64"' t.run_command( 'cmake .. {} -DCMAKE_PREFIX_PATH:PATH="{}"'.format(generator, t.current_folder)) assert str(t.out).count('>> Build-module is included') == 2 # FIXME: Known bug From 21f20ffa9eddd5945a685a6691944f2fd49428c9 Mon Sep 17 00:00:00 2001 From: jgsogo Date: Mon, 18 Jan 2021 13:00:52 +0100 Subject: [PATCH 9/9] use x64 for Windows generator --- .../functional/generators/cmake_find_package_multi_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conans/test/functional/generators/cmake_find_package_multi_test.py b/conans/test/functional/generators/cmake_find_package_multi_test.py index 7feac9eee19..85253a2e1fe 100644 --- a/conans/test/functional/generators/cmake_find_package_multi_test.py +++ b/conans/test/functional/generators/cmake_find_package_multi_test.py @@ -616,7 +616,9 @@ def test_non_multi_generator(self): t = self.t with t.chdir('not_multi'): t.run('install library/version@ -g cmake_find_package -s build_type=Release') - t.run_command('cmake .. -DCMAKE_MODULE_PATH:PATH="{}"'.format(t.current_folder)) + generator = '-G "Visual Studio 15 Win64"' if platform.system() == "Windows" else '' + t.run_command( + 'cmake .. {} -DCMAKE_MODULE_PATH:PATH="{}"'.format(generator, t.current_folder)) assert str(t.out).count('>> Build-module is included') == 1 assert '>> nonamespace libs: library::library' in t.out t.run_command('cmake --build .') # Compiles and links.