I'm trying to build the iotedge_downstream_device_sample sample from the Azure IoT (https://github.com/Azure/azure-iot-sdk-c.git). I have followed the steps outlined in https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/devbox_setup.md#linux.
After adding cmake_minimum_required(VERSION 3.10) to the third line of azure-iot-sdk-c/iothub_client/samples/iotedge_downstream_device_sample/CMakeLists.txt and I run "cmake .", I get the following error.
CMake Error at CMakeLists.txt:5 (if): if given arguments: "NOT" "AND" "NOT" "AND" "NOT" "ON" Unknown arguments specified
-- Configuring incomplete, errors occurred!
Lines 5-7 of my CMakeLists.txt file are: if(NOT ${use_mqtt} AND NOT ${use_amqp} AND NOT ${use_http}) message(FATAL_ERROR "iotedge_downstream_device_sample being generated without protocol support") endif()
I'm confused by the error message. Is the issue with "use_mqtt"/"use_amqp"/"use_http" not being defined? I would have expected that to be mentioned, not the words "NOT"/"AND"/"ON". I have tried adding the lines to turn on using http and mqtt/amqp off, but it had no effect: option(use_http "set use_http to ON if http is to be used, set to OFF to not use http" ON) option(use_mqtt "set use_mqtt to ON if mqtt is to be used, set to OFF to not use mqtt" OFF) option(use_http "set use_amqp to ON if amqp is to be used, set to OFF to not use amqp" OFF)
There is something fundamental I'm not getting about cmake.
For completeness, here is my entire CMakeLists.txt file: #Copyright (c) Microsoft. All rights reserved. #Licensed under the MIT license. See LICENSE file in the project root for full license information. cmake_minimum_required(VERSION 3.10)
if(NOT ${use_mqtt} AND NOT ${use_amqp} AND NOT ${use_http}) message(FATAL_ERROR "iotedge_downstream_device_sample being generated without protocol support") endif()
compileAsC99()
set(iotedge_downstream_c_files iotedge_downstream_device_sample.c )
IF(WIN32) #windows needs this define add_definitions(-D_CRT_SECURE_NO_WARNINGS) ENDIF(WIN32)
include_directories(.)
add_executable(iotedge_downstream_device_sample ${iotedge_downstream_c_files}) if(${build_as_dynamic}) target_link_libraries(iotedge_downstream_device_sample iothub_client_dll) else() target_link_libraries(iotedge_downstream_device_sample iothub_client)
if(${use_http})
target_link_libraries(iotedge_downstream_device_sample iothub_client_http_transport)
add_definitions(-DUSE_HTTP)
endif()
if(${use_amqp})
target_link_libraries(iotedge_downstream_device_sample iothub_client_amqp_transport iothub_client_amqp_ws_transport)
linkUAMQP(iotedge_downstream_device_sample)
add_definitions(-DUSE_AMQP)
endif()
if(${use_mqtt})
target_link_libraries(iotedge_downstream_device_sample iothub_client_mqtt_transport iothub_client_mqtt_ws_transport)
linkMqttLibrary(iotedge_downstream_device_sample)
add_definitions(-DUSE_MQTT)
endif()
endif()
CMakeLists.txt
is not standalone. You can easilty spot that by absent ofcmake_minimum_required
line. You need to use top-levelCMakeLists.txt
for build libraries and samples. – Tsyvarev