From ca8cd7f29bd10c914d3ba08ec4cd9dbe557965e7 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 10 Jan 2025 13:30:15 +0100 Subject: [PATCH 1/2] add vs_debugger info to incubating CMakeDeps --- conan/tools/cmake/cmakedeps2/cmakedeps.py | 7 ++++++- .../toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/conan/tools/cmake/cmakedeps2/cmakedeps.py b/conan/tools/cmake/cmakedeps2/cmakedeps.py index 0847d18485a..0eba5441ccd 100644 --- a/conan/tools/cmake/cmakedeps2/cmakedeps.py +++ b/conan/tools/cmake/cmakedeps2/cmakedeps.py @@ -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 }}) @@ -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 diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py index 8624447226e..ebe84a29d55 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py @@ -97,6 +97,8 @@ def test_runtime_lib_dirs_multiconf(self): runtime_lib_dirs = re.search(pattern_lib_dirs, contents).group(1) assert "" in runtime_lib_dirs assert "" 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") From dbd432148b20d58088ba3c575c76cac2c9e5d753 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 10 Jan 2025 14:17:21 +0100 Subject: [PATCH 2/2] protect multiple definition --- conan/tools/cmake/toolchain/blocks.py | 6 +++++- .../toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index d1f4ec55d2c..5f3ffdf29d5 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -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 %} """) @@ -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() diff --git a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py index ebe84a29d55..8e73c26982c 100644 --- a/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py +++ b/test/functional/toolchains/cmake/cmakedeps/test_cmakedeps_new_paths.py @@ -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 @@ -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