Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in CLion for CMakeListsPrivate.txt generation when using lib_extra_dirs in Windows #4071

Closed
john-contact opened this issue Sep 30, 2021 · 4 comments
Assignees
Milestone

Comments

@john-contact
Copy link

john-contact commented Sep 30, 2021

Configuration

Operating system:

Windows 10

PlatformIO Version (platformio --version):

PlatformIO Core, version 5.2.0

Description of problem

Hey everyone, hopefully you can help me resolve this or at least I can bring this to your attention.

It seems that if I use an absolute path in lib_extra_dirs, it attempts to be smart in its generation of CMakeListsPrivate.txt by replacing the drive and user directory with $ENV{HOMEDRIVE}$ENV{HOMEPATH}, which then evaluates to include backslashes and breaks cmake. This occurs even if you explicitly use forward slashes in the absolute path.

Steps to Reproduce

  1. In platform.ini, define lib_extra_dirs to be an absolute path beginning with the drive and home directory (e.g. C:/Users/john_contactci/...
  2. Re-init the Platform-IO project in CLion
  3. See that the error "Syntax error in cmake code when parsing string"

Actual Results

CMake Error at CMakeLists.txt:33 (add_executable):
  Syntax error in cmake code when parsing string

    C:\Users\john_contactci/AppData/Local/Maestro/libs/maestro-embedded-config/include/MaestroEmbeddedConfiguration.h

  Invalid character escape '\U'.

Due to the backslash in the path.

Expected Results

Include the path listed in lib_extra_dirs as-is and without replacing it with vars for the drive and homepath. Or, if you're going to replace parts of the path then ensure that the backslashes are replaced or escaped.

If problems with PlatformIO Build System:

In platform.ini:

lib_extra_dirs=C:/Users/john_contactci/AppData/Local/Maestro/libs
lib_deps =
	maestro-embedded-config
	maestro-serialization

Additional info

I'm on Windows 10 using the CLion PlatformIO plugin (version 212.5080.54). My toolchain is configured to use the bundled CMake in CLion, version 3.20.2.

The libraries I'm attempting to link against and include are custom libraries stored locally at the path listed in lib_extra_dirs. The headers are stored under the subdirectory include and the DLL is stored under the subdirectory lib.

In platform.ini:

lib_extra_dirs=C:/Users/john_contactci/AppData/Local/Maestro/libs
lib_deps =
	maestro-embedded-config
	maestro-serialization

In the resulting generated CMakeListsPrivate.txt:

    FILE(GLOB_RECURSE EXTRA_LIB_SOURCES
        ${CMAKE_CURRENT_LIST_DIR}/.pio/libdeps/teensy40/*.*
        $ENV{HOMEDRIVE}$ENV{HOMEPATH}/AppData/Local/Maestro/libs/*.*
    )

Later on EXTRA_LIB_SOURCES is appended to SRC_LIST:

list(APPEND SRC_LIST ${EXTRA_LIB_SOURCES})

And this results in the following error from CMakeLists.txt:

CMake Error at CMakeLists.txt:33 (add_executable):
  Syntax error in cmake code when parsing string

    C:\Users\john_contactci/AppData/Local/Maestro/libs/maestro-embedded-config/include/MaestroEmbeddedConfiguration.h

  Invalid character escape '\U'.

Due to the backslash in the path.

For reference, line 33 of CMakeLists.txt:

add_executable(Z_DUMMY_TARGET ${SRC_LIST})

Which is why I mention the bit about EXTRA_LIB_SOURCES being appended to SRC_LIST above.

Things I have tried to no avail:

  • Defining a PLATFORMIO_LIB_EXTRA_DIRS env var, which results in the same problem.
  • Throwing quotes around the path, which just results in it being treated as a relative path rather than absolute.
  • Using backslashes but escaping them (i.e. \\) in the absolute path.

Any assistance or work around would be greatly appreciated!

Thanks!

@ivankravets ivankravets added this to the 5.2.1 milestone Oct 1, 2021
@ivankravets ivankravets modified the milestones: 5.2.1, 5.2.2 Oct 11, 2021
@ivankravets ivankravets modified the milestones: 5.2.3, 5.2.4 Nov 5, 2021
@ivankravets ivankravets modified the milestones: 5.2.4, 5.2.5 Dec 2, 2021
@valeros valeros closed this as completed in f13734d Dec 2, 2021
@valeros
Copy link
Member

valeros commented Dec 2, 2021

Hi @john-contact , thanks for reporting! It should be fixed in the development branch. It would be great if you could retest the latest PlatformIO core with your project. Just run pio upgrade --dev and reinit your project.

@john-contact
Copy link
Author

Hey @valeros , thanks for picking this one up!

I think this about 99% of the way there.

I now get:

Cannot resolve compiler path '/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++.exe'

If I take a look at the generated CMakeListsPrivate.txt, I see the definition for the c++ compiler path:

SET(CMAKE_CXX_COMPILER "${ENV_HOME_PATH}/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++.exe")

Which given the output I see implies that ENV_HOME_PATH is undefined (or empty). A few lines down (after the C and C++ compiler paths and corresponding flags are defined), I see your patch using TO_CMAKE_PATH:

file(TO_CMAKE_PATH $ENV{HOMEDRIVE}$ENV{HOMEPATH} ENV_HOME_PATH)

If I move that TO_CMAKE_PATH line to be before the compiler path+flags definitions, the issue is gone and everything appears fixed at that point.

Basically, from looking at the associated commit f13734d, I think that if you move your patch in file platformio/project/tpls/clion/CMakeListsPrivate.txt.tpl to instead be before line 60 it will fix it. Like this:

...

# Convert "Home Directory" that may contain unescaped backslashes on Windows
% if "windows" in systype:
file(TO_CMAKE_PATH $ENV{HOMEDRIVE}$ENV{HOMEPATH} ENV_HOME_PATH)
% end

SET(CMAKE_C_COMPILER "{{ _normalize_path(cc_path) }}")
SET(CMAKE_CXX_COMPILER "{{ _normalize_path(cxx_path) }}")
SET(CMAKE_CXX_FLAGS "{{ _normalize_path(to_unix_path(cxx_flags)) }}")
SET(CMAKE_C_FLAGS "{{ _normalize_path(to_unix_path(cc_flags)) }}")

...

Thanks again for the help with this, and let me know if you need anything from my end!

@valeros
Copy link
Member

valeros commented Dec 2, 2021

Thanks for the quick response, my fault. Please pull the latest changes via pio upgrade --dev and try again.

@john-contact
Copy link
Author

@valeros Awesome, that fixed it. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants