File: MergedFilesBuild.cmake

package info (click to toggle)
kst 2.0.8-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 30,748 kB
  • sloc: cpp: 97,086; ansic: 13,364; python: 2,970; sh: 761; yacc: 184; lex: 143; makefile: 141; javascript: 122; perl: 30; xml: 30
file content (90 lines) | stat: -rw-r--r-- 3,464 bytes parent folder | download | duplicates (4)
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
# ***************************************************************************
# *                                                                         *
# *   Copyright : (C) 2010 The University of Toronto                        *
# *   email     : netterfield@astro.utoronto.ca                             *
# *                                                                         *
# *   Copyright : (C) 2010 Peter Kümmel                                     *
# *   email     : syntheticpp@gmx.net                                       *
# *                                                                         *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU General Public License as published by  *
# *   the Free Software Foundation; either version 2 of the License, or     *
# *   (at your option) any later version.                                   *
# *                                                                         *
# ***************************************************************************


macro(merged_files_build _allinone_name _list)
	set(_file_list ${_allinone_name}_files)
	set(_file_const ${CMAKE_CURRENT_BINARY_DIR}/${_allinone_name}_const.cpp)
	set(_file_touched ${CMAKE_CURRENT_BINARY_DIR}/${_allinone_name}_touched.cpp)

	# don't touch existing or non-empty file,
	# so a cmake re-run doesn't touch all created files
	set(_rebuild_file_const 0)
	if (NOT EXISTS ${_file_const})
		set(_rebuild_file_const 1)
	else()
		FILE(READ ${_file_const} _file_content)
		if (NOT _file_content)
			set(_rebuild_file_const 1)
		endif()
	endif()

	set(_rebuild_file_touched 0)
	if (NOT EXISTS ${_file_touched})
		set(_rebuild_file_touched 1)
	else()
		FILE(READ ${_file_touched} _file_content)
		if (NOT _file_content)
			set(_rebuild_file_touched 1)
		endif()
	endif()

	if (merged_files_rebuild)
		set(_rebuild_file_const 1)
		set(_rebuild_file_touched 1)
	endif()

	if (_rebuild_file_const)
		file(WRITE  ${_file_const} "// autogenerated file \n//\n")
		file(APPEND ${_file_const} "//    * clear or delete this file to build it again by cmake \n//\n\n")
	endif()

	if (_rebuild_file_touched)
		file(WRITE  ${_file_touched} "// autogenerated file \n//\n")
		file(APPEND ${_file_touched} "//    * clear or delete this file to build it again by cmake \n//\n")
		file(APPEND ${_file_touched} "//    * don't touch this file \n//\n\n")
		file(APPEND ${_file_touched} "#define DONT_INCLUDE_CONST_FILES\n")
		file(APPEND ${_file_touched} "#include \"${_file_const}\"\n\n\n")
	endif()

	set(${_file_list} ${_file_const} ${_file_touched})

	foreach (_current_FILE ${${_list}})
		get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)

		GET_FILENAME_COMPONENT(_file_name ${_abs_FILE} NAME_WE)
		STRING(REGEX REPLACE "-" "_" _file_name "${_file_name}")
		set(__macro_name ${_file_name}___ASSUME_CONST)

		if (_rebuild_file_const)
			file(APPEND ${_file_const}  "#define ${__macro_name}\n")
			file(APPEND ${_file_const}  "#if defined(${__macro_name}) && !defined(DONT_INCLUDE_CONST_FILES)\n")
			file(APPEND ${_file_const}  "#include \"${_abs_FILE}\"\n")
			file(APPEND ${_file_const}  "#endif\n\n")
		endif()

		if (_rebuild_file_touched)
			file(APPEND ${_file_touched}  "#ifndef ${__macro_name}\n")
			file(APPEND ${_file_touched}  "#include \"${_abs_FILE}\"\n")
			file(APPEND ${_file_touched}  "#endif\n\n")
		endif()
	endforeach (_current_FILE)
endmacro()