File: UseMarkdown.cmake

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (116 lines) | stat: -rw-r--r-- 3,301 bytes parent folder | download | duplicates (7)
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
# - Convert markdown source files to HTML as a custom target
#
#  include(UseMarkdown)
#  add_markdown_target(<target_name> <directory to copy to> <markdownfile> [<markdownfile>...] [RENAME <newname>])
#    Relative paths for the destination directory are considered with
#    with respect to CMAKE_CURRENT_BINARY_DIR. The RENAME argument is only
#    valid with a single markdown file as input.
#
#
#  install_markdown_target(<target_name> [extra arguments to INSTALL(FILES ...) ])
#
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2011-2012.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__add_markdown_target)
	return()
endif()
set(__add_markdown_target YES)

define_property(TARGET
	PROPERTY
	MARKDOWN_TARGET_OUTPUTS
	BRIEF_DOCS
	"Markdown target outputs"
	FULL_DOCS
	"Output files of a target created by add_markdown_target")

function(add_markdown_target _target _dest)

	if(NOT ARGN)
		message(WARNING
			"In add_markdown_target call for target ${_target}, no source files were specified!")
		return()
	endif()

	find_package(Markdown QUIET)
	if(NOT MARKDOWN_EXECUTABLE)
		message(FATAL_ERROR "Can't find a markdown conversion tool!")
	endif()

	set(NEW_NAME)
	list(FIND ARGN "RENAME" _renameloc)
	if(_renameloc GREATER -1)
		list(LENGTH ARGN _len)
		if(NOT _len EQUAL 3)
			message(FATAL_ERROR
				"Specifying RENAME requires 1 input file and 1 output name!")
		endif()
		list(GET ARGN 2 NEW_NAME)
		list(GET ARGN 0 ARGN)
	endif()

	set(ALLFILES)
	set(SOURCES)
	foreach(fn ${ARGN})
		# Produce an absolute path to the input file
		if(IS_ABSOLUTE "${fn}")
			get_filename_component(fullpath "${fn}" ABSOLUTE)
			get_filename_component(fn "${fn}" NAME)
		else()
			get_filename_component(fullpath
				"${CMAKE_CURRENT_SOURCE_DIR}/${fn}"
				ABSOLUTE)
		endif()
		get_filename_component(fn_noext "${fn}" NAME_WE)

		# Clean up output file name
		if(NEW_NAME)
			get_filename_component(absout "${_dest}/${NEW_NAME}" ABSOLUTE)
		else()
			get_filename_component(absout "${_dest}/${fn_noext}.html" ABSOLUTE)
		endif()

		add_custom_command(OUTPUT "${absout}"
			COMMAND
			${CMAKE_COMMAND}
			ARGS -E make_directory "${_dest}"
			COMMAND
			${MARKDOWN_EXECUTABLE}
			ARGS "${fullpath}" > "${absout}"
			MAIN_DEPENDENCY "${fullpath}"
			VERBATIM
			COMMENT "Converting Markdown ${fn} to HTML in ${absout}...")
		list(APPEND SOURCES "${fullpath}")
		list(APPEND ALLFILES "${absout}")
	endforeach()

	# Custom target depending on all the file copy commands
	add_custom_target(${_target}
		ALL
		SOURCES ${SOURCES}
		DEPENDS ${ALLFILES})
	set_property(TARGET ${_target} PROPERTY MARKDOWN_TARGET_OUTPUTS "${ALLFILES}")
endfunction()

function(install_markdown_target _target)
	get_target_property(_mtoutputs ${_target} MARKDOWN_TARGET_OUTPUTS)
	if(NOT _mtoutputs)
		message(WARNING
			"install_markdown_target called on a target not created with add_markdown_target!")
		return()
	endif()

	# Forward the call to install
	install(FILES ${_mtoutputs} ${ARGN})
endfunction()