-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
149 lines (137 loc) · 4.74 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
#
# Copyright (C) 2016-2018 Giel van Schijndel
#
# This file is part of AwesomeAssert.
#
# AwesomeAssert is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# AwesomeAssert is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the
# GNU Lesser General Public License along with AwesomeAssert.
# If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.2)
if(NOT CMAKE_VERSION VERSION_LESS 3.3)
# Apply VISIBILITY property to non-shared targets as well
cmake_policy(SET CMP0063 NEW)
endif()
project(AwesomeAssert CXX)
if(UNIX AND (
(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
AND CMAKE_GENERATOR STREQUAL "Ninja")
# These compilers generate coloured output, but by default only when their output channel is a
# terminal (TTY/PTY). Ninja however captures all output in a pipe (per-subprocess), disabling
# coloured compiler diagnostics. We forcefully enable it because Ninja, since 1.0.0
# (ninja-build/ninja#198) takes care to strip VT100 CSI control sequences from the output if Ninja
# itself is writing to a pipe instead of a terminal. As a result this should give us the best of
# both worlds: coloured output when we're running in a terminal, plain output for editors, IDEs,
# etc.
set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Ignore GCC-specific false positives about attributes
set(CMAKE_CXX_FLAGS "-Wno-attributes ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
endif()
set(PUBLIC_HEADER_TOP_DIR include/awesome)
set(PUBLIC_HEADER_DIR ${PUBLIC_HEADER_TOP_DIR}/assert)
set(PUBLIC_HEADERS_TOP
${PUBLIC_HEADER_TOP_DIR}/assert.hpp
)
set(PUBLIC_HEADERS
${PUBLIC_HEADER_DIR}/format-helpers.hpp
)
add_library(${PROJECT_NAME}_static STATIC
src/assert.cpp
src/format-helpers.cpp
${PUBLIC_HEADERS_TOP}
${PUBLIC_HEADERS}
)
target_include_directories(${PROJECT_NAME}_static PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
)
target_compile_features(${PROJECT_NAME}_static PUBLIC
cxx_constexpr
cxx_explicit_conversions
cxx_extern_templates
cxx_func_identifier
cxx_noexcept
cxx_nullptr
cxx_override
cxx_range_for
cxx_relaxed_constexpr
cxx_rvalue_references
cxx_static_assert
cxx_strong_enums
cxx_trailing_return_types
)
add_library(${PROJECT_NAME} SHARED
$<TARGET_PROPERTY:${PROJECT_NAME}_static,SOURCES>
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<TARGET_PROPERTY:${PROJECT_NAME}_static,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_features(${PROJECT_NAME} PUBLIC
$<TARGET_PROPERTY:${PROJECT_NAME}_static,INTERFACE_COMPILE_FEATURES>
)
set_target_properties(
${PROJECT_NAME}_static
${PROJECT_NAME}
PROPERTIES
VISIBILITY_INLINES_HIDDEN ON
CXX_VISIBILITY_PRESET hidden
)
include(GenerateExportHeader)
set(EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/${PUBLIC_HEADER_TOP_DIR}/awesome_export.h)
list(APPEND PUBLIC_HEADERS_TOP ${EXPORT_FILE_NAME})
generate_export_header(${PROJECT_NAME}
BASE_NAME Awesome
EXPORT_FILE_NAME ${EXPORT_FILE_NAME}
)
# Make generated export header available for the target and its dependendees
target_include_directories(${PROJECT_NAME}_static PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${PUBLIC_HEADER_TOP_DIR}>
)
target_compile_definitions(${PROJECT_NAME}_static PUBLIC AWESOME_STATIC_DEFINE)
install(TARGETS
${PROJECT_NAME} ${PROJECT_NAME}_static
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(FILES
${PUBLIC_HEADERS_TOP}
DESTINATION ${PUBLIC_HEADER_TOP_DIR}
)
install(FILES
${PUBLIC_HEADERS}
DESTINATION ${PUBLIC_HEADER_DIR}
)
install(EXPORT ${PROJECT_NAME}
DESTINATION lib/cmake
)
export(EXPORT ${PROJECT_NAME})
enable_testing()
add_executable(${PROJECT_NAME}.Test.simple
test/simple.cpp
)
target_link_libraries(${PROJECT_NAME}.Test.simple PRIVATE AwesomeAssert)
add_test(NAME ${PROJECT_NAME}.Test.simple.failure
COMMAND sh -c "$<TARGET_FILE:${PROJECT_NAME}.Test.simple> && :"
)
add_test(NAME ${PROJECT_NAME}.Test.simple.success
COMMAND ${PROJECT_NAME}.Test.simple 2 3 4 5
)
set_tests_properties(${PROJECT_NAME}.Test.simple.failure
PROPERTIES
PASS_REGULAR_EXPRESSION "Assertion `argc >= 10 - argc', with expansion `1 >= 9', failed"
ENVIRONMENT "NO_COLOR=1"
)