I'm pretty new to Zephyr and am having trouble adding and compiling code in a sibling folder. This may be further complicated by using PlatformIO, which has a slightly different build structure than the stock Zephyr structure.
The IDE is Visual Studio Code under Windows
The structure of the code is:
Parent Folder
|-ext_library (contains CMakeList.txt)
|--source
|--include
|-zephyr_project (structure generated by PlatformIO)
|--zephyr (contains the master CMakeList.txt and prj.conf)
|--source
|--include
|--lib
What I want to do is add either source files or a static library from ext_library to the zephyr_project with out manually copying source / include files or manually building the library and copying it over.
What I've tried so far:
- Adding a path to ext_library in the FILE(GLOB ...) command in the zephyr_project/zephyr/CMakeList.txt. This command pulls the source files from zephyr_project/source, but doesn't seem to like either relative or static paths to ext_library.
- Adding a CMakeList.txt in the ext_library that compiles a static library. This also requires using add_subdirectory to the zephyr CMakeLists.txt file. This didn't seem to compile the library, however, it appears to have found the ext_library/CMakeLists.txt. The evidence of this is in zephyr_project/lib folder which has some CMake folders that are empty but named the same as the ext_library/CMakeLists.txt. Other evidence is that the message(...) commands in both CMakeLists.txt are being printed.
- Using both static and relative paths to the ext_library folder.
- Using cmake FILE(COPY ...), the files weren't copied. No apparent error.
What has worked: Manually copying code from the ext_library/source and ext_library/include into the appropriate folders in zephyr_project.
Additional info: zephyr_project/zephyr/CMakeLists.txt (original + attempt at adding the ext_library as a subdirectory)
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(firmware)
set(EXT_LIB "C:/Users/mcelr/Desktop/project/ext_library")
add_subdirectory(${EXT_LIB} ${PROJECT_SOURCE_DIR})
FILE(GLOB app_sources
"../src/*.c*"
)
ext_library/CMakeLists.txt (CMAKE_CURRENT_SOURCE_DIR does point to the correct directory at runtime, as confirmed via removed message(...) logging)
cmake_minimum_required(VERSION 3.13.1)
project(ext_lib)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
add_library(ext_lib_zephyr STATIC
${CMAKE_CURRENT_SOURCE_DIR}/source/packet.c
${CMAKE_CURRENT_SOURCE_DIR}/source/checksum.c
)
Thank you so much for any advice or hints to solve this, Austin