Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding math library with `-lm` to CMake build of nrf mesh breaks SES project generation

I am building a project with CMake, inside nRF SDK for Mesh 3.2.0, which uses the math library:

1. source file includes math.h

2. CMakeLists.txt adds m to target_link_libraries().

This section of the file now looks like this:

target_link_libraries(${target}
    rtt_${PLATFORM}
    uECC_${PLATFORM}
    m)   # added 'm' to link to math library

3. Project builds and links correctly with CMake

4. Attempting to generate Segger projects with -DGENERATE_SES_PROJECTS=ON produces the following error:

CMake Error at CMake/GenerateSESProject.cmake:23 (get_property):
  get_property could not find TARGET m.  Perhaps it has not yet been created.
Call Stack (most recent call first):
  examples/experimental_dimming/dimming_client/CMakeLists.txt:131 (add_ses_project)

5. I cannot find a different way of linking to the math library in the mesh SDK CMake build system:

I have tried the following techniques without success:

5a. Explicitly referencing the .a file for the math library (see https://devzone.nordicsemi.com/f/nordic-q-a/49435/undefined-reference-for-round-function-within-mesh-sdk)

 ... this builds and links OK but also breaks SES project generation in the same way.

5b. Adding CONFIG_NEWLIB_LIBC to CFLAGS _and_ cmake's flags (see https://devzone.nordicsemi.com/f/nordic-q-a/43631/using-math-h-on-nrf9160)

... this makes the SES project and compiles, but fails the link with undefined reference to `sqrt'

5c. Adding lm or -lm to set_target_link_options() (tried both) (see https://devzone.nordicsemi.com/f/nordic-q-a/44735/configure-math-h-lib-with-cmake-on-sdk-mesh/176144)

... this makes the SES project and compiles, but fails the link with undefined reference to `sqrt'

Here is the relevant output when cmake is run:

-- Configuring CMake for nRF5 SDK for Bluetooth Mesh 3.2.0
-- Found PythonInterp: /nix/store/611gq7s9s11w5ri95fbq2adi9ifrhkmn-python3-3.7.4/bin/python (found version "3.7.4")
-- Found Doxygen: /nix/store/4gn9n0n0iqyyxqbzn3835h3rj5qlqsbx-doxygen-1.8.15/bin/doxygen (found version "1.8.15") found components:  doxygen dot
-- SDK_ROOT=[ELIDED]/nRF5_SDK_15.3.0_59ac345 --- set with command line ARG
-- PC-Lint executable not found. Linting disabled.
-- SDK: nRF5_SDK_15.3.0_59ac345
-- Platform: nrf52832_xxAA
-- Arch: cortex-m4f
-- SoftDevice: s132_6.1.1
-- Board: pca10040
-- The C compiler identification is GNU 8.3.1
-- The ASM compiler identification is GNU
-- Found assembler: [ELIDED]/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc
-- Check for working C compiler: [ELIDED]/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc
-- Check for working C compiler:[ELIDED]/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Mscgen not found. Cannot generate message sequence charts in documentation.
-- Target compiler flags are: -mcpu=cortex-m4;-mthumb;-mabi=aapcs;-mfloat-abi=hard;-mfpu=fpv4-sp-d16

Related