File: CMakeLists.txt

package info (click to toggle)
swi-prolog 9.2.9%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 84,456 kB
  • sloc: ansic: 401,705; perl: 374,799; lisp: 9,080; cpp: 8,920; java: 5,525; sh: 3,282; javascript: 2,690; python: 2,655; ruby: 1,594; yacc: 845; makefile: 440; xml: 317; sed: 12; sql: 6
file content (371 lines) | stat: -rw-r--r-- 11,097 bytes parent folder | download | duplicates (2)
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
cmake_minimum_required(VERSION 3.5)
project(swipl-doc-core)

include(Documentation)

set(DOC SWI-Prolog-${SWIPL_VERSION_STRING})

# Libraries documented in .doc files
set(DOC_LIB assoc.tex broadcast.tex clpb.tex clpfd.tex clpqr.tex
    library.tex libsummary.tex nbset.tex pio.tex predicateoptions.tex
    record.tex registry.tex)
if(GMP_FOUND)
set(DOC_LIB ${DOC_LIB} simplex.tex)
endif()
prepend(DOC_LIB lib/ ${DOC_LIB})

set(FIGS broadcast by-sa profnode swipl xrefchatdep xrefchatfile)

# Main files
set(DOC_CORE abstract.tex intro.tex overview.tex builtin.tex module.tex
    foreign.tex wasm.tex runtime.tex hack.tex summary.tex xpce.tex glossary.tex
    ide.tex license.tex threads.tex engines.tex streams.tex
    attvar.tex chr.tex xref.tex bit64.tex dialect.tex extensions.tex ssu.tex
    tabling.tex packs.tex)
if(MULTI_THREADED)
list(APPEND DOC_CORE profile.tex)
endif()

set(STYFILES html.sty txt.sty)

# FIXME: we should reduce dependencies
add_custom_command(
    OUTPUT ${PLDOC2TEX_STATE}
    COMMAND ${PROG_SWIPL} -f none --no-packs -o ${PLDOC2TEX_STATE}
            --class=development --no-autoload --no-stand_alone
	    -c ${CMAKE_CURRENT_SOURCE_DIR}/pldoc2tex.pl
            -- --nopce
    DEPENDS pldoc2tex.pl swipl core prolog_home
            pldoc clib sgml http nlp utf8proc
    VERBATIM)

add_custom_target(
    pldoc2tex_state
    DEPENDS ${PLDOC2TEX_STATE})

function(copy_file file)
  add_custom_command(
      OUTPUT ${file}
      COMMAND ${CMAKE_COMMAND} -E copy_if_different
              ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${file}
      VERBATIM)
  set(cpfiles ${cpfiles} ${file} PARENT_SCOPE)
endfunction()

function(copy_figures)
  foreach(f ${ARGN})
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/figs/${f}.pdf)
    copy_file(figs/${f}.pdf)
  endif()
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/figs/${f}.png)
    copy_file(figs/${f}.png)
  endif()
  endforeach()
  set(cpfiles ${cpfiles} ${file} PARENT_SCOPE)
endfunction()

function(doc2tex)
  foreach(f ${ARGN})
    string(REGEX REPLACE "\\.tex" ".doc" docin ${f})
    get_filename_component(dir ${f} DIRECTORY)
    if(dir)
      add_custom_command(
	  OUTPUT ${f}
	  COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
	  COMMAND ${PROG_SWIPL} -f none --no-packs ${DOC2TEX} ${CMAKE_CURRENT_SOURCE_DIR}/${docin} ${f}
	  DEPENDS ${docin} ${DOC2TEX_DEPENDS}
	  VERBATIM)
    else()
      add_custom_command(
	  OUTPUT ${f}
	  COMMAND ${PROG_SWIPL} -f none --no-packs ${DOC2TEX} ${CMAKE_CURRENT_SOURCE_DIR}/${docin} ${f}
	  DEPENDS ${docin} ${DOC2TEX_DEPENDS}
	  VERBATIM)
    endif()
  endforeach()
endfunction()

doc2tex(${DOC_CORE})

# pldoc(tex input
#	[OPTIONS ...]
#	[DEPENDS ...]

set(PLDOC_LIB)

function(pldoc tex input)
    set(options
	--source=${CMAKE_CURRENT_SOURCE_DIR}
        --out=${tex})
    set(depends ${PLDOC2TEX_DEPENDS})
    set(byproducts)

    set(PLDOC_LIB ${PLDOC_LIB} ${tex} PARENT_SCOPE)

    if(input MATCHES "^library")
      string(REGEX REPLACE "library\\((.*)\\)" "\\1" base ${input})
      set(depends "../library/${base}.pl")
    endif()

    foreach(arg ${ARGN})
      if(arg MATCHES "^--")
        set(options ${options} ${arg})
      elseif(arg STREQUAL "DEPENDS")
      elseif(arg STREQUAL "OPTIONS")
      else()
        set(depends ${depends} ${arg})
      endif()
    endforeach()

    if(tex MATCHES "^lib/")
      set(haspl)
      foreach(dep ${depends})
	get_filename_component(ext ${dep} EXT)
	if(ext STREQUAL ".pl")
	  set(haspl true)
	endif()
      endforeach()

      if(haspl)
	set(options ${options} --summaries)
	get_filename_component(base ${tex} NAME_WE)
	set(byproducts lib/summaries.d/${base}.tex)
      endif()
    endif()

    add_custom_command(
	OUTPUT  ${tex}
	COMMAND ${CMAKE_COMMAND} -E env --unset=DISPLAY
		${PROG_SWIPL} -f none --no-packs ${PLDOC2TEX} ${options} "${input}"
	DEPENDS ${depends}
	BYPRODUCTS ${byproducts}
	VERBATIM)
