ARM-software / CMSIS_5

CMSIS Version 5 Development Repository
http://arm-software.github.io/CMSIS_5/index.html
Apache License 2.0
1.33k stars 1.08k forks source link

How to integrate all dsp library in a static library? #1302

Closed EdXian closed 3 years ago

EdXian commented 3 years ago

Hi all, For some reason, I have to integrate all DSP library into a static library something like libarm_cortexM4lf_math.a . The following snippets shows how I build the library:

cmake_minimum_required(VERSION 3.14.0)
project(cmsislib)

set(THIRD_PARTY_PATH ${CMAKE_SOURCE_DIR}/../../thirdparty)
set(ROOT ${THIRD_PARTY_PATH}/CMSIS_5)
set(DSP ${ROOT}/CMSIS/DSP)
list(APPEND CMAKE_MODULE_PATH ${DSP})
add_subdirectory("${DSP}/Source" bin_dsp)

add_library(
    arm_cortexM4lf_math
    $<TARGET_OBJECTS:CMSISDSPBasicMath>
    $<TARGET_OBJECTS:CMSISDSPBayes>
    $<TARGET_OBJECTS:CMSISDSPCommon>
    $<TARGET_OBJECTS:CMSISDSPComplexMath>
    $<TARGET_OBJECTS:CMSISDSPController>
    $<TARGET_OBJECTS:CMSISDSPDistance>
    $<TARGET_OBJECTS:CMSISDSPFastMath>
    $<TARGET_OBJECTS:CMSISDSPFiltering>
    $<TARGET_OBJECTS:CMSISDSPInterpolation>
    $<TARGET_OBJECTS:CMSISDSPMatrix>
    $<TARGET_OBJECTS:CMSISDSPQuaternionMath>
    $<TARGET_OBJECTS:CMSISDSPStatistics>
    $<TARGET_OBJECTS:CMSISDSPSupport>
    $<TARGET_OBJECTS:CMSISDSPSVM>
    $<TARGET_OBJECTS:CMSISDSPTransform>

)

target_compile_definitions(arm_cortexM4lf_math PRIVATE

    )

target_include_directories(
        arm_cortexM4lf_math PRIVATE
        ${DSP}/Include
    )

CMake commands:

cmake -S . -B ./build \
  -DROOT="../../thirdparty/CMSIS_5" \
  -DCMAKE_PREFIX_PATH="/opt/gcc-arm-none-eabi/bin/" \
  -DCMAKE_TOOLCHAIN_FILE="../../thirdparty/CMSIS_5/CMSIS/DSP/gcc.cmake" \
  -DARM_CPU="cortex-m4" \
  -DPLATFORM="FVP" \
  -G "Unix Makefiles" 

After building the library, I found the code size of the static library is 1.8MB which is much smaller than the official-released version. Any Idea?

christophe0606 commented 3 years ago

@EdXian Indeed, as you have seen, the current cmake is not building a final CMSIS-DSP library but only the intermediate libraries : one per sub folder.

The CMSIS-DSP library is a virtual library but in cmake can be used as a normal library and it will link the sub-libraries.

Of course, if the goal is to build a new CMSIS-DSP static library then you need to add another step as you have done.

What was the size of the officially released version ?

I am getting a similar size when building the library through cmake and linking all of the intermediate libraries (like libCMSISDSPBasicMath.a) into a final library.

In cmake you can also do:

add_library(arm_cortexM4lf_math STATIC)
target_link_libraries(arm_cortexM4lf_math PRIVATE CMSISDSP)

and remove the $ ...

and it should work and link all the sub libraries into your final libarm_cortexM4lf_math.a

EdXian commented 3 years ago

Hi @christophe0606 , The officially released version (v5.7.0) is downloaded from this page. The size of libarm_cortexM4lf_math.a is about 6MB.

christophe0606 commented 3 years ago

@EdXian Have you tried fromelf or size commands to dump the sections ? It may give an idea of the origin of the difference. Perhaps debug symbols ?

EdXian commented 3 years ago

Hi @christophe0606 , You are right! I trired to give the following command to build the static library.

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -g ")

Finally, I got a new static library which size is about 6 MB. BTW, I just tested some dsp function with these two libraries and both of them could compute the same result.

christophe0606 commented 3 years ago

@EdXian Great you was able to solve your issue.