Skip to content

Commit

Permalink
new test for new CMakeDeps shared linking (#17437)
Browse files Browse the repository at this point in the history
* new test for new CMakeDeps shared linking

* run with cmake 3.23
  • Loading branch information
memsharded authored Jan 17, 2025
1 parent 4bb0bcc commit ecb0fab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions conan/internal/model/cpp_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
24 changes: 24 additions & 0 deletions test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ecb0fab

Please sign in to comment.