1 ## -------------------------------------------------------------------------
2 FUNCTION(NormPaths output_files)
6 FILE(TO_CMAKE_PATH ${_f} _d)
7 LIST(APPEND _out ${_d})
9 SET(${output_files} "${_out}" PARENT_SCOPE)
12 ## -------------------------------------------------------------------------
13 FUNCTION(Wrap_Qt_CPP output_files)
18 STRING(FIND "${_txt}" "Q_OBJECT" _pos)
19 IF(NOT ${_pos} EQUAL -1)
21 QT4_WRAP_CPP(_s ${_f})
22 SET(_out ${_out} ${_s})
23 ENDIF(NOT ${_pos} EQUAL -1)
26 SET(${output_files} "${_out}" PARENT_SCOPE)
29 ## -------------------------------------------------------------------------
30 FUNCTION(Wrap_Qt_UI output_files)
31 NormPaths(_source_dir ${PROJECT_SOURCE_DIR})
32 NormPaths(_binary_dir ${PROJECT_BINARY_DIR})
36 GET_FILENAME_COMPONENT(_name ${_f} NAME_WE)
37 GET_FILENAME_COMPONENT(_dir ${_f} DIRECTORY)
38 SET(_base_dir ${_source_dir})
39 STRING(FIND "${_dir}" "${_base_dir}" _pos)
41 SET(_base_dir ${_binary_dir})
42 STRING(FIND "${_dir}" "${_base_dir}" _pos)
43 ENDIF(${_pos} EQUAL -1)
44 IF(NOT ${_pos} EQUAL -1)
45 STRING(REPLACE "${_base_dir}/" "" _dir ${_dir})
46 SET(_out_f ${_binary_dir}/${_dir}/ui_${_name}.h)
47 LIST(APPEND _out ${_out_f})
51 ARGS -o ${_out_f} ${_f}
52 MAIN_DEPENDENCY ${_f} VERBATIM
54 ENDIF(NOT ${_pos} EQUAL -1)
57 SET(${output_files} "${_out}" PARENT_SCOPE)
60 ## -------------------------------------------------------------------------
71 ## -- Configure inputs to be cmake-path compatible
72 NormPaths(_sources ${lib_source_files})
73 NormPaths(_headers ${lib_header_files})
74 NormPaths(_qt_uis ${lib_qt_ui_files})
76 # -- Prepare Qt4-based code
78 ## -- Guess what headers sould be qt-moc'ed
79 Wrap_Qt_CPP(_qt_moc_sources ${_headers})
81 SET(_sources ${_sources} ${_qt_moc_sources})
82 ENDIF(_qt_moc_sources)
84 ## -- Guess what qt-ui's sould be qt-uic'ed
85 ## -- Wrap qt-ui headers: this is equivalent to QT4_WRAP_UI except to change
87 Wrap_Qt_UI(_qt_ui_headers ${_qt_uis})
89 SET(_headers ${_headers} ${_qt_ui_headers})
90 SET(_sources ${_sources} ${_qt_ui_headers})
94 ## -- Ok, compile library
96 NormPaths(_cur_binary_dir ${CMAKE_CURRENT_BINARY_DIR})
97 ADD_LIBRARY(${lib_name} SHARED ${_sources} ${_headers})
98 SET_TARGET_PROPERTIES(
101 VERSION "${lib_version}"
102 SOVERSION "${lib_short_version}"
104 GENERATE_EXPORT_HEADER(
106 BASE_NAME ${lib_name}
107 EXPORT_MACRO_NAME ${lib_name}_EXPORT
108 EXPORT_FILE_NAME ${lib_name}_Export.h
109 STATIC_DEFINE ${lib_name}_BUILT_AS_STATIC
111 SET(${lib_name}_LIB ${lib_name} CACHE INTERNAL "Library ${lib_name}")
116 ## -------------------------------------------------------------------------
126 ## -- Configure inputs to be cmake-path compatible
127 NormPaths(_global_source_dir ${PROJECT_SOURCE_DIR})
128 NormPaths(_global_binary_dir ${PROJECT_BINARY_DIR})
129 NormPaths(_source_dir ${lib_source_dir})
130 STRING(REPLACE "${_global_source_dir}" "" _local_source_dir ${_source_dir})
131 SET(_binary_dir ${_global_binary_dir}${_local_source_dir})
133 ## -- Some useful variables
134 SET(_sources_extensions .c .cpp .cxx)
135 SET(_headers_extensions .h .hpp .hxx)
136 SET(_qt_ui_extensions .ui)
137 SET(_dirs ${_source_dir} ${_binary_dir})
142 ## -- Glob source code
144 FOREACH(_e ${_sources_extensions})
145 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
146 SET(_sources ${_sources} ${_f})
148 FOREACH(_e ${_headers_extensions})
149 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
150 SET(_headers ${_headers} ${_f})
152 FOREACH(_e ${_qt_ui_extensions})
153 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
154 SET(_qt_uis ${_qt_uis} ${_f})
158 ## -- Configure some files
159 FILE(GLOB_RECURSE _configs "${_source_dir}/*.in")
160 FOREACH(_c ${_configs})
162 ## -- Build input and output names
163 NormPaths(_input_file ${_c})
164 GET_FILENAME_COMPONENT(_input_name ${_input_file} NAME)
165 GET_FILENAME_COMPONENT(_input_dir ${_input_file} DIRECTORY)
166 STRING(REPLACE ".in" "" _output_name ${_input_name})
167 STRING(REPLACE "${_global_source_dir}" "" _output_dir ${_input_dir})
168 SET(_output_file "${_global_binary_dir}${_output_dir}/${_output_name}")
171 CONFIGURE_FILE(${_input_file} ${_output_file} @ONLY)
173 ## -- Add it to the correct list
174 GET_FILENAME_COMPONENT(_output_ext ${_output_name} EXT)
176 "${_output_ext}" STREQUAL ".h"
178 "${_output_ext}" STREQUAL ".hpp"
180 "${_output_ext}" STREQUAL ".hxx"
182 SET(_headers ${_headers})
185 "${_output_ext}" STREQUAL ".c"
187 "${_output_ext}" STREQUAL ".cpp"
189 "${_output_ext}" STREQUAL ".cxx"
191 SET(_sources ${_sources})
193 IF("${_output_ext}" STREQUAL ".ui")
194 SET(_qt_uis ${_qt_uis})
198 LIST(APPEND _sources ${ARGN})
203 ${lib_name} ${lib_type}
204 "${_sources}" "${_headers}" "${_qt_uis}"
205 "${lib_version}" "${lib_short_version}"
210 ## -------------------------------------------------------------------------
220 ## -- Configure inputs to be cmake-path compatible
221 NormPaths(_def_file ${def_file})
222 GET_FILENAME_COMPONENT(_def_name ${_def_file} NAME_WE)
223 GET_FILENAME_COMPONENT(_def_dir ${_def_file} DIRECTORY)
224 NormPaths(_global_source_dir ${PROJECT_SOURCE_DIR})
225 NormPaths(_global_binary_dir ${PROJECT_BINARY_DIR})
226 STRING(REPLACE "${_global_source_dir}" "" _out_dir ${_def_dir})
227 SET(_out_base "${_global_binary_dir}${_out_dir}")
228 SET(_out_header "${_out_base}/${_def_name}.h")
229 SET(_lib_name "${prefix}${_def_name}")
230 SET(_input_extra_code "${_global_source_dir}${_out_dir}/${_def_name}_extra.cxx")
232 ## -- Infere source code filenames
233 MATH(EXPR _last_range "${number_of_files}-1")
235 FOREACH(_n RANGE 0 ${_last_range})
236 LIST(APPEND _out_code ${_out_base}/${_def_name}_${_n}.cxx)
239 ## -- Add extra code, if any
240 SET(_all_out_code ${_out_code})
241 IF(EXISTS ${_input_extra_code})
242 LIST(APPEND _all_out_code ${_input_extra_code})
243 ENDIF(EXISTS ${_input_extra_code})
245 ## -- Command to write source code
247 OUTPUT ${_out_header} ${_out_code}
248 DEPENDS ${cpPlugins_bash_BuildInstances_APP} ${_def_file}
249 COMMAND ${cpPlugins_bash_BuildInstances_APP} ${_def_file} ${_lib_name} ${_out_base}/${_def_name} ${number_of_files}
254 "${_lib_name}" SHARED
255 "${_all_out_code}" "${_out_header}" ""
256 "${version}" "${short_version}"
260 SET(${out_lib_name} ${_lib_name} PARENT_SCOPE)
264 ## -------------------------------------------------------------------------
265 FUNCTION(Wrap_cpPlugins output_lib source_dir version short_version prefix)
267 ## -- Configure inputs to be cmake-path compatible
268 NormPaths(_source_dir ${source_dir})
269 NormPaths(_global_source_dir ${PROJECT_SOURCE_DIR})
270 NormPaths(_global_binary_dir ${PROJECT_BINARY_DIR})
271 STRING(REPLACE "${_global_source_dir}" "" _out_dir ${_source_dir})
272 SET(_out_dir "${_global_binary_dir}${_out_dir}")
273 FILE(MAKE_DIRECTORY ${_out_dir})
274 GET_FILENAME_COMPONENT(_lib_name ${_source_dir} NAME_WE)
275 SET(_lib_name ${prefix}${_lib_name})
277 ## -- Get source code
278 FILE(GLOB_RECURSE _hdr_h "${_source_dir}/*.h")
279 FILE(GLOB_RECURSE _hdr_hxx "${_source_dir}/*.hxx")
280 FILE(GLOB_RECURSE _hdr_hpp "${_source_dir}/*.hpp")
281 FILE(GLOB_RECURSE _src_c "${_source_dir}/*.c")
282 FILE(GLOB_RECURSE _src_cxx "${_source_dir}/*.cxx")
283 FILE(GLOB_RECURSE _src_cpp "${_source_dir}/*.cpp")
284 FILE(GLOB_RECURSE _qt_ui "${_source_dir}/*.ui")
286 ## -- Identify sources to wrap
288 FOREACH(_h ${_hdr_h})
289 FILE(READ ${_h} _txt)
290 STRING(FIND "${_txt}" "cpPluginsObject" _res)
291 IF(NOT ${_res} EQUAL -1)
292 LIST(APPEND _hdr_to_wrap ${_h})
293 ENDIF(NOT ${_res} EQUAL -1)
296 ## -- Integrate all source files
297 SET(_all_src ${_src_c} ${_src_cpp} ${_src_cxx})
298 SET(_all_hdr ${_hdr_h} ${_hdr_hpp} ${_hdr_hxx})
302 SET(_host ${_out_dir}/${_lib_name}_host.cxx)
305 DEPENDS ${cpPlugins_bash_HostCreator_APP} ${_hdr_to_wrap}
306 COMMAND ${cpPlugins_bash_HostCreator_APP} ${_lib_name} ${_host} ${_hdr_to_wrap}
308 SET(_all_src ${_all_src} ${_host})
311 ## -- Ok, build library
315 "${_all_src}" "${_all_hdr}" "${_qt_ui}"
316 "${version}" "${short_version}"
319 SET(${output_lib} ${_lib_name} PARENT_SCOPE)
321 MESSAGE(FATAL_ERROR "No source code found to build \"${_lib_name}\"")
325 ## -------------------------------------------------------------------------
326 FUNCTION(AppFromDir output_app source_dir)
328 ## -- Configure inputs to be cmake-path compatible
329 NormPaths(_global_source_dir ${PROJECT_SOURCE_DIR})
330 NormPaths(_global_binary_dir ${PROJECT_BINARY_DIR})
331 NormPaths(_source_dir ${source_dir})
332 STRING(REPLACE "${_global_source_dir}" "" _local_source_dir ${_source_dir})
333 SET(_binary_dir ${_global_binary_dir}${_local_source_dir})
335 SET(_app_name ${${output_app}})
337 GET_FILENAME_COMPONENT(_app_name ${_source_dir} NAME_WE)
339 SET(_app_name_option OFF)
341 LIST(GET ARGN 0 _app_name_option)
345 "Build \"${_app_name}\" application"
349 ## -- Real build commands
350 IF(BUILD_${_app_name})
351 ## -- Some useful variables
352 SET(_sources_extensions .c .cpp .cxx)
353 SET(_headers_extensions .h .hpp .hxx)
354 SET(_qt_ui_extensions .ui)
355 SET(_dirs ${_source_dir} ${_binary_dir})
360 ## -- Glob source code
362 FOREACH(_e ${_sources_extensions})
363 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
364 SET(_sources ${_sources} ${_f})
366 FOREACH(_e ${_headers_extensions})
367 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
368 SET(_headers ${_headers} ${_f})
370 FOREACH(_e ${_qt_ui_extensions})
371 FILE(GLOB_RECURSE _f "${_d}/*${_e}")
372 SET(_qt_uis ${_qt_uis} ${_f})
376 ## -- Configure some files
377 FILE(GLOB_RECURSE _configs "${_source_dir}/*.in")
378 FOREACH(_c ${_configs})
380 ## -- Build input and output names
381 NormPaths(_input_file ${_c})
382 GET_FILENAME_COMPONENT(_input_name ${_input_file} NAME)
383 GET_FILENAME_COMPONENT(_input_dir ${_input_file} DIRECTORY)
384 STRING(REPLACE ".in" "" _output_name ${_input_name})
385 STRING(REPLACE "${_global_source_dir}" "" _output_dir ${_input_dir})
386 SET(_output_file "${_global_binary_dir}${_output_dir}/${_output_name}")
389 CONFIGURE_FILE(${_input_file} ${_output_file} @ONLY)
391 ## -- Add it to the correct list
392 GET_FILENAME_COMPONENT(_output_ext ${_output_name} EXT)
394 "${_output_ext}" STREQUAL ".h"
396 "${_output_ext}" STREQUAL ".hpp"
398 "${_output_ext}" STREQUAL ".hxx"
400 SET(_headers ${_headers})
403 "${_output_ext}" STREQUAL ".c"
405 "${_output_ext}" STREQUAL ".cpp"
407 "${_output_ext}" STREQUAL ".cxx"
409 SET(_sources ${_sources})
411 IF("${_output_ext}" STREQUAL ".ui")
412 SET(_qt_uis ${_qt_uis})
416 # -- Prepare Qt4-based code
419 ## -- Guess what headers sould be qt-moc'ed
420 Wrap_Qt_CPP(_qt_moc_sources ${_headers})
422 SET(_sources ${_sources} ${_qt_moc_sources})
423 ENDIF(_qt_moc_sources)
424 ## -- Guess what qt-ui's sould be qt-uic'ed
425 ## -- Wrap qt-ui headers: this is equivalent to QT4_WRAP_UI except to
426 ## -- change the output file
427 Wrap_Qt_UI(_qt_ui_headers ${_qt_uis})
429 SET(_headers ${_headers} ${_qt_ui_headers})
430 SET(_sources ${_sources} ${_qt_ui_headers})
431 ENDIF(_qt_ui_headers)
434 ## -- Ok, compile application
441 SET(_gui_type MACOSX_BUNDLE)
443 ADD_EXECUTABLE(${_app_name} ${_gui_type} ${_sources})
444 SET(${output_app} ${_app_name} PARENT_SCOPE)
446 SET(${output_app} "" PARENT_SCOPE)
447 MESSAGE(FATAL_ERROR "No source code found to build \"${_app_name}\"")
449 ENDIF(BUILD_${_app_name})