Shared cmake folder
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1395 lines
40 KiB

  1. #################################################
  2. #
  3. # (C) 2010-2012 Serghei Amelian
  4. # serghei (DOT) amelian (AT) gmail.com
  5. #
  6. # (C) 2011-2012 Timothy Pearson
  7. # kb9vqf (AT) pearsoncomputing.net
  8. #
  9. # Improvements and feedback are welcome
  10. #
  11. # This file is released under GPL >= 2
  12. #
  13. #################################################
  14. include( KDE3Macros ) # we will need this module for a while
  15. #################################################
  16. #####
  17. ##### tde_message_fatal
  18. macro( tde_message_fatal )
  19. message( FATAL_ERROR
  20. "#################################################\n"
  21. " ${ARGV}\n"
  22. "#################################################" )
  23. endmacro( tde_message_fatal )
  24. #################################################
  25. #####
  26. ##### tde_get_arg( <ARG_NAME> <COUNT> <RETURN> <REST> <ARGS...> )
  27. ##### ARG_NAME(string): name of an argument to find in ARGS
  28. ##### COUNT(number): argument dimension, a number of items returned in RETURN
  29. ##### RETURN(list ref): items returned for argument as they found in ARGS
  30. ##### REST(list ref): rest of items except argument name and items returned in RETURN
  31. ##### ARGS(list): source list of arguments
  32. macro( tde_get_arg ARG_NAME COUNT RETURN REST )
  33. unset( ${RETURN} )
  34. unset( ${REST} )
  35. list( APPEND ${REST} ${ARGN} )
  36. list( FIND ${REST} ${ARG_NAME} _arg_idx)
  37. if( NOT ${_arg_idx} EQUAL -1 )
  38. list( REMOVE_AT ${REST} ${_arg_idx} )
  39. set( _i 0 )
  40. while( ${_i} LESS ${COUNT} )
  41. list( GET ${REST} ${_arg_idx} _arg )
  42. list( REMOVE_AT ${REST} ${_arg_idx} )
  43. list( APPEND ${RETURN} ${_arg} )
  44. math( EXPR _i "${_i} + 1" )
  45. endwhile()
  46. endif()
  47. endmacro( tde_get_arg )
  48. ################################################
  49. #####
  50. ##### tde_execute_process( <ARGS...> [MESSAGE <MSG>] )
  51. ##### MSG: fatal error message (standard message will be written if not supplied)
  52. ##### ARGS: execute_process arguments
  53. macro( tde_execute_process )
  54. tde_get_arg( MESSAGE 1 _message _rest_args ${ARGV} )
  55. tde_get_arg( RESULT_VARIABLE 1 _result_variable _tmp ${_rest_args} )
  56. tde_get_arg( COMMAND 1 _command _tmp ${_rest_args} )
  57. tde_get_arg( OUTPUT_VARIABLE 1 _output_variable _tmp ${_rest_args} )
  58. tde_get_arg( CACHE 3 _cache _rest_args2 ${_rest_args} )
  59. # handle optional FORCE parameter
  60. if( DEFINED _cache )
  61. list( GET _cache 2 _tmp )
  62. if( _tmp STREQUAL FORCE )
  63. set( _rest_args ${_rest_args2} )
  64. else()
  65. tde_get_arg( CACHE 2 _cache _rest_args ${_rest_args} )
  66. endif()
  67. endif()
  68. if( NOT DEFINED _result_variable )
  69. list( APPEND _rest_args RESULT_VARIABLE _exec_result )
  70. set( _result_variable _exec_result )
  71. endif()
  72. execute_process( ${_rest_args} )
  73. if( DEFINED _output_variable AND DEFINED _cache )
  74. set( ${_output_variable} ${${_output_variable}} CACHE ${_cache} )
  75. endif()
  76. if( ${_result_variable} )
  77. if( DEFINED _message )
  78. tde_message_fatal( ${_message} )
  79. else()
  80. if( ${${_result_variable}} MATCHES "^[0-9]+$" )
  81. set( ${_result_variable} "status ${${_result_variable}} returned!" )
  82. endif()
  83. tde_message_fatal( "Error executing '${_command}': ${${_result_variable}}" )
  84. endif()
  85. endif()
  86. endmacro( tde_execute_process )
  87. if( DEFINED MASTER_SOURCE_DIR )
  88. return( )
  89. endif( )
  90. ########### slave part ends here ###############
  91. ################################################
  92. #####
  93. ##### tde_install_icons( <icons...> THEME <svgicons> DESTINATION <destdir> )
  94. ##### default theme: hicolor
  95. ##### default destination: ${SHARE_INSTALL_DIR}/icons
  96. macro( tde_install_icons )
  97. tde_get_arg( DESTINATION 1 _dest _args ${ARGV} )
  98. tde_get_arg( THEME 1 _req_theme _icons ${_args} )
  99. #defaults
  100. if( NOT _icons )
  101. set( _icons "*" )
  102. endif( NOT _icons )
  103. if( NOT _dest )
  104. set( _dest "${ICON_INSTALL_DIR}" )
  105. endif( NOT _dest )
  106. foreach( _icon ${_icons} )
  107. unset( _theme ) # clearing
  108. file(GLOB _icon_files *-${_icon}.png *-${_icon}.mng _icon_files *-${_icon}.svg* )
  109. foreach( _icon_file ${_icon_files} )
  110. # FIXME need a review
  111. string( REGEX MATCH "^.*/([a-zA-Z][a-zA-Z])([0-9a-zA-Z]+)\\-([a-z]+)\\-([^/]+)$" _dummy "${_icon_file}" )
  112. set( _type "${CMAKE_MATCH_1}" )
  113. set( _size "${CMAKE_MATCH_2}" )
  114. set( _group "${CMAKE_MATCH_3}" )
  115. set( _name "${CMAKE_MATCH_4}" )
  116. # we must ignore invalid icon names
  117. if( _type AND _size AND _group AND _name )
  118. # autodetect theme
  119. if( NOT _req_theme )
  120. unset( _theme )
  121. if( "${_type}" STREQUAL "cr" )
  122. set( _theme crystalsvg )
  123. elseif( "${_type}" STREQUAL "lo" )
  124. set( _theme locolor )
  125. endif( "${_type}" STREQUAL "cr" )
  126. # defaulting
  127. if( NOT _theme )
  128. set( _theme hicolor )
  129. endif( NOT _theme )
  130. else( NOT _req_theme )
  131. set( _theme ${_req_theme} )
  132. endif( NOT _req_theme )
  133. # fix "group" name
  134. if( "${_group}" STREQUAL "mime" )
  135. set( _group "mimetypes" )
  136. endif( "${_group}" STREQUAL "mime" )
  137. if( "${_group}" STREQUAL "filesys" )
  138. set( _group "places" )
  139. endif( "${_group}" STREQUAL "filesys" )
  140. if( "${_group}" STREQUAL "device" )
  141. set( _group "devices" )
  142. endif( "${_group}" STREQUAL "device" )
  143. if( "${_group}" STREQUAL "app" )
  144. set( _group "apps" )
  145. endif( "${_group}" STREQUAL "app" )
  146. if( "${_group}" STREQUAL "action" )
  147. set( _group "actions" )
  148. endif( "${_group}" STREQUAL "action" )
  149. if( "${_size}" STREQUAL "sc" )
  150. install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/scalable/${_group}/ RENAME ${_name} )
  151. else( "${_size}" STREQUAL "sc" )
  152. install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/${_size}x${_size}/${_group}/ RENAME ${_name} )
  153. endif( "${_size}" STREQUAL "sc" )
  154. endif( _type AND _size AND _group AND _name )
  155. endforeach( _icon_file )
  156. endforeach( _icon )
  157. endmacro( tde_install_icons )
  158. #################################################
  159. #####
  160. ##### tde_add_lut( <source> <result> [depends] )
  161. ##### default depends: source
  162. macro( tde_add_lut _src _lut _dep )
  163. set( create_hash_table ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
  164. if( NOT _dep )
  165. set( _dep ${_src} )
  166. endif( NOT _dep )
  167. add_custom_command( OUTPUT ${_lut}
  168. COMMAND perl ARGS ${create_hash_table} ${CMAKE_CURRENT_SOURCE_DIR}/${_src} -i > ${_lut}
  169. DEPENDS ${_src} )
  170. set_source_files_properties( ${_dep} PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_lut} )
  171. unset( _dep )
  172. endmacro( tde_add_lut )
  173. #################################################
  174. #####
  175. ##### tde_add_luts( <sources...> )
  176. macro( tde_add_luts )
  177. foreach( _src ${ARGV} )
  178. get_filename_component( _lut ${_src} NAME_WE )
  179. set( _lut "${_lut}.lut.h" )
  180. tde_add_lut( ${_src} ${_lut} ${_src} )
  181. endforeach( _src )
  182. endmacro( tde_add_luts )
  183. #################################################
  184. #####
  185. ##### tde_file_to_cpp( <source> <destination> <variable> )
  186. macro( tde_file_to_cpp _src _dst _var )
  187. if( IS_ABSOLUTE ${_dst} )
  188. set( dst ${_dst} )
  189. else( )
  190. set( dst "${CMAKE_CURRENT_BINARY_DIR}/${_dst}" )
  191. endif( )
  192. file( READ ${_src} text )
  193. string( REGEX REPLACE "\n" "\\\\n\"\n\"" text "${text}" )
  194. set( text "/* Generated by CMake */\n\nconst char *${_var} = \n\n\"${text}\";\n" )
  195. string( REGEX REPLACE "\n\"\";\n$" ";\n" text "${text}" )
  196. file( WRITE ${dst} "${text}" )
  197. endmacro( )
  198. #################################################
  199. #####
  200. ##### tde_install_la_file( <target> <destination> )
  201. macro( tde_install_la_file _target _destination )
  202. get_target_property( _target_location ${_target} LOCATION )
  203. get_filename_component( _laname ${_target_location} NAME_WE )
  204. get_filename_component( _soname ${_target_location} NAME )
  205. set( _laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la )
  206. file( WRITE ${_laname}
  207. "# ${_laname} - a libtool library file, generated by cmake
  208. # The name that we can dlopen(3).
  209. dlname='${_soname}'
  210. # Names of this library
  211. library_names='${_soname} ${_soname} ${_soname}'
  212. # The name of the static archive
  213. old_library=''
  214. # Libraries that this one depends upon.
  215. dependency_libs=''
  216. # Version information.\ncurrent=0\nage=0\nrevision=0
  217. # Is this an already installed library?\ninstalled=yes
  218. # Should we warn about portability when linking against -modules?\nshouldnotlink=yes
  219. # Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''
  220. # Directory that this library needs to be installed in:
  221. libdir='${_destination}'
  222. " )
  223. install( FILES ${_laname} DESTINATION ${_destination} )
  224. endmacro( tde_install_la_file )
  225. #################################################
  226. #####
  227. ##### tde_add_ui_files
  228. macro( tde_add_ui_files _sources )
  229. foreach( _ui_file ${ARGN} )
  230. get_filename_component( _ui_basename ${_ui_file} NAME_WE )
  231. get_filename_component( _ui_absolute_path ${_ui_file} ABSOLUTE )
  232. list( APPEND ${_sources} ${_ui_basename}.cpp )
  233. add_custom_command( OUTPUT ${_ui_basename}.h ${_ui_basename}.cpp
  234. COMMAND ${CMAKE_COMMAND}
  235. -DUIC_EXECUTABLE:FILEPATH=${UIC_EXECUTABLE}
  236. -DTQT_REPLACE_SCRIPT:FILEPATH=${TQT_REPLACE_SCRIPT}
  237. -DTDE_QTPLUGINS_DIR:FILEPATH=${TDE_QTPLUGINS_DIR}
  238. -DUI_FILE:FILEPATH=${_ui_absolute_path}
  239. -DMASTER_SOURCE_DIR:FILEPATH=${CMAKE_SOURCE_DIR}
  240. -DMASTER_BINARY_DIR:FILEPATH=${CMAKE_BINARY_DIR}
  241. -P ${CMAKE_MODULE_PATH}/tde_uic.cmake
  242. COMMAND ${MOC_EXECUTABLE} ${_ui_basename}.h >> ${_ui_basename}.cpp
  243. DEPENDS ${_ui_absolute_path} )
  244. endforeach( _ui_file )
  245. endmacro( tde_add_ui_files )
  246. #################################################
  247. #####
  248. ##### tde_moc
  249. macro( tde_moc _sources )
  250. foreach( _input_file ${ARGN} )
  251. get_filename_component( _input_file "${_input_file}" ABSOLUTE )
  252. get_filename_component( _basename ${_input_file} NAME_WE )
  253. set( _output_file "${_basename}.moc.cpp" )
  254. add_custom_command( OUTPUT ${_output_file}
  255. COMMAND
  256. ${TMOC_EXECUTABLE} ${_input_file} -o ${_output_file}
  257. DEPENDS
  258. ${_input_file} )
  259. list( APPEND ${_sources} ${_output_file} )
  260. endforeach( )
  261. endmacro( )
  262. #################################################
  263. #####
  264. ##### tde_automoc
  265. macro( tde_automoc )
  266. foreach( _src_file ${ARGN} )
  267. get_filename_component( _src_file "${_src_file}" ABSOLUTE )
  268. if( EXISTS "${_src_file}" )
  269. # read source file and check if have moc include
  270. file( READ "${_src_file}" _src_content )
  271. string( REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _moc_includes "${_src_content}" )
  272. # found included moc(s)?
  273. if( _moc_includes )
  274. foreach( _moc_file ${_moc_includes} )
  275. # extracting moc filename
  276. string( REGEX MATCH "[^ <\"]+\\.moc" _moc_file "${_moc_file}" )
  277. set( _moc_file "${CMAKE_CURRENT_BINARY_DIR}/${_moc_file}" )
  278. # create header filename
  279. get_filename_component( _src_path "${_src_file}" ABSOLUTE )
  280. get_filename_component( _src_path "${_src_path}" PATH )
  281. get_filename_component( _src_header "${_moc_file}" NAME_WE )
  282. set( _header_file "${_src_path}/${_src_header}.h" )
  283. # if header doesn't exists, check in META_INCLUDES
  284. if( NOT EXISTS "${_header_file}" )
  285. unset( _found )
  286. foreach( _src_path ${_meta_includes} )
  287. set( _header_file "${_src_path}/${_src_header}.h" )
  288. if( EXISTS "${_header_file}" )
  289. set( _found 1 )
  290. break( )
  291. endif( )
  292. endforeach( )
  293. if( NOT _found )
  294. get_filename_component( _moc_file "${_moc_file}" NAME )
  295. tde_message_fatal( "AUTOMOC error: '${_moc_file}' cannot be generated.\n Reason: '${_src_file}.h' not found." )
  296. endif( )
  297. endif( )
  298. # moc-ing header
  299. add_custom_command( OUTPUT ${_moc_file}
  300. COMMAND ${TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file}
  301. DEPENDS ${_header_file} )
  302. # create dependency between source file and moc file
  303. set_property( SOURCE ${_src_file} APPEND PROPERTY OBJECT_DEPENDS ${_moc_file} )
  304. endforeach( _moc_file )
  305. endif( _moc_includes )
  306. endif( EXISTS "${_src_file}" )
  307. endforeach( _src_file )
  308. endmacro( tde_automoc )
  309. #################################################
  310. #####
  311. ##### __tde_internal_process_sources
  312. macro( __tde_internal_process_sources _sources )
  313. unset( ${_sources} )
  314. foreach( _arg ${ARGN} )
  315. get_filename_component( _ext ${_arg} EXT )
  316. get_filename_component( _name ${_arg} NAME_WE )
  317. get_filename_component( _path ${_arg} PATH )
  318. # if not path, set it to "."
  319. if( NOT _path )
  320. set( _path "./" )
  321. endif( NOT _path )
  322. # handle .ui files
  323. if( ${_ext} STREQUAL ".ui" )
  324. tde_add_ui_files( ${_sources} ${_arg} )
  325. # handle .skel files
  326. elseif( ${_ext} STREQUAL ".skel" )
  327. kde3_add_dcop_skels( ${_sources} ${_path}/${_name}.h )
  328. # handle .stub files
  329. elseif( ${_ext} STREQUAL ".stub" )
  330. kde3_add_dcop_stubs( ${_sources} ${_path}/${_name}.h )
  331. # handle .kcfgc files
  332. elseif( ${_ext} STREQUAL ".kcfgc" )
  333. kde3_add_kcfg_files( ${_sources} ${_arg} )
  334. # handle any other files
  335. else( ${_ext} STREQUAL ".ui" )
  336. list(APPEND ${_sources} ${_arg} )
  337. endif( ${_ext} STREQUAL ".ui" )
  338. endforeach( _arg )
  339. endmacro( __tde_internal_process_sources )
  340. #################################################
  341. #####
  342. ##### tde_install_libtool_file
  343. macro( tde_install_libtool_file _target _destination )
  344. get_target_property( _target_location ${_target} LOCATION )
  345. # get name of target
  346. get_filename_component( _name ${_target_location} NAME_WE )
  347. # get .la name
  348. set( _laname ${_name}.la )
  349. # get .so name
  350. get_filename_component( _soname ${_target_location} NAME )
  351. # get version of target
  352. get_target_property( _target_version ${_target} VERSION )
  353. get_target_property( _target_soversion ${_target} SOVERSION )
  354. # we have so version
  355. if( _target_version )
  356. set( _library_name_1 "${_soname}.${_target_version}" )
  357. set( _library_name_2 "${_soname}.${_target_soversion}" )
  358. set( _library_name_3 "${_soname}" )
  359. string( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" _dummy "${_target_version}" )
  360. set( _version_current "${CMAKE_MATCH_1}" )
  361. set( _version_age "${CMAKE_MATCH_2}" )
  362. set( _version_revision "${CMAKE_MATCH_3}" )
  363. # we have no so version (module?)
  364. else( _target_version )
  365. set( _library_name_1 "${_soname}" )
  366. set( _library_name_2 "${_soname}" )
  367. set( _library_name_3 "${_soname}" )
  368. set( _version_current "0" )
  369. set( _version_age "0" )
  370. set( _version_revision "0" )
  371. endif( _target_version )
  372. if( IS_ABSOLUTE ${_destination} )
  373. set( _libdir "${_destination}" )
  374. else( IS_ABSOLUTE ${_destination} )
  375. set( _libdir "${CMAKE_INSTALL_PREFIX}/${_destination}" )
  376. endif( IS_ABSOLUTE ${_destination} )
  377. configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_libtool_file.cmake "${_laname}" @ONLY )
  378. install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${_laname}" DESTINATION ${_destination} )
  379. endmacro( tde_install_libtool_file )
  380. #################################################
  381. #####
  382. ##### tde_install_export / tde_import
  383. function( tde_install_export )
  384. file( GLOB export_files ${CMAKE_CURRENT_BINARY_DIR}/export-*.cmake )
  385. set( mode "WRITE" )
  386. foreach( filename ${export_files} )
  387. file( READ ${filename} content )
  388. file( ${mode} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" "${content}" )
  389. set( mode "APPEND" )
  390. endforeach( )
  391. install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" DESTINATION ${CMAKE_INSTALL_DIR} )
  392. endfunction( )
  393. macro( tde_import _library )
  394. message( STATUS "checking for '${_library}'" )
  395. string( TOUPPER "BUILD_${_library}" _build )
  396. if( ${_build} )
  397. message( STATUS " ok, activated for build" )
  398. else()
  399. if( EXISTS "${TDE_CMAKE_DIR}/${_library}.cmake" )
  400. include( "${TDE_CMAKE_DIR}/${_library}.cmake" )
  401. message( STATUS " ok, found import file" )
  402. else()
  403. tde_message_fatal( "'${_library}' are required,\n but is not installed nor selected for build" )
  404. endif()
  405. endif()
  406. endmacro()
  407. #################################################
  408. #####
  409. ##### tde_add_library
  410. macro( tde_add_library _arg_target )
  411. unset( _target )
  412. unset( _type )
  413. unset( _static_pic )
  414. unset( _automoc )
  415. unset( _meta_includes )
  416. unset( _no_libtool_file )
  417. unset( _no_export )
  418. unset( _version )
  419. unset( _sources )
  420. unset( _destination )
  421. unset( _embed )
  422. unset( _link )
  423. unset( _dependencies )
  424. unset( _storage )
  425. set( _shouldnotlink no )
  426. foreach( _arg ${ARGV} )
  427. # this variable help us to skip
  428. # storing unapropriate values (i.e. directives)
  429. unset( _skip_store )
  430. # found one of directives: "SHARED", "STATIC", "MODULE"
  431. if( "${_arg}" STREQUAL "SHARED" OR "${_arg}" STREQUAL "STATIC" OR "${_arg}" STREQUAL "MODULE" )
  432. set( _skip_store 1 )
  433. set( _type "${_arg}" )
  434. endif( "${_arg}" STREQUAL "SHARED" OR "${_arg}" STREQUAL "STATIC" OR "${_arg}" STREQUAL "MODULE" )
  435. # found directive "STATIC_PIC"
  436. if( "${_arg}" STREQUAL "STATIC_PIC" )
  437. set( _skip_store 1 )
  438. set( _type "STATIC" )
  439. set( _static_pic 1 )
  440. endif( "${_arg}" STREQUAL "STATIC_PIC" )
  441. # found directive "AUTOMOC"
  442. if( "${_arg}" STREQUAL "AUTOMOC" )
  443. set( _skip_store 1 )
  444. set( _automoc 1 )
  445. endif( "${_arg}" STREQUAL "AUTOMOC" )
  446. # found directive "META_INCLUDES"
  447. if( "${_arg}" STREQUAL "META_INCLUDES" )
  448. set( _skip_store 1 )
  449. set( _storage "_meta_includes" )
  450. endif( )
  451. # found directive "NO_LIBTOOL_FILE"
  452. if( "${_arg}" STREQUAL "NO_LIBTOOL_FILE" )
  453. set( _skip_store 1 )
  454. set( _no_libtool_file 1 )
  455. endif( "${_arg}" STREQUAL "NO_LIBTOOL_FILE" )
  456. # found directive "NO_EXPORT"
  457. if( "${_arg}" STREQUAL "NO_EXPORT" )
  458. set( _skip_store 1 )
  459. set( _no_export 1 )
  460. endif( "${_arg}" STREQUAL "NO_EXPORT" )
  461. # found directive "VERSION"
  462. if( "${_arg}" STREQUAL "VERSION" )
  463. set( _skip_store 1 )
  464. set( _storage "_version" )
  465. endif( "${_arg}" STREQUAL "VERSION" )
  466. # found directive "SOURCES"
  467. if( "${_arg}" STREQUAL "SOURCES" )
  468. set( _skip_store 1 )
  469. set( _storage "_sources" )
  470. endif( "${_arg}" STREQUAL "SOURCES" )
  471. # found directive "EMBED"
  472. if( "${_arg}" STREQUAL "EMBED" )
  473. set( _skip_store 1 )
  474. set( _storage "_embed" )
  475. endif( "${_arg}" STREQUAL "EMBED" )
  476. # found directive "LINK"
  477. if( "${_arg}" STREQUAL "LINK" )
  478. set( _skip_store 1 )
  479. set( _storage "_link" )
  480. endif( "${_arg}" STREQUAL "LINK" )
  481. # found directive "DEPENDENCIES"
  482. if( "${_arg}" STREQUAL "DEPENDENCIES" )
  483. set( _skip_store 1 )
  484. set( _storage "_dependencies" )
  485. endif( "${_arg}" STREQUAL "DEPENDENCIES" )
  486. # found directive "DESTINATION"
  487. if( "${_arg}" STREQUAL "DESTINATION" )
  488. set( _skip_store 1 )
  489. set( _storage "_destination" )
  490. unset( ${_storage} )
  491. endif( "${_arg}" STREQUAL "DESTINATION" )
  492. # storing value
  493. if( _storage AND NOT _skip_store )
  494. list( APPEND ${_storage} ${_arg} )
  495. list( REMOVE_DUPLICATES ${_storage} )
  496. endif( _storage AND NOT _skip_store )
  497. endforeach( _arg )
  498. # if no type is set, we choose one
  499. # based on BUILD_SHARED_LIBS
  500. if( NOT _type )
  501. if( BUILD_SHARED_LIBS )
  502. set( _type "SHARED" )
  503. else( BUILD_SHARED_LIBS )
  504. set( _type "STATIC" )
  505. endif( BUILD_SHARED_LIBS )
  506. endif( NOT _type )
  507. # change target name, based on type
  508. string( TOLOWER "${_type}" _type_lower )
  509. set( _target "${_arg_target}-${_type_lower}" )
  510. # create variables like "LIB_xxx" for convenience
  511. if( ${_type} STREQUAL "SHARED" )
  512. string( TOUPPER "${_arg_target}" _tmp )
  513. set( LIB_${_tmp} ${_target} CACHE INTERNAL LIB_${tmp} FORCE )
  514. endif( ${_type} STREQUAL "SHARED" )
  515. # disallow target without sources
  516. if( NOT _sources )
  517. message( FATAL_ERROR "\nTarget [$_target] have no sources." )
  518. endif( NOT _sources )
  519. # processing different types of sources
  520. __tde_internal_process_sources( _sources ${_sources} )
  521. # set automoc
  522. if( _automoc )
  523. tde_automoc( ${_sources} )
  524. endif( _automoc )
  525. # add target
  526. add_library( ${_target} ${_type} ${_sources} )
  527. # we assume that modules have no prefix and no version
  528. # also, should not link
  529. if( ${_type} STREQUAL "MODULE" )
  530. set_target_properties( ${_target} PROPERTIES PREFIX "" )
  531. unset( _version )
  532. set( _shouldnotlink yes )
  533. endif( ${_type} STREQUAL "MODULE" )
  534. # set real name of target
  535. set_target_properties( ${_target} PROPERTIES OUTPUT_NAME ${_arg_target} )
  536. # set -fPIC flag for static libraries
  537. if( _static_pic )
  538. set_target_properties( ${_target} PROPERTIES COMPILE_FLAGS -fPIC )
  539. endif( _static_pic )
  540. # set version
  541. if( _version )
  542. string( REGEX MATCH "^[0-9]+" _soversion ${_version} )
  543. set_target_properties( ${_target} PROPERTIES VERSION ${_version} SOVERSION ${_soversion} )
  544. endif( _version )
  545. # set interface libraries (only for shared)
  546. unset( _shared_libs )
  547. foreach( _lib ${_link} )
  548. #get_target_property( _lib_type ${_lib} TYPE )
  549. #if( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" )
  550. if( NOT ${_lib} MATCHES ".+-static" )
  551. list( APPEND _shared_libs ${_lib} )
  552. endif( NOT ${_lib} MATCHES ".+-static" )
  553. #endif( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" )
  554. endforeach( _lib )
  555. target_link_libraries( ${_target} LINK_INTERFACE_LIBRARIES ${_shared_libs} )
  556. # set embedded archives
  557. if( _embed )
  558. list( INSERT _link 0 -Wl,-whole-archive ${_embed} -Wl,-no-whole-archive )
  559. endif( _embed )
  560. # set link libraries
  561. if( _link )
  562. target_link_libraries( ${_target} ${_link} )
  563. endif( )
  564. # set dependencies
  565. if( _dependencies )
  566. add_dependencies( ${_target} ${_dependencies} )
  567. endif( _dependencies )
  568. # if destination directory is set
  569. if( _destination )
  570. # we export only shared libs (no static, no modules);
  571. # also, do not export targets marked as "NO_EXPORT" (usually for tdeinit)
  572. if( "SHARED" STREQUAL ${_type} AND NOT _no_export )
  573. # get target properties: output name, version, soversion
  574. get_target_property( _output ${_target} LOCATION )
  575. get_filename_component( _output ${_output} NAME )
  576. get_target_property( _version ${_target} VERSION )
  577. get_target_property( _soversion ${_target} SOVERSION )
  578. if( _version )
  579. set( _location "${_destination}/${_output}.${_version}" )
  580. set( _soname "${_output}.${_soversion}" )
  581. else( )
  582. set( _location "${_destination}/${_output}" )
  583. set( _soname "${_output}" )
  584. endif( )
  585. configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_export_library.cmake "${PROJECT_BINARY_DIR}/export-${_target}.cmake" @ONLY )
  586. endif( )
  587. # install target
  588. install( TARGETS ${_target} DESTINATION ${_destination} )
  589. # install .la files for dynamic libraries
  590. if( NOT "STATIC" STREQUAL ${_type} AND NOT _no_libtool_file )
  591. tde_install_libtool_file( ${_target} ${_destination} )
  592. endif( )
  593. endif( _destination )
  594. endmacro( tde_add_library )
  595. #################################################
  596. #####
  597. ##### tde_add_kpart
  598. macro( tde_add_kpart _target )
  599. tde_add_library( ${_target} ${ARGN} MODULE )
  600. endmacro( tde_add_kpart )
  601. #################################################
  602. #####
  603. ##### tde_curdatetime
  604. macro( tde_curdatetime result )
  605. tde_execute_process( COMMAND "date" "+%m/%d/%Y %H:%M:%S" OUTPUT_VARIABLE ${result} )
  606. string( REGEX REPLACE "(..)/(..)/(....) (........).*" "\\1/\\2/\\3 \\4" ${result} ${${result}} )
  607. endmacro( tde_curdatetime )
  608. #################################################
  609. #####
  610. ##### tde_add_executable
  611. macro( tde_add_executable _arg_target )
  612. unset( _target )
  613. unset( _automoc )
  614. unset( _meta_includes )
  615. unset( _setuid )
  616. unset( _sources )
  617. unset( _destination )
  618. unset( _link )
  619. unset( _dependencies )
  620. unset( _storage )
  621. # metadata
  622. unset( _description )
  623. unset( _license )
  624. unset( _copyright )
  625. unset( _authors )
  626. unset( _product )
  627. unset( _organization )
  628. unset( _version )
  629. unset( _datetime )
  630. unset( _notes )
  631. # default metadata
  632. set( _product "Trinity Desktop Environment" )
  633. tde_curdatetime( _datetime )
  634. foreach( _arg ${ARGV} )
  635. # this variable help us to skip
  636. # storing unapropriate values (i.e. directives)
  637. unset( _skip_store )
  638. # found directive "AUTOMOC"
  639. if( "${_arg}" STREQUAL "AUTOMOC" )
  640. set( _skip_store 1 )
  641. set( _automoc 1 )
  642. endif( "${_arg}" STREQUAL "AUTOMOC" )
  643. # found directive "META_INCLUDES"
  644. if( "${_arg}" STREQUAL "META_INCLUDES" )
  645. set( _skip_store 1 )
  646. set( _storage "_meta_includes" )
  647. endif( )
  648. # found directive "SETUID"
  649. if( "${_arg}" STREQUAL "SETUID" )
  650. set( _skip_store 1 )
  651. set( _setuid 1 )
  652. endif( "${_arg}" STREQUAL "SETUID" )
  653. # found directive "SOURCES"
  654. if( "${_arg}" STREQUAL "SOURCES" )
  655. set( _skip_store 1 )
  656. set( _storage "_sources" )
  657. endif( "${_arg}" STREQUAL "SOURCES" )
  658. # found directive "LINK"
  659. if( "${_arg}" STREQUAL "LINK" )
  660. set( _skip_store 1 )
  661. set( _storage "_link" )
  662. endif( "${_arg}" STREQUAL "LINK" )
  663. # found directive "DEPENDENCIES"
  664. if( "${_arg}" STREQUAL "DEPENDENCIES" )
  665. set( _skip_store 1 )
  666. set( _storage "_dependencies" )
  667. endif( "${_arg}" STREQUAL "DEPENDENCIES" )
  668. # found directive "DESTINATION"
  669. if( "${_arg}" STREQUAL "DESTINATION" )
  670. set( _skip_store 1 )
  671. set( _storage "_destination" )
  672. unset( ${_storage} )
  673. endif( "${_arg}" STREQUAL "DESTINATION" )
  674. # metadata
  675. if( "${_arg}" STREQUAL "DESCRIPTION" )
  676. set( _skip_store 1 )
  677. set( _storage "_description" )
  678. endif( )
  679. if( "${_arg}" STREQUAL "LICENSE" )
  680. set( _skip_store 1 )
  681. set( _storage "_license" )
  682. endif( )
  683. if( "${_arg}" STREQUAL "COPYRIGHT" )
  684. set( _skip_store 1 )
  685. set( _storage "_copyright" )
  686. endif( )
  687. if( "${_arg}" STREQUAL "AUTHORS" )
  688. set( _skip_store 1 )
  689. set( _storage "_authors" )
  690. endif( )
  691. if( "${_arg}" STREQUAL "PRODUCT" )
  692. set( _skip_store 1 )
  693. set( _storage "_product" )
  694. endif( )
  695. if( "${_arg}" STREQUAL "ORGANIZATION" )
  696. set( _skip_store 1 )
  697. set( _storage "_organization" )
  698. endif( )
  699. if( "${_arg}" STREQUAL "VERSION" )
  700. set( _skip_store 1 )
  701. set( _storage "_version" )
  702. endif( )
  703. if( "${_arg}" STREQUAL "DATETIME" )
  704. set( _skip_store 1 )
  705. set( _storage "_datetime" )
  706. endif( )
  707. if( "${_arg}" STREQUAL "NOTES" )
  708. set( _skip_store 1 )
  709. set( _storage "_notes" )
  710. endif( )
  711. # storing value
  712. if( _storage AND NOT _skip_store )
  713. #set( ${_storage} "${${_storage}} ${_arg}" )
  714. list( APPEND ${_storage} ${_arg} )
  715. endif( _storage AND NOT _skip_store )
  716. endforeach( _arg )
  717. set( _target "${_arg_target}" )
  718. # disallow target without sources
  719. if( NOT _sources )
  720. message( FATAL_ERROR "\nTarget [$_target] have no sources." )
  721. endif( NOT _sources )
  722. # processing different types of sources
  723. __tde_internal_process_sources( _sources ${_sources} )
  724. # set automoc
  725. if( _automoc )
  726. tde_automoc( ${_sources} )
  727. endif( _automoc )
  728. # add target
  729. add_executable( ${_target} ${_sources} )
  730. # set link libraries
  731. if( _link )
  732. target_link_libraries( ${_target} ${_link} )
  733. endif( _link )
  734. # set dependencies
  735. if( _dependencies )
  736. add_dependencies( ${_target} ${_dependencies} )
  737. endif( _dependencies )
  738. # set destination directory
  739. if( _destination )
  740. if( _setuid )
  741. install( TARGETS ${_target} DESTINATION ${_destination} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE SETUID )
  742. else( _setuid )
  743. install( TARGETS ${_target} DESTINATION ${_destination} )
  744. endif( _setuid )
  745. endif( _destination )
  746. # embed icon, name, and metadata
  747. set( ELF_EMBEDDING_METADATA "\"${_target}\" \"${_description}\" \"${_license}\" \"${_copyright}\" \"${_authors}\" \"${_product}\" \"${_organization}\" \"${_version}\" \"${_datetime}\" \"${_target}\" \"${_notes}\"" )
  748. separate_arguments( ELF_EMBEDDING_METADATA )
  749. if( EXISTS ${CMAKE_INSTALL_PREFIX}/bin/tdelfeditor )
  750. add_custom_command(
  751. TARGET ${_target}
  752. POST_BUILD
  753. COMMAND ${CMAKE_INSTALL_PREFIX}/bin/tdelfeditor -m ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ELF_EMBEDDING_METADATA} || true
  754. COMMAND ${CMAKE_INSTALL_PREFIX}/bin/tdelfeditor -e ${CMAKE_CURRENT_BINARY_DIR}/${_target} || true
  755. COMMAND ${CMAKE_INSTALL_PREFIX}/bin/tdelfeditor -t ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${_target} || true
  756. )
  757. endif( EXISTS ${CMAKE_INSTALL_PREFIX}/bin/tdelfeditor )
  758. endmacro( tde_add_executable )
  759. #################################################
  760. #####
  761. ##### tde_add_tdeinit_executable
  762. macro( tde_add_tdeinit_executable _target )
  763. configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_tdeinit_executable.cmake ${_target}_tdeinit_executable.cpp COPYONLY )
  764. configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_tdeinit_module.cmake ${_target}_tdeinit_module.cpp COPYONLY )
  765. unset( _sources )
  766. unset( _runtime_destination )
  767. unset( _library_destination )
  768. unset( _plugin_destination )
  769. # default storage is _sources
  770. set( _storage _sources )
  771. # set default export to NO_EXPORT
  772. set( _export "NO_EXPORT" )
  773. foreach( _arg ${ARGN} )
  774. # this variable help us to skip
  775. # storing unapropriate values (i.e. directives)
  776. unset( _skip_store )
  777. # found directive "EXPORT"
  778. if( "${_arg}" STREQUAL "EXPORT" )
  779. set( _skip_store 1 )
  780. unset( _export )
  781. endif( "${_arg}" STREQUAL "EXPORT" )
  782. # found directive "RUNTIME_DESTINATION"
  783. if( "${_arg}" STREQUAL "RUNTIME_DESTINATION" )
  784. set( _skip_store 1 )
  785. set( _storage "_runtime_destination" )
  786. unset( ${_storage} )
  787. endif( "${_arg}" STREQUAL "RUNTIME_DESTINATION" )
  788. # found directive "LIBRARY_DESTINATION"
  789. if( "${_arg}" STREQUAL "LIBRARY_DESTINATION" )
  790. set( _skip_store 1 )
  791. set( _storage "_library_destination" )
  792. unset( ${_storage} )
  793. endif( "${_arg}" STREQUAL "LIBRARY_DESTINATION" )
  794. # found directive "PLUGIN_DESTINATION"
  795. if( "${_arg}" STREQUAL "PLUGIN_DESTINATION" )
  796. set( _skip_store 1 )
  797. set( _storage "_plugin_destination" )
  798. unset( ${_storage} )
  799. endif( "${_arg}" STREQUAL "PLUGIN_DESTINATION" )
  800. # storing value
  801. if( _storage AND NOT _skip_store )
  802. list( APPEND ${_storage} ${_arg} )
  803. set( _storage "_sources" )
  804. endif( _storage AND NOT _skip_store )
  805. endforeach( _arg )
  806. # if destinations are not set, we using some defaults
  807. # we assume that tdeinit executable MUST be installed
  808. # (otherwise why we build it?)
  809. if( NOT _runtime_destination )
  810. set( _runtime_destination ${BIN_INSTALL_DIR} )
  811. endif( NOT _runtime_destination )
  812. if( NOT _library_destination )
  813. set( _library_destination ${LIB_INSTALL_DIR} )
  814. endif( NOT _library_destination )
  815. if( NOT _plugin_destination )
  816. set( _plugin_destination ${PLUGIN_INSTALL_DIR} )
  817. endif( NOT _plugin_destination )
  818. # create the library
  819. tde_add_library( tdeinit_${_target} ${_sources} SHARED ${_export}
  820. DESTINATION ${_library_destination}
  821. )
  822. # create the executable
  823. tde_add_executable( ${_target}
  824. SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${_target}_tdeinit_executable.cpp
  825. LINK tdeinit_${_target}-shared
  826. DESTINATION ${_runtime_destination}
  827. )
  828. # create the plugin
  829. tde_add_kpart( ${_target}
  830. SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${_target}_tdeinit_module.cpp
  831. LINK tdeinit_${_target}-shared
  832. DESTINATION ${_plugin_destination}
  833. )
  834. endmacro( tde_add_tdeinit_executable )
  835. #################################################
  836. #####
  837. ##### tde_create_translation
  838. macro( tde_create_translation )
  839. unset( _srcs )
  840. unset( _lang )
  841. unset( _dest )
  842. unset( _directive )
  843. unset( _var )
  844. foreach( _arg ${ARGN} )
  845. # found directive "FILES"
  846. if( "${_arg}" STREQUAL "FILES" )
  847. unset( _srcs )
  848. set( _var _srcs )
  849. set( _directive 1 )
  850. endif( )
  851. # found directive "LANG"
  852. if( "${_arg}" STREQUAL "LANG" )
  853. unset( _lang )
  854. set( _var _lang )
  855. set( _directive 1 )
  856. endif( )
  857. # found directive "DESTINATION"
  858. if( "${_arg}" STREQUAL "DESTINATION" )
  859. unset( _dest )
  860. set( _var _dest )
  861. set( _directive 1 )
  862. endif( )
  863. # collect data
  864. if( _directive )
  865. unset( _directive )
  866. elseif( _var )
  867. list( APPEND ${_var} ${_arg} )
  868. endif()
  869. endforeach( )
  870. if( NOT MSGFMT_EXECUTABLE )
  871. tde_message_fatal( "MSGFMT_EXECUTABLE variable is not defined" )
  872. elseif( NOT _lang )
  873. tde_message_fatal( "missing LANG directive" )
  874. elseif( NOT _dest )
  875. set( _dest "${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES" )
  876. endif( )
  877. # if no file specified, include all *.po files
  878. if( NOT _srcs )
  879. file( GLOB _srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.po )
  880. endif()
  881. if( NOT _srcs )
  882. tde_message_fatal( "no source files" )
  883. endif()
  884. # generate *.mo files
  885. foreach( _src ${_srcs} )
  886. get_filename_component( _src ${_src} ABSOLUTE )
  887. get_filename_component( _out ${_src} NAME_WE )
  888. set( _out_name "${_out}-${_lang}.mo" )
  889. set( _out_real_name "${_out}.mo" )
  890. add_custom_command(
  891. OUTPUT ${_out_name}
  892. COMMAND ${MSGFMT_EXECUTABLE} ${_src} -o ${_out_name}
  893. DEPENDS ${_src} )
  894. add_custom_target( "${_out}-${_lang}-translation" ALL DEPENDS ${_out_name} )
  895. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_out_name} RENAME ${_out_real_name} DESTINATION ${_dest} )
  896. endforeach( )
  897. endmacro( )
  898. #################################################
  899. #####
  900. ##### tde_create_handbook
  901. macro( tde_create_handbook )
  902. unset( _target )
  903. unset( _dest )
  904. unset( _noindex )
  905. unset( _srcs )
  906. unset( _extra )
  907. unset( _srcdir )
  908. set( _lang en )
  909. set( _first_arg 1 )
  910. set( _var _target )
  911. foreach( _arg ${ARGN} )
  912. # found directive "NOINDEX"
  913. if( "${_arg}" STREQUAL "NOINDEX" )
  914. set( _noindex 1 )
  915. set( _directive 1 )
  916. endif()
  917. # found directive "FILES"
  918. if( "${_arg}" STREQUAL "FILES" )
  919. unset( _srcs )
  920. set( _var _srcs )
  921. set( _directive 1 )
  922. endif()
  923. # found directive "EXTRA"
  924. if( "${_arg}" STREQUAL "EXTRA" )
  925. unset( _extra )
  926. set( _var _extra )
  927. set( _directive 1 )
  928. endif()
  929. # found directive "SRCDIR"
  930. if( "${_arg}" STREQUAL "SRCDIR" )
  931. unset( _srcdir )
  932. set( _var _srcdir )
  933. set( _directive 1 )
  934. endif()
  935. # found directive DESTINATION
  936. if( _arg STREQUAL "DESTINATION" )
  937. unset( _dest )
  938. set( _var _dest )
  939. set( _directive 1 )
  940. endif()
  941. # found directive "LANG"
  942. if( "${_arg}" STREQUAL "LANG" )
  943. unset( _lang )
  944. set( _var _lang )
  945. set( _directive 1 )
  946. endif()
  947. # collect data
  948. if( _directive )
  949. unset( _directive )
  950. elseif( _var )
  951. if( _first_arg )
  952. set( _target "${_arg}" )
  953. else()
  954. list( APPEND ${_var} ${_arg} )
  955. endif()
  956. endif()
  957. unset( _first_arg )
  958. endforeach()
  959. # if no target specified, try to guess it from DESTINATION
  960. if( NOT _target )
  961. if( NOT _dest )
  962. tde_message_fatal( "target name cannot be determined because DESTINATION is not set" )
  963. endif()
  964. string( REPLACE "/" "-" _target "${_dest}" )
  965. endif()
  966. set( _target "${_target}-${_lang}-handbook" )
  967. # if no file specified, include all docbooks, stylesheets and images
  968. if( NOT _srcs )
  969. file( GLOB _srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.docbook *.css *.png )
  970. endif()
  971. # if no destination specified, defaulting to HTML_INSTALL_DIR
  972. if( NOT _dest )
  973. set( _dest "${HTML_INSTALL_DIR}/${_lang}" )
  974. # if destination is NOT absolute path,
  975. # we assume that is relative to HTML_INSTALL_DIR
  976. elseif( NOT IS_ABSOLUTE ${_dest} )
  977. set( _dest "${HTML_INSTALL_DIR}/${_lang}/${_dest}" )
  978. endif()
  979. if( NOT _srcs )
  980. tde_message_fatal( "no source files" )
  981. endif()
  982. if( NOT _noindex )
  983. # check for index.docbook
  984. list( FIND _srcs "index.docbook" _find_index )
  985. if( -1 EQUAL _find_index )
  986. tde_message_fatal( "missing index.docbook file" )
  987. endif()
  988. # check for srcdir
  989. if( _srcdir )
  990. set( _srcdir "--srcdir=${_srcdir}" )
  991. endif()
  992. add_custom_command(
  993. OUTPUT index.cache.bz2
  994. COMMAND ${KDE3_MEINPROC_EXECUTABLE} ${_srcdir} --check --cache index.cache.bz2 ${CMAKE_CURRENT_SOURCE_DIR}/index.docbook
  995. DEPENDS ${_srcs} )
  996. add_custom_target( ${_target} ALL DEPENDS index.cache.bz2 )
  997. list( APPEND _srcs ${CMAKE_CURRENT_BINARY_DIR}/index.cache.bz2 )
  998. tde_install_empty_directory( ${_dest} )
  999. tde_install_symlink( ${TDE_HTML_DIR}/${_lang}/common ${_dest} )
  1000. endif()
  1001. install( FILES ${_srcs} ${_extra} DESTINATION ${_dest} )
  1002. endmacro( )
  1003. #################################################
  1004. #####
  1005. ##### tde_include_tqt
  1006. macro( tde_include_tqt )
  1007. foreach( _cpp ${ARGN} )
  1008. set_source_files_properties( ${_cpp} PROPERTIES COMPILE_FLAGS "-include tqt.h" )
  1009. endforeach()
  1010. endmacro( )
  1011. #################################################
  1012. #####
  1013. ##### tde_install_symlink
  1014. macro( tde_install_symlink _target _link )
  1015. # if path is relative, we must to prefix it with CMAKE_INSTALL_PREFIX
  1016. if( IS_ABSOLUTE "${_link}" )
  1017. set( _destination "${_link}" )
  1018. else( IS_ABSOLUTE "${_link}" )
  1019. set( _destination "${CMAKE_INSTALL_PREFIX}/${_link}" )
  1020. endif( IS_ABSOLUTE "${_link}" )
  1021. get_filename_component( _path "${_destination}" PATH )
  1022. if( NOT IS_DIRECTORY "\$ENV{DESTDIR}${_path}" )
  1023. install( CODE "file( MAKE_DIRECTORY \"\$ENV{DESTDIR}${_path}\" )" )
  1024. endif( NOT IS_DIRECTORY "\$ENV{DESTDIR}${_path}" )
  1025. install( CODE "execute_process( COMMAND ln -s ${_target} \$ENV{DESTDIR}${_destination} )" )
  1026. endmacro( tde_install_symlink )
  1027. #################################################
  1028. #####
  1029. ##### tde_install_empty_directory
  1030. macro( tde_install_empty_directory _path )
  1031. # if path is relative, we must to prefix it with CMAKE_INSTALL_PREFIX
  1032. if( IS_ABSOLUTE "${_path}" )
  1033. set( _destination "${_path}" )
  1034. else( IS_ABSOLUTE "${_path}" )
  1035. set( _destination "${CMAKE_INSTALL_PREFIX}/${_path}" )
  1036. endif( IS_ABSOLUTE "${_path}" )
  1037. install( CODE "file( MAKE_DIRECTORY \"\$ENV{DESTDIR}${_destination}\" )" )
  1038. endmacro( tde_install_empty_directory )
  1039. #################################################
  1040. #####
  1041. ##### tde_conditional_add_subdirectory
  1042. macro( tde_conditional_add_subdirectory _cond _path )
  1043. if( ${_cond} )
  1044. add_subdirectory( "${_path}" )
  1045. endif( ${_cond} )
  1046. endmacro( tde_conditional_add_subdirectory )
  1047. #################################################
  1048. #####
  1049. ##### tde_auto_add_subdirectories
  1050. macro( tde_auto_add_subdirectories )
  1051. file( GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} * )
  1052. foreach( _dir ${_dirs} )
  1053. if( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_dir} )
  1054. if( NOT ${_dir} STREQUAL ".svn" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_dir}/CMakeLists.txt )
  1055. add_subdirectory( ${_dir} )
  1056. endif()
  1057. endif()
  1058. endforeach()
  1059. endmacro()
  1060. #################################################
  1061. #####
  1062. ##### tde_save / tde_restore
  1063. macro( tde_save )
  1064. foreach( _var ${ARGN} )
  1065. set( __bak_${_var} ${${_var}} )
  1066. endforeach()
  1067. endmacro()
  1068. macro( tde_save_and_set _var )
  1069. set( __bak_${_var} ${${_var}} )
  1070. set( ${_var} ${ARGN} )
  1071. endmacro( )
  1072. macro( tde_restore )
  1073. foreach( _var ${ARGN} )
  1074. set( ${_var} ${__bak_${_var}} )
  1075. unset( __bak_${_var} )
  1076. endforeach()
  1077. endmacro()
  1078. #################################################
  1079. #####
  1080. ##### tde_setup_install_path
  1081. macro( tde_setup_install_path _path _default )
  1082. if( DEFINED ${_path} )
  1083. set( ${_path} "${${_path}}" CACHE INTERNAL "" FORCE )
  1084. else( )
  1085. set( ${_path} "${_default}" )
  1086. endif( )
  1087. endmacro( )
  1088. ##################################################
  1089. if( ${CMAKE_SOURCE_DIR} MATCHES ${CMAKE_BINARY_DIR} )
  1090. tde_message_fatal( "Please use out-of-source building, like this:
  1091. \n rm ${CMAKE_SOURCE_DIR}/CMakeCache.txt
  1092. mkdir /tmp/${PROJECT_NAME}.build
  1093. cd /tmp/${PROJECT_NAME}.build
  1094. cmake ${CMAKE_SOURCE_DIR} [arguments...]" )
  1095. endif( )
  1096. #################################################
  1097. #####
  1098. ##### tde_setup_architecture_flags
  1099. macro( tde_setup_architecture_flags )
  1100. message( STATUS "Detected ${CMAKE_SYSTEM_PROCESSOR} CPU architecture" )
  1101. ## Immediate symbol binding is not available on ARM architectures
  1102. if(${CMAKE_SYSTEM_PROCESSOR} MATCHES arm*)
  1103. set( LINKER_IMMEDIATE_BINDING_FLAGS "" CACHE INTERNAL "" FORCE )
  1104. else( )
  1105. set( LINKER_IMMEDIATE_BINDING_FLAGS "-z\ now" CACHE INTERNAL "" FORCE )
  1106. endif( )
  1107. endmacro( )