-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
379 lines (302 loc) · 10.9 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# Copyright (c) 2022, Eugene Gershnik
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.21)
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW) #use DOWNLOAD_EXTRACT_TIMESTAMP
endif()
project(libuuid-cmake VERSION "2.40.4")
if (NOT DEFINED LIBUUID_STATIC AND NOT DEFINED LIBUUID_SHARED)
if (BUILD_SHARED_LIBS OR PROJECT_IS_TOP_LEVEL)
set(LIBUUID_SHARED ON)
else()
set(LIBUUID_SHARED OFF)
endif()
if(NOT BUILD_SHARED_LIBS OR PROJECT_IS_TOP_LEVEL)
set(LIBUUID_STATIC ON)
else()
set(LIBUUID_STATIC OFF)
endif()
endif()
set(LIBUUID_SHARED ${LIBUUID_SHARED} CACHE BOOL "Whether to produce shared lib" FORCE)
set(LIBUUID_STATIC ${LIBUUID_STATIC} CACHE BOOL "Whether to produce static lib" FORCE)
if (NOT DEFINED LIBUUID_RUNSTATEDIR)
set(LIBUUID_RUNSTATEDIR "/run")
endif()
if (NOT DEFINED LIBUUID_LOCALSTATEDIR)
set(LIBUUID_LOCALSTATEDIR "/var")
endif()
set(LIBUUID_RUNSTATEDIR ${LIBUUID_RUNSTATEDIR} CACHE STRING "Run state directory" FORCE)
set(LIBUUID_LOCALSTATEDIR ${LIBUUID_LOCALSTATEDIR} CACHE STRING "Local state directory" FORCE)
include(FetchContent)
FetchContent_Declare(util-linux
# We cannot use plain Git here because occasianolly
# util-linux does some git shenanigans that result in
# old removed files being detected as modified by git
# (e.g. tests/expected/libmount/optstr-apply-user-x)
# It is safer to fetch the whole thing as a tarball from
# Github
#GIT_REPOSITORY https://github.com/util-linux/util-linux
#GIT_TAG v${PROJECT_VERSION}
#GIT_SHALLOW TRUE
#GIT_PROGRESS TRUE
#GIT_SUBMODULES_RECURSE FALSE
URL https://github.com/util-linux/util-linux/archive/v${PROJECT_VERSION}.tar.gz
PATCH_COMMAND patch -p0 -s -f -i ${CMAKE_CURRENT_LIST_DIR}/patches/patch_2.40.diff
LOG_PATCH ON
)
FetchContent_MakeAvailable(util-linux)
set(ORIG_SRC ${util-linux_SOURCE_DIR})
include(config.cmake)
set(PUBLIC_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
add_library(uuid_header INTERFACE EXCLUDE_FROM_ALL)
# Single interface only library for the public header
# This is to avoid having the header in both shared and static libs
# Which is not well supported by some generators (e.g. Xcode)
list(APPEND INSTALL_LIBS uuid_header)
target_sources(uuid_header
INTERFACE
$<BUILD_INTERFACE:${PUBLIC_INCLUDE_DIR}/uuid/uuid.h>
$<INSTALL_INTERFACE:include/uuid/uuid.h>
)
set_target_properties(uuid_header PROPERTIES PUBLIC_HEADER ${PUBLIC_INCLUDE_DIR}/uuid/uuid.h)
add_custom_command(
OUTPUT ${PUBLIC_INCLUDE_DIR}/uuid/uuid.h
DEPENDS ${ORIG_SRC}/libuuid/src/uuid.h
COMMAND ${CMAKE_COMMAND} -E make_directory ${PUBLIC_INCLUDE_DIR}/uuid
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ORIG_SRC}/libuuid/src/uuid.h ${PUBLIC_INCLUDE_DIR}/uuid
)
set_source_files_properties(${PUBLIC_INCLUDE_DIR}/uuid/uuid.h PROPERTIES GENERATED ON)
#Define static and shared libs
if (LIBUUID_SHARED)
list(APPEND BUILD_SUFFIXES "shared")
endif()
if (LIBUUID_STATIC)
list(APPEND BUILD_SUFFIXES "static")
endif()
set(LIBTYPE_static STATIC)
set(LIBTYPE_shared SHARED)
foreach(suffix ${BUILD_SUFFIXES})
add_library(uuid_${suffix} ${LIBTYPE_${suffix}})
list(APPEND INSTALL_LIBS uuid_${suffix})
target_link_libraries(uuid_${suffix}
PUBLIC
uuid_header
PRIVATE
"$<$<PLATFORM_ID:SunOS>:socket>"
)
target_compile_definitions(uuid_${suffix}
PRIVATE
_PATH_RUNSTATEDIR="${LIBUUID_RUNSTATEDIR}"
_PATH_LOCALSTATEDIR="${LIBUUID_LOCALSTATEDIR}"
${CONFIG_DEFINES}
"PACKAGE_STRING=${PROJECT_NAME} ${PROJECT_VERSION}"
#Illumos doesn't have ifr_hwaddr in struct ifreq
"$<$<PLATFORM_ID:SunOS>:ifr_hwaddr=ifr_ifru.ifru_addr>"
)
target_include_directories(uuid_${suffix}
INTERFACE
$<BUILD_INTERFACE:${PUBLIC_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include> # means <prefix>/include
PRIVATE
${ORIG_SRC}/include
)
target_sources(uuid_${suffix}
PRIVATE
${ORIG_SRC}/libuuid/src/uuid.h
${ORIG_SRC}/libuuid/src/uuidP.h
${ORIG_SRC}/libuuid/src/clear.c
${ORIG_SRC}/libuuid/src/compare.c
${ORIG_SRC}/libuuid/src/copy.c
${ORIG_SRC}/libuuid/src/gen_uuid.c
${ORIG_SRC}/libuuid/src/isnull.c
${ORIG_SRC}/libuuid/src/pack.c
${ORIG_SRC}/libuuid/src/parse.c
${ORIG_SRC}/libuuid/src/unpack.c
${ORIG_SRC}/libuuid/src/unparse.c
${ORIG_SRC}/libuuid/src/uuidd.h
${ORIG_SRC}/libuuid/src/uuid_time.c
${ORIG_SRC}/libuuid/src/predefined.c
${ORIG_SRC}/lib/randutils.c
${ORIG_SRC}/lib/md5.c
${ORIG_SRC}/lib/sha1.c
)
add_library(uuid::uuid_${suffix} ALIAS uuid_${suffix})
if (PROJECT_IS_TOP_LEVEL)
add_executable(test_uuid_${suffix} EXCLUDE_FROM_ALL)
list(APPEND BUILT_TESTS test_uuid_${suffix})
list(APPEND TESTS_TO_RUN "COMMAND;echo;Testing ${suffix};&&;\$<TARGET_FILE:test_uuid_${suffix}>")
target_link_libraries(test_uuid_${suffix}
PRIVATE
uuid::uuid_${suffix}
)
target_include_directories(test_uuid_${suffix}
PRIVATE
${ORIG_SRC}/include
)
target_compile_definitions(test_uuid_${suffix}
PRIVATE
${CONFIG_DEFINES}
)
target_sources(test_uuid_${suffix}
PRIVATE
${ORIG_SRC}/libuuid/src/test_uuid.c
)
add_executable(test_uuid_ns_${suffix})
list(APPEND BUILT_TESTS test_uuid_ns_${suffix})
list(APPEND TESTS_TO_RUN "COMMAND;echo;Testing Namespaces ${suffix};&&;\$<TARGET_FILE:test_uuid_ns_${suffix}>")
target_link_libraries(test_uuid_ns_${suffix}
PRIVATE
uuid::uuid_${suffix}
)
target_include_directories(test_uuid_ns_${suffix}
PRIVATE
${ORIG_SRC}/include
)
target_compile_definitions(test_uuid_ns_${suffix}
PRIVATE
${CONFIG_DEFINES}
)
target_sources(test_uuid_ns_${suffix}
PRIVATE
${ORIG_SRC}/tests/helpers/test_uuid_namespace.c
)
endif()
endforeach()
#Set uuid::uuid alias to an appropriate variant
if (LIBUUID_SHARED AND LIBUUID_STATIC)
if (BUILD_SHARED_LIBS)
add_library(uuid::uuid ALIAS uuid_shared)
elseif (LIBUUID_STATIC)
add_library(uuid::uuid ALIAS uuid_static)
endif()
elseif (LIBUUID_SHARED)
add_library(uuid::uuid ALIAS uuid_shared)
elseif (LIBUUID_STATIC)
add_library(uuid::uuid ALIAS uuid_static)
endif()
#Set filenames names of shared and static libraries
if (LIBUUID_SHARED)
set_target_properties(uuid_shared PROPERTIES OUTPUT_NAME "uuid")
endif()
if (LIBUUID_STATIC AND NOT ${CMAKE_IMPORT_LIBRARY_SUFFIX} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX})
set_target_properties(uuid_static PROPERTIES OUTPUT_NAME "uuid")
endif()
#Shared library versioning
if (LIBUUID_SHARED)
set_target_properties(uuid_shared PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
)
if (HAVE_LD_VERSION_SCRIPT)
target_link_options(uuid_shared
PRIVATE
LINKER:--version-script=${ORIG_SRC}/libuuid/src/libuuid.sym
)
set_target_properties(uuid_shared PROPERTIES LINK_DEPENDS ${ORIG_SRC}/libuuid/src/libuuid.sym)
endif()
endif()
# Running tests
if (PROJECT_IS_TOP_LEVEL AND (LIBUUID_SHARED OR LIBUUID_STATIC))
add_custom_target(run-tests
DEPENDS ${BUILT_TESTS}
${TESTS_TO_RUN}
)
endif()
# Installing
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(
TARGETS ${INSTALL_LIBS}
EXPORT uuid
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/uuid
)
install(
EXPORT uuid
NAMESPACE uuid::
FILE uuid-exports.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/uuid
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/uuid-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/uuid-config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/uuid
)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/uuid-config-version.cmake
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/uuid-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/uuid-config-version.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/uuid
)
file(RELATIVE_PATH FROM_PCFILEDIR_TO_PREFIX ${CMAKE_INSTALL_FULL_DATAROOTDIR}/uuid ${CMAKE_INSTALL_PREFIX})
string(REGEX REPLACE "/+$" "" FROM_PCFILEDIR_TO_PREFIX "${FROM_PCFILEDIR_TO_PREFIX}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/uuid.pc.in
${CMAKE_CURRENT_BINARY_DIR}/uuid.pc
@ONLY
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/uuid.pc
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig
)
# Man pages
if (PROJECT_IS_TOP_LEVEL AND ASCIIDOCTOR_PATH AND GZIP)
set(MAN_SOURCES
${ORIG_SRC}/libuuid/man/uuid.3.adoc
${ORIG_SRC}/libuuid/man/uuid_clear.3.adoc
${ORIG_SRC}/libuuid/man/uuid_compare.3.adoc
${ORIG_SRC}/libuuid/man/uuid_copy.3.adoc
${ORIG_SRC}/libuuid/man/uuid_generate.3.adoc
${ORIG_SRC}/libuuid/man/uuid_is_null.3.adoc
${ORIG_SRC}/libuuid/man/uuid_parse.3.adoc
${ORIG_SRC}/libuuid/man/uuid_time.3.adoc
${ORIG_SRC}/libuuid/man/uuid_unparse.3.adoc
)
foreach(mansrc ${MAN_SOURCES})
cmake_path(GET mansrc STEM LAST_ONLY manstem)
set(mandst ${CMAKE_CURRENT_BINARY_DIR}/man/${manstem})
add_custom_command(
OUTPUT ${mandst}
DEPENDS ${mansrc}
COMMAND ${ASCIIDOCTOR_PATH} -b manpage -B ${ORIG_SRC} -o ${mandst} ${mansrc}
)
add_custom_command(
OUTPUT ${mandst}.gz
DEPENDS ${mandst}
COMMAND ${CMAKE_COMMAND} -E rm -f ${mandst}.gz
COMMAND ${GZIP} ${mandst}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man
)
list(APPEND MAN_PAGES ${mandst}.gz)
endforeach()
add_custom_target(man ALL
DEPENDS ${MAN_PAGES}
)
target_sources(man
PRIVATE
${MAN_SOURCES}
)
install(
FILES ${MAN_PAGES}
DESTINATION ${CMAKE_INSTALL_MANDIR}/man3
)
install(CODE "
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink uuid_generate.3.gz \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}/man3/uuid_generate_random.3.gz)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink uuid_generate.3.gz \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}/man3/uuid_generate_time.3.gz)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink uuid_generate.3.gz \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_MANDIR}/man3/uuid_generate_time_safe.3.gz)
")
elseif(PROJECT_IS_TOP_LEVEL)
if (NOT ASCIIDOCTOR_PATH)
message(WARNING "asciidoctor not found - man page generation is disabled")
endif()
if (NOT GZIP)
message(WARNING "gzip not found - man page generation is disabled")
endif()
endif()