File: CombineSources.cmake

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (32 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (13)
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
# include several source files (in SRCS) in one or more
# combined files; each combined file holds maximally 
# MAXNUM files.
# BASE gives basename for created files;
# files corresponding to the pattern are deleted
# first, so that there are no relicts from previous runs
# with possibly different MAXNUM
MACRO(COMBINE_SOURCES BASE SRCS MAXNUM)
	LIST(LENGTH SRCS SRCS_LENGTH)
	SET(COMB_COUNTER 0)
	FILE(GLOB EXISTING "${BASE}.*.cpp")
	IF("$EXISTING")
		FILE(REMOVE ${EXISTING})
	ENDIF()
	SET(OUT "${BASE}.${COMB_COUNTER}.cpp")
	FILE(WRITE ${OUT})
	SET(COUNTER 0)
	FOREACH(SRC ${SRCS})
		if(${SRC} MATCHES "^/.*$") # absolute filename
			FILE(APPEND ${OUT} "#include<${SRC}>\n")
		else()
			FILE(APPEND ${OUT} "#include<${CMAKE_SOURCE_DIR}/${SRC}>\n")
		endif()
		MATH(EXPR COUNTER "${COUNTER}+1")
		IF(${COUNTER} EQUAL ${MAXNUM})
			SET(COUNTER 0)
			MATH(EXPR COMB_COUNTER ${COMB_COUNTER}+1)
			SET(OUT "${BASE}.${COMB_COUNTER}.cpp")
			FILE(WRITE ${OUT})
		ENDIF()
	ENDFOREACH()
ENDMACRO()