-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
150 lines (134 loc) · 4.75 KB
/
CMakeLists.txt
File metadata and controls
150 lines (134 loc) · 4.75 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
#
# Copyright (C) 2016-2026 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.29)
project(AwesomeAssert CXX)
find_program(CLANG_TIDY_EXE "clang-tidy")
message(STATUS "CLANG_TIDY_EXE=${CLANG_TIDY_EXE}")
if(CLANG_TIDY_EXE)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} --config-file=${CMAKE_SOURCE_DIR}/.clang-tidy)
endif()
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)
if(DEFINED CMAKE_CXX_CLANG_TIDY)
list(APPEND CMAKE_CXX_CLANG_TIDY --use-color=1)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(
-Werror
-Wall
-Wextra
-Wconversion
)
endif()
add_library(${PROJECT_NAME}_static STATIC)
target_sources(${PROJECT_NAME}_static
PRIVATE
src/assert.cpp
src/format-helpers.cpp
)
target_sources(${PROJECT_NAME}_static
PUBLIC
FILE_SET HEADERS
TYPE HEADERS
BASE_DIRS include
FILES
include/awesome/assert.hpp
include/awesome/assert/format-helpers.hpp
)
target_compile_features(${PROJECT_NAME}_static PUBLIC cxx_std_17)
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}/include/awesome/export.h)
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_sources(${PROJECT_NAME}_static
PUBLIC
FILE_SET generated_headers
TYPE HEADERS
BASE_DIRS ${PROJECT_BINARY_DIR}/include
FILES
${EXPORT_FILE_NAME}
)
target_compile_definitions(${PROJECT_NAME}_static PUBLIC AWESOME_STATIC_DEFINE)
include(GNUInstallDirs)
if(NOT DEFINED CMAKE_INSTALL_ARCHIVEDIR)
set(CMAKE_INSTALL_ARCHIVEDIR "${CMAKE_INSTALL_LIBDIR}")
endif()
install(TARGETS
${PROJECT_NAME} ${PROJECT_NAME}_static
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_ARCHIVEDIR}
FILE_SET HEADERS
FILE_SET generated_headers
)
install(EXPORT ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_ARCHIVEDIR}/cmake
NAMESPACE Awesome::
FILE ${PROJECT_NAME}Config.cmake
)
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME Assert)
set_target_properties(${PROJECT_NAME}_static PROPERTIES EXPORT_NAME Assert_static)
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"
)