Skip to content

Commit

Permalink
various: Enclose string if checks in quotes
Browse files Browse the repository at this point in the history
Fixes possible issues whereby string variables are checked
without being properly encased in quote marks. This is needed
because unescaped variables will be treated as variable names,
then errors will be emitted when they are dereferenced and those
variables do not exist. This fixes issue like the following:

       *************************
       * Running CMake for ncp *
       *************************
    CMake Error at CMakeLists.txt:10 (if):
      if given arguments:
        "STREQUAL" "nrf52840dongle_nrf52840"
      Unknown arguments specified

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
  • Loading branch information
nordicjm committed Jul 25, 2023
1 parent 5ccffbe commit 8b75c62
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion applications/matter_weather_station/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(APPLICATION_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/configuration/\${BOARD}"
set(multiprotocol_rpmsg_KCONFIG_ROOT "\\\${ZEPHYR_CONNECTEDHOMEIP_MODULE_DIR}/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.root")
set(hci_rpmsg_KCONFIG_ROOT "\\\${ZEPHYR_CONNECTEDHOMEIP_MODULE_DIR}/config/nrfconnect/chip-module/Kconfig.hci_rpmsg.root")

if(OVERLAY_CONFIG STREQUAL "overlay-factory_data.conf")
if("${OVERLAY_CONFIG}" STREQUAL "overlay-factory_data.conf")
set(PM_STATIC_YML_FILE ${APPLICATION_CONFIG_DIR}/pm_static_factory_data.yml)
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ endmacro()

function(get_board_without_ns_suffix board_in board_out)
string(REGEX REPLACE "(_?ns)$" "" board_in_without_suffix ${board_in})
if(NOT ${board_in} STREQUAL ${board_in_without_suffix})
if(NOT "${board_in}" STREQUAL "${board_in_without_suffix}")
if (NOT CONFIG_ARM_NONSECURE_FIRMWARE)
message(FATAL_ERROR "${board_in} is not a valid name for a board without "
"'CONFIG_ARM_NONSECURE_FIRMWARE' set. This because the 'ns'/'_ns' ending "
Expand Down
12 changes: 6 additions & 6 deletions samples/bluetooth/direct_test_mode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#
cmake_minimum_required(VERSION 3.20.0)

if (DEFINED SHIELD AND ${BOARD} STREQUAL "nrf5340dk_nrf5340_cpunet")
if(DEFINED SHIELD AND "${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet")
string(REPLACE " " ";" SHIELD_LIST "${SHIELD}")
foreach(sh IN_LIST SHIELD_LIST)
if (${sh} STREQUAL "nrf21540_ek")
if (CONFIG_DTM_USB)
foreach(sh IN LISTS SHIELD_LIST)
if("${sh}" STREQUAL "nrf21540_ek")
if(CONFIG_DTM_USB)
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/nrf21540_ek_usb.overlay)
else()
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/nrf21540_ek.overlay)
Expand All @@ -20,11 +20,11 @@ if (DEFINED SHIELD AND ${BOARD} STREQUAL "nrf5340dk_nrf5340_cpunet")
endforeach()
endif()

if (NOT DEFINED remote_shell_DTC_OVERLAY_FILE AND CONFIG_DTM_USB)
if(NOT DEFINED remote_shell_DTC_OVERLAY_FILE AND CONFIG_DTM_USB)
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/usb.overlay)
endif()

if (CONFIG_DTM_USB)
if(CONFIG_DTM_USB)
set(remote_shell_CONF_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/prj_usb.conf)
endif()

Expand Down
2 changes: 1 addition & 1 deletion samples/matter/light_bulb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(CONF_FILE)
get_filename_component(CONFIG_FILE_NAME ${CONF_FILE} NAME)
endif()

