-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
165 lines (140 loc) · 4.61 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
# Copyright (c) 2020-2024 midnightBITS
# This file is licensed under MIT license (see LICENSE for details)
cmake_minimum_required (VERSION 3.12)
project (utfconv
VERSION 1.0.4
DESCRIPTION "Conversion library between string, u16string, u32string and u8string"
LANGUAGES CXX)
set(PROJECT_VERSION_STABILITY "")
set(UTFCONV_BUILD_AS_STANDALONE OFF CACHE BOOL "Force build as if standalone")
set(CONAN_CMAKE_SILENT_OUTPUT ON)
if (UTFCONV_BUILD_AS_STANDALONE OR CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
message(STATUS "utfconv: Standalone")
set(UTFCONV_STANDALONE ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Standalone will be compiled with C++20 to suppport char8_t,
# clients need at least 17 to compile (for string_view for instance).
set(STANDARD 20 CACHE BOOL "Tweak the required standard")
set(CMAKE_CXX_STANDARD ${STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_BINARY_DIR}/conan")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${PROJECT_BINARY_DIR}/conan")
find_package(mbits-semver REQUIRED CONFIG)
else()
message(STATUS "utfconv: Subdir")
set(UTFCONV_STANDALONE OFF)
endif()
set(UTFCONV_TESTING ${UTFCONV_STANDALONE} CACHE BOOL "Compile and/or run self-tests")
set(UTFCONV_INSTALL ${UTFCONV_STANDALONE} CACHE BOOL "Install the library")
if(UTFCONV_TESTING)
set(CONAN_CMAKE_SILENT_OUTPUT ON)
find_package(GTest REQUIRED CONFIG)
endif()
if (UTFCONV_TESTING)
set(COVERALLS_PREFIX UTFCONV_)
list(APPEND UTFCONV_COVERALLS_DIRS
include/utf
src
)
include(tools/coveralls/Coveralls.cmake)
endif()
# See <https://github.com/lefticus/cppbestpractices/blob/v1.0.0/02-Use_the_Tools_Available.md#compilers>
if (MSVC)
set(UTFCONV_ADDITIONAL_WALL_FLAGS
/permissive-
/Zc:__cplusplus
/utf-8
/W4
/w14242
/w14254
/w14263
/w14265
/w14287
/we4289
/w14296
/w14311
/w14545
/w14546
/w14547
/w14549
/w14555
/w14619
/w14640
/w14826
/w14905
/w14906
/w14928
/w14946)
else()
set(UTFCONV_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")
list(APPEND UTFCONV_ADDITIONAL_WALL_FLAGS -fcolor-diagnostics) # -Wlifetime
else()
list(APPEND UTFCONV_ADDITIONAL_WALL_FLAGS
-fdiagnostics-color
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
)
endif()
endif()
configure_file(src/version.hpp.in include/utf/version.hpp @ONLY)
set(SRCS
src/utf.cpp
src/version.cpp
include/utf/utf.hpp
"${CMAKE_CURRENT_BINARY_DIR}/include/utf/version.hpp"
)
add_library(${PROJECT_NAME} STATIC ${SRCS})
target_compile_options(${PROJECT_NAME} PRIVATE ${UTFCONV_ADDITIONAL_WALL_FLAGS})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/src
)
target_link_libraries(${PROJECT_NAME} PUBLIC mbits::semver)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
##################################################################
## INSTALL
##################################################################
if (UTFCONV_INSTALL)
install(TARGETS ${PROJECT_NAME} EXPORT mbits)
install(EXPORT mbits NAMESPACE "mbits::" DESTINATION lib/cmake)
install(DIRECTORY include/utf DESTINATION include)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/utf/version.hpp" DESTINATION include/utf)
endif()
##################################################################
## TESTING
##################################################################
if (UTFCONV_TESTING)
set(EXTERNAL_GTEST ON)
include( ${CMAKE_CURRENT_SOURCE_DIR}/tools/testing/googletest.cmake )
add_test_executable(${PROJECT_NAME}-test DATA_PATH data LIBRARIES ${PROJECT_NAME})
target_compile_options(${PROJECT_NAME}-test PRIVATE ${UTFCONV_ADDITIONAL_WALL_FLAGS})
target_compile_features(${PROJECT_NAME}-test PRIVATE cxx_std_17)
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}-test)
endif()