This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Differentiating compiler options between ZDebug and ZRelease build configs with NCS/SES

The following questions are in regards to the instructions at nRF_Connect_SDK-modifying-a-sample-application.

In the Windows environment, I am transitioning from using nRF5_SDK_16.0.0 to using

  • nRF Connect SDK v1.3.0, with
  • SES 4.52
  • board nrf52840dk_nrf52840.

1. In the section NRF_Connect_SDK-configuring-build-types, it's not clear to me as to how to set compiler options individually per build configs ZDebug vs ZRelease.

  • For example, if we want the ZDebug build to include compiler options like "-g -O0 -DDEBUG" but the ZRelease build to instead include compiler options like "-O3 -DNDEBUG", how do we do this?

The figure in maintaining-cmakelist-txt-in-ses shows how to set compiler defines and options, but those options would apply to both ZDebug and ZRelease, as far as I can tell.

Furthermore, when I built nrf_desktop for ZDebug and then ZRelease to see what happens, I saw in the build outputs that both builds had "-O2" and "-g" compiler options.

  • There were very few differences between those two build outputs other than things like ZDebug had an include path for rtt but ZRelease did not, as you would expect when you look at the diff between the debug/release .conf files.
  • I was hoping to see at least some optimization differences, or at least a "-DDEBUG" difference, between the two build outputs to help me figure out the answer to this question.

2. In my opinion, the section selecting-a-build-type-in-ses or the previous section should indicate that the SES menus "Build/Build Configuration" and "Build/Set Active Build Configuration" are not applicable with this SDK. I originally was looking for ZDebug and ZRelease options to show up in those menus after following the instructions in the previous section.

3. In the instruction on how to set the CONF_FILE variable for the build configs (see step 2 in Creating build type files), doesn't the path "${CMAKE_CURRENT_SOURCE_DIR}" need to be in the CONF_FILE setting, as in:

