-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
177 lines (147 loc) · 5.06 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# This file creates project 'AsioAmqp' with one library targets 'aiso_amqp'.
# After installation this project can be found
# by 'find_package(... CONFIG)' command:
#
# find_package(AsioAmqp CONFIG REQUIRED)
# target_link_libraries(... asio_amqp)
#
# Note that requirements propagated automatically, for example:
# * <prefix>/include added to header search path
# * SECRWEBSERVER_DEBUG=1 added on Debug
####
# Set minimum version of CMake. Since command 'project' use
# VERSION sub-option we need 3.2.2
cmake_minimum_required(VERSION 3.3.2)
include(${CMAKE_SOURCE_DIR}/cmake/add_sources.cmake)
####
# Set variables:
# * PROJECT_NAME
# * PROJECT_VERSION
project(AsioAmqp VERSION 1.1.0)
####
# Get hunter to fetch and build dependencies and
# third party libraries if required
sanity_require(LIBRARY openssl VERSION any)
sanity_require(LIBRARY boost VERSION any COMPONENTS program_options)
sanity_require(LIBRARY gtest VERSION any)
####
# Find all packages required for this project.
# hunter will ensure they have been downloaded and built
interface_tree(include)
source_tree(src)
test_tree(tests)
####
# Create targets
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src")
add_library(asio_amqp ${INTERFACE_FILES} ${SOURCE_FILES})
target_link_libraries(asio_amqp PUBLIC ${CMAKE_THREAD_LIBS_INIT}
amqpcpp
ValueLib_debug
ValueLib_data
ValueLib_stdext
sanity::openssl
boost::program_options
)
####
# Create tests
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/tests")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/tests")
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(asio_amqp_tests ${TEST_FILES})
target_link_libraries(asio_amqp_tests asio_amqp sanity::gtest::main)
add_test(AllTestsInAsioAmqp asio_amqp_tests)
####
# Properties of targets
# Add definitions for targets
# Values:
# * Debug: -DSECRWEBSERVER_DEBUG=1
# * Release: -DSECRWEBSERVER_DEBUG=0
# * other: -DSECRWEBSERVER_DEBUG=0
target_compile_definitions(asio_amqp PUBLIC "ASIO_AMQP_DEBUG=$<CONFIG:Debug>")
# Generate:
# * ${CMAKE_CURRENT_BINARY_DIR}/secrwebserver_export.h with SECRWEBSERVER_EXPORT
include(GenerateExportHeader)
generate_export_header(asio_amqp)
# Global includes. Used by all targets
# Note:
# * header location in project: secrwebserver/include/secrwebserver/server.h
# * header can be included by C++ code `#include <secrwebserver/server.h>`
# * header location in project: ${CMAKE_CURRENT_BINARY_DIR}/secrwebserver_export.h
# * header can be included by: `#include <secrwebserver_export.h>`
target_include_directories(
asio_amqp PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
# PRIVATE SYSTEM ${Boost_INCLUDE_DIRS}
)
####
# Installation
# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/include/
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with function 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
# Targets:
# * <prefix>/lib/libsecrwebserver.a
# * header location after install: <prefix>/include/secrwebserver/server.h
# * headers can be included by C++ code `#include <secrwebserver/server.h>`
install(
TARGETS asio_amqp
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
# Headers:
# * include/secrwebserver/server.h -> <prefix>/include/secrwebserver/server.h
install(
DIRECTORY "include/asio_amqp"
DESTINATION "${include_install_dir}"
FILES_MATCHING PATTERN "*.h"
)
# Export headers:
# * ${CMAKE_CURRENT_BINARY_DIR}/secrwebserver_export.h -> <prefix>/include/secrwebserver_export.h
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/asio_amqp_export.h"
DESTINATION "${include_install_dir}"
)
# Config
# * <prefix>/lib/cmake/secrwebserver/SECRWebServerConfig.cmake
# * <prefix>/lib/cmake/secrwebserver/SECRWebServerConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
# Config
# * <prefix>/lib/cmake/asio_amqp/SECRWebServerTargets.cmake
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)