endfunction()

function(libdoc lib)
  string(REGEX REPLACE "_" "" texf ${lib})
  pldoc(lib/${texf}.tex "library(${lib})" ${ARGN})
  set(PLDOC_LIB ${PLDOC_LIB} PARENT_SCOPE)
endfunction()

function(libsdoc)
  foreach(lib ${ARGN})
    libdoc(${lib})
  endforeach()
  set(PLDOC_LIB ${PLDOC_LIB} PARENT_SCOPE)
endfunction()

has_package(ssl HAVE_SSL_PACKAGE)
has_package(archive HAVE_ARCHIVE_PACKAGE)
if(HAVE_SSL_PACKAGE)
  set(doc_depends_ssl ${doc_depends_ssl} ssl)
endif()
if(HAVE_ARCHIVE_PACKAGE)
  set(doc_depends_ssl ${doc_depends_ssl} archive)
endif()

# Specify how to generate tex files from PlDoc
# NOTE: all files must be included from lib/library.doc and
# NOTE: lib/libsummary.doc

libsdoc(apply dicts error url pairs option optparse ordsets aggregate
        charsio debug csv lists check random varnumbers
        quasi_quotations solution_sequences iostream persistency yall
        settings occurs ansi_term readutil prolog_xref intercept
        prolog_jiti tables listing strings terms ugraphs portray_text
        increval prolog_debug prolog_trace rbtrees statistics heaps fastrw gensym
        www_browser macros prolog_versions prolog_coverage)
if(MULTI_THREADED)
  libsdoc(thread_pool thread rwlocks)
endif()
if(NOT STATIC_EXTENSIONS)
libdoc(shlib --subsection)
endif()
libdoc(pure_input --subsection)
libdoc(explain --subsection)
pldoc(lib/prologpack.tex "library(prolog_pack)"
      OPTIONS --section DEPENDS ${doc_depends_ssl})
pldoc(lib/assoclib.tex lib/assoclib.md
      OPTIONS --lib=assoc --module=assoc
      DEPENDS lib/assoclib.md ../library/assoc.pl)
pldoc(lib/clpblib.tex lib/clpblib.md
      OPTIONS --lib=clpb --module=clpb
      DEPENDS lib/clpblib.md ../library/clp/clpb.pl)
pldoc(textdebugger.tex textdebugger.md
      DEPENDS textdebugger.md)
pldoc(lib/clpfdlib.tex lib/clpfdlib.md
      OPTIONS --lib=clpfd --module=clpfd
      DEPENDS lib/clpfdlib.md ../library/clp/clpfd.pl)
if(GMP_FOUND)
pldoc(lib/simplexlib.tex lib/simplexlib.md
      OPTIONS --lib=simplex --module=simplex
      DEPENDS lib/simplexlib.md ../library/clp/simplex.pl)
endif()
pldoc(lib/predopts.tex lib/predopts.txt
      OPTIONS --lib=predicate_options
      DEPENDS lib/predopts.txt ../library/predicate_options.pl)
pldoc(lib/help.tex "library(help)"
      OPTIONS --subsection
      DEPENDS nlp)
has_package(xpce HAVE_XPCE)
if(HAVE_XPCE)
pldoc(lib/main.tex "library(main)"
      DEPENDS pl2xpce)
else()
pldoc(lib/main.tex "library(main)")
endif()
pldoc(lib/dcgbasics.tex "library(dcg/basics)")
pldoc(lib/dcghighorder.tex "library(dcg/high_order)")
if(MULTI_THREADED)
  pldoc(libprofile.tex "library(prolog_profile)" --subsection)
endif()

# Check that we do not have both a .doc file and extract from the
# Prolog source
foreach(f ${PLDOC_LIB})
  string(REGEX REPLACE "\\.tex" ".doc" docin ${f})
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${docin})
    message("WARNING: DOC file for ${f}")
  endif()
endforeach()

doc2tex(${DOC_LIB})

# Create SWI-Prolog-<version>.tex

add_custom_command(
    OUTPUT  ${DOC}.doc
    COMMAND ${PROG_SWIPL} -f none --no-packs ${CMAKE_CURRENT_SOURCE_DIR}/select.pl PDF
                  ${CMAKE_CURRENT_SOURCE_DIR}/main.doc > ${DOC}.doc
    DEPENDS main.doc select.pl)
