Closed Nihlus closed 5 years ago
@Nihlus Sorry for the long delay, I'm extremely busy these weeks... As to your problems, I'll relate to each at the order they appeared:
project()
call, since this is what initializes CMake itself behind the scenes, kind of.
In our case, you're trying to call a function from a framework that is actually part of a toolchain. All toolchains are read after the call to project()
, or more accurately - As part of it. So if you'd think about it for a moment you'll realize you're trying to call an undefined function, which of course fails the execution of the script.find_arduino_library
function attempts to link the board's CoreLib (Core Library) target to the found library target, i.e. to itself. However, the CoreLib target is only created inside the add_arduino_executable
or add_arduino_library
functions, since these are the ones that create the "top-level" target one would be working with.
With that being said, I agree that it's unclear why this assumption has been made, or worse - How should the Find API should be used. It's definitely a note to the project's developers to fix in future versions..c
or .cpp
files, it's called a header-only library.
Due to a user request, support for these types of libraries in the Arduino context also has been added to the framework, but currently it requires calling a different function. You can read more about it here: Header-Only LibrariesLet me know if anything has helped you, good luck 😃
@MrPointer Thanks for getting back to me!
target_sources
. This is a fundamental function of modern CMake, and not being able to use it makes using the library rather clunky. It works fine on add_arduino_executable
.At the very least, a more descriptive error message ought to be emitted.
See above, although I can try with a source file as well. It might help.
I think you've misunderstood me - if you have a look at the CMakeLists.txt file in the microui library at this point (which is header-only, due to me just using a dummy file. I'll try with sources, too), I was referring to it not linking to any other libraries, but the main executable in turn not being able to link to it. I was not referring to linking to a nonexistent library.
@Nihlus Well, as strange as it may seem - I haven't elaborated enough on each item, so please let me.
project()
call, even on non-toolchain-based projects.
However, it's completely acceptable to have a project structure like yours, where the top-level CMakeLists.txt sets some global definitions which are later used by sub-projects - It simply requires the top-level CMake file to define a project, named as you'd like (usually NONE).Edit: Issues number 3 and 4 are solved by #60, Issue number 2 can be discussed #56.
@Nihlus Please update if there's anything else to this issue before I close it.
I have some issues using a multi-project structure for my project. In general, I have a root CMakeLists.txt with common configuration, from which I add subdirectories where my subprojects live. These subprojects are one executable (the main program) and a custom arduino library. The library is not packaged, and is developed as a part of the project.
I've hit a number of issues, worked around a couple, and finally hit a roadblock. These are the problems I hit:
get_board_id
fails if called before aproject()
call, preventing it from being used in the root file without creating a fake project with an `Unknown CMake command" fault.find_arduino_library
fails if called before anadd_arduino_executable
oradd_arduino_library
, preventing it from being used in the root file. Instead, it must be used in a subdirectory, making it unclear which libraries are available to which targets, and in what order to load them.add_arduino_library
fails completely if_sources
is omitted, preventingtarget_sources
from being used.find_arduino_library
fails once more if called afteradd_arduino_library
with explicit source specification, with the same error as 2.Removing the libraries altogether to continue results in
find_arduino_library
failing when the executable attempts to link to it, due to it not being able to find the target.The full source for the project scaffolding is available here: https://github.com/Nihlus/plantbuddy Each problem stage has its own branch, so they can be individually inspected. In each branch succeeding
roadblock-1
, the workaround has been applied.roadblock-1
can be considered the ideal setup.Any help with this would be much appreciated. I love being able to use CMake & CLion for my arduino projects, and in single-project mode, I haven't had any issues at all.