source: pacpusframework/branches/0.0.x/cmake/PacpusUtilities.cmake@ 366

Last change on this file since 366 was 64, checked in by Marek Kurdej, 11 years ago

Modified property: added svn:keywords=Id.

  • Property svn:keywords set to Id
File size: 7.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>\n"
30 "#include <qplugin.h>\n"
31 "\n"
32 "#include <Pacpus/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 if(MSVC9)
91 set(${output} "msvc2008")
92 elseif(MSVC10)
93 set(${output} "msvc2010")
94 else(MSVC11)
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()
159
160# ========================================
161# Pacpus add library and set debug postfix
162# ========================================
163function(pacpus_add_library target)
164 add_library(
165 ${ARGV}
166 )
167 set_target_properties(
168 ${target}
169 PROPERTIES DEBUG_POSTFIX "_d"
170 )
171endfunction()
172
173# ========================================
174# Pacpus add executable and set debug postfix
175# ========================================
176function(pacpus_add_executable target)
177 add_executable(
178 ${ARGV}
179 )
180 set_target_properties(
181 ${target}
182 PROPERTIES DEBUG_POSTFIX "_d"
183 )
184endfunction()
185
186# ========================================
187# Pacpus install
188# ========================================
189function(pacpus_install)
190 install(
191 TARGETS ${ARGV}
192 RUNTIME DESTINATION ${PACPUS_INSTALL_DIR}/bin
193 LIBRARY DESTINATION ${PACPUS_INSTALL_DIR}/lib
194 ARCHIVE DESTINATION ${PACPUS_INSTALL_DIR}/lib
195 )
196 if(MSVC)
197 # install debug information files .pdb
198 foreach(target ${ARGV})
199 get_target_property(target_filepath ${target} LOCATION_DEBUG)
200 get_filename_component(target_directory ${target_filepath} PATH)
201 get_filename_component(target_basename ${target_filepath} NAME_WE)
202
203 set(target_pdb "${target_directory}/${target_basename}.pdb")
204 install(FILES ${target_pdb}
205 CONFIGURATIONS Debug
206 DESTINATION ${PACPUS_INSTALL_DIR}/lib
207 )
208 endforeach()
209 endif(MSVC)
210endfunction()
211
212# ========================================
213# Pacpus folder
214# ========================================
215function(pacpus_folder target folder_name)
216 if(PACPUS_USE_SOLUTION_FOLDERS AND MSVC)
217 set_target_properties(${target}
218 PROPERTIES FOLDER ${folder_name}
219 )
220 endif()
221endfunction()
Note: See TracBrowser for help on using the repository browser.