-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
179 lines (154 loc) · 6.87 KB
/
Copy pathCMakeLists.txt
File metadata and controls
179 lines (154 loc) · 6.87 KB
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
177
178
179
################################################################################
# CLI - A simple command line interface.
# Copyright (C) 2016-2021 Daniele Pallastrelli
#
# Boost Software License - Version 1.0 - August 17th, 2003
#
# Permission is hereby granted, free of charge, to any person or organization
# obtaining a copy of the software and accompanying documentation covered by
# this license (the "Software") to use, reproduce, display, distribute,
# execute, and transmit the Software, and to prepare derivative works of the
# Software, and to permit third-parties to whom the Software is furnished to
# do so, all subject to the following:
#
# The copyright notices in the Software and this entire statement, including
# the above license grant, this restriction and the following disclaimer,
# must be included in all copies of the Software, in whole or in part, and
# all derivative works of the Software, unless such copies or derivative
# works are solely in the form of machine-executable object code generated by
# a source language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
################################################################################
cmake_minimum_required(VERSION 3.8...3.27)
project(
cli
VERSION 2.2.0
# DESCRIPTION "A library for interactive command line interfaces in modern C++"
LANGUAGES CXX
)
include(GNUInstallDirs)
# ---------------------------------------------------------------
# Options
# ---------------------------------------------------------------
option(CLI_BuildExamples "Build the examples." OFF)
option(CLI_BuildTests "Build the unit tests." OFF)
option(CLI_UseBoostAsio "Use Boost.Asio library." OFF)
option(CLI_UseStandaloneAsio "Use standalone Asio library." OFF)
# ---------------------------------------------------------------
# Library
# ---------------------------------------------------------------
add_library(cli INTERFACE)
add_library(cli::cli ALIAS cli)
target_include_directories(cli
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
find_package(Threads REQUIRED)
target_link_libraries(cli INTERFACE Threads::Threads)
# ---------------------------------------------------------------
# Boost.Asio support
# ---------------------------------------------------------------
if(CLI_UseBoostAsio)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) # <PackageName>_ROOT
endif()
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW) # uppercase variables like BOOST_ROOT
endif()
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD) # re-enable FindBoost
endif()
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost 1.66 QUIET COMPONENTS system date_time)
add_definitions(-DBOOST_ALL_NO_LIB) # for windows
if(Boost_FOUND)
message(STATUS "Using compiled Boost libraries on ${CMAKE_SYSTEM_NAME}")
target_link_libraries(cli INTERFACE Boost::system Boost::date_time)
else()
message(STATUS "Boost libraries not found. Falling back to header-only mode.")
target_compile_definitions(cli INTERFACE
BOOST_ERROR_CODE_HEADER_ONLY
BOOST_SYSTEM_NO_LIB
)
# find headers (default locations)
find_path(BOOST_INCLUDE_PATH "boost/version.hpp")
if(NOT BOOST_INCLUDE_PATH)
message(FATAL_ERROR "Boost headers not found for header-only fallback!")
endif()
target_include_directories(cli INTERFACE ${BOOST_INCLUDE_PATH})
endif()
target_compile_definitions(cli INTERFACE BOOST_ASIO_NO_DEPRECATED=1)
endif()
# ---------------------------------------------------------------
# Standalone Asio support
# ---------------------------------------------------------------
if(CLI_UseStandaloneAsio)
find_path(STANDALONE_ASIO_INCLUDE_PATH NAMES "asio.hpp" HINTS ${ASIO_INCLUDEDIR})
mark_as_advanced(STANDALONE_ASIO_INCLUDE_PATH)
if(NOT STANDALONE_ASIO_INCLUDE_PATH)
message(FATAL_ERROR "Standalone Asio headers not found. Set ASIO_INCLUDEDIR or STANDALONE_ASIO_INCLUDE_PATH.")
endif()
add_library(standalone_asio INTERFACE IMPORTED)
target_include_directories(standalone_asio SYSTEM INTERFACE ${STANDALONE_ASIO_INCLUDE_PATH})
target_link_libraries(standalone_asio INTERFACE Threads::Threads)
target_link_libraries(cli INTERFACE standalone_asio)
endif()
# ---------------------------------------------------------------
# C++ standard
# ---------------------------------------------------------------
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
target_compile_features(cli INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
# ---------------------------------------------------------------
# Windows specific
# ---------------------------------------------------------------
if(WIN32)
# Set _WIN32_WINNT for Windows 10+
if(NOT DEFINED _WIN32_WINNT)
add_definitions(-D_WIN32_WINNT=0x0A00)
endif()
endif()
# ---------------------------------------------------------------
# Examples
# ---------------------------------------------------------------
if(CLI_BuildExamples)
add_subdirectory(examples)
endif()
# ---------------------------------------------------------------
# Tests
# ---------------------------------------------------------------
if(CLI_BuildTests)
enable_testing()
add_subdirectory(test)
endif()
# ---------------------------------------------------------------
# Install
# ---------------------------------------------------------------
if(NOT CMAKE_SKIP_INSTALL_RULES)
install(DIRECTORY include/cli DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
include(CMakePackageConfigHelpers)
configure_package_config_file(
"cliConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cliConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cli"
)
# Generate pkg-config .pc file
set(PKGCONFIG_INSTALL_DIR
${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig
CACHE PATH "Installation directory for pkg-config (cli.pc) file"
)
configure_file("cli.pc.in" "cli.pc" @ONLY)
install(TARGETS cli EXPORT cliTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT cliTargets FILE cliTargets.cmake NAMESPACE cli:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cli)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cliConfig.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cli")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cli.pc" DESTINATION ${PKGCONFIG_INSTALL_DIR})
endif()