3.2.1.3 : La génération du CMakeFind

Voici le create_find_project.cmake : Définissons les différents templates à utiliser :
1
2
3
set(FIND_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files")
set(FIND_HEADER_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_header_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with header")
set(FIND_PROGRAM_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_program.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with program")


Une fonction générique pour un projet :
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
# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	headerFile : header to be searched
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find projectName libraryTargetName headerFile extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find)


Une fonction générique pour les headers :
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
# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	headerFile : header to be searched (will be used in the header template)
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find_header projectName headerFile extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_HEADER_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_header)


Une fonction générique pour les programmes :
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
# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	programFile : header to be searched (will be used in the program template)
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find_program projectName programTargetName extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_PROGRAM_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_program)


Une fonction générique pour un projet complet :
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
# Create the full CMake Find macro for this project
# 	projectName : name of the project to be used
# 	listIncludeFile : list of all include files of the project (or only the most important)
# 	listLibrary : list of all libraries of the project
# 	listProgram : list of the programs of the projet
# 	extraIncludeFile : extra include file to be used
# 	ARGN : list of extra dependencies of the project
function(phoenix_create_find_full projectName listIncludeFile listLibrary listProgram extraIncludeFile)
	set(findFileName "${CMAKE_CURRENT_BINARY_DIR}/Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
		install(FILES ${extraIncludeFile} DESTINATION share/cmake)
	endif()
	
	file(WRITE ${findFileName} "\n")
	file(APPEND ${findFileName} "#########################################\n")
	file(APPEND ${findFileName} "#	Author : Pierre Aubert\n")
	file(APPEND ${findFileName} "#	Mail : pierre.aubert@lapp.in2p3.fr\n")
	file(APPEND ${findFileName} "#	Licence : CeCILL-C\n")
	file(APPEND ${findFileName} "#########################################\n\n")
	
# 	Let's deal with the multiple inclusion in the same project
	file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_FOUND)\n")
	file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
	file(APPEND ${findFileName} "\tinclude_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
	file(APPEND ${findFileName} "\t${EXTRA_INCLUDE_CMAKE}\n")
	file(APPEND ${findFileName} "\treturn()\n")
	file(APPEND ${findFileName} "endif()\n\n")
	
# 	Let's deal with the extra find package
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		file(APPEND ${findFileName} "find_package(${dependencyModule} REQUIRED)\n")
		string(APPEND fullDependModule "")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	file(APPEND ${findFileName} "\n")
	
# 	Let's deal with the list of include
	list(LENGTH listIncludeFile nbIncludeFile)
	if(${nbIncludeFile} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Header of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_INCLUDE_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(includeFile ${listIncludeFile})
			file(APPEND ${findFileName} " ${includeFile}")
		endforeach(includeFile)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/include/${projectName} \${CMAKE_INSTALL_PREFIX}/include/${projectName}\n")
		file(APPEND ${findFileName} "\t\$ENV{HOME}/usr/include/${projectName} \${CMAKE_INCLUDE_PATH}/${projectName} /usr/include/${projectName} /usr/local/include/${projectName}\n")
		file(APPEND ${findFileName} ")\n\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(STATUS \"Found ${PROJECT_NAME_UPPER} headers : \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\")\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_INCLUDE_DIR \"\${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} include directory\")\n")
		file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"${PROJECT_NAME_UPPER} headers not found\")\n")
		file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "include_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
		file(APPEND ${findFileName} "\n\n")
	endif()
	
	list(LENGTH listLibrary nbLibrary)
	if(${nbLibrary} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Libraries of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		
		file(APPEND ${findFileName} "set(LIBRARY_SUFFIX \".so\")\n")
		file(APPEND ${findFileName} "if(APPLE)\n")
		file(APPEND ${findFileName} "\tset(LIBRARY_SUFFIX \".dylib\")\n")
		file(APPEND ${findFileName} "endif()\n\n")
	
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_LIBRARY_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(libraryName ${listLibrary})
			file(APPEND ${findFileName} " lib${libraryName}\${LIBRARY_SUFFIX}")
		endforeach(libraryName)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/lib \${CMAKE_INSTALL_PREFIX}/lib \$ENV{HOME}/usr/lib \${CMAKE_INCLUDE_PATH}/lib /usr/lib /usr/local/lib /lib\n")
		file(APPEND ${findFileName} ")\n\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_LIBRARY_DIR)\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_PREFIX \"\${${PROJECT_NAME_UPPER}_LIBRARY_DIR}/..\")\n")
		
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER} ")
		foreach(libraryName ${listLibrary})
			file(APPEND ${findFileName} " ${libraryName}")
		endforeach(libraryName)
		file(APPEND ${findFileName} " ${EXTRA_DEPENDENCIES_LIB} CACHE STRING \"${PROJECT_NAME_UPPER} libraries and dependencies\")\n")
		
		file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
		file(APPEND ${findFileName} "else()\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Libraries of ${PROJECT_NAME_UPPER} not found\")\n")
		file(APPEND ${findFileName} "endif()\n\n")
	endif()
	
	list(LENGTH listProgram nbProgram)
	if(${nbProgram} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Programs of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(programName ${listProgram})
			file(APPEND ${findFileName} " ${programName}")
		endforeach(programName)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/bin \${CMAKE_INSTALL_PREFIX}/bin \$ENV{HOME}/usr/bin \${CMAKE_INCLUDE_PATH}/bin /usr/bin /usr/local/bin /bin\n")
		file(APPEND ${findFileName} ")\n")
		file(APPEND ${findFileName} "\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(STATUS \"Found programs of ${PROJECT_NAME_UPPER} : \${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\")\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} program directory\")\n")
		foreach(programName ${listProgram})
			string(TOUPPER ${programName} PROGRAM_NAME_UPPER)
			file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_${PROGRAM_NAME_UPPER}_EXECUTABLE \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}/${programName}\" CACHE STRING \"${PROJECT_NAME_UPPER}'s ${programName} program\")\n")
		endforeach(programName)
		file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Programs of ${PROJECT_NAME_UPPER} not found\")\n")
		file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\n\n")
	endif()
	file(APPEND ${findFileName} "set(${PROJECT_NAME_UPPER}_FOUND \"YES\" CACHE BOOL \"${PROJECT_NAME_UPPER} progect found\")\n")
	
	file(APPEND ${findFileName} "${EXTRA_INCLUDE_CMAKE}\n\n")
	
	install(FILES ${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_full)


Le fichier create_find_project.cmake complet :
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
set(FIND_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files")
set(FIND_HEADER_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_header_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with header")
set(FIND_PROGRAM_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_program.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with program")

# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	headerFile : header to be searched
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find projectName libraryTargetName headerFile extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find)

# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	headerFile : header to be searched (will be used in the header template)
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find_header projectName headerFile extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_HEADER_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_header)

# Create the target to create the find cmake file
# 	projectName : name of the project to be used
# 	libraryTargetName : name of the library to be searched
# 	programFile : header to be searched (will be used in the program template)
# 	extraIncludeFile : extra include file to be used
function(phoenix_create_find_program projectName programTargetName extraIncludeFile)
	set(findFileName "Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	set(fullDependModule "")
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}")
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
	endif()
	configure_file(${FIND_PROGRAM_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY)
	
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_program)

# Create the full CMake Find macro for this project
# 	projectName : name of the project to be used
# 	listIncludeFile : list of all include files of the project (or only the most important)
# 	listLibrary : list of all libraries of the project
# 	listProgram : list of the programs of the projet
# 	extraIncludeFile : extra include file to be used
# 	ARGN : list of extra dependencies of the project
function(phoenix_create_find_full projectName listIncludeFile listLibrary listProgram extraIncludeFile)
	set(findFileName "${CMAKE_CURRENT_BINARY_DIR}/Find${projectName}.cmake")
	string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
	
	if(extraIncludeFile STREQUAL "")
		set(EXTRA_INCLUDE_CMAKE "")
	else()
		set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
		install(FILES ${extraIncludeFile} DESTINATION share/cmake)
	endif()
	
	file(WRITE ${findFileName} "\n")
	file(APPEND ${findFileName} "#########################################\n")
	file(APPEND ${findFileName} "#	Author : Pierre Aubert\n")
	file(APPEND ${findFileName} "#	Mail : pierre.aubert@lapp.in2p3.fr\n")
	file(APPEND ${findFileName} "#	Licence : CeCILL-C\n")
	file(APPEND ${findFileName} "#########################################\n\n")
	
# 	Let's deal with the multiple inclusion in the same project
	file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_FOUND)\n")
	file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
	file(APPEND ${findFileName} "\tinclude_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
	file(APPEND ${findFileName} "\t${EXTRA_INCLUDE_CMAKE}\n")
	file(APPEND ${findFileName} "\treturn()\n")
	file(APPEND ${findFileName} "endif()\n\n")
	
# 	Let's deal with the extra find package
	set(EXTRA_DEPENDENCIES_LIB "")
	foreach(dependencyModule ${ARGN})
		file(APPEND ${findFileName} "find_package(${dependencyModule} REQUIRED)\n")
		string(APPEND fullDependModule "")
		string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
		string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
	endforeach(dependencyModule)
	file(APPEND ${findFileName} "\n")
	
# 	Let's deal with the list of include
	list(LENGTH listIncludeFile nbIncludeFile)
	if(${nbIncludeFile} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Header of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_INCLUDE_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(includeFile ${listIncludeFile})
			file(APPEND ${findFileName} " ${includeFile}")
		endforeach(includeFile)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/include/${projectName} \${CMAKE_INSTALL_PREFIX}/include/${projectName}\n")
		file(APPEND ${findFileName} "\t\$ENV{HOME}/usr/include/${projectName} \${CMAKE_INCLUDE_PATH}/${projectName} /usr/include/${projectName} /usr/local/include/${projectName}\n")
		file(APPEND ${findFileName} ")\n\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(STATUS \"Found ${PROJECT_NAME_UPPER} headers : \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\")\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_INCLUDE_DIR \"\${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} include directory\")\n")
		file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"${PROJECT_NAME_UPPER} headers not found\")\n")
		file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "include_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
		file(APPEND ${findFileName} "\n\n")
	endif()
	
	list(LENGTH listLibrary nbLibrary)
	if(${nbLibrary} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Libraries of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		
		file(APPEND ${findFileName} "set(LIBRARY_SUFFIX \".so\")\n")
		file(APPEND ${findFileName} "if(APPLE)\n")
		file(APPEND ${findFileName} "\tset(LIBRARY_SUFFIX \".dylib\")\n")
		file(APPEND ${findFileName} "endif()\n\n")
	
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_LIBRARY_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(libraryName ${listLibrary})
			file(APPEND ${findFileName} " lib${libraryName}\${LIBRARY_SUFFIX}")
		endforeach(libraryName)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/lib \${CMAKE_INSTALL_PREFIX}/lib \$ENV{HOME}/usr/lib \${CMAKE_INCLUDE_PATH}/lib /usr/lib /usr/local/lib /lib\n")
		file(APPEND ${findFileName} ")\n\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_LIBRARY_DIR)\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_PREFIX \"\${${PROJECT_NAME_UPPER}_LIBRARY_DIR}/..\")\n")
		
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER} ")
		foreach(libraryName ${listLibrary})
			file(APPEND ${findFileName} " ${libraryName}")
		endforeach(libraryName)
		file(APPEND ${findFileName} " ${EXTRA_DEPENDENCIES_LIB} CACHE STRING \"${PROJECT_NAME_UPPER} libraries and dependencies\")\n")
		
		file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
		file(APPEND ${findFileName} "else()\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Libraries of ${PROJECT_NAME_UPPER} not found\")\n")
		file(APPEND ${findFileName} "endif()\n\n")
	endif()
	
	list(LENGTH listProgram nbProgram)
	if(${nbProgram} GREATER_EQUAL 1)
		file(APPEND ${findFileName} "###############################################\n")
		file(APPEND ${findFileName} "#\tFind Programs of project ${projectName}\n")
		file(APPEND ${findFileName} "###############################################\n\n")
		
		file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR\n")
		file(APPEND ${findFileName} "\tNAMES")
		foreach(programName ${listProgram})
			file(APPEND ${findFileName} " ${programName}")
		endforeach(programName)
		file(APPEND ${findFileName} "\n")
		file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/bin \${CMAKE_INSTALL_PREFIX}/bin \$ENV{HOME}/usr/bin \${CMAKE_INCLUDE_PATH}/bin /usr/bin /usr/local/bin /bin\n")
		file(APPEND ${findFileName} ")\n")
		file(APPEND ${findFileName} "\n")
		
		file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(STATUS \"Found programs of ${PROJECT_NAME_UPPER} : \${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\")\n")
		file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} program directory\")\n")
		foreach(programName ${listProgram})
			string(TOUPPER ${programName} PROGRAM_NAME_UPPER)
			file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_${PROGRAM_NAME_UPPER}_EXECUTABLE \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}/${programName}\" CACHE STRING \"${PROJECT_NAME_UPPER}'s ${programName} program\")\n")
		endforeach(programName)
		file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Programs of ${PROJECT_NAME_UPPER} not found\")\n")
		file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
		file(APPEND ${findFileName} "\n\n")
	endif()
	file(APPEND ${findFileName} "set(${PROJECT_NAME_UPPER}_FOUND \"YES\" CACHE BOOL \"${PROJECT_NAME_UPPER} progect found\")\n")
	
	file(APPEND ${findFileName} "${EXTRA_INCLUDE_CMAKE}\n\n")
	
	install(FILES ${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_full)
Lien de téléchargement ici.

Et les différents templates pour :