conan-io / cmake-conan

CMake wrapper for conan C and C++ package manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[develop2] Backslash in CONAN_GENERATORS_FOLDER leads to an escape character fail on Windows

Alex-PLACET opened this issue · comments

Hi
On Windows, the CONAN_GENERATORS_FOLDER variable, which is an output of a call of conan install, has backslash. It leads to a character escape later in the code

Example:

[cmake] -- CMake-Conan: CONAN_GENERATORS_FOLDER=C:\Users\alexi\Documents\Dev\project
[cmake] -- CMake-Conan: CONANFILE=C:/Users/alexi/Documents/Dev/project/conanfile.py
[cmake] -- CMake-Conan: find_package(Threads) found, 'conan install' already ran
[cmake] -- Could NOT find Threads (missing: Threads_DIR)
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] CMake Error at C:/Users/alexi/Documents/Dev/project/build/Debug/CMakeFiles/CMakeScratch/TryCompile-abq9g1/CMakeLists.txt:2 (set):
[cmake]   Syntax error in cmake code at
[cmake] 
[cmake]     C:/Users/alexi/Documents/Dev/project/build/Debug/CMakeFiles/CMakeScratch/TryCompile-abq9g1/CMakeLists.txt:2
[cmake] 
[cmake]   when parsing string
[cmake] 
[cmake]     C:\Users\alexi\Documents\Dev\project\build\Debug\conan\build\Debug\generators;C:/Qt/6.6.0/msvc2019_64/lib/cmake/Qt6;C:/Qt/6.6.0/msvc2019_64/lib/cmake/Qt6/3rdparty/extra-cmake-modules/find-modules;C:/Qt/6.6.0/msvc2019_64/lib/cmake/Qt6/3rdparty/kwin
[cmake] 
[cmake]   Invalid character escape '\U'.

A fix is to add
cmake_path(CONVERT ${CONAN_GENERATORS_FOLDER} TO_CMAKE_PATH_LIST CONAN_GENERATORS_FOLDER)

A pullrequest is ongoing

Hi @Alex-PLACET

Thanks for the report and your contribution.
It is not fully clear in what situations this is failing. Because even if it has the backslash, this is working, at least for the common and tested use cases.
If possible, it would be amazing to have a test that would fail without this fix, to avoid this for breaking in the future too.

hey @memsharded, let me chip in here - I had exactly the same problem using CLion, Conan plugin and Threads - had, because after @Alex-PLACET fix it works flawlessly on Mac AND Windows now.

Here's the minimal repro repository: https://github.com/nCore/conan-cmake-backslash-generator-problem
This project does not work and does not contain fix from @Alex-PLACET in conan_provider.cmake

Thanks for the repro case @nCore

It helps to understand, it is not failing in most cases, but only in those that the CMakeLists.txt of the consumers can have some try_compile and similar checks, where the processing of the setup is not exactly the same.

Though I'd prefer #579 to include some tests that covers this, I understand this can be breaking, and I prefer to merge it quickly, if someone (I am also pinging @juansblanco, just in case), can add later some test that covers this use case, that would be really appreciated.

Closed by #579