Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeDeps: Fix imported library config suffix #13841

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions conan/tools/cmake/cmakedeps/templates/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def template(self):
if(NOT TARGET ${_LIB_NAME})
add_library(${_LIB_NAME} UNKNOWN IMPORTED)
endif()
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY})
else()
if(NOT TARGET ${_LIB_NAME})
add_library(${_LIB_NAME} SHARED IMPORTED)
endif()
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_SHARED_FOUND_LIBRARY})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_IMPLIB ${CONAN_FOUND_LIBRARY})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_SHARED_FOUND_LIBRARY})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_IMPLIB${config_suffix} ${CONAN_FOUND_LIBRARY})
message(DEBUG "Found DLL and STATIC at ${CONAN_SHARED_FOUND_LIBRARY}, ${CONAN_FOUND_LIBRARY}")
endif()
unset(CONAN_SHARED_FOUND_LIBRARY CACHE)
Expand All @@ -83,10 +83,8 @@ def template(self):
add_library(${_LIB_NAME} ${library_type} IMPORTED)
endif()
message(DEBUG "Created target ${_LIB_NAME} ${library_type} IMPORTED")
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY} IMPORTED_NO_SONAME ${no_soname_mode})
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY} IMPORTED_NO_SONAME ${no_soname_mode})
endif()
# Link library file
set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY})
list(APPEND _out_libraries_target ${_LIB_NAME})
message(VERBOSE "Conan: Found: ${CONAN_FOUND_LIBRARY}")
else()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,37 @@ def package_info(self):
assert "talk: Release!" in client.out
assert "main: Debug!" in client.out

@pytest.mark.tool("cmake", "3.21")
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows DLL specific")
def test_cmake_target_runtime_dlls():
# https://github.com/conan-io/conan/issues/13504

client = TestClient()
client.run("new cmake_lib -d name=hello -d version=1.0")
client.run('create . -tf="" -s build_type=Release -o "hello/*":shared=True')

client.run("new cmake_exe -d name=foo -d version=1.0 -d requires=hello/1.0 -f")
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(foo CXX)
find_package(hello CONFIG REQUIRED)
add_executable(foo src/foo.cpp src/main.cpp)
target_link_libraries(foo PRIVATE hello::hello)
# Make sure CMake copies DLLs from dependencies, next to the executable
# in this case it should copy hello.dll
add_custom_command(TARGET foo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:foo> $<TARGET_FILE_DIR:foo>
COMMAND_EXPAND_LISTS)
""")
client.save({"CMakeLists.txt": cmakelists})
client.run('install . -s build_type=Release -o "hello/*":shared=True')
client.run_command("cmake -S . -B build/ -DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake")
client.run_command("cmake --build build --config Release")
client.run_command("build\\Release\\foo.exe")

assert os.path.exists(os.path.join(client.current_folder, "build", "Release", "hello.dll"))
assert "hello/1.0: Hello World Release!" in client.out # if the DLL wasn't copied, the application would not run and show output


@pytest.mark.tool("cmake")
def test_quiet():
Expand Down