-
Notifications
You must be signed in to change notification settings - Fork 425
/
CMakeLists.txt
703 lines (584 loc) · 26.3 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
##############################################################################
# @file CMakeLists.txt
# Build executables, static and dylibs, packages, build systems, etc., for
# HTML Tidy.
#
# Read this file or use cmake-gui (Windows) or ccmake (everything else) for
# guided build.
#
# @author Geoff McLane [[email protected]]
# @author HTACG, et al (consult git log)
#
# @copyright
# Copyright (c) 1998-2017 HTACG
# @copyright
# See tidy.h for license.
#
# @date Consult git log.
##############################################################################
cmake_minimum_required (VERSION 2.8.12)
set(LIB_NAME tidy)
set(LIBTIDY_DESCRIPTION "${LIB_NAME} - HTML syntax checker")
set(LIBTIDY_URL "https://www.html-tidy.org")
project (${LIB_NAME})
#################################################
# Setup
#################################################
#------------------------------------------------------------------------
# Release Information
# Release version and date are found in `version.txt`; update *that*
# file when required. It will be read into variable `versionFile`
# (stripping any newlines or spaces). This file must be formatted into
# two lines: the dot-separated MAJOR.MINOR.POINT version, followed by
# the date separated YEAR.MONTH.DAY release date.
#------------------------------------------------------------------------
file(READ version.txt versionFile)
if (NOT versionFile)
message(FATAL_ERROR "Unable to determine libtidy version. version.txt file is missing.")
endif()
string(STRIP "${versionFile}" VERSION_TEXT)
string(REGEX REPLACE "(.*)[\r\n|\n](.*)" "\\1" LIBTIDY_VERSION ${VERSION_TEXT})
string(REGEX REPLACE "(.*)[\r\n|\n](.*)" "\\2" LIBTIDY_DATE ${VERSION_TEXT})
# Establish version number
if (LIBTIDY_VERSION)
string(REPLACE "." ";" VERSION_LIST ${LIBTIDY_VERSION})
list(GET VERSION_LIST 0 TIDY_MAJOR_VERSION)
list(GET VERSION_LIST 1 TIDY_MINOR_VERSION)
list(GET VERSION_LIST 2 TIDY_POINT_VERSION)
set(TIDY_SO_VERSION "${TIDY_MAJOR_VERSION}${TIDY_MINOR_VERSION}")
else ()
message(FATAL_ERROR "*** FAILED to get a VERSION from version.txt!")
endif ()
# Establish version date
if (LIBTIDY_DATE)
string(REPLACE "." ";" DATE_LIST ${LIBTIDY_DATE})
list(GET DATE_LIST 0 tidy_YEAR)
list(GET DATE_LIST 1 tidy_MONTH)
list(GET DATE_LIST 2 tidy_DAY)
else ()
message(FATAL_ERROR "*** FAILED to get a DATE from version.txt!")
endif ()
# Establish SOVERSION. Tidy uses a weird form of semantic versioning,
# wherein even minor versions are stable versions with SONAMEs, and
# odd minor versions are `next` versions that should NOT be released,
# are NOT stable, and should NOT have a valid SONAME.
if (TIDY_SO_VERSION)
math(EXPR NO_SONAME "${TIDY_SO_VERSION} % 2")
if ( NO_SONAME EQUAL 0)
message("-> TIDY_SO_VERSION = ${TIDY_SO_VERSION}. This is an EVEN (stable) release.")
else ()
message("-> TIDY_SO_VERSION = ${TIDY_SO_VERSION}. This is an ODD (development) release.")
endif ()
else ()
message(FATAL_ERROR "*** FAILED to build a TIDY_SO_VERSION!")
endif ()
#------------------------------------------------------------------------
# Library Types and Linking
# By default, *both* static and dynamic library types are built. The
# shared library can be turned off if not needed. The console program
# can be configured for static linking or dynamic linking.
#------------------------------------------------------------------------
set( LIB_TYPE STATIC ) # set default message
option( BUILD_SHARED_LIB "Set OFF to NOT build shared library" ON )
# Issue #326 - Allow linkage choice of console app tidy
option( TIDY_CONSOLE_SHARED "Set ON to link with shared(DLL) lib." OFF )
if (TIDY_CONSOLE_SHARED)
if (NOT BUILD_SHARED_LIB)
message(FATAL_ERROR "Enable shared build for this tidy linkage!")
endif ()
endif ()
#------------------------------------------------------------------------
# Miscellaneous Options
#------------------------------------------------------------------------
option( BUILD_TAB2SPACE "Set ON to build utility app, tab2space" OFF )
option( BUILD_SAMPLE_CODE "Set ON to build the sample code" OFF )
option( TIDY_COMPAT_HEADERS "Set ON to include compatibility headers" OFF )
#------------------------------------------------------------------------
# Man Page
# Allow building with non-default man page directory.
#------------------------------------------------------------------------
if (NOT MAN_INSTALL_DIR)
set(MAN_INSTALL_DIR share/man/man1)
endif ()
#------------------------------------------------------------------------
# Localization
# Allow building without extra language support.
#------------------------------------------------------------------------
option( SUPPORT_LOCALIZATIONS "Set OFF to build without additional languages." ON )
if (SUPPORT_LOCALIZATIONS)
add_definitions ( -DSUPPORT_LOCALIZATIONS=1 )
else ()
add_definitions ( -DSUPPORT_LOCALIZATIONS=0 )
endif ()
#------------------------------------------------------------------------
# Console Application
# Allow building without console support, which mostly prevents
# console strings from existing in the library. Note that this will
# prevent the console application from being built, since it can't be
# linked.
#------------------------------------------------------------------------
option( SUPPORT_CONSOLE_APP "Set OFF to build libraries only without console application support." ON )
if (SUPPORT_CONSOLE_APP)
add_definitions ( -DSUPPORT_CONSOLE_APP=1 )
else ()
add_definitions ( -DSUPPORT_CONSOLE_APP=0 )
endif ()
#------------------------------------------------------------------------
# Diagnostics
# Enable building with logs, some memory diagnostics.
#------------------------------------------------------------------------
option( ENABLE_DEBUG_LOG "Set ON to output debugging messages." OFF )
option( ENABLE_ALLOC_DEBUG "Set ON to output node allocation diagnostics." OFF )
option( ENABLE_MEMORY_DEBUG "Set ON to output some memory diagnostics." OFF )
if ( ENABLE_DEBUG_LOG )
add_definitions( -DENABLE_DEBUG_LOG )
message(STATUS "*** Debug Logging is enabled.")
else ()
message(STATUS "*** Debug Logging is NOT enabled.")
endif ()
if (ENABLE_ALLOC_DEBUG)
add_definitions ( -DDEBUG_ALLOCATION ) # see lexer.c for details
message(STATUS "*** Note, lexer.c node allocation diagnostics are ON")
endif ()
if (ENABLE_MEMORY_DEBUG)
add_definitions ( -DDEBUG_MEMORY ) # see alloc.c for details
message(STATUS "*** Note, alloc.c memory diagnostics are ON")
endif ()
if (WIN32)
option( ENABLE_CRTDBG_MEMORY "Set ON to enable the Windows CRT debug library." OFF )
if (ENABLE_CRTDBG_MEMORY)
add_definitions ( -D_CRTDBG_MAP_ALLOC ) # see tidy.c for details
message(STATUS "*** Note, tidy.c Windows CRT memory debug is ON")
endif ()
endif ()
#------------------------------------------------------------------------
# Complier Flags
# Setup other compiler-specific and platform-specific compiler flags.
#------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_GNUCXX)
set( WARNING_FLAGS -Wall )
endif(CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set( WARNING_FLAGS "-Wall -Wno-overloaded-virtual" )
endif()
if(WIN32 AND MSVC)
# C4996: The compiler encountered a deprecated declaration.
# C4090: 'function' : different 'const' qualifiers
# C4244: '=' : conversion from '__int64' to 'uint', possible loss of data
# C4267: 'function' : conversion from 'size_t' to 'uint', possible loss of data
foreach(warning 4996 4090 4244 4267)
set(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}")
endforeach()
set( MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS" )
# to distinguish between debug and release lib in windows
set( CMAKE_DEBUG_POSTFIX "d" ) # little effect in unix
else()
# add any gcc flags
endif()
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}" )
#------------------------------------------------------------------------
# Static Windows Runtime
# Option to statically link to the Windows runtime. Maybe only
# applies to WIN32/MSVC.
#------------------------------------------------------------------------
if (MSVC)
option( USE_STATIC_RUNTIME "Set ON to change /MD(DLL) to /MT(static)" OFF )
if (USE_STATIC_RUNTIME)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
message(STATUS "Using /MT STATIC runtime")
else ()
message(STATUS "Using /MD DYNAMIC runtime")
endif ()
endif ()
#------------------------------------------------------------------------
# Macro Values
# These additional macros are set in Tidy's source code. It is *very*
# seldom that you would ever have to change any of these in order to
# achieve a functioning build.
#------------------------------------------------------------------------
add_definitions ( -DLIBTIDY_VERSION="${LIBTIDY_VERSION}" )
add_definitions ( -DRELEASE_DATE="${tidy_YEAR}/${tidy_MONTH}/${tidy_DAY}" )
# Optionally specify an extra version point for pre-release/debug versions.
if (TIDY_RC_NUMBER)
add_definitions ( -DRC_NUMBER="${TIDY_RC_NUMBER}" )
endif ()
# If your OS doesn't have native ISO2022 support, then build with this flag.
if (NO_NATIVE_ISO2022_SUPPORT)
add_definitions ( -DNO_NATIVE_ISO2022_SUPPORT=1 )
endif ()
# If your OS doesn't have library function access(), build with this flag.
if (NO_ACCESS_SUPPORT)
add_definitions ( -DNO_ACCESS_SUPPORT=1 )
endif ()
# Delete me? Not used in Tidy source!
add_definitions ( -DHAVE_CONFIG_H )
#------------------------------------------------------------------------
# Runtime Configuration File Support
# By default on Unix-like systems when building for the console program,
# support runtime configuration files in /etc/ and in ~/. To prevent this,
# set ENABLE_CONFIG_FILES to NO. Specify -DTIDY_CONFIG_FILE and/or
# -DTIDY_USER_CONFIG_FILE to override the default paths in tidyplatform.h.
# @note: this section refactored to support #584.
#------------------------------------------------------------------------
if ( UNIX AND SUPPORT_CONSOLE_APP )
option ( ENABLE_CONFIG_FILES "Set to OFF to disable Tidy runtime configuration file support" ON )
# All Unixes support getpwnam(); undef'd in tidyplatform.h if necessary.
add_definitions( -DSUPPORT_GETPWNAM=1 )
else ()
option ( ENABLE_CONFIG_FILES "Set to ON to enable Tidy runtime configuration file support" OFF )
if ( SUPPORT_GETPWNAM )
add_definitions( -DSUPPORT_GETPWNAM=1 )
endif ()
endif ()
if ( ENABLE_CONFIG_FILES )
message(STATUS "*** Building support for runtime configuration files.")
add_definitions( -DTIDY_ENABLE_CONFIG_FILES )
# define a default here so we can pass to XSL.
if ( NOT TIDY_CONFIG_FILE )
set( TIDY_CONFIG_FILE "/etc/tidy.conf" )
endif ()
# define a default here so we can pass to XSL.
if ( NOT TIDY_USER_CONFIG_FILE )
set( TIDY_USER_CONFIG_FILE "~/.tidyrc" )
endif ()
# do *not* add these unless ENABLE_CONFIG_FILES!
add_definitions( -DTIDY_CONFIG_FILE="${TIDY_CONFIG_FILE}" )
add_definitions( -DTIDY_USER_CONFIG_FILE="${TIDY_USER_CONFIG_FILE}" )
endif ()
#------------------------------------------------------------------------
# Shared Library
# Setup whether or not we will build the shared library.
#------------------------------------------------------------------------
if(BUILD_SHARED_LIB)
set(LIB_TYPE SHARED)
message(STATUS "*** Also building DLL library ${LIB_TYPE}, version ${LIBTIDY_VERSION}, date ${LIBTIDY_DATE}")
else()
message(STATUS "*** Only building static library ${LIB_TYPE}, version ${LIBTIDY_VERSION}, date ${LIBTIDY_DATE}")
endif()
#################################################
# Build
#################################################
#------------------------------------------------------------------------
# File Locations and File Lists
# Setup whether or not we will build the shared library.
#------------------------------------------------------------------------
include_directories ( "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src" )
set ( SRCDIR src )
set ( INCDIR include )
set ( CFILES
${SRCDIR}/access.c ${SRCDIR}/attrs.c ${SRCDIR}/istack.c
${SRCDIR}/parser.c ${SRCDIR}/tags.c ${SRCDIR}/entities.c
${SRCDIR}/lexer.c ${SRCDIR}/pprint.c ${SRCDIR}/charsets.c
${SRCDIR}/clean.c ${SRCDIR}/message.c ${SRCDIR}/config.c
${SRCDIR}/alloc.c ${SRCDIR}/attrdict.c ${SRCDIR}/buffio.c
${SRCDIR}/fileio.c ${SRCDIR}/streamio.c ${SRCDIR}/tagask.c
${SRCDIR}/tmbstr.c ${SRCDIR}/utf8.c ${SRCDIR}/tidylib.c
${SRCDIR}/mappedio.c ${SRCDIR}/gdoc.c ${SRCDIR}/language.c
${SRCDIR}/messageobj.c ${SRCDIR}/sprtf.c )
set ( HFILES
${INCDIR}/tidyplatform.h ${INCDIR}/tidy.h ${INCDIR}/tidyenum.h
${INCDIR}/tidybuffio.h )
if (TIDY_COMPAT_HEADERS)
set ( HFILES ${HFILES} ${INCDIR}/buffio.h ${INCDIR}/platform.h )
endif ()
set ( LIBHFILES
${SRCDIR}/access.h ${SRCDIR}/attrs.h ${SRCDIR}/attrdict.h ${SRCDIR}/charsets.h
${SRCDIR}/clean.h ${SRCDIR}/config.h ${SRCDIR}/entities.h
${SRCDIR}/fileio.h ${SRCDIR}/forward.h ${SRCDIR}/lexer.h
${SRCDIR}/mappedio.h ${SRCDIR}/message.h ${SRCDIR}/parser.h
${SRCDIR}/pprint.h ${SRCDIR}/streamio.h ${SRCDIR}/tags.h
${SRCDIR}/tmbstr.h ${SRCDIR}/utf8.h ${SRCDIR}/tidy-int.h
${SRCDIR}/version.h ${SRCDIR}/gdoc.h ${SRCDIR}/language.h
${SRCDIR}/language_en.h ${SRCDIR}/sprtf.h )
#------------------------------------------------------------------------
# Target Locations
#------------------------------------------------------------------------
if (NOT LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib${LIB_SUFFIX})
endif ()
if (NOT BIN_INSTALL_DIR)
set(BIN_INSTALL_DIR bin)
endif ()
if (NOT INCLUDE_INSTALL_DIR)
set(INCLUDE_INSTALL_DIR include)
endif ()
#------------------------------------------------------------------------
# Static Library
# The static library always builds.
#------------------------------------------------------------------------
set(name tidy-static)
add_library ( ${name} STATIC ${CFILES} ${HFILES} ${LIBHFILES} )
target_include_directories( ${name} PUBLIC "${PROJECT_SOURCE_DIR}/include")
if (WIN32)
set_target_properties( ${name} PROPERTIES
OUTPUT_NAME ${LIB_NAME}_static )
else ()
set_target_properties( ${name} PROPERTIES
OUTPUT_NAME ${LIB_NAME} )
endif ()
if (NOT TIDY_CONSOLE_SHARED) # user wants default static linkage
list ( APPEND add_LIBS ${name} )
endif ()
install(TARGETS ${name}
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
)
install( FILES ${HFILES} DESTINATION ${INCLUDE_INSTALL_DIR} )
#------------------------------------------------------------------------
# Dynamic Library
# If the user option is still on.
#------------------------------------------------------------------------
if (BUILD_SHARED_LIB)
set(name tidy-share)
if (UNIX AND APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif ()
add_library ( ${name} SHARED ${CFILES} ${HFILES} ${LIBHFILES} )
target_include_directories( ${name} PUBLIC "${PROJECT_SOURCE_DIR}/include")
set_target_properties( ${name} PROPERTIES
OUTPUT_NAME ${LIB_NAME} )
set_target_properties( ${name} PROPERTIES
VERSION ${LIBTIDY_VERSION}
SOVERSION ${TIDY_SO_VERSION}
NO_SONAME ${NO_SONAME} )
set_target_properties( ${name} PROPERTIES
COMPILE_FLAGS "-DBUILD_SHARED_LIB -DBUILDING_SHARED_LIB")
install(TARGETS ${name}
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
)
if(MSVC)
install(FILES $<TARGET_PDB_FILE:tidy-share> DESTINATION ${LIB_INSTALL_DIR} OPTIONAL)
endif()
if (TIDY_CONSOLE_SHARED) # user wants shared/dll linkage
list ( APPEND add_LIBS ${name} )
endif ()
endif ()
#------------------------------------------------------------------------
# Main Executable
# The main executable will be linked with either the static or the
# shared library.
#------------------------------------------------------------------------
if (SUPPORT_CONSOLE_APP)
set(name ${LIB_NAME})
set ( BINDIR console )
add_executable( ${name} ${BINDIR}/tidy.c )
target_link_libraries( ${name} ${add_LIBS} )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
if (APPLE)
string(TIMESTAMP CURRENT_YEAR "%Y")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/console/Info.plist.in
${CMAKE_CURRENT_BINARY_DIR}/Info.plist
)
target_link_options(${name} PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist)
endif ()
if (NOT TIDY_CONSOLE_SHARED)
set_target_properties( ${name} PROPERTIES
COMPILE_FLAGS "-DTIDY_STATIC" )
endif ()
install (TARGETS ${name} DESTINATION bin)
endif ()
#------------------------------------------------------------------------
# Miscellaneous Targets
#------------------------------------------------------------------------
if (BUILD_TAB2SPACE)
set(name tab2space)
add_executable( ${name} ${BINDIR}/tab2space.c )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
# no INSTALL of this 'local' tool - use depreciated
endif ()
if (BUILD_SAMPLE_CODE)
set(name test71)
set(dir console)
add_executable( ${name} ${dir}/${name}.cxx )
if (MSVC)
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
endif ()
target_link_libraries( ${name} ${add_LIBS} )
# no INSTALL of this 'local' sample
endif ()
#################################################
# Create man pages
#################################################
if (UNIX AND SUPPORT_CONSOLE_APP)
find_program( XSLTPROC_FOUND xsltproc )
if (XSLTPROC_FOUND)
## NOTE: man name must match exe ie currently `${LIB_NAME}.1` not `tidy.1`
## also could use `manpath` command output to determine target install path
set(TIDY_MANFILE ${LIB_NAME}.1)
message(STATUS "*** Generating man ${TIDY_MANFILE} custom commands...")
set(TIDY1XSL ${CMAKE_CURRENT_BINARY_DIR}/tidy1.xsl)
set(TIDYHELP ${CMAKE_CURRENT_BINARY_DIR}/tidy-help.xml)
set(TIDYCONFIG ${CMAKE_CURRENT_BINARY_DIR}/tidy-config.xml)
add_custom_target(man ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}")
## Populate the @VARIABLES@ in the input file.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/man/tidy1.xsl.in
${TIDY1XSL}
)
# Run the built EXE to generate xml output .
add_custom_command(
TARGET man
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME} -xml-help > ${TIDYHELP}
COMMENT "Generate ${TIDYHELP}"
VERBATIM
)
# Run the built EXE to generate more xml output.
add_custom_command(
TARGET man
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME} -xml-config > ${TIDYCONFIG}
COMMENT "Generate ${TIDYCONFIG}"
VERBATIM
)
# Run xsltproc to generate the install files.
add_custom_command(
TARGET man
DEPENDS ${TIDYHELP}
COMMAND xsltproc ARGS ${TIDY1XSL} ${TIDYHELP} > ${CMAKE_CURRENT_BINARY_DIR}/${TIDY_MANFILE}
COMMENT "Generate ${TIDY_MANFILE}"
VERBATIM
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TIDY_MANFILE} DESTINATION ${MAN_INSTALL_DIR})
else ()
message(STATUS "*** NOTE: xsltproc NOT FOUND! Can NOT generate man page.")
message(STATUS "*** You need to install xsltproc in your system.")
endif ()
endif ()
#################################################
# Create MSI,EXE, DMG, DEB/RPM
# TODO: Check each of these builds
#################################################
set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
endif()
#------------------------------------------------------------------------
# System Runtime Libraries
# Need to ensure that system DLLs get included in a binary
# distribution, but since it can miss some - seems incomplete - make
# optional.
#------------------------------------------------------------------------
option( ADD_SYSTEM_RUNTIMES "Set ON to include system runtime DLLS in distribution" OFF )
if (MSVC AND ADD_SYSTEM_RUNTIMES)
if (NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
# Visual Studio Express does include redistributable components so
# squelch the warning.
set (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
endif ()
set (CMAKE_INSTALL_DEBUG_LIBRARIES OFF)
include (InstallRequiredSystemLibraries)
endif ()
#------------------------------------------------------------------------
# Windows
# MSI - this needs WiX Tooset installed and a path to candle.exe
# EXE - this needs NSIS tools to be in path
# Everything Else
# RPM required to build RPM's, and might not be installed by default.
#------------------------------------------------------------------------
if (WIN32)
set(CPACK_GENERATOR "NSIS;WIX;ZIP")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_WIX_UPGRADE_GUID "D809598A-B513-4752-B268-0BAC403B00E4")
elseif ( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set(CPACK_GENERATOR "productbuild")
set(CPACK_SOURCE_GENERATOR "TGZ")
else ()
set(CPACK_GENERATOR "DEB;RPM")
set(CPACK_SOURCE_GENERATOR "TGZ")
endif ()
#------------------------------------------------------------------------
# General
#------------------------------------------------------------------------
set(CPACK_PACKAGE_NAME "${LIB_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${LIBTIDY_DESCRIPTION}")
set(CPACK_PACKAGE_VENDOR "HTML Tidy Advocacy Community Group")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VERSION ${LIBTIDY_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR "${TIDY_MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${TIDY_MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${TIDY_POINT_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README/README.html")
#------------------------------------------------------------------------
# Windows: it looks like only the LICENSE.txt file is used by Windows,
# for either package type (.exe and .msi).
# Linux: none of the files are shown publicly by default when installing
# from a .deb or .rpm.
# Mac: cannot show HTML; need RTF. CPACK_RESOURCE_FILE_WELCOME isn't
# needed.
#------------------------------------------------------------------------
if (APPLE)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/build/macos/Installer-License.rtf")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/build/macos/Installer-Introduction.rtf")
else ()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/README/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README/README.html")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/README/README.html")
endif ()
#------------------------------------------------------------------------
# Debian
#------------------------------------------------------------------------
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${LIBTIDY_URL})
set(CPACK_DEBIAN_PACKAGE_SECTION "Libraries")
set(CPACK_SOURCE_IGNORE_FILES "${PROJECT_SOURCE_DIR}/build" )
#------------------------------------------------------------------------
# RPM config
#------------------------------------------------------------------------
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/share/man" "/usr/share/man/man1")
set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test/;${CMAKE_CURRENT_SOURCE_DIR}/build/;${CMAKE_CURRENT_SOURCE_DIR}/.git/")
#------------------------------------------------------------------------
# Package name configuration
# The default is LIB_NAME-CPACK_PACKAGE_VERSION-CMAKE_SYSTEM_NAME,
# but we want to include system name for Unixes, and correct the
# system name on Apple targets.
#------------------------------------------------------------------------
if (UNIX AND NOT APPLE)
set(CPACK_PACKAGE_FILE_NAME "${LIB_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${BITNESS}bit")
endif ()
if (APPLE AND NOT IOS)
if (CMAKE_OSX_ARCHITECTURES)
set(CPACK_PACKAGE_FILE_NAME "${LIB_NAME}-${CPACK_PACKAGE_VERSION}-macOS-${CMAKE_OSX_ARCHITECTURES}")
string(REPLACE ";" "+" CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
else ()
set(CPACK_PACKAGE_FILE_NAME "${LIB_NAME}-${CPACK_PACKAGE_VERSION}-macOS-${BITNESS}bit")
endif ()
endif ()
if (IOS)
set(CPACK_PACKAGE_FILE_NAME "${LIB_NAME}-${CPACK_PACKAGE_VERSION}-iOS-${BITNESS}bit")
endif ()
#------------------------------------------------------------------------
# Build the Package
#------------------------------------------------------------------------
include(CPack)
#------------------------------------------------------------------------
# pkg-config
#------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}.pc"
@ONLY
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}.pc"
DESTINATION "${LIB_INSTALL_DIR}/pkgconfig"
)
# eof