I am experimenting with different build options using CMAKE for module creation. My proposed build process looks something like this
Step 1: Build static library (MY_LIB.lib) from several source files for my px4 module. This happens outside of the main CMAKE build process
Step 2: Generate a CMAKE list from the above build. Move the files over (header, library.a and cmakelist.txt) into Firmware\src\module<my_module>
Step 3: Initiate the build process (ie: make px4fmu-v2_ekf2)
My Cmakelist.txt looks something like this:
px4_add_module( MODULE examples__module_app MAIN my_module_app STACK_MAIN 2000 SRCS empty_file.c DEPENDS platforms__common ) target_link_libraries(examples__ module_app MY_LIB.lib)
Where MY_LIB.lib is the shared library I built manually by hand.
Unfortunately I’m stuck with a bit of a problem here. It seems that when I compile my source files into a static library and start the build process there seems to be some linking problems at the very end of Step3.
For instance, certain POSIX functions like ‘perror’ or ‘timer_create’ are undefined references when using the shared library method. The strange thing is that if I did not use the shared library method and built my module by listing all the individual .c files
In my CMAKE list like so:
px4_add_module( MODULE examples__module_app MAIN my_module_app STACK_MAIN 2000 SRCS Main.c #contains POSIX functoins like timer_create empty_file.c DEPENDS platforms__common )
This works without issues.
In Step1, I made sure to have the same include paths and build define macros from the ones that get generated by CMAKE. I referrred to the generated flags found within flags.cmake
Current include dirs for Step1:
Firmware/src Firmware/build_px4fmu-v2_ekf2 Firmware/build_px4fmu-v2_ekf2/src Firmware/src/modules Firmware/src/include Firmware/src/lib Firmware/src/platforms Firmware/src/drivers/boards/px4fmu-v2 Firmware/build_px4fmu-v2_ekf2/src/modules/px4_messages Firmware/build_px4fmu-v2_ekf2/src/modules Firmware/mavlink/include/mavlink Firmware/src/lib/DriverFramework/framework/include Firmware/src/lib/matrix Firmware/build_px4fmu-v2_ekf2/px4fmu-v2/NuttX/nuttx-export/include Firmware/build_px4fmu-v2_ekf2/px4fmu-v2/NuttX/nuttx-export/include/cxx Firmware/build_px4fmu-v2_ekf2/px4fmu-v2/NuttX/nuttx-export/arch/chip Firmware/build_px4fmu-v2_ekf2/px4fmu-v2/NuttX/nuttx-export/arch/common Firmware/build_px4fmu-v2_ekf2/external/Install/include
Is there a way to over-ride the common flags for a module in the CMAKE process with my own? it seems the common build flags apply to all modules. Ideally, i’d like to customize everything inside flags.make