--init and CMAKE_CURRENT_LIST_DIR?


#1

I’m just wondering why they didn’t have the --init use the built in CMAKE_CURRENT_LIST_DIR variable on the end of the CMakeListsPrivate.txt generated by the platformio init command?

I occasionally jump between different linux boxes, all of which have identical platformio installations and user home directories, but some of which have the network share mapped slightly differently. As a result, I had to keep editing the CMakeListsPrivate.txt to change the project directory path in the last line. Initially I tried using a ‘set’ but then got tired of changing the one path in the set so I looked around and found you could use that variable to get the current directory where the CMakeListsPrivate.txt and CMakeLists.txt were located, and thus save having to constantly change the path at all if you move the location of the project or otherwise map it differently.

e.g.:

FILE(GLOB_RECURSE SRC_LIST “${CMAKE_CURRENT_LIST_DIR}/src/.” “${CMAKE_CURRENT_LIST_DIR}/lib/.” ;"${CMAKE_CURRENT_LIST_DIR}/.piolibdeps/.")


#2

Resolved in https://github.com/platformio/platformio-core/commit/4dfa885a85d8d0f0216099bfccbeffca4b57a705

Please run in terminal

pio upgrade --dev
pip init -d /path/to/project --ide clion

Does it work now?


#3

hmmm, it changed, but still is going to be such that it will create issues on different platforms. The substitution I’m seeing is simply replacing /home/swood with $ENV{HOME}

(run from the project directory following your syntax)

$ tail -1 CMakeListsPrivate.txt 
FILE(GLOB_RECURSE SRC_LIST "/home/swood/Arduino/ESP32/I2SDac/src/*.*" "/home/swood/Arduino/ESP32/I2SDac/lib/*.*" "/home/swood/Arduino/ESP32/I2SDac/.piolibdeps/*.*")

$ pio upgrade --dev
Please wait while upgrading PlatformIO ...
PlatformIO has been successfully upgraded to 3.6.4b1
Release notes: https://docs.platformio.org/en/latest/history.html

$ pio init -d `pwd` --ide clion --board esp32dev
The current working directory /home/swood/Arduino/ESP32/I2SDac will be used for the project.

The next files/directories have been created in /home/swood/Arduino/ESP32/I2SDac
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File

Project has been successfully updated including configuration files for `clion` IDE.

$ tail -1 CMakeListsPrivate.txt 
FILE(GLOB_RECURSE SRC_LIST "$ENV{HOME}/Arduino/ESP32/I2SDac/src/*.*" "$ENV{HOME}/Arduino/ESP32/I2SDac/lib/*.*" "$ENV{HOME}/Arduino/ESP32/I2SDac/.piolibdeps/*.*")

While I wholeheartedly appreciate that someone actually looked into it, the point of my original post is that using CMAKE_CURRENT_LIST_DIR replaces everything up to the project’s root dir. Meaning the location of the actual project in any given filesystem becomes irrelevant. Whether it be in my home dir or in /mnt/Fileserver/Arduino or elsewhere.

i.e. in this instance I’m working in my home dir (/home/swood/Arduino) which has a symlink to the Arduino folder in my mounted share because unix allows me to use that as a temporary work-around. The actual file is in a (nfs or samba mounted) folder called /media/TheWild/Chiquita/Development/Arduino but i can’t use it there without editing the CMakeListsPrivate.txt manually after the --init, thus the suggestion. On the server Chiquita, the file actually resides in /mnt/MediaSonic/Development/Arduino.

But, if I manually edit it as in my original post:

FILE(GLOB_RECURSE SRC_LIST “${CMAKE_CURRENT_LIST_DIR}/src/.” “${CMAKE_CURRENT_LIST_DIR}/lib/.” ;"${CMAKE_CURRENT_LIST_DIR}/.piolibdeps/.")

platformio can handle it just fine regardless of which system or folder structure I’m working within.