Hi,
My quest to compile both my application and framework code for both Linux and IDF continues. Today I tried to write a CMakeLists.txt that is aware if it is being compiled for IDF or native Linux.
Issue #1: idf.py does not define IDF_PLATFORM. Easily fixed by updating it:
Code: Select all
cmake_args = ["cmake", "-G", args.generator, "-DPYTHON_DEPS_CHECKED=1", "-DIDF_PLATFORM=1"]
Issue #2: The IDF cmake function "project" in project.cmake does not define IDF_PLATFORM. Also easily fixed:
Code: Select all
execute_process(COMMAND "${CMAKE_COMMAND}"
...
-D "ESP_PLATFORM=1"
...
WORKING_DIRECTORY "${PROJECT_PATH}")
Issue #3: When CMake is run in script mode, i.e. via the -P switch as in #2, there are certain functionalities of CMake that cannot be used. Among these are
project,
target_compile_definitions and
add_library, the latter actually being referred to in the
documentation on how to write IDF components in "pure" CMake for IDF.
So, I end up with the following error and subsequent failure.
Executing "cmake -G 'Unix Makefiles' -DPYTHON_DEPS_CHECKED=1 -DIDF_PLATFORM=1 --warn-uninitialized /home/permal/electronics/IO-Card-G3/software"...
Warn about uninitialized values.
-- Found Git: /usr/bin/git (found version "2.17.1")
CMake Error at main/CMakeLists.txt:6 (add_library):
add_library command is not scriptable
Call Stack (most recent call first):
/home/permal/esp/esp-idf/tools/cmake/scripts/expand_requirements.cmake:169 (include)
/home/permal/esp/esp-idf/tools/cmake/scripts/expand_requirements.cmake:207 (expand_component_requirements)
CMake Error at /home/permal/esp/esp-idf/tools/cmake/project.cmake:74 (include):
include could not find load file:
/home/permal/electronics/IO-Card-G3/software/build/component_depends.cmake
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
Issue #4: CMakeLists.txt in "main" needs to be duplicated in top-level CMakeLists.txt when compiling for Linux. This is because IDF expects the main app to be in the "main" folder and as such the "add_executable()" call when compiling for Linux needs to either refer to files in "main" folder like this:
project(g3)
include_directories(externals/smooth/include)
add_subdirectory(externals/smooth)
add_executable(g3 main/main.cpp)
target_link_libraries(g3 smooth pthread)
or, we can use an empty cpp file like this and link in the main library:
project(g3)
include_directories(externals/smooth/include)
add_subdirectory(main)
add_subdirectory(externals/smooth)
add_executable(g3 empty.cpp)
target_link_libraries(g3 main smooth pthread)
The first alternative is no good because of duplication. The second is slightly better, but still rather ugly. I'd prefer removing the requirement of putting files in "main" so that the top-level c-list can be used both for Linux and IDF.
For reference, the top-level project is here:
https://github.com/PerMalmberg/IO-Card- ... eLists.txt
and the submodule is here:
https://github.com/PerMalmberg/Smooth/b ... eLists.txt
Issue 1,2 and 4 are at least solvable or has a workaround, but number 3 still prevents me from getting any further. What's your take on this Angus?
Re the IDF_PLATFORM, should I create a PR for that or is it already on its way?