The way proposed in MCUXpresso SDK Projects with NXP CMake Format — MCUXpresso SDK Documentation has several disadvantages: it depends on custom/proprietary NXP CMake extension, and you only can add files one by one, plus it it ignores the standard CMake way of doing things, e.g. global options are not honored.
A much easier way and what is using standard CMake files and rules is what I prefer, and what I'm using.
For example:
- create in the project root directory a folder for your sources, e.g. name it 'src'
- place all your .c and .h files into that src folder.
- Add the attached CMakeLists.txt into that src folder. It will build a library with all the sources name 'srcLib'
- in your SDK root CMakeLists.txt, you have to add the following line to reference the CMakeLists.txt:
add_subdirectory(./src src)
- add the following lines to the root CMakeLists.txt to link with your library:
target_link_libraries(
${MCUX_SDK_PROJECT_NAME}
PUBLIC
srcLib # library of src folder
)
That's it: that way you add your own source files to the SDK, and have full control over it with standard CMake features, and do not depend on any CMake extensions.
I hope this helps,
Erich
-