Skip to content

Commit

Permalink
Makes the SDK installable and a find module in CMake. Builds with -fP…
Browse files Browse the repository at this point in the history
…IC always.
  • Loading branch information
andrew-buckley committed Nov 9, 2016
1 parent 63cdf6b commit 3cce7d1
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 91 deletions.
115 changes: 44 additions & 71 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ option(build_python "builds the Python native iothub_client module" OFF)
option(build_javawrapper "builds the native iothub_client library for java C wrapper" OFF)
option(dont_use_uploadtoblob "set dont_use_uploadtoblob to ON if the functionality of upload to blob is to be excluded, OFF otherwise. It requires HTTP" OFF)
option(no_logging "disable logging" OFF)
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF)
option(use_firmware_update "build the Raspberry PI firmware_update sample" OFF)

#setting nuget_e2e_tests will only generate e2e tests to run with nuget packages. Install-packages from Package Manager Console in VS before building the projects
Expand Down Expand Up @@ -77,11 +78,9 @@ endif()

if (LINUX)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
if((NOT "${build_python}" STREQUAL "OFF") OR ("${build_javawrapper}" STREQUAL "ON"))
# now all static libraries use PIC flag for Python shared lib
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")
endif()
# now all static libraries use PIC flag for Python shared lib
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")
endif()
endif()

Expand All @@ -94,14 +93,13 @@ if(NOT "${compileOption_CXX}" STREQUAL "OFF")
set(CMAKE_CXX_FLAGS "${compileOption_CXX} ${CMAKE_CXX_FLAGS}")
endif()

add_subdirectory(c-utility)
add_subdirectory(uamqp)
add_subdirectory(umqtt)

enable_testing()
include("dependencies.cmake")

if(NOT ${skip_unittests})
include("dependencies-test.cmake")
endif()

include_directories(${SHARED_UTIL_INC_FOLDER}/azure_c_shared_utility)
enable_testing()

#this project uses several other projects that are build not by these CMakeFiles
#this project also targets several OSes
Expand Down Expand Up @@ -136,66 +134,7 @@ if (NOT DEFINED ARCHITECTURE OR ARCHITECTURE STREQUAL "")
endif()
message(STATUS "iothub architecture: ${ARCHITECTURE}")

function(linkUAMQP whatExecutableIsBuilding)
include_directories(${UAMQP_INC_FOLDER})

if(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)

target_link_libraries(${whatExecutableIsBuilding} uamqp aziotsharedutil ws2_32 secur32)

if(${use_openssl} OR ${use_wsio})
target_link_libraries(${whatExecutableIsBuilding} $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)

file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
else()
target_link_libraries(${whatExecutableIsBuilding} uamqp aziotsharedutil ssl crypto)
endif()

if(${use_wsio})
target_link_libraries(${whatExecutableIsBuilding} websockets)
endif()
endfunction(linkUAMQP)

function(includeMqtt)
include_directories(${MQTT_INC_FOLDER})
endfunction(includeMqtt)

function(linkMqttLibrary whatExecutableIsBuilding)
includeMqtt()
target_link_libraries(${whatExecutableIsBuilding} umqtt)
endfunction(linkMqttLibrary)

function(includeHttp)
endfunction(includeHttp)

function(linkHttp whatExecutableIsBuilding)
includeHttp()
if(WIN32)
if(WINCE)
target_link_libraries(${whatExecutableIsBuilding} crypt32.lib)
target_link_libraries(${whatExecutableIsBuilding} ws2.lib)
else()
target_link_libraries(${whatExecutableIsBuilding} winhttp.lib)
endif()
else()
target_link_libraries(${whatExecutableIsBuilding} curl)
endif()
endfunction(linkHttp)

function(linkWebSockets whatExecutableIsBuilding)
if(${use_wsio})
target_link_libraries(${whatExecutableIsBuilding} websockets)
endif()
endfunction(linkWebSockets)

function(linkSharedUtil whatIsBuilding)
target_link_libraries(${whatIsBuilding} aziotsharedutil)
endfunction(linkSharedUtil)
include("configs/azure_iot_sdksFunctions.cmake")

