cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

ENV treats ; as a delimiter for multiple variables

Open Renari opened this issue 3 years ago • 3 comments

  # Get the path to the current cmake binary
  string(REGEX REPLACE "[/|\\]cmake(\\.exe)?$" "" CMAKE_PATH "${CMAKE_COMMAND}")
  # escape Windows path
  string(REPLACE "\\" "/" ESCAPED_PATH "$ENV{PATH}")

  conan_cmake_run(CONANFILE "conanfile.txt"
          ENV "PATH=${CMAKE_PATH};${ESCAPED_PATH}"
          BUILD missing)

Results in:

Conan executing: C:/Program Files/Conan/conan/conan.exe install V:/QtTest/conanfile.txt -s arch=x86_64 -s build_type=Debug -s compiler=Visual Studio -s compiler.version=16 -s compiler.runtime=MDd -e=PATH=V:/JetBrains/apps/CLion/ch-0/212.4746.93/bin/cmake/win/bin -e=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE//Extensions/Microsoft/IntelliCode/CLI -e=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/HostX64/x64

With this error:

ERROR: Invalid input 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE//Extensions/Microsoft/IntelliCode/CLI', use 'name=value'

Renari avatar Jul 28 '21 23:07 Renari

This is a CMake thing. The semicolon is a special character that delimits list elements. You must look at how your argument is used and apply the appropriate amount of backslashes to escape the semicolon. Every unquoted variable substitution does a list expansion, which strips a backslash from semicolons.
From what I counted, cmake-conan does 5 unquoted variable substitutions:

get_filename_component(cmake_path "${CMAKE_COMMAND}" DIRECTORY)
set(esc [[\\\\\]])
string(REPLACE "\\" "/" escaped_path "$ENV{PATH}")
string(REPLACE ";" "${esc};" escaped_path "${escaped_path}")

conan_cmake_run(
    CONANFILE "conanfile.txt"
    ENV "PATH=${cmake_path}${esc};${escaped_path}"
    BUILD missing
)

friendlyanon avatar Jul 29 '21 01:07 friendlyanon

Tried this today with the same results, also tried escaping up to 7 times to see if it made a difference, it did not.

Renari avatar Jul 30 '21 12:07 Renari

You are right, I just tested things and it seems you need 26 escapes: set(esc [[\\\\\\\\\\\\\\\\\\\\\\\\\]])
Kinda crazy! This script should improve its argument handling a lot.

friendlyanon avatar Jul 30 '21 14:07 friendlyanon