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, 

    It seems that the config files are not used. You can modify like this:

    # Define configuration files.
    set(CONF_FILE "configuration/${BOARD}/app_${CMAKE_BUILD_TYPE}.conf")
    
    #########################################
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(central_uart)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/main.c
    )
    # NORDIC SDK APP END
    
    zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
    

    I also modify central_uart as this project central_uart_build_type.zip to use build type, and it can work as expected in west build and Segger.  

    -Amanda H.

  • In my comment way above (it says 21 days ago right now), I wrote:

    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}")

    Then I showed in that old comment that my status messages inserted above showed up in the output:

    -- NOTE: CMAKE_BUILD_TYPE: ZDebug
    -- NOTE: CONF_FILE: C:/ncs/v1.3.0/nrf/samples/bluetooth/central_uart/app_ZDebug.conf

    So I'm not sure what you are doing differently than what I already did.  My output above shows that CMAKE found the CONF_FILE.

    Is the issue where the location that we put the conf file?

  • Hi Mike,

    variant said:
    Is the issue where the location that we put the conf file?

    It might be. I use your code in the CMakeLists.txt and modify the location as:

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

    It works as expected. Try this central_uart_build_type_0717.zip

    -Amanda H.

      

  • Hi Amanda,

    From my experiments, I’ve determined that

    • It does matter where we place the CONF_FILE assignment in CMakeLists.txt.
    • It does not matter where we actually put the .conf file within the project.

    In other words:  The .conf file like app_ZRelease.conf can be placed anywhere in the project, so the CONF_FILE value itself doesn’t matter.  But it does matter where in CMakeLists.txt that the CONF_FILE assignment is placed.

    With the first bullet being met, I was able to control the compile optimizations specified in the .conf file.

    Per the first bullet:  In CMakeLists.txt, the CONF_FILE setting must be before the find_package for Zephyr, as in:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    
    cmake_minimum_required(VERSION 3.8.2)
    
    # changes to specify CONF_FILE
    if (CMAKE_BUILD_TYPE)
      set(CONF_FILE "arbitrary/app_${CMAKE_BUILD_TYPE}.conf")
    endif()
    message(STATUS "NOTE: CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
    message(STATUS "NOTE: CONF_FILE: ${CONF_FILE}")
    # end CONF_FILE changes
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(central_uart)
    
     

    Note in the above that the actual location of the .conf file is in an arbitrary place (per the second bullet), under a directory called “arbitrary”, which is under the project directory central_uart.  I could have just as well put the .conf file in the central_uart top-level directory, as in: 

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

     Do you agree?

    The advantage of using CMAKE_CURRENT_SOURCE_DIR when specifying the value of CONF_FILE in CMakeLists.txt is that you can later use an assert_exists() to make sure that the .conf file pointed to by CONF_FILE exists.  I was not able to get the assert_exists() to work properly without using CMAKE_CURRENT_SOURCE_DIR to set the path in the CONF_FILE value. 

    Here's an example using CMAKE_CURRENT_SOURCE_DIR in CONF_FILE, and then using the assert_exists(), which is at the end of the snippet: 

    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}")
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(central_uart)
    assert_exists(CONF_FILE)
    

    Also, as a reminder, mainly for my benefit: Whenever you change the CONF_FILE value in CMakeLists.txt, you must re-open the solution in SES with the Clean Build Directory checked for that change to take affect.  If you don’t change the CONF_FILE value in CMakeLists.txt but change a value within the .conf file (e.g., change the value of CONFIG_SPEED_OPTIMIZATIONS in app_ZRelease.conf), you must re-open the solution in SES, but you don’t need to have the Clean Build Directory checked.

Related