source: pacpusframework/trunk/cmake/PacpusUtilities.cmake@ 3

Last change on this file since 3 was 3, checked in by sgosseli, 12 years ago
  • Add the existing Pacpus files from pacpusdev and pacpuscore.
  • Provide a clean build system based on multiple CMake files.
File size: 5.0 KB
Line 
1#################################################
2# ___________ ____ ______ __ __ _____ #
3# \____ \__ \ _/ ___\\____ \| | \/ ___/ #
4# | |_> > __ \\ \___| |_> > | /\___ \ #
5# | __(____ /\___ > __/|____//____ > #
6# |__| \/ \/|__| \/ #
7# #
8#################################################
9
10# ========================================
11# Create a Pacpus plugin
12# ========================================
13function(PACPUS_PLUGIN OUT_CPP OUT_H PLUGIN_NAME)
14
15 set(PLUGIN_NAME ${PLUGIN_NAME}Plugin)
16 set(${OUT_CPP} ${PLUGIN_NAME}.cpp PARENT_SCOPE)
17 set(${OUT_H} ${PLUGIN_NAME}.h PARENT_SCOPE)
18
19 string(TOUPPER ${PLUGIN_NAME} PLUGIN_NAME_UPPER)
20
21 # create the header file
22 file(WRITE ${PLUGIN_NAME}.h
23 "// Autogenerated file by PacpusPlugin.cmake\n"
24 "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
25 "\n"
26 "#ifndef __${PLUGIN_NAME_UPPER}_H__\n"
27 "#define __${PLUGIN_NAME_UPPER}_H__\n"
28 "\n"
29 "#include <qobject.h>\n"
30 "#include <qplugin.h>\n"
31 "\n"
32 "#include \"kernel/PacpusPluginInterface.h\"\n"
33 "\n"
34 "/// Auto-generated plugin class\n"
35 "class ${PLUGIN_NAME}\n"
36 " : public QObject\n"
37 " , public PacpusPluginInterface\n"
38 "{\n"
39 " Q_OBJECT\n"
40 " Q_INTERFACES(PacpusPluginInterface)\n"
41 "\n"
42 "public:\n"
43 " ${PLUGIN_NAME}();\n"
44 " ~${PLUGIN_NAME}();\n"
45 "\n"
46 "protected:\n"
47 " QString name();\n"
48 "};\n"
49 "\n"
50 "#endif // __${PLUGIN_NAME_UPPER}_H__\n"
51 )
52
53 # create the cpp file
54 file(WRITE ${PLUGIN_NAME}.cpp
55 "// Autogenerated file by PacpusPlugin.cmake\n"
56 "// DO NOT EDIT!!! ALL CHANGES WOULD BE REMOVED BY THE NEXT CALL OF CMAKE\n"
57 "\n"
58 "#include \"${PLUGIN_NAME}.h\"\n"
59 "\n"
60 "${PLUGIN_NAME}::${PLUGIN_NAME}()\n"
61 "{\n"
62 "}\n"
63 "\n"
64 "${PLUGIN_NAME}::~${PLUGIN_NAME}()\n"
65 "{\n"
66 "}\n"
67 "\n"
68 "QString ${PLUGIN_NAME}::name()\n"
69 "{\n"
70 " return \"${PLUGIN_NAME}\";\n"
71 "}\n"
72 "\n"
73 "Q_EXPORT_PLUGIN2(${PLUGIN_NAME}, ${PLUGIN_NAME})\n"
74 )
75endfunction(PACPUS_PLUGIN)
76
77# ========================================
78# Replace backslashes by slashes
79# ========================================
80macro(pacpus_purge_backslash var)
81 string(REGEX REPLACE "\\\\" "/" ${var} ${${var}})
82endmacro()
83
84# ========================================
85# Get the version of MSVC as a string
86# ========================================
87macro(pacpus_get_msvc output)
88 # By default, unknown
89 set(${output} "unknown")
90 # MSVC9 == 2008
91 if (MSVC9)
92 set(${output} "msvc2008")
93 endif()
94 # MSVC10 == 2010
95 if (MSVC10)
96 set(${output} "msvc2010")
97 endif()
98 # MSVC11 == "2012"
99 if (MSVC11)
100 set(${output} "msvc2012")
101 endif()
102endmacro()
103
104# ========================================
105# Print a debug message
106# ========================================
107function(pacpus_output_status msg)
108 message(STATUS "${msg}")
109 string(REPLACE "\\" "\\\\" msg "${msg}")
110 string(REPLACE "\"" "\\\"" msg "${msg}")
111endfunction()
112
113# ========================================
114# Pacpus log message
115# ========================================
116function(pacpus_info text)
117 set(status_cond)
118 set(status_then)
119 set(status_else)
120
121 set(status_current_name "cond")
122 foreach(arg ${ARGN})
123 if(arg STREQUAL "THEN")
124 set(status_current_name "then")
125 elseif(arg STREQUAL "ELSE")
126 set(status_current_name "else")
127 else()
128 list(APPEND status_${status_current_name} ${arg})
129 endif()
130 endforeach()
131
132 if(DEFINED status_cond)
133 set(status_placeholder_length 32)
134 string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
135 string(LENGTH "${text}" status_text_length)
136 if(status_text_length LESS status_placeholder_length)
137 string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
138 elseif(DEFINED status_then OR DEFINED status_else)
139 pacpus_output_status("${text}")
140 set(status_text "${status_placeholder}")
141 else()
142 set(status_text "${text}")
143 endif()
144
145 if(DEFINED status_then OR DEFINED status_else)
146 if(${status_cond})
147 string(REPLACE ";" " " status_then "${status_then}")
148 string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
149 pacpus_output_status("${status_text} ${status_then}")
150 else()
151 string(REPLACE ";" " " status_else "${status_else}")
152 string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
153 pacpus_output_status("${status_text} ${status_else}")
154 endif()
155 else()
156 string(REPLACE ";" " " status_cond "${status_cond}")
157 string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
158 pacpus_output_status("${status_text} ${status_cond}")
159 endif()
160 else()
161 pacpus_output_status("${text}")
162 endif()
163endfunction()
Note: See TracBrowser for help on using the repository browser.