From 7feb4f3ab290f2cf713c08dee3b75d7328003855 Mon Sep 17 00:00:00 2001 From: Chip Collier Date: Tue, 27 Aug 2024 13:59:52 +0200 Subject: [PATCH 1/4] Fix for generated CMake build when using tools.build.linker_scripts The generated build otherwise appends the "-Tfoo.ld" argument directly without a preceding space before which can generate an invalid command line. --- conan/tools/cmake/toolchain/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index fffa48aa273..873ae08c2fa 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -254,7 +254,7 @@ class LinkerScriptsBlock(Block): # Add linker flags from tools.build:linker_scripts conf message(STATUS "Conan toolchain: Defining linker script flag: {{ linker_script_flags }}") - string(APPEND CONAN_EXE_LINKER_FLAGS {{ linker_script_flags }}) + string(APPEND CONAN_EXE_LINKER_FLAGS " {{ linker_script_flags }}") """) def context(self): From 09d3616331f72678a4210849391feb6219301270 Mon Sep 17 00:00:00 2001 From: Chip Collier Date: Tue, 27 Aug 2024 15:28:07 +0200 Subject: [PATCH 2/4] Avoids the warning regarding arguments not being separated by space. ``` CMake Warning (dev) at /home/chipc/.conan2/p/b/mypkgbc25b469ad9ce/b/build/generators/conan_toolchain.cmake:54: Syntax Warning in cmake code at column 43 Argument not separated from preceding token by whitespace. ``` --- conan/tools/cmake/toolchain/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 873ae08c2fa..2c7ee1ed0ae 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -265,7 +265,7 @@ def context(self): linker_scripts = [linker_script.replace('\\', '/') for linker_script in linker_scripts] linker_scripts = [relativize_path(p, self._conanfile, "${CMAKE_CURRENT_LIST_DIR}") for p in linker_scripts] - linker_script_flags = ['-T"' + linker_script + '"' for linker_script in linker_scripts] + linker_script_flags = ['-T' + linker_script for linker_script in linker_scripts] return {"linker_script_flags": " ".join(linker_script_flags)} From 04b5db74c741c81a9f8cee84be47622af3cecc5f Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 28 Aug 2024 11:46:53 +0200 Subject: [PATCH 3/4] fix test --- conan/tools/cmake/toolchain/blocks.py | 2 +- test/integration/toolchains/cmake/test_cmaketoolchain.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 2c7ee1ed0ae..24edd9dfdce 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -265,7 +265,7 @@ def context(self): linker_scripts = [linker_script.replace('\\', '/') for linker_script in linker_scripts] linker_scripts = [relativize_path(p, self._conanfile, "${CMAKE_CURRENT_LIST_DIR}") for p in linker_scripts] - linker_script_flags = ['-T' + linker_script for linker_script in linker_scripts] + linker_script_flags = [r'-T\"' + linker_script + r'\"' for linker_script in linker_scripts] return {"linker_script_flags": " ".join(linker_script_flags)} diff --git a/test/integration/toolchains/cmake/test_cmaketoolchain.py b/test/integration/toolchains/cmake/test_cmaketoolchain.py index d62de1aeb38..2b6c8ac4025 100644 --- a/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1152,7 +1152,8 @@ def test_set_linker_scripts(): "profile": profile}) client.run("install . -pr:b profile -pr:h profile") toolchain = client.load("conan_toolchain.cmake") - assert 'string(APPEND CONAN_EXE_LINKER_FLAGS -T"/usr/local/src/flash.ld" -T"C:/local/extra_data.ld")' in toolchain + assert 'string(APPEND CONAN_EXE_LINKER_FLAGS ' \ + r'" -T\"/usr/local/src/flash.ld\" -T\"C:/local/extra_data.ld\"")' in toolchain def test_test_package_layout(): From 5dc917eb277815d02bff68de19239f574b912984 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 28 Aug 2024 16:42:32 +0200 Subject: [PATCH 4/4] fix test --- test/unittests/tools/cmake/test_cmaketoolchain.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittests/tools/cmake/test_cmaketoolchain.py b/test/unittests/tools/cmake/test_cmaketoolchain.py index 3eabef9b4b5..0420540f73a 100644 --- a/test/unittests/tools/cmake/test_cmaketoolchain.py +++ b/test/unittests/tools/cmake/test_cmaketoolchain.py @@ -650,10 +650,12 @@ def test_compilers_block(conanfile): def test_linker_scripts_block(conanfile): - conanfile.conf.define("tools.build:linker_scripts", ["path_to_first_linker_script", "path_to_second_linker_script"]) + conanfile.conf.define("tools.build:linker_scripts", + ["path_to_first_linker_script", "path_to_second_linker_script"]) toolchain = CMakeToolchain(conanfile) content = toolchain.content - assert f'string(APPEND CONAN_EXE_LINKER_FLAGS -T"path_to_first_linker_script" -T"path_to_second_linker_script")' in content + assert r'string(APPEND CONAN_EXE_LINKER_FLAGS " -T\"path_to_first_linker_script\" ' \ + r'-T\"path_to_second_linker_script\"")' in content class TestCrossBuild: