cmake_minimum_required(VERSION 3.2) project(mqtt_cassandra_bridge) find_package(Boost COMPONENTS system program_options unit_test_framework REQUIRED) include(ExternalProject) set(SHARED_COMPILE_OPTIONS "-std=c++14") set(SHARED_SOURCES misc_support.h) # Cassandra set(CPP_DRIVER ${CMAKE_CURRENT_BINARY_DIR}/cpp-driver) ExternalProject_Add(cpp-driver URL https://github.com/datastax/cpp-driver/archive/2.1.0-beta.tar.gz URL_MD5 d3cfde8731acc2f0f51ef9caf41068dc PREFIX ${CPP_DRIVER} # PATCH_COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/cmake-cassandra.tmp.cmake /CMakeLists.txt CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_C_COMPILER:FILE=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER:FILE=${CMAKE_CXX_COMPILER} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_LD_FLAGS=${CMAKE_LD_FLAGS} ) # ble-toys set(BLE_TOYS ${CMAKE_CURRENT_BINARY_DIR}/ble-toys) ExternalProject_Add(ble-toys GIT_REPOSITORY https://trygvis.io/git/2015/02/ble-toys.git GIT_TAG f6493150c1a7172bcd8c9cc1790829285f707ee9 GIT_SUBMODULES json PREFIX ${BLE_TOYS} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_C_COMPILER:FILE=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER:FILE=${CMAKE_CXX_COMPILER} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_LD_FLAGS=${CMAKE_LD_FLAGS} ) # nghttp2 set(NGHTTP2 ${CMAKE_CURRENT_BINARY_DIR}/nghttp2) ExternalProject_Add(nghttp2 URL https://github.com/tatsuhiro-t/nghttp2/releases/download/v1.0.5/nghttp2-1.0.5.tar.xz URL_MD5 ff25d732d79128c4fa426393a635c21e PREFIX ${NGHTTP2} BUILD_ALWAYS 0 CONFIGURE_COMMAND cd && autoreconf -i && automake && autoconf && ./configure CFLAGS=${CMAKE_C_FLAGS} CXXFLAGS=${CMAKE_CXX_FLAGS} --prefix= --enable-asio-lib ${NGHTTP2_CONFIGURE_EXTRA_ARGS} BUILD_COMMAND cd && make INSTALL_COMMAND cd && make install ) # Mosquitto # TODO: proper discovery # OpenSSL # TODO: proper discovery # sm-mqtt-consumer add_executable(sm-mqtt-consumer sm-mqtt-consumer.cpp cassandra_support.h mqtt_support.h ${SHARED_SOURCES}) add_dependencies(sm-mqtt-consumer cpp-driver) ## Boost target_link_libraries(sm-mqtt-consumer PRIVATE ${Boost_LIBRARIES}) ## Cassandra target_include_directories(sm-mqtt-consumer PRIVATE ${CPP_DRIVER}/include) target_link_libraries(sm-mqtt-consumer PRIVATE ${CPP_DRIVER}/lib/libcassandra.so) ## Mosquitto target_compile_options(sm-mqtt-consumer PUBLIC ${SHARED_COMPILE_OPTIONS}) target_link_libraries(sm-mqtt-consumer PRIVATE mosquitto mosquittopp) ## Ble toys add_dependencies(sm-mqtt-consumer ble-toys) target_include_directories(sm-mqtt-consumer PRIVATE ${BLE_TOYS}/include) target_link_libraries(sm-mqtt-consumer PRIVATE ${BLE_TOYS}/lib/trygvis/libtrygvis-sensor.a) # raw-mqtt-consumer add_executable(raw-mqtt-consumer raw-mqtt-consumer.cpp cassandra_support.h mqtt_support.h ${SHARED_SOURCES}) add_dependencies(raw-mqtt-consumer cpp-driver) ## Boost target_link_libraries(raw-mqtt-consumer PRIVATE ${Boost_LIBRARIES}) ## Cassandra target_include_directories(raw-mqtt-consumer PRIVATE ${CPP_DRIVER}/include) target_link_libraries(raw-mqtt-consumer PRIVATE ${CPP_DRIVER}/lib/libcassandra.so) ## Mosquitto target_compile_options(raw-mqtt-consumer PUBLIC ${SHARED_COMPILE_OPTIONS}) target_link_libraries(raw-mqtt-consumer PRIVATE mosquitto mosquittopp) ## Ble toys add_dependencies(raw-mqtt-consumer ble-toys) target_include_directories(raw-mqtt-consumer PRIVATE ${BLE_TOYS}/include) target_link_libraries(raw-mqtt-consumer PRIVATE ${BLE_TOYS}/lib/trygvis/libtrygvis-sensor.a) # sm-http-server add_executable(sm-http-server sm-http-server.cpp cassandra_support.h http_support.h ${SHARED_SOURCES}) target_compile_options(sm-http-server PUBLIC ${SHARED_COMPILE_OPTIONS}) ## Boost target_link_libraries(sm-http-server PRIVATE ${Boost_LIBRARIES}) ## Cassandra add_dependencies(sm-http-server cpp-driver) target_include_directories(sm-http-server PRIVATE ${CPP_DRIVER}/include) target_link_libraries(sm-http-server PRIVATE ${CPP_DRIVER}/lib/libcassandra.so) ## Nghttp2 add_dependencies(sm-http-server nghttp2) target_include_directories(sm-http-server PRIVATE ${NGHTTP2}/include) target_link_libraries(sm-http-server PRIVATE ${NGHTTP2}/lib/libnghttp2_asio.a ${NGHTTP2}/lib/libnghttp2.a) ## Misc target_link_libraries(sm-http-server PRIVATE ssl crypto pthread) # Testing enable_testing() add_executable(http-tests http-tests.cpp http_support.h) target_compile_options(http-tests PUBLIC ${SHARED_COMPILE_OPTIONS}) add_dependencies(http-tests nghttp2) target_include_directories(http-tests PRIVATE ${NGHTTP2}/include) target_link_libraries(http-tests PRIVATE ${NGHTTP2}/lib/libnghttp2_asio.a ${NGHTTP2}/lib/libnghttp2.a) target_link_libraries(http-tests PRIVATE ssl crypto pthread) target_link_libraries(http-tests PRIVATE ${Boost_LIBRARIES}) target_compile_definitions(http-tests PUBLIC -DBOOST_TEST_DYN_LINK) add_test(NAME http-tests COMMAND http-tests)