if(NOT CONFIG_FILE_NAME STREQUAL "prj_no_dfu.conf")
if(NOT "${CONFIG_FILE_NAME}" STREQUAL "prj_no_dfu.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

Expand Down
2 changes: 1 addition & 1 deletion samples/matter/light_switch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(CONF_FILE)
get_filename_component(CONFIG_FILE_NAME ${CONF_FILE} NAME)
endif()

if(NOT CONFIG_FILE_NAME STREQUAL "prj_no_dfu.conf")
if(NOT "${CONFIG_FILE_NAME}" STREQUAL "prj_no_dfu.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

Expand Down
4 changes: 2 additions & 2 deletions samples/matter/lock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if(CONF_FILE)
get_filename_component(CONFIG_FILE_NAME ${CONF_FILE} NAME)
endif()

if(CONFIG_FILE_NAME STREQUAL "prj_thread_wifi_switched.conf")
if("${CONFIG_FILE_NAME}" STREQUAL "prj_thread_wifi_switched.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_thread_wifi_switched.yml)
elseif(NOT CONFIG_FILE_NAME STREQUAL "prj_no_dfu.conf")
elseif(NOT "${CONFIG_FILE_NAME}" STREQUAL "prj_no_dfu.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

Expand Down
2 changes: 1 addition & 1 deletion samples/matter/template/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(CONF_FILE)
get_filename_component(CONFIG_FILE_NAME ${CONF_FILE} NAME)
endif()

if(NOT CONFIG_FILE_NAME STREQUAL "prj_no_dfu.conf")
if(NOT "${CONFIG_FILE_NAME}" STREQUAL "prj_no_dfu.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

Expand Down
2 changes: 1 addition & 1 deletion samples/matter/window_covering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CONF_FILE)
get_filename_component(CONFIG_FILE_NAME ${CONF_FILE} NAME)
endif()

if(NOT CONFIG_FILE_NAME STREQUAL "prj_no_dfu.conf")
if(NOT "${CONFIG_FILE_NAME}" STREQUAL "prj_no_dfu.conf")
set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

Expand Down
12 changes: 6 additions & 6 deletions samples/peripheral/radio_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

cmake_minimum_required(VERSION 3.20.0)

if (DEFINED SHIELD AND ${BOARD} STREQUAL "nrf5340dk_nrf5340_cpunet")
if(DEFINED SHIELD AND "${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet")
string(REPLACE " " ";" SHIELD_LIST "${SHIELD}")
foreach(sh IN_LIST SHIELD_LIST)
if (${sh} STREQUAL "nrf21540_ek")
if (CONFIG_RADIO_TEST_USB)
foreach(sh IN LISTS SHIELD_LIST)
if("${sh}" STREQUAL "nrf21540_ek")
if(CONFIG_RADIO_TEST_USB)
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/nrf21540_ek_usb.overlay)
else()
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/nrf21540_ek.overlay)
Expand All @@ -21,11 +21,11 @@ if (DEFINED SHIELD AND ${BOARD} STREQUAL "nrf5340dk_nrf5340_cpunet")
endforeach()
endif()

if (NOT DEFINED remote_shell_DTC_OVERLAY_FILE AND CONFIG_RADIO_TEST_USB)
if(NOT DEFINED remote_shell_DTC_OVERLAY_FILE AND CONFIG_RADIO_TEST_USB)
set(remote_shell_DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/usb.overlay)
endif()

if (CONFIG_RADIO_TEST_USB)
if(CONFIG_RADIO_TEST_USB)
set(remote_shell_CONF_FILE ${CMAKE_CURRENT_LIST_DIR}/conf/remote_shell/prj_usb.conf)
endif()

Expand Down
2 changes: 1 addition & 1 deletion samples/zigbee/ncp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
cmake_minimum_required(VERSION 3.20.0)

# Set USB as default transport when nRF52 Dongle board is selected
if (${BOARD} STREQUAL "nrf52840dongle_nrf52840")
if("${BOARD}" STREQUAL "nrf52840dongle_nrf52840")
set(CONF_FILE "prj_usb.conf")
endif()

Expand Down
8 changes: 3 additions & 5 deletions samples/zigbee/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
cmake_minimum_required(VERSION 3.20.0)

# Set USB as default transport when sample is built for the nRF52 Dongle
if (${BOARD} STREQUAL "nrf52840dongle_nrf52840")
if("${BOARD}" STREQUAL "nrf52840dongle_nrf52840")
set(CONF_FILE "prj_usb.conf")
endif()

# Include app_usb.overlay when sample is built with prj_usb.conf
if (CONF_FILE)
if (${CONF_FILE} STREQUAL "prj_usb.conf")
set(DTC_OVERLAY_FILE "app_usb.overlay")
endif()
if("${CONF_FILE}" STREQUAL "prj_usb.conf")
set(DTC_OVERLAY_FILE "app_usb.overlay")
endif()

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
Expand Down
8 changes: 4 additions & 4 deletions share/ncs-package/cmake/NcsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT NO_BOILERPLATE)
set(EXACT "EXACT")
endif()

if(NOT ${NCS_TOOLCHAIN_MINIMUM_REQUIRED} STREQUAL NONE)
if(NOT "${NCS_TOOLCHAIN_MINIMUM_REQUIRED}" STREQUAL "NONE")
find_package(NcsToolchain ${NCS_TOOLCHAIN_MINIMUM_REQUIRED} ${EXACT} QUIET)
if(${NcsToolchain_FOUND})
message("-- Using NCS Toolchain ${NcsToolchain_VERSION} for building. (${NcsToolchain_DIR})")
Expand All @@ -53,16 +53,16 @@ if(NOT NO_BOILERPLATE)
endif()

set(ZEPHYR_TOOLCHAIN_VARIANT ${NCS_TOOLCHAIN_VARIANT} CACHE STRING "NCS Toolchain Variant")
if(${ZEPHYR_TOOLCHAIN_VARIANT} AND ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL zephyr)
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "zephyr")
set(ZEPHYR_SDK_INSTALL_DIR ${NCS_ZEPHYR_SDK_INSTALL_DIR} CACHE PATH "NCS Zephyr SDK install dir")
endif()
set(GNUARMEMB_TOOLCHAIN_PATH ${NCS_GNUARMEMB_TOOLCHAIN_PATH} CACHE PATH "NCS GNU ARM emb path")

if(${CMAKE_GENERATOR} STREQUAL Ninja)
if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
set(CMAKE_MAKE_PROGRAM ${NCS_TOOLCHAIN_NINJA} CACHE INTERNAL "NCS Toolchain ninja")
endif()

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(env_list_delimeter ";")
else()
set(env_list_delimeter ":")
Expand Down
4 changes: 2 additions & 2 deletions subsys/bootloader/cmake/sign.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if(NCS_SYSBUILD_PARTITION_MANAGER)
set(sign_depends ${slot}_hex)
endif()
else()
if (${slot} STREQUAL "s1_image")
if ("${slot}" STREQUAL "s1_image")
# The s1_image slot is built as a child image, add the dependency and
# path to its hex file accordingly. We cannot use the shared variables
# from the s1 child image since its configure stage might not have executed
Expand Down Expand Up @@ -148,7 +148,7 @@ endif()
elseif (CONFIG_SB_SIGNING_CUSTOM)
set(custom_sign_cmd "${CONFIG_SB_SIGNING_COMMAND}")

if ((custom_sign_cmd STREQUAL "") OR (NOT EXISTS ${SIGNATURE_PUBLIC_KEY_FILE}))
if (("${custom_sign_cmd}" STREQUAL "") OR (NOT EXISTS ${SIGNATURE_PUBLIC_KEY_FILE}))
message(FATAL_ERROR "You must specify a signing command and valid public key file for custom signing.")
endif()

Expand Down
2 changes: 1 addition & 1 deletion subsys/dfu/fmfu_fdev/cddl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ find_program(
clang-format-4
)

if (${CLANG_FORMAT} STREQUAL CLANG_FORMAT-NOTFOUND)
if(NOT CLANG_FORMAT)
message(WARNING
"'clang-format' not found, generated code will not be formatted")
else()
Expand Down
2 changes: 1 addition & 1 deletion subsys/nrf_security/tfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ endif()
# TF-M build require that PSA Crypto APIs are compiled
set(COMPILE_PSA_APIS True)

if (${PROJECT_NAME} STREQUAL "Bootloader")
if ("${PROJECT_NAME}" STREQUAL "Bootloader")
set(CONFIG_CC3XX_MBEDTLS_RSA_C True)
set(CONFIG_MBEDTLS_RSA_C True)
set(CONFIG_MBEDTLS_PKCS1_V21 True)
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/hw_unique_key_tfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
endif()


if (CONFIG_HUK_TEST_BOARD_SNR STREQUAL "")
if("${CONFIG_HUK_TEST_BOARD_SNR}" STREQUAL "")
message(WARNING "If it is to be run on target, this test requires setting "
"CONFIG_HUK_TEST_BOARD_SNR")
else()
Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/zigbee/osif/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ target_compile_definitions(app PRIVATE
# nrfxlib_crypto is linked in here because it can't be linked
# in Zigbee subsys CMakeLists.txt.

if (${BOARD} STREQUAL "nrf5340dk_nrf5340_cpuapp")
if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp")
target_compile_definitions(app PRIVATE
CONFIG_ZIGBEE_USE_SOFTWARE_AES=1
)
)
zephyr_link_libraries(nrfxlib_crypto)
endif()

Expand Down
2 changes: 1 addition & 1 deletion tests/unity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ find_program(
RUBY_EXECUTABLE
ruby
)
if(${RUBY_EXECUTABLE} STREQUAL RUBY_EXECUTABLE-NOTFOUND)
if(NOT RUBY_EXECUTABLE)
message(FATAL_ERROR "Unable to find ruby")
endif()

Expand Down

0 comments on commit 8b75c62

Please sign in to comment.