forked from JeffersonLab/clara-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
157 lines (116 loc) · 4.05 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
# SPDX-FileCopyrightText: © The Clara Framework Authors
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.16.3)
project(Clara LANGUAGES CXX)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Debug Release MinSizeRel RelWithDebInfo)
endif()
option(CLARA_BUILD_TESTS "Build tests" ON)
option(CLARA_BUILD_DOCS "Build docs" ON)
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
include(GNUInstallDirs)
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
endif()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE PATH "")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(ENABLE_THREAD_SANITIZER "Enable thread-sanitizer support" OFF)
if(ENABLE_THREAD_SANITIZER)
set(THREAD_SANITIZER -fsanitize=thread -fno-omit-frame-pointer)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_compile_options(-Wall -Wextra)
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
file(RELATIVE_PATH relDir
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
set(CMAKE_INSTALL_RPATH @loader_path @loader_path/${relDir})
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/ThirdParty" CACHE PATH
"Directory under which to collect all populated content")
include(FetchContent)
if(CLARA_BUILD_TESTS)
enable_testing()
endif()
set(CLARA_MSG_ZEROMQ_MIN_VERSION 4.3)
set(CLARA_MSG_PROTOBUF_MIN_VERSION 3.6)
find_package(ZeroMQ ${CLARA_MSG_ZEROMQ_MIN_VERSION} REQUIRED)
find_package(Protobuf ${CLARA_MSG_PROTOBUF_MIN_VERSION} REQUIRED)
include(EnsureProtobufTarget)
add_subdirectory(src/third_party)
add_subdirectory(src)
if(CLARA_BUILD_DOCS)
add_subdirectory(doc)
endif()
if(CLARA_BUILD_TESTS)
add_subdirectory(test)
endif()
# package configuration
set(CMAKE_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/clara")
include(CMakePackageConfigHelpers)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/clara-config.cmake.in
${PROJECT_BINARY_DIR}/clara-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
install(FILES
${PROJECT_BINARY_DIR}/clara-config.cmake
${PROJECT_SOURCE_DIR}/cmake/Modules/FindZeroMQ.cmake
${PROJECT_SOURCE_DIR}/cmake/Modules/EnsureProtobufTarget.cmake
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
COMPONENT Clara_Devel)
# export targets
export(EXPORT ClaraTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/clara-targets.cmake
NAMESPACE Clara::)
install(EXPORT ClaraTargets
FILE clara-targets.cmake
NAMESPACE Clara::
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
COMPONENT Clara_Devel)
# pkg-config
string(CONCAT PKGCONF_REQ_PUB
"libzmq >= ${CLARA_MSG_ZEROMQ_MIN_VERSION}, "
"protobuf >= ${CLARA_MSG_PROTOBUF_MIN_VERSION}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/clara.pc.in
${CMAKE_CURRENT_BINARY_DIR}/clara.pc
@ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/clara.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Clara_Devel)
# uninstall target
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)