Skip to content

Commit

Permalink
add vs_debugger info to incubating CMakeDeps (#17561)
Browse files Browse the repository at this point in the history
* add vs_debugger info to incubating CMakeDeps

* protect multiple definition
  • Loading branch information
memsharded authored Jan 17, 2025
1 parent ecb0fab commit 27fdff1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion conan/tools/cmake/cmakedeps2/cmakedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def generate(self):
{% endfor %}
{% if host_runtime_dirs %}
set(CONAN_RUNTIME_LIB_DIRS {{ host_runtime_dirs }} )
# Only for VS, needs CMake>=3.27
set(CMAKE_VS_DEBUGGER_ENVIRONMENT "PATH=${CONAN_RUNTIME_LIB_DIRS};%PATH%")
{% endif %}
{% if cmake_program_path %}
list(PREPEND CMAKE_PROGRAM_PATH {{ cmake_program_path }})
Expand Down Expand Up @@ -250,7 +252,10 @@ def _get_host_runtime_dirs(self):
host_runtime_dirs.setdefault(config, []).append(paths)

is_win = self._conanfile.settings.get_safe("os") == "Windows"
for req in self._conanfile.dependencies.host.values():

host_req = self._conanfile.dependencies.host
test_req = self._conanfile.dependencies.test
for req in list(host_req.values()) + list(test_req.values()):
config = req.settings.get_safe("build_type", self._cmakedeps.configuration)
aggregated_cppinfo = req.cpp_info.aggregated_components()
runtime_dirs = aggregated_cppinfo.bindirs if is_win else aggregated_cppinfo.libdirs
Expand Down
6 changes: 5 additions & 1 deletion conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class VSDebuggerEnvironment(Block):
# for execution of applications with shared libraries within the VS IDE
{% if vs_debugger_path %}
# if the file exists it will be loaded by FindFiles block and the variable defined there
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake")
# This variable requires CMake>=3.27 to work
set(CMAKE_VS_DEBUGGER_ENVIRONMENT "{{ vs_debugger_path }}")
endif()
{% endif %}
""")

Expand Down Expand Up @@ -521,7 +525,7 @@ class FindFiles(Block):
template = textwrap.dedent("""\
# Define paths to find packages, programs, libraries, etc.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake")
message(STATUS "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake")
message(STATUS "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/conan_cmakedeps_paths.cmake")
else()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_cmake_generated(client):
c = client
c.run("create dep")
c.run(f"build pkg -c tools.cmake.cmakedeps:new={new_value}")
assert "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake" in c.out
assert "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake" in c.out
assert "Conan: Target declared imported INTERFACE library 'dep::dep'" in c.out


Expand Down Expand Up @@ -71,7 +71,7 @@ def package_info(self):
c.save({"dep/conanfile.py": dep})
c.run("create dep")
c.run(f"build pkg -c tools.cmake.cmakedeps:new={new_value}")
assert "Conan toolchain: Including CMakeDeps generated conan_find_paths.cmake" in c.out
assert "Conan toolchain: Including CMakeDeps generated conan_cmakedeps_paths.cmake" in c.out
assert "Hello from dep dep-Config.cmake!!!!!" in c.out


Expand All @@ -97,6 +97,8 @@ def test_runtime_lib_dirs_multiconf(self):
runtime_lib_dirs = re.search(pattern_lib_dirs, contents).group(1)
assert "<CONFIG:Release>" in runtime_lib_dirs
assert "<CONFIG:Debug>" in runtime_lib_dirs
# too simple of a check, but this is impossible to test automatically
assert "set(CMAKE_VS_DEBUGGER_ENVIRONMENT" in contents


@pytest.mark.tool("cmake")
Expand Down

0 comments on commit 27fdff1

Please sign in to comment.