Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change cmake #3

Closed
wants to merge 4 commits into from
Closed

Change cmake #3

wants to merge 4 commits into from

Conversation

larsonmpdx
Copy link
Contributor

These changes allow using the base aws iot CMakeLists.txt from an external project using add_subdirectory():

  • change all instances of CMAKE_SOURCE_DIR (this is the path to the original CMakeLists.txt) to PROJECT_SOURCE_DIR (path to the current project or subproject CMakeLists.txt), and fix the resulting paths
  • The network .in file isn't its own project so it gets a different replacement variable, CMAKE_CURRENT_LIST_DIR

I have tested this with openssl on linux. I haven't tested the msvc parts or other network parts, or muchd detailed testing. it meets my needs but probably there are small fixes to get the whole project switched over. I can provide an example "including" CMakeLists.txt if that helps.

I understand you don't normally merge PRs in a public way, but I'd like to see this or something like it to support my add_subdirectory() use case.

@chaurah
Copy link
Contributor

chaurah commented Apr 6, 2017

Hi @larsonmpdx,
Thank you for this contribution. I have actually been considering a few different ways to improve the build system and make it reduce dependencies between the different parts. I have added an internal task for us to take your updates into consideration. But I would definitely like to hear about how you're using the project and what issues you are facing because of cmake or other reasons. It would be extremely helpful as we work towards our next release.

Rahul

@larsonmpdx
Copy link
Contributor Author

I'm using it for a basic logging project. I was using the C library but I ran into some odd bugs around connecting/disconnecting that this library avoids, and I don't have any resource constraints. Also, I need the pluggable openssl support in this library in order to use the ATECC-508A crypo chip down the line, and the shadow handling is better.

I clone aws-iot-device-sdk-cpp into a subdirectory in my project with git submodule and then use my own cmakelists.txt (sanitized example below). If the original "CMAKE_" variables replaced in this PR were present they'd reference the directory of my cmakelists.txt and the build wouldn't work. From some googling this is a common cmake problem and changing to the "PROJECT_" variables is the typical solution.

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(logger CXX)

# Set required compiler standard to standard c++11. Disable extensions.
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11

# Configure Compiler flags
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CUSTOM_COMPILER_FLAGS "-Wall -Wpointer-arith -Wcast-qual -Wcast-align")

add_subdirectory(deps/aws-iot-device-sdk-cpp/)

set(LOGGER_TARGET_NAME logger_cxx)
set(LOGGER_SOURCES
        logger.cc;
        [other files ...]
)
add_executable(${LOGGER_TARGET_NAME} "${LOGGER_SOURCES}")

# Add SDK includes
target_include_directories(${LOGGER_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/deps/aws-iot-device-sdk-cpp/common)
target_include_directories(${LOGGER_TARGET_NAME} PUBLIC ${CMAKE_BINARY_DIR}/third_party/rapidjson/src/include)
target_include_directories(${LOGGER_TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/deps/aws-iot-device-sdk-cpp/include)

set(SDK_TARGET_NAME aws-iot-sdk-cpp)
target_link_libraries(logger_cxx PUBLIC ${SDK_TARGET_NAME} [other libs...])

# Add Network libraries #
set(NETWORK_WRAPPER_DEST_TARGET ${LOGGER_TARGET_NAME})
include(${PROJECT_SOURCE_DIR}/deps/aws-iot-device-sdk-cpp/network/CMakeLists.txt.in)

@chaurah
Copy link
Contributor

chaurah commented Apr 18, 2017

Hi @larsonmpdx,
Thanks for the background information. Do you mind if I ask about how you're implementing the logging code? Are you simply publishing to a pre-decided topic? I have been wondering if a basic logging client makes sense for a while now. It could be useful for both general use as well as simply as a logging stream in addition to the console log stream for SDK logs.

This particular pull request will be a part of the next release of the SDK. If you find any further issues that can be addressed please do let us know.

Rahul

@larsonmpdx
Copy link
Contributor Author

I'm just calling it a logger, it records IoT sensor data. We do publish all messages from all clients to a single mqtt topic because the aws managed mqtt product is able to keep track of client id separate from the mqtt topic and add it back at the message broker. General log messages going to another topic sounds like a good idea.

Thanks for looking at this

@lolsborn
Copy link

lolsborn commented May 16, 2017

This change is super useful for us too. Right now this library is a thorn in my side because it's the only cmake dependency that I have to build and link to separately.

I had to also update the unit tests CMakeLists.

It would be great if there was a flag or something to disable building tests / samples.

@larsonmpdx larsonmpdx mentioned this pull request Jun 5, 2017
@chaurah
Copy link
Contributor

chaurah commented Jun 7, 2017

This pull request has been merged in v1.1 release of the SDK.
Rahul

@chaurah chaurah closed this Jun 7, 2017
ebolton-density referenced this pull request in DensityCo/aws-iot-device-sdk-cpp Jul 6, 2022
Improved help prompt.
Support reading privkey from file.
Support combining flags.
Clean-up and improved code readability.
Fixed bug with None types when passing to provisiond.
/dpu/<sn> as topic header
elryno referenced this pull request in DensityCo/aws-iot-device-sdk-cpp Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants