|
| 1 | +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) |
| 2 | +project(aws-iot-sdk-cpp CXX) |
| 3 | + |
| 4 | +###################################### |
| 5 | +# Section : Disable in-source builds # |
| 6 | +###################################### |
| 7 | + |
| 8 | +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) |
| 9 | + message( FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder." ) |
| 10 | +endif() |
| 11 | + |
| 12 | +option(BUILD_DOCS "Create HTML based API documentation (requires Doxygen)" OFF) |
| 13 | + |
| 14 | +######################################## |
| 15 | +# Section : Common SDK Build setttings # |
| 16 | +######################################## |
| 17 | + |
| 18 | +# Set required compiler standard to standard c++11. Disable extensions. |
| 19 | +set(CMAKE_CXX_STANDARD 11) # C++11... |
| 20 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... |
| 21 | +set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 |
| 22 | + |
| 23 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archive) |
| 24 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 25 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 26 | + |
| 27 | +# Configure Compiler flags |
| 28 | +if(UNIX AND NOT APPLE) |
| 29 | + # Prefer pthread if found |
| 30 | + set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 31 | + set(CUSTOM_COMPILER_FLAGS "-fno-exceptions -Wall -Werror") |
| 32 | +elseif(APPLE) |
| 33 | + set(CUSTOM_COMPILER_FLAGS "-fno-exceptions") |
| 34 | +elseif(WIN32) |
| 35 | + set(CUSTOM_COMPILER_FLAGS "/W4") |
| 36 | +endif() |
| 37 | + |
| 38 | +############################# |
| 39 | +# Add SDK Target # |
| 40 | +############################# |
| 41 | +# Create library file. The Client applications MUST link to below target if using this CMake file |
| 42 | +set(SDK_TARGET_NAME aws-iot-sdk-cpp) |
| 43 | +add_library(${SDK_TARGET_NAME} "") |
| 44 | + |
| 45 | +# Download and include rapidjson, not optional |
| 46 | +configure_file(CMakeLists-rapidjson.txt.in ${CMAKE_BINARY_DIR}/third_party/rapidjson/download/CMakeLists.txt) |
| 47 | +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . |
| 48 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/third_party/rapidjson/download) |
| 49 | +execute_process(COMMAND ${CMAKE_COMMAND} --build . |
| 50 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/third_party/rapidjson/download) |
| 51 | +target_include_directories(${SDK_TARGET_NAME} PRIVATE ${CMAKE_BINARY_DIR}/third_party/rapidjson/src/include) |
| 52 | + |
| 53 | +# Get Common SDK Sources |
| 54 | +file(GLOB_RECURSE SDK_SOURCES FOLLOW_SYMLINKS ${CMAKE_SOURCE_DIR}/src/*.cpp) |
| 55 | +target_include_directories(${SDK_TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) |
| 56 | +target_sources(${SDK_TARGET_NAME} PRIVATE ${SDK_SOURCES}) |
| 57 | + |
| 58 | +# Configure Threading library |
| 59 | +find_package(Threads REQUIRED) |
| 60 | +set(THREAD_LIBRARY_LINK_STRING "Threads::Threads") |
| 61 | +target_link_libraries(${SDK_TARGET_NAME} "Threads::Threads") |
| 62 | + |
| 63 | +if(BUILD_DOCS) |
| 64 | + find_package(Doxygen REQUIRED) |
| 65 | + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/docs) |
| 66 | + set(DOC_BINARY_DIR ${CMAKE_BINARY_DIR}/docs) |
| 67 | + set(DOC_SOURCE_DIR ${CMAKE_SOURCE_DIR}/.) |
| 68 | + |
| 69 | + set(doxygen_conf_in ${CMAKE_SOURCE_DIR}/doxygen/doxygen.conf.in) |
| 70 | + set(doxygen_conf ${CMAKE_BINARY_DIR}/doxygen/doxygen.conf) |
| 71 | + |
| 72 | + configure_file(${doxygen_conf_in} ${doxygen_conf} @ONLY) |
| 73 | + |
| 74 | + add_custom_target(generate-sdk-docs |
| 75 | + COMMAND ${DOXYGEN_EXECUTABLE} ${doxygen_conf} |
| 76 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/docs |
| 77 | + COMMENT "Generating SDK docs" |
| 78 | + VERBATIM) |
| 79 | +endif() |
| 80 | + |
| 81 | +################################################ |
| 82 | +# Set up directory structure for Visual Studio # |
| 83 | +################################################ |
| 84 | +# TODO : Figure out a better way of handling Visual Studio solutions |
| 85 | +if(MSVC) |
| 86 | + file(GLOB SDK_COMMON_HEADERS "${CMAKE_SOURCE_DIR}/include/*.hpp") |
| 87 | + file(GLOB SDK_UTIL_COMMON_HEADERS "${CMAKE_SOURCE_DIR}/include/util/*.hpp") |
| 88 | + file(GLOB SDK_UTIL_LOGGING_HEADERS "${CMAKE_SOURCE_DIR}/include/util/logging/*.hpp") |
| 89 | + file(GLOB SDK_UTIL_MEMORY_STL_HEADERS "${CMAKE_SOURCE_DIR}/include/util/memory/stl/*.hpp") |
| 90 | + file(GLOB SDK_UTIL_THREADING_HEADERS "${CMAKE_SOURCE_DIR}/include/util/threading/*.hpp") |
| 91 | + file(GLOB SDK_MQTT_HEADERS "${CMAKE_SOURCE_DIR}/include/mqtt/*.hpp") |
| 92 | + file(GLOB SDK_SHADOW_HEADERS "${CMAKE_SOURCE_DIR}/include/shadow/*.hpp") |
| 93 | + |
| 94 | + file(GLOB SDK_COMMON_SOURCES "${CMAKE_SOURCE_DIR}/src/*.cpp") |
| 95 | + file(GLOB SDK_UTIL_COMMON_SOURCES "${CMAKE_SOURCE_DIR}/src/util/*.cpp") |
| 96 | + file(GLOB SDK_UTIL_LOGGING_SOURCES "${CMAKE_SOURCE_DIR}/src/util/logging/*.cpp") |
| 97 | + file(GLOB SDK_UTIL_THREADING_SOURCES "${CMAKE_SOURCE_DIR}/src/util/threading/*.cpp") |
| 98 | + file(GLOB SDK_MQTT_SOURCES "${CMAKE_SOURCE_DIR}/src/mqtt/*.cpp") |
| 99 | + file(GLOB SDK_SHADOW_SOURCES "${CMAKE_SOURCE_DIR}/src/shadow/*.cpp") |
| 100 | + |
| 101 | + # Required to make Header files visible in Visual Studio |
| 102 | + file(GLOB_RECURSE SDKHeaders FOLLOW_SYMLINKS ${CMAKE_SOURCE_DIR}/include/*.hpp) |
| 103 | + target_sources(${SDK_TARGET_NAME} PUBLIC ${SDKHeaders}) |
| 104 | + |
| 105 | + source_group("Header Files\\aws-iot" FILES ${SDK_COMMON_HEADERS}) |
| 106 | + source_group("Header Files\\aws-iot\\util" FILES ${SDK_UTIL_COMMON_HEADERS}) |
| 107 | + source_group("Header Files\\aws-iot\\util\\logging" FILES ${SDK_UTIL_LOGGING_HEADERS}) |
| 108 | + source_group("Header Files\\aws-iot\\util\\memory\\stl" FILES ${SDK_UTIL_MEMORY_STL_HEADERS}) |
| 109 | + source_group("Header Files\\aws-iot\\util\\threading" FILES ${SDK_UTIL_THREADING_HEADERS}) |
| 110 | + source_group("Header Files\\aws-iot\\mqtt" FILES ${SDK_MQTT_HEADERS}) |
| 111 | + source_group("Header Files\\aws-iot\\shadow" FILES ${SDK_SHADOW_HEADERS}) |
| 112 | + |
| 113 | + source_group("Source Files\\aws-iot" FILES ${SDK_COMMON_SOURCES}) |
| 114 | + source_group("Source Files\\aws-iot\\util" FILES ${SDK_UTIL_COMMON_SOURCES}) |
| 115 | + source_group("Source Files\\aws-iot\\util\\logging" FILES ${SDK_UTIL_LOGGING_SOURCES}) |
| 116 | + source_group("Source Files\\aws-iot\\util\\threading" FILES ${SDK_UTIL_THREADING_SOURCES}) |
| 117 | + source_group("Source Files\\aws-iot\\mqtt" FILES ${SDK_MQTT_SOURCES}) |
| 118 | + source_group("Source Files\\aws-iot\\shadow" FILES ${SDK_SHADOW_SOURCES}) |
| 119 | +endif() |
| 120 | + |
| 121 | +##################################### |
| 122 | +# Section : Define specific Targets # |
| 123 | +##################################### |
| 124 | + |
| 125 | +if(UNIX) |
| 126 | + add_subdirectory(cli) |
| 127 | +endif() |
| 128 | + |
| 129 | +add_subdirectory(tests/integration) |
| 130 | + |
| 131 | +add_subdirectory(tests/unit) |
| 132 | + |
| 133 | +add_subdirectory(samples/PubSub) |
| 134 | + |
| 135 | +add_subdirectory(samples/ShadowDelta) |
0 commit comments