1 | #################################################
|
---|
2 | # ___________ ____ ______ __ __ _____ #
|
---|
3 | # \____ \__ \ _/ ___\\____ \| | \/ ___/ #
|
---|
4 | # | |_> > __ \\ \___| |_> > | /\___ \ #
|
---|
5 | # | __(____ /\___ > __/|____//____ > #
|
---|
6 | # |__| \/ \/|__| \/ #
|
---|
7 | # #
|
---|
8 | #################################################
|
---|
9 |
|
---|
10 |
|
---|
11 | # TODO Compatibility macro
|
---|
12 | ## ========================================
|
---|
13 | ## Qt macro compatibility Qt4 / Qt5
|
---|
14 | ## ========================================
|
---|
15 | function(qt_wrap_cpp OUT_MOC_SRCS FILES_TO_MOC)
|
---|
16 |
|
---|
17 | if(QT4_FOUNDED)
|
---|
18 | qt4_wrap_cpp(MOC_SRCS ${FILES_TO_MOC})
|
---|
19 |
|
---|
20 | elseif(Qt5Core_FOUND)
|
---|
21 | qt5_wrap_cpp(MOC_SRCS ${FILES_TO_MOC})
|
---|
22 |
|
---|
23 | else()
|
---|
24 | message(WARNING "QT not found, can't wrap moc File")
|
---|
25 | endif()
|
---|
26 |
|
---|
27 | set(${OUT_MOC_SRCS} ${MOC_SRCS} PARENT_SCOPE)
|
---|
28 |
|
---|
29 | endfunction(qt_wrap_cpp)
|
---|
30 |
|
---|
31 | ## ========================================
|
---|
32 | ## Qt macro compatibility Qt4 / Qt5
|
---|
33 | ## ========================================
|
---|
34 | function(qt_wrap_ui OUT_UI_SRCS UI_FILES)
|
---|
35 | if(QT4_FOUND)
|
---|
36 | qt4_wrap_ui( UI_SRCS ${UI_FILES})
|
---|
37 |
|
---|
38 | elseif(Qt5Core_FOUND)
|
---|
39 | qt5_wrap_ui( UI_SRCS ${UI_FILES})
|
---|
40 |
|
---|
41 | else()
|
---|
42 | message(WARNING "QT not found, can't wrap ui File")
|
---|
43 | endif()
|
---|
44 |
|
---|
45 | set(${OUT_UI_SRCS} ${UI_SRCS} PARENT_SCOPE)
|
---|
46 |
|
---|
47 | endfunction()
|
---|
48 |
|
---|
49 | # ========================================
|
---|
50 | # Generic macro for Pacpus plugin
|
---|
51 | # ========================================
|
---|
52 | function(PACPUS_PLUGIN OUT_CPP OUT_H PLUGIN_NAME)
|
---|
53 |
|
---|
54 | if(QT4_FOUND)
|
---|
55 | pacpus_plugin_qt4(PLUGIN_CPP PLUGIN_H ${PROJECT_NAME} )
|
---|
56 | #message("Create QT4 Plugin")
|
---|
57 |
|
---|
58 | elseif(Qt5Core_FOUND)
|
---|
59 | pacpus_plugin_qt5(PLUGIN_CPP PLUGIN_H ${PROJECT_NAME} )
|
---|
60 |
|
---|
61 | else()
|
---|
62 | message(WARNING "QT not found, can't create Plugin")
|
---|
63 | endif()
|
---|
64 |
|
---|
65 | set(${OUT_CPP} ${PLUGIN_CPP} PARENT_SCOPE)
|
---|
66 | set(${OUT_H} ${PLUGIN_H} PARENT_SCOPE)
|
---|
67 |
|
---|
68 | endfunction(PACPUS_PLUGIN)
|
---|
69 |
|
---|
70 | # ========================================
|
---|
71 | # Create a Pacpus plugin QT4
|
---|
72 | # ========================================
|
---|
73 | function(PACPUS_PLUGIN_QT4 OUT_CPP OUT_H PLUGIN_NAME)
|
---|
74 |
|
---|
75 | set(PLUGIN_NAME ${PLUGIN_NAME}Plugin)
|
---|
76 | set(${OUT_CPP} ${PLUGIN_NAME}.cpp PARENT_SCOPE)
|
---|
77 | set(${OUT_H} ${PLUGIN_NAME}.h PARENT_SCOPE)
|
---|
78 |
|
---|
79 | string(TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPER)
|
---|
80 |
|
---|
81 | # create the header file
|
---|
82 | file(WRITE ${PLUGIN_NAME}.h
|
---|
83 | "// Autogenerated file by PacpusPlugin.cmake\n"
|
---|
84 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
85 | "\n"
|
---|
86 | "#ifndef __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
87 | "#define __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
88 | "\n"
|
---|
89 | "#include <QObject>\n"
|
---|
90 | "#include <qplugin.h>\n"
|
---|
91 | "\n"
|
---|
92 | "#include <Pacpus/kernel/PacpusPluginInterface.h>\n"
|
---|
93 | "\n"
|
---|
94 | "/// Auto-generated plugin class\n"
|
---|
95 | "class ${PLUGIN_NAME}\n"
|
---|
96 | " : public QObject\n"
|
---|
97 | " , public PacpusPluginInterface\n"
|
---|
98 | "{\n"
|
---|
99 | " Q_OBJECT\n"
|
---|
100 | " Q_INTERFACES(PacpusPluginInterface)\n"
|
---|
101 | "\n"
|
---|
102 | "public:\n"
|
---|
103 | " ${PLUGIN_NAME}();\n"
|
---|
104 | " ~${PLUGIN_NAME}();\n"
|
---|
105 | "\n"
|
---|
106 | "protected:\n"
|
---|
107 | " QString name();\n"
|
---|
108 | "};\n"
|
---|
109 | "\n"
|
---|
110 | "#endif // __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
111 | )
|
---|
112 |
|
---|
113 | # create the cpp file
|
---|
114 | file(WRITE ${PLUGIN_NAME}.cpp
|
---|
115 | "// Autogenerated file by PacpusPlugin.cmake\n"
|
---|
116 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
117 | "\n"
|
---|
118 | "#include \"${PLUGIN_NAME}.h\"\n"
|
---|
119 | "\n"
|
---|
120 | "${PLUGIN_NAME}::${PLUGIN_NAME}()\n"
|
---|
121 | "{\n"
|
---|
122 | "}\n"
|
---|
123 | "\n"
|
---|
124 | "${PLUGIN_NAME}::~${PLUGIN_NAME}()\n"
|
---|
125 | "{\n"
|
---|
126 | "}\n"
|
---|
127 | "\n"
|
---|
128 | "QString ${PLUGIN_NAME}::name()\n"
|
---|
129 | "{\n"
|
---|
130 | " return \"${PLUGIN_NAME}\";\n"
|
---|
131 | "}\n"
|
---|
132 | "\n"
|
---|
133 | "Q_EXPORT_PLUGIN2(${PLUGIN_NAME}, ${PLUGIN_NAME})\n"
|
---|
134 | )
|
---|
135 | endfunction(PACPUS_PLUGIN_QT4)
|
---|
136 |
|
---|
137 | # ========================================
|
---|
138 | # Create a Pacpus plugin QT5
|
---|
139 | # ========================================
|
---|
140 | function(PACPUS_PLUGIN_QT5 OUT_CPP OUT_H PLUGIN_NAME)
|
---|
141 |
|
---|
142 | set(PLUGIN_NAME ${PLUGIN_NAME}Plugin)
|
---|
143 | set(${OUT_CPP} ${PLUGIN_NAME}.cpp ${PLUGIN_NAME}.json PARENT_SCOPE)
|
---|
144 | set(${OUT_H} ${PLUGIN_NAME}.h PARENT_SCOPE)
|
---|
145 |
|
---|
146 | string(TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPER)
|
---|
147 |
|
---|
148 | # create the header file
|
---|
149 | file(WRITE ${PLUGIN_NAME}.h
|
---|
150 | "// Autogenerated file by PacpusUtilities.cmake\n"
|
---|
151 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
152 | "\n"
|
---|
153 | "#ifndef __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
154 | "#define __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
155 | "\n"
|
---|
156 | "#include <QObject>\n"
|
---|
157 | "#include <qplugin.h>\n"
|
---|
158 | "\n"
|
---|
159 | "#include <Pacpus/kernel/PacpusPluginInterface.h>\n"
|
---|
160 | "\n"
|
---|
161 | "/// Auto-generated plugin class\n"
|
---|
162 | "class ${PLUGIN_NAME}\n"
|
---|
163 | " : public QObject\n"
|
---|
164 | " , public PacpusPluginInterface\n"
|
---|
165 | "{\n"
|
---|
166 | " Q_OBJECT\n"
|
---|
167 | " //Qt5 Plugins Macro\n"
|
---|
168 | " Q_PLUGIN_METADATA(IID \"papus." ${PLUGIN_NAME} "\" FILE \"" ${PLUGIN_NAME} ".json\")\n"
|
---|
169 | " Q_INTERFACES(PacpusPluginInterface)\n"
|
---|
170 | "\n"
|
---|
171 | "public:\n"
|
---|
172 | " ${PLUGIN_NAME}();\n"
|
---|
173 | " ~${PLUGIN_NAME}();\n"
|
---|
174 | "\n"
|
---|
175 | "protected:\n"
|
---|
176 | " QString name();\n"
|
---|
177 | "};\n"
|
---|
178 | "\n"
|
---|
179 | "#endif // __${PLUGIN_NAME_UPPER}_H__\n"
|
---|
180 | )
|
---|
181 |
|
---|
182 | # create the cpp file
|
---|
183 | file(WRITE ${PLUGIN_NAME}.cpp
|
---|
184 | "// Autogenerated file by PacpusUtilities.cmake\n"
|
---|
185 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
186 | "\n"
|
---|
187 | "#include \"${PLUGIN_NAME}.h\"\n"
|
---|
188 | "\n"
|
---|
189 | "${PLUGIN_NAME}::${PLUGIN_NAME}()\n"
|
---|
190 | "{\n"
|
---|
191 | "}\n"
|
---|
192 | "\n"
|
---|
193 | "${PLUGIN_NAME}::~${PLUGIN_NAME}()\n"
|
---|
194 | "{\n"
|
---|
195 | "}\n"
|
---|
196 | "\n"
|
---|
197 | "QString ${PLUGIN_NAME}::name()\n"
|
---|
198 | "{\n"
|
---|
199 | " return \"${PLUGIN_NAME}\";\n"
|
---|
200 | "}\n"
|
---|
201 | "\n"
|
---|
202 | "//Qt4 Plugin Macro desactivated\n"
|
---|
203 | "//Q_EXPORT_PLUGIN2(${PLUGIN_NAME}, ${PLUGIN_NAME})\n"
|
---|
204 | )
|
---|
205 |
|
---|
206 | file(WRITE ${PLUGIN_NAME}.json
|
---|
207 | "{\n"
|
---|
208 | " \"Keys\": [\""${PLUGIN_NAME} "\"]\n"
|
---|
209 | "}\n"
|
---|
210 | )
|
---|
211 | endfunction(PACPUS_PLUGIN_QT5)
|
---|
212 |
|
---|
213 | # ========================================
|
---|
214 | # Replace backslashes by slashes
|
---|
215 | # ========================================
|
---|
216 | macro(pacpus_purge_backslash var)
|
---|
217 | string(REGEX REPLACE "\\\\" "/" ${var} "${${var}}")
|
---|
218 | endmacro()
|
---|
219 |
|
---|
220 | # ========================================
|
---|
221 | # Get the version of MSVC as a string
|
---|
222 | # ========================================
|
---|
223 | macro(pacpus_get_msvc output)
|
---|
224 | # By default, unknown
|
---|
225 | set(${output} "unknown")
|
---|
226 | if(MSVC9)
|
---|
227 | set(${output} "msvc2008")
|
---|
228 | elseif(MSVC10)
|
---|
229 | set(${output} "msvc2010")
|
---|
230 | else(MSVC11)
|
---|
231 | set(${output} "msvc2012")
|
---|
232 | endif()
|
---|
233 | endmacro()
|
---|
234 |
|
---|
235 | # ========================================
|
---|
236 | # Print a debug message
|
---|
237 | # ========================================
|
---|
238 | function(pacpus_output_status msg)
|
---|
239 | message(STATUS "${msg}")
|
---|
240 | string(REPLACE "\\" "\\\\" msg "${msg}")
|
---|
241 | string(REPLACE "\"" "\\\"" msg "${msg}")
|
---|
242 | endfunction()
|
---|
243 |
|
---|
244 | # ========================================
|
---|
245 | # Pacpus log message
|
---|
246 | # ========================================
|
---|
247 | function(pacpus_info text)
|
---|
248 | set(status_cond)
|
---|
249 | set(status_then)
|
---|
250 | set(status_else)
|
---|
251 |
|
---|
252 | set(status_current_name "cond")
|
---|
253 | foreach(arg ${ARGN})
|
---|
254 | if(arg STREQUAL "THEN")
|
---|
255 | set(status_current_name "then")
|
---|
256 | elseif(arg STREQUAL "ELSE")
|
---|
257 | set(status_current_name "else")
|
---|
258 | else()
|
---|
259 | list(APPEND status_${status_current_name} ${arg})
|
---|
260 | endif()
|
---|
261 | endforeach()
|
---|
262 |
|
---|
263 | if(DEFINED status_cond)
|
---|
264 | set(status_placeholder_length 32)
|
---|
265 | string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
|
---|
266 | string(LENGTH "${text}" status_text_length)
|
---|
267 | if(status_text_length LESS status_placeholder_length)
|
---|
268 | string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
|
---|
269 | elseif(DEFINED status_then OR DEFINED status_else)
|
---|
270 | pacpus_output_status("${text}")
|
---|
271 | set(status_text "${status_placeholder}")
|
---|
272 | else()
|
---|
273 | set(status_text "${text}")
|
---|
274 | endif()
|
---|
275 |
|
---|
276 | if(DEFINED status_then OR DEFINED status_else)
|
---|
277 | if(${status_cond})
|
---|
278 | string(REPLACE ";" " " status_then "${status_then}")
|
---|
279 | string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
|
---|
280 | pacpus_output_status("${status_text} ${status_then}")
|
---|
281 | else()
|
---|
282 | string(REPLACE ";" " " status_else "${status_else}")
|
---|
283 | string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
|
---|
284 | pacpus_output_status("${status_text} ${status_else}")
|
---|
285 | endif()
|
---|
286 | else()
|
---|
287 | string(REPLACE ";" " " status_cond "${status_cond}")
|
---|
288 | string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
|
---|
289 | pacpus_output_status("${status_text} ${status_cond}")
|
---|
290 | endif()
|
---|
291 | else()
|
---|
292 | pacpus_output_status("${text}")
|
---|
293 | endif()
|
---|
294 | endfunction()
|
---|
295 |
|
---|
296 | # ========================================
|
---|
297 | # Pacpus add library and set debug postfix
|
---|
298 | # ========================================
|
---|
299 | function(pacpus_add_library target)
|
---|
300 | add_library(
|
---|
301 | ${ARGV}
|
---|
302 | )
|
---|
303 | set_target_properties(
|
---|
304 | ${target}
|
---|
305 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
306 | )
|
---|
307 | endfunction()
|
---|
308 |
|
---|
309 | # ========================================
|
---|
310 | # Pacpus add executable and set debug postfix
|
---|
311 | # ========================================
|
---|
312 | function(pacpus_add_executable target)
|
---|
313 | add_executable(
|
---|
314 | ${ARGV}
|
---|
315 | )
|
---|
316 | set_target_properties(
|
---|
317 | ${target}
|
---|
318 | PROPERTIES DEBUG_POSTFIX "_d"
|
---|
319 | )
|
---|
320 | endfunction()
|
---|
321 |
|
---|
322 | # ========================================
|
---|
323 | # Pacpus install
|
---|
324 | # ========================================
|
---|
325 | function(pacpus_install)
|
---|
326 | install(
|
---|
327 | TARGETS ${ARGV}
|
---|
328 | RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin
|
---|
329 | LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
330 | ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
331 | )
|
---|
332 | if(MSVC)
|
---|
333 | # install debug information files .pdb
|
---|
334 | foreach(target ${ARGV})
|
---|
335 | get_target_property(target_filepath ${target} LOCATION_DEBUG)
|
---|
336 | get_filename_component(target_directory ${target_filepath} PATH)
|
---|
337 | get_filename_component(target_basename ${target_filepath} NAME_WE)
|
---|
338 |
|
---|
339 | set(target_pdb "${target_directory}/${target_basename}.pdb")
|
---|
340 | install(FILES ${target_pdb}
|
---|
341 | CONFIGURATIONS Debug
|
---|
342 | DESTINATION ${PACPUS_INSTALL_DIR}/lib
|
---|
343 | )
|
---|
344 | endforeach()
|
---|
345 | endif(MSVC)
|
---|
346 | endfunction()
|
---|
347 |
|
---|
348 | # ========================================
|
---|
349 | # Pacpus folder
|
---|
350 | # ========================================
|
---|
351 | function(pacpus_folder target folder_name)
|
---|
352 | if(PACPUS_USE_SOLUTION_FOLDERS AND MSVC)
|
---|
353 | set_target_properties(${target}
|
---|
354 | PROPERTIES FOLDER ${folder_name}
|
---|
355 | )
|
---|
356 | endif()
|
---|
357 | endfunction()
|
---|
358 |
|
---|
359 | # ========================================
|
---|
360 | # Get sub directories
|
---|
361 | # ========================================
|
---|
362 | MACRO(SUBDIRLIST result curdir)
|
---|
363 | FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
---|
364 | SET(dirlist "")
|
---|
365 | FOREACH(child ${children})
|
---|
366 | IF(IS_DIRECTORY ${curdir}/${child})
|
---|
367 | SET(dirlist ${dirlist} ${child})
|
---|
368 | ENDIF()
|
---|
369 | ENDFOREACH()
|
---|
370 | SET(${result} ${dirlist})
|
---|
371 | ENDMACRO()
|
---|
372 |
|
---|
373 |
|
---|
374 | # ========================================
|
---|
375 | # Create export header for plugins
|
---|
376 | # ========================================
|
---|
377 | function(CREATE_EXPORT OUT_H PLUGIN_NAME)
|
---|
378 |
|
---|
379 | set(${OUT_H} "export_${PLUGIN_NAME}.h" PARENT_SCOPE)
|
---|
380 |
|
---|
381 | string(TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPER)
|
---|
382 |
|
---|
383 | # create the header file
|
---|
384 | file(WRITE "export_${PLUGIN_NAME}.h"
|
---|
385 | "// Autogenerated file by PacpusUtilities.cmake\n"
|
---|
386 | "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
|
---|
387 | "\n"
|
---|
388 |
|
---|
389 | "#ifndef __EXPORT_${PLUGIN_NAME_UPPER}__H__\n"
|
---|
390 | "#define __EXPORT_${PLUGIN_NAME_UPPER}_H__\n"
|
---|
391 | "\n"
|
---|
392 | "// Export macro for use DLL for Windows only\n"
|
---|
393 | "#ifdef WIN32\n"
|
---|
394 | "# ifdef ${PLUGIN_NAME_UPPER}_EXPORT\n"
|
---|
395 | "// make DLL\n"
|
---|
396 | "# define ${PLUGIN_NAME_UPPER}_API __declspec(dllexport)\n"
|
---|
397 | "# else\n"
|
---|
398 | "// use DLL\n"
|
---|
399 | "# define ${PLUGIN_NAME_UPPER}_API __declspec(dllimport)\n"
|
---|
400 | "# endif\n"
|
---|
401 | "#else\n"
|
---|
402 | "// On other platforms, simply ignore this\n"
|
---|
403 | "# define ${PLUGIN_NAME_UPPER}_API\n"
|
---|
404 | "//#endif\n"
|
---|
405 |
|
---|
406 | "#endif // __EXPORT_${PLUGIN_NAME_UPPER}_H__\n"
|
---|
407 | )
|
---|
408 | endfunction(CREATE_EXPORT)
|
---|