-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
178 lines (155 loc) · 4.84 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
177
178
cmake_minimum_required(VERSION 3.12)
project(args
VERSION 0.12.3
DESCRIPTION ""
LANGUAGES CXX)
set(PROJECT_VERSION_STABILITY "") # or "-alpha", or "-beta", or "-rc.5"
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
message(STATUS "Libargs: Standalone")
set(LIBARG_TESTING_DEFAULT ON)
set(LIBARG_INSTALL_DEFAULT ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# It needs at least 17 to compile, but can use concepts to protect some interfaces.
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
message(STATUS "Building for C++${CMAKE_CXX_STANDARD}")
else()
message(STATUS "Building for C++${CMAKE_CXX_STANDARD} (set externally)")
endif()
else()
message(STATUS "Libargs: Subdir")
set(LIBARG_TESTING_DEFAULT OFF)
set(LIBARG_INSTALL_DEFAULT OFF)
endif()
set(LIBARGS_TESTING ${LIBARG_TESTING_DEFAULT} CACHE BOOL "Compile and/or run self-tests")
set(LIBARGS_INSTALL ${LIBARG_INSTALL_DEFAULT} CACHE BOOL "Install the library")
set(LIBARGS_SHARED OFF CACHE BOOL "Build an .so instead of the .a archive")
if (LIBARGS_TESTING)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
message(STATUS "Python3_EXECUTABLE=${Python3_EXECUTABLE}")
set(COVERALLS_PREFIX LIBARGS_)
set(LIBARGS_COVERALLS_DIRS include/args src)
include(tools/coveralls/Coveralls.cmake)
endif()
set(LIBARGS_WALL_FLAGS ON CACHE BOOL "Compile with -Wall/-W4 warning levels")
if (LIBARGS_WALL_FLAGS)
if (MSVC)
set(ADDITIONAL_WALL_FLAGS
/permissive-
/Zc:__cplusplus
/W4
/w14242
/w14254
/w14263
/w14265
/w14287
/we4289
/w14296
/w14311
/w14545
/w14546
/w14547
/w14549
/w14555
/w14619
/w14640
/w14826
/w14905
/w14906
/w14928
/w14946)
else()
set(ADDITIONAL_WALL_FLAGS
-Wall -Wextra
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wpedantic
-Wconversion
-Wsign-conversion
-Wnull-dereference
-Wdouble-promotion
-Wformat=2
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
list(APPEND ADDITIONAL_WALL_FLAGS -fcolor-diagnostics) # -Wlifetime
else()
list(APPEND ADDITIONAL_WALL_FLAGS
-fdiagnostics-color
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
)
endif()
endif()
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.in" "${CMAKE_CURRENT_BINARY_DIR}/include/args/version.hpp" @ONLY)
set(BUILD_SHARED_LIBS ${LIBARGS_SHARED})
add_library(args
src/actions.cpp
src/parser.cpp
src/printer.cpp
src/translator.cpp
include/args/actions.hpp
include/args/api.hpp
include/args/parser.hpp
include/args/printer.hpp
include/args/translator.hpp
"${CMAKE_CURRENT_BINARY_DIR}/include/args/version.hpp"
)
target_compile_options(args PRIVATE ${ADDITIONAL_WALL_FLAGS})
target_compile_definitions(args PRIVATE LIBARGS_EXPORTING)
target_compile_features(args PRIVATE cxx_std_17)
target_include_directories(args
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
if (LIBARGS_SHARED)
target_compile_definitions(args PUBLIC LIBARGS_SHARED)
endif()
include(CheckCXXSourceCompiles)
function(check_charconv)
check_cxx_source_compiles("#include <charconv>
int main() {}" HAS_CHARCONV_)
set(HAS_CHARCONV ${HAS_CHARCONV_} PARENT)
endfunction()
check_cxx_source_compiles("#include <charconv>
int main() {}" HAS_CHARCONV)
if (NOT HAS_CHARCONV)
message(FATAL_ERROR "The compiler has no access to <charconv>")
endif()
##################################################################
## INSTALL
##################################################################
if (LIBARGS_INSTALL)
install(TARGETS args EXPORT mbits)
install(EXPORT mbits NAMESPACE "mbits::" DESTINATION lib/cmake)
install(DIRECTORY include/args DESTINATION include)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/args/version.hpp" DESTINATION include/args)
endif()
##################################################################
## TESTING
##################################################################
if (LIBARGS_TESTING)
add_executable(args-test tests/args-test.cpp)
target_compile_options(args-test PRIVATE ${ADDITIONAL_WALL_FLAGS})
set_target_properties(args-test
PROPERTIES
FOLDER tests
)
target_link_libraries(args-test args)
add_test(
NAME args.exit
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/args-test.py"
"$<TARGET_FILE:args-test>"
)
enable_testing()
endif()