3 #=============================================================================
4 # Copyright 2006-2009 Kitware, Inc.
5 # Copyright 2006 Alexander Neundorf <neundorf@kde.org>
7 # Distributed under the OSI-approved BSD License (the "License");
8 # see accompanying file Copyright.txt for details.
10 # This software is distributed WITHOUT ANY WARRANTY; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # See the License for more information.
13 #=============================================================================
14 # (To distribute this file outside of CMake, substitute the full
15 # License text for the above reference.)
17 # See FindKDE3.cmake for documentation.
19 # this file contains the following macros:
26 # KDE3_INSTALL_LIBTOOL_FILE
27 # KDE3_CREATE_FINAL_FILE
29 # KDE3_ADD_KDEINIT_EXECUTABLE
35 include(AddFileDependencies)
37 #create the kidl and skeletion file for dcop stuff
38 #usage: KDE_ADD_COP_SKELS(foo_SRCS ${dcop_headers})
39 macro(KDE3_ADD_DCOP_SKELS _sources)
40 foreach (_current_FILE ${ARGN})
42 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
43 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
45 set(_skel ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_skel.cpp)
46 set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl)
48 if (NOT HAVE_${_basename}_KIDL_RULE)
49 set(HAVE_${_basename}_KIDL_RULE ON)
51 add_custom_command(OUTPUT ${_kidl}
52 COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
53 ARGS ${_tmp_FILE} > ${_kidl}
59 if (NOT HAVE_${_basename}_SKEL_RULE)
60 set(HAVE_${_basename}_SKEL_RULE ON)
62 add_custom_command(OUTPUT ${_skel}
63 COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
64 ARGS --c++-suffix cpp --no-signals --no-stub ${_kidl}
70 set(${_sources} ${${_sources}} ${_skel})
77 macro(KDE3_ADD_DCOP_STUBS _sources)
78 foreach (_current_FILE ${ARGN})
80 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
82 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
84 set(_stub_CPP ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_stub.cpp)
85 set(_kidl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.kidl)
87 if (NOT HAVE_${_basename}_KIDL_RULE)
88 set(HAVE_${_basename}_KIDL_RULE ON)
91 add_custom_command(OUTPUT ${_kidl}
92 COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
93 ARGS ${_tmp_FILE} > ${_kidl}
100 if (NOT HAVE_${_basename}_STUB_RULE)
101 set(HAVE_${_basename}_STUB_RULE ON)
103 add_custom_command(OUTPUT ${_stub_CPP}
104 COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
105 ARGS --c++-suffix cpp --no-signals --no-skel ${_kidl}
111 set(${_sources} ${${_sources}} ${_stub_CPP})
118 macro(KDE3_ADD_KCFG_FILES _sources)
119 foreach (_current_FILE ${ARGN})
121 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
123 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
125 file(READ ${_tmp_FILE} _contents)
126 string(REGEX REPLACE "^(.*\n)?File=([^\n]+)\n.*$" "\\2" _kcfg_FILE "${_contents}")
128 set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
129 set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
131 add_custom_command(OUTPUT ${_src_FILE}
132 COMMAND ${KDE3_KCFGC_EXECUTABLE}
133 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} ${_tmp_FILE}
134 DEPENDS ${_tmp_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${_kcfg_FILE} )
136 set(${_sources} ${${_sources}} ${_src_FILE})
143 #create the moc files and add them to the list of sources
144 #usage: KDE_ADD_MOC_FILES(foo_SRCS ${moc_headers})
145 macro(KDE3_ADD_MOC_FILES _sources)
146 foreach (_current_FILE ${ARGN})
148 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
150 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
151 set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp)
153 add_custom_command(OUTPUT ${_moc}
154 COMMAND ${QT_MOC_EXECUTABLE}
155 ARGS ${_tmp_FILE} -o ${_moc}
159 set(${_sources} ${${_sources}} ${_moc})
165 get_filename_component( KDE3_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
167 #create the implementation files from the ui files and add them to the list of sources
168 #usage: KDE_ADD_UI_FILES(foo_SRCS ${ui_files})
169 macro(KDE3_ADD_UI_FILES _sources )
170 foreach (_current_FILE ${ARGN})
172 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
174 get_filename_component(_basename ${_tmp_FILE} NAME_WE)
175 set(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
176 set(_src ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
177 set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc.cpp)
179 add_custom_command(OUTPUT ${_header}
180 COMMAND ${QT_UIC_EXECUTABLE}
181 ARGS -L ${KDE3_LIB_DIR}/kde3/plugins/designer -nounload -o ${_header} ${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE}
185 add_custom_command(OUTPUT ${_src}
186 COMMAND ${CMAKE_COMMAND}
188 -DKDE_UIC_PLUGIN_DIR:FILEPATH=${KDE3_LIB_DIR}/kde3/plugins/designer
189 -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE}
190 -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE}
191 -DKDE_UIC_CPP_FILE:FILEPATH=${_src}
192 -DKDE_UIC_H_FILE:FILEPATH=${_header}
193 -P ${KDE3_MODULE_DIR}/kde3uic.cmake
197 add_custom_command(OUTPUT ${_moc}
198 COMMAND ${QT_MOC_EXECUTABLE}
199 ARGS ${_header} -o ${_moc}
203 set(${_sources} ${${_sources}} ${_src} ${_moc} )
210 set(_matching_FILES )
211 foreach (_current_FILE ${ARGN})
213 get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
215 # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
216 # here. this is required to make bouic work correctly:
217 # we need to add generated .cpp files to the sources (to compile them),
218 # but we cannot let automoc handle them, as the .cpp files don't exist yet when
219 # cmake is run for the very first time on them -> however the .cpp files might
220 # exist at a later run. at that time we need to skip them, so that we don't add two
221 # different rules for the same moc file
222 get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
224 if (EXISTS ${_abs_FILE} AND NOT _skip)
226 file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]")
228 get_filename_component(_abs_PATH ${_abs_FILE} PATH)
230 foreach (_current_MOC_INC IN LISTS _match)
231 string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
233 get_filename_component(_basename ${_current_MOC} NAME_WE)
234 # set(_header ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.h)
235 set(_header ${_abs_PATH}/${_basename}.h)
236 set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
238 add_custom_command(OUTPUT ${_moc}
239 COMMAND ${QT_MOC_EXECUTABLE}
240 ARGS ${_header} -o ${_moc}
244 ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
254 # only used internally by KDE3_INSTALL_ICONS
255 macro (_KDE3_ADD_ICON_INSTALL_RULE _install_SCRIPT _install_PATH _group _orig_NAME _install_NAME)
257 # if the string doesn't match the pattern, the result is the full string, so all three have the same content
258 if (NOT ${_group} STREQUAL ${_install_NAME} )
259 set(_icon_GROUP "actions")
261 if (${_group} STREQUAL "mime")
262 set(_icon_GROUP "mimetypes")
265 if (${_group} STREQUAL "filesys")
266 set(_icon_GROUP "filesystems")
269 if (${_group} STREQUAL "device")
270 set(_icon_GROUP "devices")
273 if (${_group} STREQUAL "app")
274 set(_icon_GROUP "apps")
277 if (${_group} STREQUAL "action")
278 set(_icon_GROUP "actions")
281 # message(STATUS "icon: ${_current_ICON} size: ${_size} group: ${_group} name: ${_name}" )
282 install(FILES ${_orig_NAME} DESTINATION ${_install_PATH}/${_icon_GROUP}/ RENAME ${_install_NAME} )
288 macro (KDE3_INSTALL_ICONS _theme )
289 set(_defaultpath "${CMAKE_INSTALL_PREFIX}/share/icons")
290 # first the png icons
291 file(GLOB _icons *.png)
292 foreach (_current_ICON ${_icons} )
293 string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\1" _size "${_current_ICON}")
294 string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\2" _group "${_current_ICON}")
295 string(REGEX REPLACE "^.*/[a-zA-Z]+([0-9]+)\\-([a-z]+)\\-(.+\\.png)$" "\\3" _name "${_current_ICON}")
296 _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
297 ${_defaultpath}/${_theme}/${_size}x${_size}
298 ${_group} ${_current_ICON} ${_name})
301 # and now the svg icons
302 file(GLOB _icons *.svgz)
303 foreach (_current_ICON ${_icons} )
304 string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\1" _group "${_current_ICON}")
305 string(REGEX REPLACE "^.*/crsc\\-([a-z]+)\\-(.+\\.svgz)$" "\\2" _name "${_current_ICON}")
306 _KDE3_ADD_ICON_INSTALL_RULE(${CMAKE_CURRENT_BINARY_DIR}/install_icons.cmake
307 ${_defaultpath}/${_theme}/scalable
308 ${_group} ${_current_ICON} ${_name})
313 macro(KDE3_INSTALL_LIBTOOL_FILE _target)
314 get_target_property(_target_location ${_target} LOCATION)
316 get_filename_component(_laname ${_target_location} NAME_WE)
317 get_filename_component(_soname ${_target_location} NAME)
318 set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la)
320 file(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
321 file(APPEND ${_laname} "# The name that we can dlopen(3).\n")
322 file(APPEND ${_laname} "dlname='${_soname}'\n")
323 file(APPEND ${_laname} "# Names of this library\n")
325 file(APPEND ${_laname} "library_names='${_soname}'\n")
327 file(APPEND ${_laname} "library_names='${_soname} ${_soname} ${_soname}'\n")
329 file(APPEND ${_laname} "# The name of the static archive\n")
330 file(APPEND ${_laname} "old_library=''\n")
331 file(APPEND ${_laname} "# Libraries that this one depends upon.\n")
332 file(APPEND ${_laname} "dependency_libs=''\n")
333 # file(APPEND ${_laname} "dependency_libs='${${_target}_LIB_DEPENDS}'\n")
334 file(APPEND ${_laname} "# Version information.\ncurrent=0\nage=0\nrevision=0\n")
335 file(APPEND ${_laname} "# Is this an already installed library?\ninstalled=yes\n")
336 file(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\nshouldnotlink=yes\n")
337 file(APPEND ${_laname} "# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''\n")
338 file(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
339 file(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/lib/kde3'\n")
341 install_files(${KDE3_LIBTOOL_DIR} FILES ${_laname})
345 macro(KDE3_CREATE_FINAL_FILE _filename)
346 file(WRITE ${_filename} "//autogenerated file\n")
347 foreach (_current_FILE ${ARGN})
348 file(APPEND ${_filename} "#include \"${_current_FILE}\"\n")
354 # option(KDE3_ENABLE_FINAL "Enable final all-in-one compilation")
355 option(KDE3_BUILD_TESTS "Build the tests")
358 macro(KDE3_ADD_KPART _target_NAME _with_PREFIX)
359 #is the first argument is "WITH_PREFIX" then keep the standard "lib" prefix, otherwise SET the prefix empty
360 if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
363 set(_first_SRC ${_with_PREFIX})
366 # if (KDE3_ENABLE_FINAL)
367 # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${_first_SRC} ${ARGN})
368 # add_library(${_target_NAME} MODULE ${_target_NAME}_final.cpp)
370 add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
374 set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
377 KDE3_INSTALL_LIBTOOL_FILE(${_target_NAME})
382 macro(KDE3_ADD_KDEINIT_EXECUTABLE _target_NAME )
384 # if (KDE3_ENABLE_FINAL)
385 # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN})
386 # add_library(kdeinit_${_target_NAME} SHARED ${_target_NAME}_final.cpp)
388 add_library(kdeinit_${_target_NAME} SHARED ${ARGN} )
391 configure_file(${KDE3_MODULE_DIR}/kde3init_dummy.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp)
393 add_executable( ${_target_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp )
394 target_link_libraries( ${_target_NAME} kdeinit_${_target_NAME} )
399 macro(KDE3_ADD_EXECUTABLE _target_NAME )
401 # if (KDE3_ENABLE_FINAL)
402 # KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN})
403 # add_executable(${_target_NAME} ${_target_NAME}_final.cpp)
405 add_executable(${_target_NAME} ${ARGN} )