add_custom_command(
    OUTPUT  ${DOC}.tex
    COMMAND ${PROG_SWIPL} -f none --no-packs ${DOC2TEX} ${DOC}.doc ${DOC}.tex
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${DOC}.doc ${DOC2TEX_DEPENDS}
    VERBATIM)

set(BIBTEX_DATA ${CMAKE_CURRENT_BINARY_DIR}/pl.bib)

add_custom_command(
    OUTPUT pl.bib
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
	    ${CMAKE_CURRENT_SOURCE_DIR}/pl.bib .
    DEPENDS pl.bib
    VERBATIM)

# Collect all input files

prepend(TEXFILES ${CMAKE_CURRENT_BINARY_DIR}/
	${DOC}.tex ${DOC_CORE} ${DOC_LIB} ${PLDOC_LIB})

# Collect LaTeX aux files
string(REPLACE ".tex" ".aux" AUX_FILES "${DOC_CORE}")
tex_byproducts(${DOC} TEX_BYPRODUCTS)
set(CLEAN_FILES ${AUX_FILES} ${TEX_BYPRODUCTS})
SET_DIRECTORY_PROPERTIES(PROPERTIES
			 ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILES}")

# Demand copied files (figures, etc)
set(cpfiles)
copy_figures(${FIGS})

if(BUILD_PDF_DOCUMENTATION)
add_custom_command(
    OUTPUT  ${DOC}.pdf ${DOC}.bbl
    COMMAND env TEXINPUTS=lib:$ENV{TEXINPUTS} ${RUNTEX} --pdf ${DOC}
    DEPENDS ${TEXFILES} ${BIBTEX_DATA} ${cpfiles} prolog_home
    COMMENT "Generating ${DOC}.pdf"
    VERBATIM)
else()
add_custom_command(
    OUTPUT  ${DOC}.bbl
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${CMAKE_CURRENT_SOURCE_DIR}/gen/swipl.bbl ${DOC}.bbl
    COMMENT "Copying pre-build LaTeX .bbl file"
    VERBATIM)
endif()

# Create the HTML manual. First we clean  it to avoid spurious files. If
# we cannot do that, that is ok. Ideally we use `cmake -E`, but there is
# no command to remove with wildcarts.

if(CMAKE_HOST_UNIX)
  set(clean rm -f Manual/*.html Manual/*.gif)
elseif(WIN32)
  set(clean cmd /c "del /Q Manual\*.html Manual\*.gif")
else()
  set(clean ${CMAKE_COMMAND} -E true)
endif()

prepend(cpfiles ${CMAKE_CURRENT_BINARY_DIR}/ ${cpfiles})
add_custom_command(
    OUTPUT manual.html
    COMMAND ${clean}
    COMMAND ${PROG_SWIPL} -f none --no-packs ${LATEX2HTML} --texinputs=lib:: ${DOC}
    COMMAND ${CMAKE_COMMAND} -E remove ${MAN_INDEX}
    COMMAND ${CMAKE_COMMAND} -E touch manual.html
    COMMENT "Generating HTML documentation for core system"
    DEPENDS ${TEXFILES} ${CMAKE_CURRENT_BINARY_DIR}/${DOC}.bbl ${cpfiles}
	    core latex2html)

################
# Windows and MacOS platform guides

if(WIN32)
  doc2tex(windows.tex)
  add_custom_command(
      OUTPUT windows.html
      COMMAND ${PROG_SWIPL} -f none --no-packs ${LATEX2HTML} windows
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/windows.tex
              core latex2html
      VERBATIM)

  add_custom_target(
      core.doc.windows.html
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/windows.html)
endif()

if(APPLE)
  add_custom_command(
      OUTPUT  macosx/macosx.tex
      COMMAND ${CMAKE_COMMAND} -E make_directory macosx
      COMMAND ${PROG_SWIPL} -f none --no-packs ${DOC2TEX} ${CMAKE_CURRENT_SOURCE_DIR}/macosx/macosx.doc
	                       macosx/macosx.tex
      DEPENDS macosx/macosx.doc ${DOC2TEX_DEPENDS}
      VERBATIM)

  add_custom_command(
      OUTPUT  macosx/macosx.html
      COMMAND ${PROG_SWIPL} -f none --no-packs ${LATEX2HTML} macosx
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/macosx/macosx.tex
              core latex2html
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/macosx
      VERBATIM)

  add_custom_target(
      core.doc.macosx.html
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/macosx/macosx.html)

if(BUILD_MACOS_BUNDLE)
  add_dependencies(doc core.doc.macosx.html)
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/macosx/macosx.html
	  DESTINATION ${SWIPL_INSTALL_RESOURCES})
endif()
endif(APPLE)

if(INSTALL_DOCUMENTATION)
  add_custom_target(
      core.doc.html
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/manual.html)
  add_dependencies(doc.html core.doc.html)

  if(BUILD_PDF_DOCUMENTATION)
    add_custom_target(
	core.doc.pdf
	DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${DOC}.pdf)
    add_dependencies(doc.pdf core.doc.pdf)
  endif()

  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Manual
	  DESTINATION ${SWIPL_INSTALL_DOC})
endif(INSTALL_DOCUMENTATION)