Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: trusty
language: cpp
cache: apt
env:
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)

project(qamqp LANGUAGES CXX VERSION 0.5.0)

get_filename_component(QAMQP_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
include(${QAMQP_PATH}/cmake/CMakeSettings.cmake)

add_subdirectory(src)
add_subdirectory(tests/auto)

if (${WITH_TUTORIALS})
message(STATUS "Adding tutorials...")
add_subdirectory(tutorials)
else()
message(STATUS "Not adding tutorials (use -DWITH_TUTORIALS=ON for that)...")
endif()

include(CPack)
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,78 @@ QAMQP
=============
A Qt4/Qt5 implementation of AMQP 0.9.1, focusing primarily on RabbitMQ support.


Building with CMake
------------
- ensure you have the following packages on the `PATH`
- **CMake** >= 3.12
- **Qt** >= 5.9
- **lcov**

- checkout sources
```sh
$ cd ~/src
$ git clone [email protected]:ssproessig/qamqp.git
```

- we are going to build in a separate out-of-tree build directory
- building `Debug` build with default compiler
```sh
$ mkdir -p ~/build/qamqp-debug && cd ~/build/qamqp-debug
$ cmake ~/src/qamqp
$ cmake --build .
```

- building `Release` build with **clang** compiler and **ninja** generator
```sh
$ mkdir -p ~/build/qamqp-clang-release && cd ~/build/qamqp-clang-release
$
$ EXPORT CXX=clang++-10
$
$ cmake -G Ninja ~/src/qamqp
$ cmake --build .
```

- running tests with coverage from inside the build directory
```sh
$ # ... after building, in the build directory
$ ctest -V # -V for verbose output of QTest
$ sh generate_coverage.sh
$ ...
$ firefox coverage/index.html
```

- building a release with **Visual Studio 2019 Win64** (make sure to have **[OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage)** on the `PATH`)
```bat
F:\2019\qamqp>cmake G:\_projects\qamqp
...

F:\2019\qamqp>cmake --build . --parallel 8 --config RelWithDebInfo
...

F:\2019\qamqp>Opencppcoverage --export_type html:coverage --modules "qamqp*.exe" --sources G:\_projects\qamqp\src --optimized_build --cover_children -- ctest -C RelWithDebInfo
...
... open coverage/index.html in your browser ....
...

F:\2019\qamqp>cpack -G ZIP
...
CPack: - package: F:/2019/qamqp/qamqp-0.5.0-ee2bfd8-win64.zip generated.
```


Usage
------------
Use `-DWITH_TUTORIALS=ON` to enable the tutorials in CMake.

* [hello world](https://github.com/mbroadst/qamqp/tree/master/tutorials/helloworld)
* [pubsub](https://github.com/mbroadst/qamqp/tree/master/tutorials/pubsub)
* [routing](https://github.com/mbroadst/qamqp/tree/master/tutorials/routing)
* [rpc](https://github.com/mbroadst/qamqp/tree/master/tutorials/rpc)
* [topics](https://github.com/mbroadst/qamqp/tree/master/tutorials/topics)
* [work queues](https://github.com/mbroadst/qamqp/tree/master/tutorials/workqueues)


Documentation
------------
Coming soon!
Expand Down
5 changes: 5 additions & 0 deletions cmake/00_CMake_Policies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# from CMake 3.1 on: we want the NEW interpretation in of variables
cmake_policy(SET CMP0054 NEW)

# if the generator supports it, generate build_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
65 changes: 65 additions & 0 deletions cmake/01_git_Integration.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# idea shamelessly taken from: http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
# with some additions, e.g. for finding git, checking if source directory is git directory, renaming variables to VCS

# initialize commit variables
set(GIT_BRANCH_DEFAULT "unknown")
set(GIT_COMMIT_ID_DEFAULT "0000000")
set(VCS_BRANCH ${GIT_BRANCH_DEFAULT})
set(VCS_COMMIT_ID ${GIT_COMMIT_ID_DEFAULT})

# we need the local systems git
find_package(Git REQUIRED)

# if we have git ...
if (GIT_FOUND)
# is the source directory under git version control at all?
execute_process(
COMMAND ${GIT_EXECUTABLE} status
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE VCS_IS_GIT
OUTPUT_QUIET
ERROR_QUIET
)

# only if we are under git version control...
if(VCS_IS_GIT EQUAL 0)
# Get the current working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VCS_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VCS_COMMIT_ID
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
if (VCS_BRANCH STREQUAL GIT_BRANCH_DEFAULT OR VCS_COMMIT_ID STREQUAL GIT_COMMIT_ID_DEFAULT)
message(WARNING "! Not building sources from git repository. You need to provide VCS_BRANCH and VCS_COMMIT_ID manually.")
endif()
endif()

# output the version information we are on
message(STATUS "Processing sources from '${CMAKE_SOURCE_DIR}' provided by git")
message(STATUS " on branch: ${VCS_BRANCH}")
message(STATUS " revision: ${VCS_COMMIT_ID}")
# no git -> no versioning
else()
message(WARNING "! No git executable found. Unable to determine VCS_BRANCH and VCS_COMMIT_ID. Provide them manually.")
endif()


# a helper function to add VCS information to the FILE_NAME passed
function(_add_vcs_info_to_file FILE_NAME)
set_property(
SOURCE ${FILE_NAME}
APPEND
PROPERTY COMPILE_DEFINITIONS
GIT_BRANCH="${VCS_BRANCH}" GIT_VERSION="${VCS_COMMIT_ID}"
)
endfunction()
28 changes: 28 additions & 0 deletions cmake/05_CPack_Support.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# if no PACKAGE version is set via CLI parameters, set it to development
if (NOT CPACK_PACKAGE_VERSION)
message(STATUS "! no CPACK_PACKAGE_VERSION parameter seen. Defaulting to development version ${PROJECT_VERSION}")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
endif()

# extract version information to separate numbers
string(REPLACE "." ";" VERSION_LIST ${CPACK_PACKAGE_VERSION})
list(GET VERSION_LIST 0 CPACK_PACKAGE_VERSION_MAJOR)
list(GET VERSION_LIST 1 CPACK_PACKAGE_VERSION_MINOR)
list(GET VERSION_LIST 2 CPACK_PACKAGE_VERSION_PATCH)

# append the git hash to it
set(CPACK_PACKAGE_VERSION_SIMPLE ${CPACK_PACKAGE_VERSION})
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}-${VCS_COMMIT_ID})
message(STATUS " this is version ${CPACK_PACKAGE_VERSION}.")

# general package options
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Qt5 library implementation of AMQP 0.9.1, focusing on RabbitMQ")
set(CPACK_PACKAGE_NAME "qamqp")
set(CPACK_PACKAGE_VENDOR "Matt Broadstone and contributors")
set(CPACK_PACKAGE_CONTACT [email protected])

# when packaging unter Debian (cpack -G DEB) we can auto-detect .deb dependencies
set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)

# NOTE: 'include(CPack)' MUST happen after all CPACK_ variables are set in the including sub directories (e.g. for menu links)
27 changes: 27 additions & 0 deletions cmake/06_CTest_Support.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
enable_testing()


function(add_qtest)

cmake_parse_arguments(
ADD_QTEST_PREFIX
""
"NAME"
"SOURCES;LIBS"
${ARGN}
)


add_executable(${ADD_QTEST_PREFIX_NAME} ${ADD_QTEST_PREFIX_SOURCES})

target_include_directories(${ADD_QTEST_PREFIX_NAME}
PRIVATE
${QAMQP_PATH}/src
${QAMQP_PATH}/tests/common
)
target_link_libraries(${ADD_QTEST_PREFIX_NAME} ${ADD_QTEST_PREFIX_LIBS} Qt5::Test)
_enable_compiler_coverage_flags_for(${ADD_QTEST_PREFIX_NAME})

add_test(NAME ${ADD_QTEST_PREFIX_NAME} COMMAND ${ADD_QTEST_PREFIX_NAME})

endfunction()
13 changes: 13 additions & 0 deletions cmake/10_DefaultBuildType.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "Defaulting to 'Debug' build. Use -DCMAKE_BUILD_TYPE=Release for releases.")
set(CMAKE_BUILD_TYPE "Debug")
endif()

message(STATUS "This is a '${CMAKE_BUILD_TYPE}' build with the '${CMAKE_GENERATOR}' generator.")
message(STATUS "The 'install' target will use the prefix '${CMAKE_INSTALL_PREFIX}'")

if ("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")
message(STATUS "Not using cross-compile toolchain. Building locally ...")
else()
message(STATUS "Cross-compiling using toolchain file '${CMAKE_TOOLCHAIN_FILE}' ...")
endif()
1 change: 1 addition & 0 deletions cmake/20_FindDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/21_FindQt.cmake)
21 changes: 21 additions & 0 deletions cmake/21_FindQt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
find_package(Qt5 5.9 REQUIRED COMPONENTS Core Network Test)

# now prepare the qt version for usage in our CMakeLists
get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)

# execute qmake to get version
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -version OUTPUT_VARIABLE QT_VERSION_RAW)
string(REGEX MATCH "[0-9]\.[0-9]+\.[0-9]+" QT_VERSION ${QT_VERSION_RAW})

