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

Last change on this file since 45 was 40, checked in by sgosseli, 12 years ago

Fixed: plugins were not generated correctly because of an invalid inclusion.

File size: 6.2 KB
RevLine 
[3]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"
[40]29 "#include <QObject>\n"
[3]30 "#include <qplugin.h>\n"
31 "\n"
[40]32 "#include <Pacpus/kernel/PacpusPluginInterface.h>\n"
[3]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)
[20]81 string(REGEX REPLACE "\\\\" "/" ${var} "${${var}}")
[3]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 if (MSVC9)
91 set(${output} "msvc2008")
[6]92 elseif (MSVC10)
[3]93 set(${output} "msvc2010")
[6]94 else (MSVC11)
[3]95 set(${output} "msvc2012")
96 endif()
97endmacro()
98
99# ========================================
100# Print a debug message
101# ========================================
102function(pacpus_output_status msg)
103 message(STATUS "${msg}")
104 string(REPLACE "\\" "\\\\" msg "${msg}")
105 string(REPLACE "\"" "\\\"" msg "${msg}")
106endfunction()
107
108# ========================================
109# Pacpus log message
110# ========================================
111function(pacpus_info text)
112 set(status_cond)
113 set(status_then)
114 set(status_else)
115
116 set(status_current_name "cond")
117 foreach(arg ${ARGN})
118 if(arg STREQUAL "THEN")
119 set(status_current_name "then")
120 elseif(arg STREQUAL "ELSE")
121 set(status_current_name "else")
122 else()
123 list(APPEND status_${status_current_name} ${arg})
124 endif()
125 endforeach()
126
127 if(DEFINED status_cond)
128 set(status_placeholder_length 32)
129 string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
130 string(LENGTH "${text}" status_text_length)
131 if(status_text_length LESS status_placeholder_length)
132 string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
133 elseif(DEFINED status_then OR DEFINED status_else)
134 pacpus_output_status("${text}")
135 set(status_text "${status_placeholder}")
136 else()
137 set(status_text "${text}")
138 endif()
139
140 if(DEFINED status_then OR DEFINED status_else)
141 if(${status_cond})
142 string(REPLACE ";" " " status_then "${status_then}")
143 string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
144 pacpus_output_status("${status_text} ${status_then}")
145 else()
146 string(REPLACE ";" " " status_else "${status_else}")
147 string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
148 pacpus_output_status("${status_text} ${status_else}")
149 endif()
150 else()
151 string(REPLACE ";" " " status_cond "${status_cond}")
152 string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
153 pacpus_output_status("${status_text} ${status_cond}")
154 endif()
155 else()
156 pacpus_output_status("${text}")
157 endif()
158endfunction()
[19]159
160# ========================================
[21]161# Pacpus add library and set debug postfix
162# ========================================
[22]163function(pacpus_add_library target)
164 add_library(
[21]165 ${ARGV}
166 )
167 set_target_properties(
168 ${target}
169 PROPERTIES DEBUG_POSTFIX "_d"
170 )
171endfunction()
172
173# ========================================
[19]174# Pacpus add executable and set debug postfix
175# ========================================
[22]176function(pacpus_add_executable target)
177 add_executable(
[19]178 ${ARGV}
179 )
180 set_target_properties(
181 ${target}
182 PROPERTIES DEBUG_POSTFIX "_d"
183 )
184endfunction()
185
186# ========================================
187# Pacpus install
188# ========================================
[21]189function(pacpus_install)
[19]190 install(
[21]191 TARGETS ${ARGV}
[19]192 RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin
193 LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/lib
194 ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib
195 )
196endfunction()
197
198# ========================================
199# Pacpus folder
200# ========================================
201function(pacpus_folder target folder_name)
202 if(PACPUS_USE_FOLDERS AND MSVC)
203 set_target_properties(${target}
204 PROPERTIES FOLDER ${folder_name}
205 )
206 endif()
207endfunction()
Note: See TracBrowser for help on using the repository browser.