macro(compileAsC99)
if (CMAKE_VERSION VERSION_LESS "3.1")
Expand Down Expand Up @@ -247,3 +186,37 @@ endif()
if("${build_javawrapper}" STREQUAL "ON")
add_subdirectory(../javawrapper/device/iothub_client_javawrapper javawrapper)
endif()


if(${use_installed_dependencies})
#Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)

#Install azure_iot_sdks
set(package_location "cmake")

include(CMakePackageConfigHelpers)

configure_file("configs/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
COPYONLY
)

install(EXPORT azure_iot_sdksTargets
FILE
"${PROJECT_NAME}Targets.cmake"
DESTINATION
${package_location}
)

install(
FILES
"configs/${PROJECT_NAME}Config.cmake"
"configs/${PROJECT_NAME}Functions.cmake"
DESTINATION
${package_location}
)

else()
message(WARNING "This package may only be installed when 'use_installed_dependencies' is ON")
endif()
10 changes: 10 additions & 0 deletions configs/azure_iot_sdksConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

include("${CMAKE_CURRENT_LIST_DIR}/azure_iot_sdksTargets.cmake")

get_target_property(IOTHUB_CLIENT_INCLUDES iothub_client INTERFACE_INCLUDE_DIRECTORIES)

set(IOTHUB_CLIENT_INCLUDES ${IOTHUB_CLIENT_INCLUDES} CACHE INTERNAL "")

include("${CMAKE_CURRENT_LIST_DIR}/azure_iot_sdksFunctions.cmake")
63 changes: 63 additions & 0 deletions configs/azure_iot_sdksFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

function(linkUAMQP whatExecutableIsBuilding)
include_directories(${UAMQP_INC_FOLDER})

if(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)

target_link_libraries(${whatExecutableIsBuilding} uamqp aziotsharedutil ws2_32 secur32)

if($<BOOL:${use_openssl}> OR $<BOOL:${use_wsio}>)
target_link_libraries(${whatExecutableIsBuilding} $ENV{OpenSSLDir}/lib/ssleay32.lib $ENV{OpenSSLDir}/lib/libeay32.lib)

