-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
244 lines (167 loc) · 6.04 KB
/
Copy pathCMakeLists.txt
File metadata and controls
244 lines (167 loc) · 6.04 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# ######################################################################## #
# File: /CMakeLists.txt
#
# Purpose: Top-level CMake lists file for WriteDebugString
#
# Created: 3rd August 2026
# Updated: 24th August 2026
#
# ######################################################################## #
# ##########################################################
# CMake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# require out-of-source builds
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()
# directory for CMake specific extensions and source files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# ##########################################################
# project
project(WriteDebugString
DESCRIPTION "WriteDebugString is a Windows CLI that writes messages to the debugger via OutputDebugString."
HOMEPAGE_URL "https://github.com/sistools/WriteDebugString"
LANGUAGES C CXX
)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
# handle version number
set(RX_PROJ_TAG "${PROJECT_NAME_UPPER}")
set(RX_WS "[ \t]")
file(READ "${CMAKE_SOURCE_DIR}/main.c" _impl_file)
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MAJOR${RX_WS}+([0-9]+)" MAJOR_DUMMY ${_impl_file})
set(_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MINOR${RX_WS}+([0-9]+)" MINOR_DUMMY ${_impl_file})
set(_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_PATCH${RX_WS}+([0-9]+)" PATCH_DUMMY ${_impl_file})
set(_VERSION_PATCH ${CMAKE_MATCH_1})
# set project version number here
set(PROJECT_VERSION_MAJOR ${_VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${_VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${_VERSION_PATCH})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# adhere strictly to C and C++ standards plus extensions. These are actually
# useless since we do not compile anything; they merely state our intention.
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 17)
endif()
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # GNU extensions and POSIX standard
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if(MSVC)
if(MSVC_VERSION GREATER_EQUAL 1914)
add_compile_options("/Zc:__cplusplus")
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
endif()
if(MSVC_VERSION LESS 1930)
set(CMAKE_C_STANDARD 90)
set(CMAKE_CXX_STANDARD 98)
endif()
if(MSVC_USE_MT)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif(MSVC_USE_MT)
else(MSVC)
if(MSVC_USE_MT)
# this here just to absorb warning about not using `MSVC_USE_MT` (to
# enable **prepare_cmake.sh** to be simple)
endif(MSVC_USE_MT)
endif(MSVC)
# ##########################################################
# dependencies, includes, options
# ################################################
# includes - 1
include(BuildType)
#[====[
include(LanguageFullVersion)
include(TargetMacros)
#]====]
# ################################################
# dependencies, features, and options
# ######################################
# options
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_TESTING "Build tests" ON)
# ######################################
# features
# This tool targets Windows only (WinSTL).
if(NOT WIN32)
message(FATAL_ERROR "${PROJECT_NAME} targets Windows only")
endif()
# ######################################
# dependencies
#
# required:
# - STLSoft;
#
# required if testing enabled:
# - (none);
#
# optional:
# ############################
# STLSoft
if(DEFINED STLSOFT)
message("-- STLSOFT provided as CMake variable with value '${STLSOFT}'")
set(STLSOFT_INCLUDE_DIR ${STLSOFT}/include)
elseif(DEFINED ENV{STLSOFT})
message("-- STLSOFT provided as environment variable with value '$ENV{STLSOFT}'")
set(STLSOFT_INCLUDE_DIR $ENV{STLSOFT}/include)
else()
set(STLSoft_REQUIRED_VERSION_ 1.11.1)
find_package(STLSoft ${STLSoft_REQUIRED_VERSION_} REQUIRED)
message("-- CMake package STLSoft found (version ${STLSoft_VERSION}; ${STLSoft_REQUIRED_VERSION_} requested)")
endif()
if(DEFINED STLSOFT_INCLUDE_DIR)
include_directories(${STLSOFT_INCLUDE_DIR})
endif()
# ################################################
# includes - 2
include(CMakePackageConfigHelpers)
if(BUILD_TESTING)
include(CTest)
endif(BUILD_TESTING)
include(GNUInstallDirs)
# ##########################################################
# tool
add_executable(${PROJECT_NAME_LOWER}
main.c
)
target_compile_options(${PROJECT_NAME_LOWER}
PRIVATE
$<$<OR:$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:GNU>>:
-Werror -Wall -Wextra -pedantic
-Wno-ignored-qualifiers
-Wno-incompatible-pointer-types-discards-qualifiers
-Wno-unused-parameter
>
$<$<C_COMPILER_ID:MSVC>:
/WX /W4
>
)
target_link_libraries(${PROJECT_NAME_LOWER}
$<$<STREQUAL:${STLSOFT_INCLUDE_DIR},>:STLSoft::STLSoft>
)
install(TARGETS ${PROJECT_NAME_LOWER}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES
doc/${PROJECT_NAME_LOWER}.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
# ################################################
# examples
# ################################################
# tests
if(BUILD_TESTING)
message("-- enabled building of tests ...")
else(BUILD_TESTING)
message("-- disabled building of tests - define BUILD_TESTING to enable")
endif(BUILD_TESTING)
# ##########################################################
# completion
message(NOTICE "Generating CMake build scripts for ${PROJECT_NAME} ${PROJECT_VERSION}, for C${CMAKE_C_STANDARD} C++${CMAKE_CXX_STANDARD}, with build type ${CMAKE_BUILD_TYPE}")
# ############################## end of file ############################# #