forked from daniele77/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
149 lines (128 loc) · 5.19 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
################################################################################
# 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)
project(cli VERSION 2.0.0
# DESCRIPTION "A library for interactive command line interfaces in modern C++"
LANGUAGES CXX)
include(GNUInstallDirs)
option(CLI_BuildExamples "Build the examples." OFF)
option(CLI_BuildTests "Build the unit tests." OFF)
option(CLI_UseBoostAsio "Use the boost asio library." OFF)
option(CLI_UseStandaloneAsio "Use the standalone asio library." OFF)
if(WIN32)
macro(get_WIN32_WINNT version)
if(CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif()
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif()
endmacro()
get_WIN32_WINNT(ver)
add_definitions(-D_WIN32_WINNT=${ver})
endif()
if (CLI_UseBoostAsio)
set(Boost_NO_BOOST_CMAKE ON)
add_definitions( -DBOOST_ALL_NO_LIB ) # for windows
find_package(Boost 1.55 REQUIRED COMPONENTS system)
endif()
if (CLI_UseStandaloneAsio)
find_path(STANDALONE_ASIO_INCLUDE_PATH NAMES "asio.hpp" HINTS ${ASIO_INCLUDEDIR})
mark_as_advanced(STANDALONE_ASIO_INCLUDE_PATH)
endif()
find_package(Threads REQUIRED)
# Add Library
add_library(cli INTERFACE)
# Add target alias
add_library(cli::cli ALIAS cli)
target_include_directories(cli
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(cli INTERFACE Threads::Threads)
if (CLI_UseBoostAsio)
target_link_libraries(cli INTERFACE Boost::system)
target_compile_definitions(cli INTERFACE BOOST_ASIO_NO_DEPRECATED=1)
endif()
if (CLI_UseStandaloneAsio)
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)
# alternative way:
# target_include_directories(cli SYSTEM INTERFACE ${STANDALONE_ASIO_INCLUDE_PATH})
endif()
target_compile_features(cli INTERFACE cxx_std_14)
# Examples
if (CLI_BuildExamples)
add_subdirectory(examples)
endif()
# Tests
if (CLI_BuildTests)
enable_testing()
add_subdirectory(test)
endif()
# Install
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}
)