file(COPY $ENV{OpenSSLDir}/bin/libeay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
file(COPY $ENV{OpenSSLDir}/bin/ssleay32.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
endif()
else()
target_link_libraries(${whatExecutableIsBuilding} uamqp aziotsharedutil ssl crypto)
endif()

if($<BOOL:${use_wsio}>)
target_link_libraries(${whatExecutableIsBuilding} websockets)
endif()
endfunction(linkUAMQP)

function(includeMqtt)
include_directories(${MQTT_INC_FOLDER})
endfunction(includeMqtt)

function(linkMqttLibrary whatExecutableIsBuilding)
includeMqtt()
target_link_libraries(${whatExecutableIsBuilding} umqtt)
endfunction(linkMqttLibrary)

function(includeHttp)
endfunction(includeHttp)

function(linkHttp whatExecutableIsBuilding)
includeHttp()
if(WIN32)
if(WINCE)
target_link_libraries(${whatExecutableIsBuilding} crypt32.lib)
target_link_libraries(${whatExecutableIsBuilding} ws2.lib)
else()
target_link_libraries(${whatExecutableIsBuilding} winhttp.lib)
endif()
else()
target_link_libraries(${whatExecutableIsBuilding} curl)
endif()
endfunction(linkHttp)

function(linkWebSockets whatExecutableIsBuilding)
if($<BOOL:${use_wsio}>)
target_link_libraries(${whatExecutableIsBuilding} websockets)
endif()
endfunction(linkWebSockets)

function(linkSharedUtil whatIsBuilding)
target_link_libraries(${whatIsBuilding} aziotsharedutil)
endfunction(linkSharedUtil)
14 changes: 14 additions & 0 deletions dependencies-test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

if(${use_installed_dependencies})
#These need to be set for the functions included by c-utility
set(SHARED_UTIL_SRC_FOLDER "${CMAKE_CURRENT_LIST_DIR}/c-utility/src" CACHE INTERNAL "")
set(SHARED_UTIL_ADAPTER_FOLDER "${CMAKE_CURRENT_LIST_DIR}/c-utility/adapters")
set(SHARED_UTIL_FOLDER "${CMAKE_CURRENT_LIST_DIR}/c-utility")
set_platform_files("${CMAKE_CURRENT_LIST_DIR}/c-utility")
if(NOT umock_c_FOUND)
find_package(umock_c REQUIRED CONFIG)
include_directories(${UMOCK_C_INCLUDES})
endif()
endif()
26 changes: 26 additions & 0 deletions dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.

if(${use_installed_dependencies})
if(NOT azure_c_shared_utility_FOUND)
find_package(azure_c_shared_utility REQUIRED CONFIG)
endif()
if(NOT uamqp_FOUND)
find_package(uamqp REQUIRED CONFIG)
endif()
if(NOT umqtt_FOUND)
find_package(umqtt REQUIRED CONFIG)
endif()
if(${use_wsio})
if(NOT libwebsockets_FOUND)
find_package(libwebsockets REQUIRED CONFIG)
endif()
endif()

include_directories(${AZURE_C_SHARED_UTILITY_INCLUDES}/azure_c_shared_utility)
else()
add_subdirectory(c-utility)
add_subdirectory(uamqp)
add_subdirectory(umqtt)
include_directories(${SHARED_UTIL_INC_FOLDER}/azure_c_shared_utility)
endif()
37 changes: 25 additions & 12 deletions iothub_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ if(NOT ${dont_use_uploadtoblob})
include_directories(../parson)
endif()

include_directories(${AZURE_C_SHARED_UTILITY_INCLUDES})
include_directories(${SHARED_UTIL_INC_FOLDER})

if (WINCE)
Expand Down Expand Up @@ -207,6 +208,7 @@ if(${use_http})
endif()

if(${use_amqp})
include_directories(${UAMQP_INCLUDES})
include_directories(${IOTHUB_CLIENT_AMQP_TRANSPORT_INC_FOLDER} ${UAMQP_INC_FOLDER})
add_library(iothub_client_amqp_transport
${iothub_client_amqp_transport_c_files}
Expand All @@ -221,6 +223,7 @@ if(${use_amqp})
endif()

if(${use_mqtt})
include_directories(${UMQTT_INCLUDES})
include_directories(${IOTHUB_CLIENT_MQTT_TRANSPORT_INC_FOLDER} ${MQTT_INC_FOLDER})
add_library(iothub_client_mqtt_transport
${iothub_client_mqtt_transport_c_files}
Expand Down Expand Up @@ -283,18 +286,28 @@ endif()
endif()

if(NOT IN_OPENWRT)
# Disable tests for OpenWRT
if(NOT ${skip_unittests})
add_subdirectory(tests)
endif()
# Disable tests for OpenWRT
if(NOT ${skip_unittests})
add_subdirectory(tests)
endif()
endif()

if(WIN32)
if(${use_installed_dependencies})
#Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)

if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()

install(TARGETS ${iothub_client_libs} EXPORT azure_iot_sdksTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot
)
install(FILES ${iothub_client_h_install_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot)

else()
install (TARGETS
${iothub_client_libs}
DESTINATION lib)
install (FILES
${iothub_client_h_install_files}
DESTINATION include/azureiot)
endif (WIN32)
message(WARNING "This package may only be installed when 'use_installed_dependencies' is ON")
endif()
26 changes: 24 additions & 2 deletions iothub_service_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ endif()
include_directories(${SHARED_UTIL_INC_FOLDER})

include_directories(${UAMQP_INC_FOLDER})
include_directories(${UAMQP_INCLUDES})

set(IOTHUB_SERVICE_CLIENT_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "This is the include folder for iothub_service_client" FORCE)

Expand All @@ -68,7 +69,28 @@ if (NOT ${ARCHITECTURE} STREQUAL "ARM")
endif()

if(NOT IN_OPENWRT)
# Disable tests for OpenWRT
add_subdirectory(tests)
# Disable tests for OpenWRT
if(NOT ${skip_unittests})
add_subdirectory(tests)
endif()
endif()

if(${use_installed_dependencies})
#Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)

if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()

install(TARGETS iothub_service_client EXPORT azure_iot_sdksTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot
)
install(FILES ${iothub_service_client_h_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot)

else()
message(WARNING "This package may only be installed when 'use_installed_dependencies' is ON")
endif()
Loading

0 comments on commit 3cce7d1

Please sign in to comment.