# status output
message(STATUS "...using '${QT_QMAKE_EXECUTABLE}'. Qt version: ${QT_VERSION}")

# extract version number parts
string(REPLACE "." ";" QT_VERSION_LIST ${QT_VERSION})
list(GET QT_VERSION_LIST 0 QT_VERSION_MAJOR)
list(GET QT_VERSION_LIST 1 QT_VERSION_MINOR)
list(GET QT_VERSION_LIST 2 QT_VERSION_PATCH)

# per default: we enable auto-mocing and include those generated Qt files automatically
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
23 changes: 23 additions & 0 deletions cmake/50_CompilerSwitches.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# settings to apply to all compilers
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# we aim for C++14
set(CMAKE_CXX_STANDARD 14)


# declare some "empty default implementation" macros that can be specialized per compiler
macro(_enable_compiler_coverage_flags_for __target)
endmacro()


# compiler specific settings
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
include(${CMAKE_CURRENT_LIST_DIR}/51_CompilerSwitches_GCC.cmake)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
include(${CMAKE_CURRENT_LIST_DIR}/52_CompilerSwitches_Clang.cmake)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
include(${CMAKE_CURRENT_LIST_DIR}/53_CompilerSwitches_MSVC.cmake)
endif()

# finally we support building "releases with symbol"
include(${CMAKE_CURRENT_LIST_DIR}/59_StripDebugSymbolsInRelease.cmake)
28 changes: 28 additions & 0 deletions cmake/51_CompilerSwitches_GCC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 1) determine compiler version
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE COMPILER_VERSION)
string(REGEX MATCHALL "[0-9]+" COMPILER_VERSION_COMPONENTS ${COMPILER_VERSION})
list(APPEND COMPILER_VERSION_COMPONENTS 0)
list(GET COMPILER_VERSION_COMPONENTS 0 COMPILER_MAJOR)
list(GET COMPILER_VERSION_COMPONENTS 1 COMPILER_MINOR)

