hello,
I have some project with Mbed that uses cmake now. There I have a project structure with shared interface libs that I want to have outside my main project.
That build and compiles when I use the add_subdirectory which needs the binary dir:
add_subdirectory("${MBED_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/mbed-os")
add_subdirectory("../../custom_targets" "${CMAKE_CURRENT_BINARY_DIR}/custom_targets")
add_subdirectory("../../libs/lvglDriver" "${CMAKE_CURRENT_BINARY_DIR}/lvglDriver")
set(MICROPY_DIR true) # force lvgl to create an interface lib
add_subdirectory("../../libs/lvgl" "${CMAKE_CURRENT_BINARY_DIR}/lvgl")
now I’m getting strange folder names for the object files in ./CMakeFiles/project.dir/
This is appended to the cmake_build dir which is generated by Mbed. And appending D:… to a path creates an invalid path. On the linux system, /home/me/… is appended, therefore it works.
so it looks my approach with add_subdirectory("${MBED_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/mbed-os")
is wrong.
Edit:
its still strange. I have changed the binary-path to xx-mbed-os, but the obj files are still placed into the numbered temp dirs. The xx- path is created, but there no object files.
Indeed, this is quite strange. Does everything look OK if you do cmake --trace-expand? That is, there aren’t two absolute paths being put together in your source code. If that’s all fine, making a small reproducer test case (e.g., as a zip file) that demonstrates the problem would help us figure out the CMake side of things.
thanks, I will try to prepare. But this needs the mbed-tools installation.
I have seen Martin Kojital from ARM had recently also an issue, maybe you have already some mbed installation?
I tried to use some absolut path like c:/temp, but the same numbered dirs are created.
I have another screenshot from an Ubuntu system, there the output looks fine, but you see also that the path is concatenated. There the CMAKE_CURRENT_BINARY_DIR evaluates to: /home/jojo/projects/Mbed6-Projects/apps/blinky/cmake_build/LPC1768/develop/GCC_ARM
Well, I’d like to determine whether there’s a problem with CMake by showing that the bug is not in mbed-tools specifically. If there is evidence of mbed-tools putting paths together without checking the “right” side is absolute or not, that’s the bug. If it’s not doing something like that, then extracting whatever core it is doing into a small example would help track down what CMake is doing wrong here.
Basically, if this doesn’t happen with a dummy project that does add_subdirectory(../../elsewhere customdir), I’m hard pressed to be able to do anything about it since I don’t have any control over what mbed-tools is doing .
Processing: trace.zip…
I could not find the dir names in the output, also the binary dirs look fine.
Upload of tracefile is denied for me as new user.
ok, enough for today.
Thanks a lot for your help.
after lots of checking, I’ve done something simple: I have copied the project closer to the root to get shorter pathnames. And voila, it looks better:
but what I still not understand, when I provide a relative path to add_subdirectory for the binary path, it is still prepended by the full project path. This creates long pathnames that seem to be shortened, it happens in the cmake build configuration step.I couldn’t find some sort of concatenation in the Mbed cmake files.
yes, and it is even documented like this
So thanks also for your confirmation. CMake is doing a great job, the object filename limit also prevents Ninja from failing. Ninja is still suffering from the older windows path limit, a PR to overcome this limit is stale for some time already.
Do you have also an explanation why the binary path in add_subdirectory contains a long path when only a short name is given? The temporary dir is created already in the build dir, so is this long appendix really neccessary?
CMake internally tracks all source/build directories using absolute paths. Providing a short name to add_subdirectory still references a directory that has an absolute path. The generators use that absolute path. Paths to object files are computed to prevent collisions among like-named sources while also not being dependent on the set of sources used. For source paths inside the top-level build or source directories, the object file paths are based on the relative locations. For source paths outside them, we have to use the absolute path to avoid ambiguity and collisions. That produces the long path.