-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
92 lines (72 loc) · 2.71 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cmake_minimum_required(VERSION 3.0)
project(msgflo_cpp CXX)
set(MSGFLO_VERSION 0.0.6)
# Specify C++11
add_compile_options(-std=c++11)
# AMQP-CPP configuration
set(amqp_install ${CMAKE_CURRENT_BINARY_DIR}/thirdparty-install/amqpcpp)
include(ExternalProject)
ExternalProject_Add(amqpcpp_project
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/amqpcpp
CONFIGURE_COMMAND ""
BUILD_COMMAND make CPP=${CMAKE_CXX_COMPILER} LD=${CMAKE_CXX_COMPILER}
BUILD_IN_SOURCE TRUE
INSTALL_COMMAND make install PREFIX=${amqp_install}
)
# Json11 configuration
set(JSON11 thirdparty/json11/json11.cpp thirdparty/json11/json11.hpp)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11/"
DESTINATION "include"
FILES_MATCHING PATTERN "*.hpp")
# libev, used by AMQP
find_path(libev_INCLUDE_DIRECTORY ev.h)
find_library(libev_LIB ev)
if (NOT libev_INCLUDE_DIRECTORY OR NOT libev_LIB)
message(FATAL_ERROR "Could not find header and/or library for libev")
endif ()
# Mosquitto
find_path(mosquitto_INCLUDE_DIRECTORY mosquitto.h)
find_library(mosquitto_LIB mosquitto)
if (NOT mosquitto_INCLUDE_DIRECTORY OR NOT mosquitto_LIB)
message(FATAL_ERROR "Could not find header and/or library for Mosquitto")
endif ()
# MsgFlo library
add_library(msgflo src/msgflo.cpp src/mqtt_support.cpp src/mqtt_support.h ${JSON11})
target_include_directories(msgflo
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11>
PRIVATE ${libev_INCLUDE_DIRECTORY}
PRIVATE ${amqp_install}/include
PRIVATE ${mosquitto_INCLUDE_DIRECTORY}
PRIVATE src)
# amqp just as too many unused parameters
target_compile_options(msgflo PRIVATE -Wall -Wextra -Wno-unused-parameter)
target_link_libraries(msgflo
PRIVATE ${amqp_install}/lib/libamqpcpp.a
PRIVATE ${mosquitto_LIB}
PRIVATE ${libev_LIB})
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
DESTINATION "include")
add_subdirectory(examples)
add_dependencies(msgflo amqpcpp_project)
# Installation
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
install(TARGETS msgflo
EXPORT msgflo_export
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES include)
install(EXPORT msgflo_export
FILE MsgFloTargets.cmake
NAMESPACE MsgFlo::
DESTINATION lib/cmake/MsgFlo)
configure_file(cmake/MsgFloConfig.cmake
COPYONLY
)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/MsgFlo/MsgFloConfigVersion.cmake"
VERSION ${MSGFLO_VERSION}
COMPATIBILITY AnyNewerVersion)
install(
FILES cmake/MsgFloConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/MsgFlo/MsgFloConfigVersion.cmake"
DESTINATION lib/cmake/MsgFlo)