message(STATUS "Using ${CMAKE_CXX_COMPILER} in version ${COMPILER_MAJOR}.${COMPILER_MINOR}")

# 2) control build flags according to build type
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# debugging symbols and no optimization please
add_definitions(-g3 -O0)
else(${CMAKE_BUILD_TYPE} STREQUAL "Release")
# optimize the build please
add_definitions(-O3)
endif()

# 3) finally ensure we see many warnings
add_definitions(-Wall -Wextra)

# 4) helper for coverage instrumentation
macro(_enable_compiler_coverage_flags_for __target)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set_property(TARGET ${__target} APPEND_STRING PROPERTY COMPILE_FLAGS " -fprofile-arcs -ftest-coverage ")
target_link_libraries(${__target} gcov)
endif()
endmacro()
41 changes: 41 additions & 0 deletions cmake/52_CompilerSwitches_Clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# control build flags according to build type
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# debugging symbols and no optimization please
add_definitions(-g3 -O0)

# some extended clang analyzers - MUST be enabled manually via CMake parameter
if(${CLANG_ANALYSIS})
set(CLANG_ANALYZERS address)

message(STATUS "enabling clang analysis code generation: ${CLANG_ANALYZERS}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_ANALYZERS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${CLANG_ANALYZERS}")
set(CMAKE_LINKER "${CXX_COMPILER}")
endif()

else(${CMAKE_BUILD_TYPE} STREQUAL "Release")
# optimize the build please
add_definitions(-g -O3)
endif()

# set warning options
if (DEFINED $ENV{ENV_CLANG_CXXFLAGS})
add_definitions($ENV{ENV_CLANG_CXXFLAGS})
else()
add_definitions(-Weverything
-Wno-weak-vtables -Wno-padded -Wno-packed
-Wno-c++98-compat-pedantic -Wno-c++98-compat
-Wno-exit-time-destructors -Wno-missing-prototypes
-Wno-documentation-unknown-command
-Wno-used-but-marked-unused
-Wno-gnu-zero-variadic-macro-arguments
-Wno-disabled-macro-expansion
-Wno-global-constructors
)

# clang 3.9 introduced a new warning that needs to be checked - apple clang does not yet support it
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER "3.8")
add_definitions(-Wno-undefined-func-template)
endif()
endif()
5 changes: 5 additions & 0 deletions cmake/53_CompilerSwitches_MSVC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# disable manifest generation
# read here: http://stackoverflow.com/a/8359871
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
set(CMAKE_MODULE_LINKER_FLAGS /MANIFEST:NO)
set(CMAKE_SHARED_LINKER_FLAGS /MANIFEST:NO)
Loading