From ecb0fab2dc228eec48b2a0d628526fc95ce8ea88 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 17 Jan 2025 16:08:30 +0100 Subject: [PATCH] new test for new CMakeDeps shared linking (#17437) * new test for new CMakeDeps shared linking * run with cmake 3.23 --- conan/internal/model/cpp_info.py | 2 -- .../cmake/cmakedeps/test_cmakedeps_new.py | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/conan/internal/model/cpp_info.py b/conan/internal/model/cpp_info.py index 18a3852bd3d..d05f0cd4d8d 100644 --- a/conan/internal/model/cpp_info.py +++ b/conan/internal/model/cpp_info.py @@ -495,7 +495,6 @@ def _lib_match_by_glob(dir_, filename): if matches: return matches - def _lib_match_by_regex(dir_, pattern): ret = set() # pattern is a regex compiled pattern, so let's iterate each file to find the library @@ -515,7 +514,6 @@ def _lib_match_by_regex(dir_, pattern): ret.add(full_path) return list(ret) - def _find_matching(dirs, pattern): for d in dirs: if not os.path.exists(d): diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py index 87509c06464..8ad1b74f10c 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py @@ -218,6 +218,8 @@ def test_libs_transitive(self, transitive_libraries, shared): assert "Conan: Target declared imported STATIC library 'matrix::matrix'" in c.out assert "Conan: Target declared imported STATIC library 'engine::engine'" in c.out + # if not using cmake >= 3.23 the intermediate gamelib_test linkage fail + @pytest.mark.tool("cmake", "3.23") @pytest.mark.parametrize("shared", [False, True]) def test_multilevel(self, shared): # TODO: make this shared fixtures in conftest for multi-level shared testing @@ -231,6 +233,28 @@ def test_multilevel(self, shared): c.save({}, clean_first=True) c.run("new cmake_lib -d name=gamelib -d version=0.1 -d requires=engine/0.1") + + # This specific CMake fails for shared libraries with old CMakeDeps in Linux + cmake = textwrap.dedent("""\ + cmake_minimum_required(VERSION 3.15) + project(gamelib CXX) + + find_package(engine CONFIG REQUIRED) + + add_library(gamelib src/gamelib.cpp) + target_include_directories(gamelib PUBLIC include) + target_link_libraries(gamelib PRIVATE engine::engine) + + add_executable(gamelib_test src/gamelib_test.cpp) + target_link_libraries(gamelib_test PRIVATE gamelib) + + set_target_properties(gamelib PROPERTIES PUBLIC_HEADER "include/gamelib.h") + install(TARGETS gamelib) + """) + # Testing that a local test executable links correctly with the new CMakeDeps + # It fails with the old CMakeDeps + c.save({"CMakeLists.txt": cmake, + "src/gamelib_test.cpp": '#include "gamelib.h"\nint main() { gamelib(); }'}) c.run(f"create . -o *:shared={shared} -c tools.cmake.cmakedeps:new={new_value}") c.save({}, clean_first=True)