if (CMAKE_BUILD_TYPE)

  set(CONF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/app_${CMAKE_BUILD_TYPE}.conf")

endif()

  • I found this path addition necessary. Without that path, the conf file was not found by cmake, as I learned when using assert_exists(CONF_FILE).

4. Is there something special with the names ZDebug and ZRelease vs traditional build config names Debug and Release?

  • I assume there is a link that describes these names, but I can't find one.  If you can provide a link and it's for Zephyr in general, is there any additional meaning here for nRF usage in the SDK not described in that link?

5. Is building with the command line, and perhaps just using SES for a debugger tool, the easier way to go with this SDK?

In general, I am pleased with Nordic documentation, but perhaps I am not finding the right places to look for the questions above.

  • Hi Mike, 

    I am working on your case and will reply next week.

    -Amanda H. 

  • Hi Mike,

    For example, if we want the ZDebug build to include compiler options like "-g -O0 -DDEBUG" but the ZRelease build to instead include compiler options like "-O3 -DNDEBUG", how do we do this?

    You can edit prj.conf and add "NO_OPTIMIZATIONS=Y" to set compiler optimizations as -O0 or "DEBUG_OPTIMIZATIONS=Y" to set the compiler optimizations as -Og. Please see <choice: Optimization level>.

     

    I was hoping to see at least some optimization differences, or at least a "-DDEBUG" difference, between the two build outputs to help me figure out the answer to this question.

     If you want to see the difference between compile optimization, you should see <choice: Optimization level>.

    2. In my opinion, the section selecting-a-build-type-in-ses or the previous section should indicate that the SES menus "Build/Build Configuration" and "Build/Set Active Build Configuration" are not applicable with this SDK. I originally was looking for ZDebug and ZRelease options to show up in those menus after following the instructions in the previous section.

    See the Selecting a build type in SES section on how to build the project with the app_ZDebug .conf and app_ZRelease.conf. 

    3. In the instruction on how to set the CONF_FILE variable for the build configs (see step 2 in Creating build type files), doesn't the path "${CMAKE_CURRENT_SOURCE_DIR}" need to be in the CONF_FILE setting, as in:

    I will report it. 

    4. Is there something special with the names ZDebug and ZRelease vs traditional build config names Debug and Release?

     The nRF Desktop does not use a single prj.conf file. Configuration files are provided for different build types for each supported board as here as the Creating build type files section described. If you take a look at configuration/nrf52840gmouse_nrf52840, you could see the files named with ZRelease and ZDebug as nRF Desktop build types describe:

    ZRelease – Release version of the application with no debugging features. 

    ZDebug – Debug version of the application; the same as the ZRelease build type, but with debug options enabled.

    Comparing the app_ZDebug.conf and app_ZRelease.conf, you could see what debug options are enabled.

     

    is there any additional meaning here for nRF usage in the SDK not described in that link?

     Please see build types are available for various boards in nRF Desktop in the nRF Desktop build types.

     

    5. Is building with the command line, and perhaps just using SES for a debugger tool, the easier way to go with this SDK?

    SES also can build the project. It depends on your habit. 

    -Amanda H.

  • Thanks Amanda.

    1. I understand your reply, and it makes perfect sense.  I'm trying this out on the central_uart sample, but I'm not seeing any affect yet in the build output.  I'll double check my steps tomorrow and provide more details if I am still unsuccessful.

    As an aside, I think it would helpful in the section maintaining-cmakelist-txt-in-ses, where it says "In the window that is displayed, you can define compilation options for the project", that someone adds a note there that you can set the compiler optimization levels (which to me are still compilation options) in the conf file, as you explained.   That is, that "window" they are talking about there is not the only place you can define compilation options. You can also do so in the conf files. Just a suggestion. 

    2. You pointed to the same place that I pointed to.  I was just making a suggestion that that section could possibly be more helpful with the information I suggested to add.

    3. Thanks.  By the way, my discovery here was for the central_uart sample.

    4. I see.  So it seems that the Z (for Zephyr) is just a convention, as in ZDebug/ZRelease.  So in my own projects, would there be any hidden problem if I go unconventional (not that I would) and use names app_debug.conf and app_release.conf instead of app_ZDebug.conf and app_ZRelease.conf, as long as I account for those names in the CMakeLists.txt?

  • Hi Mike,

    variant said:
    would there be any hidden problem if I go unconventional (not that I would) and use names app_debug.conf and app_release.conf instead of app_ZDebug.conf and app_ZRelease.conf, as long as I account for those names in the CMakeLists.txt?

    From the engineer:

    The CMAKE_BUILD_TYPE is actually a special variable in cmake. Zephyr does not handle it, so if you use one of the values from the documentation cmake will take over and add some changes to variables used during the building process (for example cflags). You don't want this to happen as it may contradict definitions from kconfig.

    I didn't want to introduce yet another variable so I reused cmake_build_type with "Z" prefix to build chose configuration. Since these are unknown to cmake it won't add anything specific by itself.

    (At the moment I tend to think that it might have been better to introduce the new variable to have more flexibility and avoid confusion.)

    -Amanda H. 

  • Hi Amanda,

    Thank you for the responses.  I’m still having trouble with item 1. 

    I can effect a compiler optimization change in the nrf_desktop app, but not in a sample project such as nrf\samples\bluetooth\central_uart.

    The nrf_desktop\configuration\nrf52840dk_nrf52840\app_ZDebug.conf has

    CONFIG_SPEED_OPTIMIZATIONS=y

    • In fact, all 50 .conf files in that project, be it ZDebug or ZRelease variants, have the CONFIG_SPEED_OPTIMIZATIONS=y.

    That default config results in all 207 compile commands in the build output to have the “-O2” option, which makes sense.

     If I change that CONFIG line in nrf_desktop’s nrf52840dk_nrf52840\app_ZDebug.conf to this: 

    CONFIG_SIZE_OPTIMIZATIONS=y

    Then I see all 207 compile commands have the “-Os” option instead of the “-O2” option, which also makes sense.  So far so good.

    Now, whatever I do for the central_uart project, I can’t get the compiler optimization to change in the build output. 

    First, the default prj.conf file for central_uart (with no changes on my part) results in:

    • 176 compiles, of which all 176 compiles have the “-Os” option. 
    • Also, 28 of the 176 files additionally have a “-O2” (the later -O2 overrules the earlier -Os in the compile command) for the 28 files in the bluetooth_controller library. 

    So that’s the default baseline: -Os, with some additional -O2 just for one library.  Now, here's my attempt to make a change in the compiler optimization.

    In CMakeLists.txt, I added this in the Nordic SDK App section:

    if (CMAKE_BUILD_TYPE) 
       set(CONF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/app_${CMAKE_BUILD_TYPE}.conf")
    endif()
    message(STATUS "NOTE: CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
    message(STATUS "NOTE: CONF_FILE: ${CONF_FILE}")

    In SES/Tools/Options/nRF Connect/Additional CMake Options, I added this:  '

    -DCMAKE_BUILD_TYPE=ZDebug

    I copied prj.conf to app_ZDebug.conf.

    In app_ZDebug.conf, I added the line shown below.  (I also tried this in app_ZRelease.conf when selecting ZRelease instead of ZDebug.)

    CONFIG_NCS_SAMPLES_DEFAULTS=y
    # My addition
    CONFIG_SPEED_OPTIMIZATIONS=y
    #end my addition.
     

    I also tried this:

    CONFIG_NCS_SAMPLES_DEFAULTS=y
    # My additions
    CONFIG_SIZE_OPTIMIZATIONS=n
    CONFIG_SPEED_OPTIMIZATIONS=y
    #end my additions.
     

    When I open the nRF SDK project in SES (with the Clean Build Directory option selected), I see this (i.e., I see my NOTE prints that I added in CMakeLists.txt):

    -- Cache files will be written to: C:/ncs/v1.3.0/zephyr/.cache
    CMake Warning at C:/ncs/v1.3.0/zephyr/CMakeLists.txt:1384 (message):
      __ASSERT() statements are globally ENABLED
    
    -- NOTE: CMAKE_BUILD_TYPE: ZDebug
    -- NOTE: CONF_FILE: C:/ncs/v1.3.0/nrf/samples/bluetooth/central_uart/app_ZDebug.conf

    No matter what I do in the conf file, I get the same compiler optimization flag in the build output as does the default config (128 -Os, with 28 -O2).  I should be getting 128 files compiled with -O2. 

    I also tried the same type of above CONFIG_* changes in prj.conf when I remove the CMAKE_BUILD_TYPE selection so that the plain old prj.conf is used.  Same thing.  I can’t effect a change in the build output compiler optimization flags in central_uart.

    Can you try using SES as the build tool with the central_uart app and see if you can get the build output to show a change in the compiler optimization flag from the default output, such as trying to get all compile commands to show -O2 instead of all -Os?

    Thanks!

Related