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.
tde-common-cmake/modules/TDEMacros.cmake

1699 lines
49 KiB

#################################################
#
# (C) 2010-2012 Serghei Amelian
# serghei (DOT) amelian (AT) gmail.com
#
# (C) 2011-2012 Timothy Pearson
# kb9vqf (AT) pearsoncomputing.net
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
include( KDE3Macros ) # we will need this module for a while
include( CheckCXXCompilerFlag )
#################################################
#####
##### tde_message_fatal
macro( tde_message_fatal )
message( FATAL_ERROR
"#################################################\n"
" ${ARGV}\n"
"#################################################" )
endmacro( tde_message_fatal )
#################################################
#####
##### tde_get_arg( <ARG_NAME> <COUNT> <RETURN> <REST> <ARGS...> )
##### ARG_NAME(string): name of an argument to find in ARGS
##### COUNT(number): argument dimension, a number of items returned in RETURN
##### RETURN(list ref): items returned for argument as they found in ARGS
##### REST(list ref): rest of items except argument name and items returned in RETURN
##### ARGS(list): source list of arguments
macro( tde_get_arg ARG_NAME COUNT RETURN REST )
unset( ${RETURN} )
unset( ${REST} )
list( APPEND ${REST} ${ARGN} )
list( FIND ${REST} ${ARG_NAME} _arg_idx)
if( NOT ${_arg_idx} EQUAL -1 )
list( REMOVE_AT ${REST} ${_arg_idx} )
set( _i 0 )
while( ${_i} LESS ${COUNT} )
list( GET ${REST} ${_arg_idx} _arg )
list( REMOVE_AT ${REST} ${_arg_idx} )
list( APPEND ${RETURN} ${_arg} )
math( EXPR _i "${_i} + 1" )
endwhile()
endif()
endmacro( tde_get_arg )
################################################
#####
##### tde_execute_process( <ARGS...> [MESSAGE <MSG>] )
##### MSG: fatal error message (standard message will be written if not supplied)
##### ARGS: execute_process arguments
macro( tde_execute_process )
tde_get_arg( MESSAGE 1 _message _rest_args ${ARGV} )
tde_get_arg( RESULT_VARIABLE 1 _result_variable _tmp ${_rest_args} )
tde_get_arg( COMMAND 1 _command _tmp ${_rest_args} )
tde_get_arg( OUTPUT_VARIABLE 1 _output_variable _tmp ${_rest_args} )
tde_get_arg( CACHE 3 _cache _rest_args2 ${_rest_args} )
# handle optional FORCE parameter
if( DEFINED _cache )
list( GET _cache 2 _tmp )
if( _tmp STREQUAL FORCE )
set( _rest_args ${_rest_args2} )
else()
tde_get_arg( CACHE 2 _cache _rest_args ${_rest_args} )
endif()
endif()
if( NOT DEFINED _result_variable )
list( APPEND _rest_args RESULT_VARIABLE _exec_result )
set( _result_variable _exec_result )
endif()
execute_process( ${_rest_args} )
if( DEFINED _output_variable AND DEFINED _cache )
set( ${_output_variable} ${${_output_variable}} CACHE ${_cache} )
endif()
if( ${_result_variable} )
if( DEFINED _message )
tde_message_fatal( ${_message} )
else()
if( ${${_result_variable}} MATCHES "^[0-9]+$" )
set( ${_result_variable} "status ${${_result_variable}} returned!" )
endif()
tde_message_fatal( "Error executing '${_command}': ${${_result_variable}}" )
endif()
endif()
endmacro( tde_execute_process )
if( DEFINED MASTER_SOURCE_DIR )
return( )
endif( )
########### slave part ends here ###############
################################################
#####
##### CMP0026 states we should not read the LOCATION property of a target,
##### and should be using generators instead. We can't do that here however
##### because we need the value of the property at configure time.
if( POLICY CMP0026 )
cmake_policy( PUSH )
cmake_policy( SET CMP0026 OLD )
endif( POLICY CMP0026 )
################################################
#####
##### tde_install_icons( <icons...> THEME <svgicons> DESTINATION <destdir> )
##### default theme: hicolor
##### default destination: ${SHARE_INSTALL_DIR}/icons
macro( tde_install_icons )
tde_get_arg( DESTINATION 1 _dest _args ${ARGV} )
tde_get_arg( THEME 1 _req_theme _icons ${_args} )
#defaults
if( NOT _icons )
set( _icons "*" )
endif( NOT _icons )
if( NOT _dest )
set( _dest "${ICON_INSTALL_DIR}" )
endif( NOT _dest )
foreach( _icon ${_icons} )
unset( _theme ) # clearing
file(GLOB _icon_files *-${_icon}.png *-${_icon}.mng _icon_files *-${_icon}.svg* )
foreach( _icon_file ${_icon_files} )
# FIXME need a review
string( REGEX MATCH "^.*/([a-zA-Z][a-zA-Z])([0-9a-zA-Z]+)\\-([a-z]+)\\-([^/]+)$" _dummy "${_icon_file}" )
set( _type "${CMAKE_MATCH_1}" )
set( _size "${CMAKE_MATCH_2}" )
set( _group "${CMAKE_MATCH_3}" )
set( _name "${CMAKE_MATCH_4}" )
# we must ignore invalid icon names
if( _type AND _size AND _group AND _name )
# autodetect theme
if( NOT _req_theme )
unset( _theme )
if( "${_type}" STREQUAL "cr" )
set( _theme crystalsvg )
elseif( "${_type}" STREQUAL "lo" )
set( _theme locolor )
endif( "${_type}" STREQUAL "cr" )
# defaulting
if( NOT _theme )
set( _theme hicolor )
endif( NOT _theme )
else( NOT _req_theme )
set( _theme ${_req_theme} )
endif( NOT _req_theme )
# fix "group" name
if( "${_group}" STREQUAL "mime" )
set( _group "mimetypes" )
endif( "${_group}" STREQUAL "mime" )
if( "${_group}" STREQUAL "filesys" )
set( _group "places" )
endif( "${_group}" STREQUAL "filesys" )
if( "${_group}" STREQUAL "category" )
set( _group "categories" )
endif( "${_group}" STREQUAL "category" )
if( "${_group}" STREQUAL "device" )
set( _group "devices" )
endif( "${_group}" STREQUAL "device" )
if( "${_group}" STREQUAL "app" )
set( _group "apps" )
endif( "${_group}" STREQUAL "app" )
if( "${_group}" STREQUAL "action" )
set( _group "actions" )
endif( "${_group}" STREQUAL "action" )
if( "${_size}" STREQUAL "sc" )
install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/scalable/${_group}/ RENAME ${_name} )
else( "${_size}" STREQUAL "sc" )
install( FILES ${_icon_file} DESTINATION ${_dest}/${_theme}/${_size}x${_size}/${_group}/ RENAME ${_name} )
endif( "${_size}" STREQUAL "sc" )
endif( _type AND _size AND _group AND _name )
endforeach( _icon_file )
endforeach( _icon )
endmacro( tde_install_icons )
#################################################
#####
##### tde_add_lut( <source> <result> [depends] )
##### default depends: source
macro( tde_add_lut _src _lut _dep )
set( create_hash_table ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
if( NOT _dep )
set( _dep ${_src} )
endif( NOT _dep )
add_custom_command( OUTPUT ${_lut}
COMMAND perl ARGS ${create_hash_table} ${CMAKE_CURRENT_SOURCE_DIR}/${_src} -i > ${_lut}
DEPENDS ${_src} )
set_source_files_properties( ${_dep} PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_lut} )
unset( _dep )
endmacro( tde_add_lut )
#################################################
#####
##### tde_add_luts( <sources...> )
macro( tde_add_luts )
foreach( _src ${ARGV} )
get_filename_component( _lut ${_src} NAME_WE )
set( _lut "${_lut}.lut.h" )
tde_add_lut( ${_src} ${_lut} ${_src} )
endforeach( _src )
endmacro( tde_add_luts )
#################################################
#####
##### tde_file_to_cpp( <source> <destination> <variable> )
macro( tde_file_to_cpp _src _dst _var )
if( IS_ABSOLUTE ${_dst} )
set( dst ${_dst} )
else( )
set( dst "${CMAKE_CURRENT_BINARY_DIR}/${_dst}" )
endif( )
file( READ ${_src} text )
string( REGEX REPLACE "\n" "\\\\n\"\n\"" text "${text}" )
set( text "/* Generated by CMake */\n\nconst char *${_var} = \n\n\"${text}\";\n" )
string( REGEX REPLACE "\n\"\";\n$" ";\n" text "${text}" )
file( WRITE ${dst} "${text}" )
endmacro( )
#################################################
#####
##### tde_install_la_file( <target> <destination> )
macro( tde_install_la_file _target _destination )
get_target_property( _target_location ${_target} LOCATION )
get_filename_component( _soname ${_target_location} NAME )
string( REGEX REPLACE "\\.so(\\.[0-9]+)*$" "" _laname "${_soname}" )
set( _laname ${CMAKE_CURRENT_BINARY_DIR}/${_laname}.la )
file( WRITE ${_laname}
"# ${_laname} - a libtool library file, generated by cmake
# The name that we can dlopen(3).
dlname='${_soname}'
# Names of this library
library_names='${_soname} ${_soname} ${_soname}'
# The name of the static archive
old_library=''
# Libraries that this one depends upon.
dependency_libs=''
# Version information.\ncurrent=0\nage=0\nrevision=0
# Is this an already installed library?\ninstalled=yes
# Should we warn about portability when linking against -modules?\nshouldnotlink=yes
# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''
# Directory that this library needs to be installed in:
libdir='${_destination}'
" )
install( FILES ${_laname} DESTINATION ${_destination} )
endmacro( tde_install_la_file )
#################################################
#####
##### tde_add_ui_files
macro( tde_add_ui_files _sources )
foreach( _ui_file ${ARGN} )
get_filename_component( _ui_basename ${_ui_file} NAME_WE )
get_filename_component( _ui_absolute_path ${_ui_file} ABSOLUTE )
list( APPEND ${_sources} ${_ui_basename}.cpp )
add_custom_command( OUTPUT ${_ui_basename}.h ${_ui_basename}.cpp
COMMAND ${CMAKE_COMMAND}
-DUIC_EXECUTABLE:FILEPATH=${UIC_EXECUTABLE}
-DTQT_REPLACE_SCRIPT:FILEPATH=${TQT_REPLACE_SCRIPT}
-DTDE_QTPLUGINS_DIR:FILEPATH=${TDE_QTPLUGINS_DIR}
-DMOC_EXECUTABLE:FILEPATH=${MOC_EXECUTABLE}
-DUI_FILE:FILEPATH=${_ui_absolute_path}
-DMASTER_SOURCE_DIR:FILEPATH=${CMAKE_SOURCE_DIR}
-DMASTER_BINARY_DIR:FILEPATH=${CMAKE_BINARY_DIR}
-P ${CMAKE_MODULE_PATH}/tde_uic.cmake
DEPENDS ${_ui_absolute_path} )
endforeach( _ui_file )
endmacro( tde_add_ui_files )
#################################################
#####
##### tde_moc
macro( tde_moc _sources )
foreach( _input_file ${ARGN} )
get_filename_component( _input_file "${_input_file}" ABSOLUTE )
get_filename_component( _basename ${_input_file} NAME_WE )
set( _output_file "${_basename}.moc.cpp" )
add_custom_command( OUTPUT ${_output_file}
COMMAND
${TMOC_EXECUTABLE} ${_input_file} -o ${_output_file}
DEPENDS
${_input_file} )
list( APPEND ${_sources} ${_output_file} )
endforeach( )
endmacro( )
#################################################
#####
##### tde_automoc
macro( tde_automoc )
foreach( _src_file ${ARGN} )
get_filename_component( _src_file "${_src_file}" ABSOLUTE )
if( EXISTS "${_src_file}" )
# read source file and check if have moc include
file( READ "${_src_file}" _src_content )
string( REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _moc_includes "${_src_content}" )
# found included moc(s)?
if( _moc_includes )
foreach( _moc_file ${_moc_includes} )
# extracting moc filename
string( REGEX MATCH "[^ <\"]+\\.moc" _moc_file "${_moc_file}" )
set( _moc_file "${CMAKE_CURRENT_BINARY_DIR}/${_moc_file}" )
# create header filename
get_filename_component( _src_path "${_src_file}" ABSOLUTE )
get_filename_component( _src_path "${_src_path}" PATH )
get_filename_component( _src_header "${_moc_file}" NAME_WE )
set( _header_file "${_src_path}/${_src_header}.h" )
# if header doesn't exists, check in META_INCLUDES
if( NOT EXISTS "${_header_file}" )
unset( _found )
foreach( _src_path ${_meta_includes} )
set( _header_file "${_src_path}/${_src_header}.h" )
if( EXISTS "${_header_file}" )
set( _found 1 )
break( )
endif( )
endforeach( )
if( NOT _found )
get_filename_component( _moc_file "${_moc_file}" NAME )
tde_message_fatal( "AUTOMOC error: '${_moc_file}' cannot be generated.\n Reason: '${_src_file}.h' not found." )
endif( )
endif( )
# moc-ing header
add_custom_command( OUTPUT ${_moc_file}
COMMAND ${TMOC_EXECUTABLE} ${_header_file} -o ${_moc_file}
DEPENDS ${_header_file} )
# create dependency between source file and moc file
set_property( SOURCE ${_src_file} APPEND PROPERTY OBJECT_DEPENDS ${_moc_file} )
endforeach( _moc_file )
endif( _moc_includes )
endif( EXISTS "${_src_file}" )
endforeach( _src_file )
endmacro( tde_automoc )
#################################################
#####
##### __tde_internal_process_sources
macro( __tde_internal_process_sources _sources )
unset( ${_sources} )
foreach( _arg ${ARGN} )
get_filename_component( _ext ${_arg} EXT )
get_filename_component( _name ${_arg} NAME_WE )
get_filename_component( _path ${_arg} PATH )
# if not path, set it to "."
if( NOT _path )
set( _path "./" )
endif( NOT _path )
# handle .ui files
if( ${_ext} STREQUAL ".ui" )
tde_add_ui_files( ${_sources} ${_arg} )
# handle .skel files
elseif( ${_ext} STREQUAL ".skel" )
kde3_add_dcop_skels( ${_sources} ${_path}/${_name}.h )
# handle .stub files
elseif( ${_ext} STREQUAL ".stub" )
kde3_add_dcop_stubs( ${_sources} ${_path}/${_name}.h )
# handle .kcfgc files
elseif( ${_ext} STREQUAL ".kcfgc" )
kde3_add_kcfg_files( ${_sources} ${_arg} )
# handle any other files
else( ${_ext} STREQUAL ".ui" )
list(APPEND ${_sources} ${_arg} )
endif( ${_ext} STREQUAL ".ui" )
endforeach( _arg )
endmacro( __tde_internal_process_sources )
#################################################
#####
##### tde_install_libtool_file
macro( tde_install_libtool_file _target _destination )
get_target_property( _target_location ${_target} LOCATION )
# get name of target
get_filename_component( _name ${_target_location} NAME )
string( REGEX REPLACE "\\.so(\\.[0-9]+)*$" "" _name "${_name}" )
# get .la name
set( _laname ${_name}.la )
# get .so name
get_filename_component( _soname ${_target_location} NAME )
# get version of target
get_target_property( _target_version ${_target} VERSION )
get_target_property( _target_soversion ${_target} SOVERSION )
# we have so version
if( _target_version )
set( _library_name_1 "${_soname}.${_target_version}" )
set( _library_name_2 "${_soname}.${_target_soversion}" )
set( _library_name_3 "${_soname}" )
string( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" _dummy "${_target_version}" )
set( _version_current "${CMAKE_MATCH_1}" )
set( _version_age "${CMAKE_MATCH_2}" )
set( _version_revision "${CMAKE_MATCH_3}" )
# we have no so version (module?)
else( _target_version )
set( _library_name_1 "${_soname}" )
set( _library_name_2 "${_soname}" )
set( _library_name_3 "${_soname}" )
set( _version_current "0" )
set( _version_age "0" )
set( _version_revision "0" )
endif( _target_version )
if( IS_ABSOLUTE ${_destination} )
set( _libdir "${_destination}" )
else( IS_ABSOLUTE ${_destination} )
set( _libdir "${CMAKE_INSTALL_PREFIX}/${_destination}" )
endif( IS_ABSOLUTE ${_destination} )
configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_libtool_file.cmake "${_laname}" @ONLY )
install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${_laname}" DESTINATION ${_destination} )
endmacro( tde_install_libtool_file )
#################################################
#####
##### tde_install_export / tde_import
function( tde_install_export )
file( GLOB export_files ${CMAKE_CURRENT_BINARY_DIR}/export-*.cmake )
set( mode "WRITE" )
foreach( filename ${export_files} )
file( READ ${filename} content )
file( ${mode} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" "${content}" )
set( mode "APPEND" )
endforeach( )
install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cmake" DESTINATION ${CMAKE_INSTALL_DIR} )
endfunction( )
macro( tde_import _library )
message( STATUS "checking for '${_library}'" )
string( TOUPPER "BUILD_${_library}" _build )
if( ${_build} )
message( STATUS " ok, activated for build" )
else()
if( EXISTS "${TDE_CMAKE_DIR}/${_library}.cmake" )
include( "${TDE_CMAKE_DIR}/${_library}.cmake" )
message( STATUS " ok, found import file" )
else()
tde_message_fatal( "'${_library}' are required,\n but is not installed nor selected for build" )
endif()
endif()
endmacro()
#################################################
#####
##### tde_add_library
macro( tde_add_library _arg_target )
unset( _target )
unset( _type )
unset( _static_pic )
unset( _automoc )
unset( _meta_includes )
unset( _no_libtool_file )
unset( _no_export )
unset( _version )
unset( _sources )
unset( _destination )
unset( _embed )
unset( _link )
unset( _dependencies )
unset( _storage )
unset( _exclude_from_all )
set( _shouldnotlink no )
# metadata
unset( _description )
unset( _license )
unset( _copyright )
unset( _authors )
unset( _product )
unset( _organization )
unset( _version )
unset( _datetime )
unset( _notes )
# default metadata
set( _product "Trinity Desktop Environment" )
tde_curdatetime( _datetime )
foreach( _arg ${ARGV} )
# this variable help us to skip
# storing unapropriate values (i.e. directives)
unset( _skip_store )
# found one of directives: "SHARED", "STATIC", "MODULE"
if( "+${_arg}" STREQUAL "+SHARED" OR "+${_arg}" STREQUAL "+STATIC" OR "+${_arg}" STREQUAL "+MODULE" )
set( _skip_store 1 )
set( _type "${_arg}" )
endif( "+${_arg}" STREQUAL "+SHARED" OR "+${_arg}" STREQUAL "+STATIC" OR "+${_arg}" STREQUAL "+MODULE" )
# found directive "STATIC_PIC"
if( "+${_arg}" STREQUAL "+STATIC_PIC" )
set( _skip_store 1 )
set( _type "STATIC" )
set( _static_pic 1 )
endif( "+${_arg}" STREQUAL "+STATIC_PIC" )
# found directive "AUTOMOC"
if( "+${_arg}" STREQUAL "+AUTOMOC" )
set( _skip_store 1 )
set( _automoc 1 )
endif( "+${_arg}" STREQUAL "+AUTOMOC" )
# found directive "META_INCLUDES"
if( "+${_arg}" STREQUAL "+META_INCLUDES" )
set( _skip_store 1 )
set( _storage "_meta_includes" )
endif( )
# found directive "NO_LIBTOOL_FILE"
if( "+${_arg}" STREQUAL "+NO_LIBTOOL_FILE" )
set( _skip_store 1 )
set( _no_libtool_file 1 )
endif( "+${_arg}" STREQUAL "+NO_LIBTOOL_FILE" )
# found directive "NO_EXPORT"
if( "+${_arg}" STREQUAL "+NO_EXPORT" )
set( _skip_store 1 )
set( _no_export 1 )
endif( "+${_arg}" STREQUAL "+NO_EXPORT" )
# found directive "VERSION"
if( "+${_arg}" STREQUAL "+VERSION" )
set( _skip_store 1 )
set( _storage "_version" )
endif( "+${_arg}" STREQUAL "+VERSION" )
# found directive "SOURCES"
if( "+${_arg}" STREQUAL "+SOURCES" )
set( _skip_store 1 )
set( _storage "_sources" )
endif( "+${_arg}" STREQUAL "+SOURCES" )
# found directive "EMBED"
if( "+${_arg}" STREQUAL "+EMBED" )
set( _skip_store 1 )
set( _storage "_embed" )
endif( "+${_arg}" STREQUAL "+EMBED" )
# found directive "LINK"
if( "+${_arg}" STREQUAL "+LINK" )
set( _skip_store 1 )
set( _storage "_link" )
endif( "+${_arg}" STREQUAL "+LINK" )
# found directive "DEPENDENCIES"
if( "+${_arg}" STREQUAL "+DEPENDENCIES" )
set( _skip_store 1 )
set( _storage "_dependencies" )
endif( "+${_arg}" STREQUAL "+DEPENDENCIES" )
# found directive "DESTINATION"
if( "+${_arg}" STREQUAL "+DESTINATION" )
set( _skip_store 1 )
set( _storage "_destination" )
unset( ${_storage} )
endif( "+${_arg}" STREQUAL "+DESTINATION" )
# found directive "EXCLUDE_FROM_ALL"
if( "+${_arg}" STREQUAL "+EXCLUDE_FROM_ALL" )
set( _skip_store 1 )
set( _exclude_from_all "EXCLUDE_FROM_ALL" )
endif( "+${_arg}" STREQUAL "+EXCLUDE_FROM_ALL" )
# metadata
if( "+${_arg}" STREQUAL "+DESCRIPTION" )
set( _skip_store 1 )
set( _storage "_description" )
endif( )
if( "+${_arg}" STREQUAL "+LICENSE" )
set( _skip_store 1 )
set( _storage "_license" )
endif( )
if( "+${_arg}" STREQUAL "+COPYRIGHT" )
set( _skip_store 1 )
set( _storage "_copyright" )
endif( )
if( "+${_arg}" STREQUAL "+AUTHORS" )
set( _skip_store 1 )
set( _storage "_authors" )
endif( )
if( "+${_arg}" STREQUAL "+PRODUCT" )
set( _skip_store 1 )
set( _storage "_product" )
endif( )
if( "+${_arg}" STREQUAL "+ORGANIZATION" )
set( _skip_store 1 )
set( _storage "_organization" )
endif( )
if( "+${_arg}" STREQUAL "+VERSION" )
set( _skip_store 1 )
set( _storage "_version" )
endif( )
if( "+${_arg}" STREQUAL "+DATETIME" )
set( _skip_store 1 )
set( _storage "_datetime" )
endif( )
if( "+${_arg}" STREQUAL "+NOTES" )
set( _skip_store 1 )
set( _storage "_notes" )
endif( )
# storing value
if( _storage AND NOT _skip_store )
list( APPEND ${_storage} ${_arg} )
list( REMOVE_DUPLICATES ${_storage} )
endif( _storage AND NOT _skip_store )
endforeach( _arg )
# if no type is set, we choose one
# based on BUILD_SHARED_LIBS
if( NOT _type )
if( BUILD_SHARED_LIBS )
set( _type "SHARED" )
else( BUILD_SHARED_LIBS )
set( _type "STATIC" )
endif( BUILD_SHARED_LIBS )
endif( NOT _type )
# change target name, based on type
string( TOLOWER "${_type}" _type_lower )
set( _target "${_arg_target}-${_type_lower}" )
# create variables like "LIB_xxx" for convenience
if( ${_type} STREQUAL "SHARED" )
string( TOUPPER "${_arg_target}" _tmp )
set( LIB_${_tmp} ${_target} CACHE INTERNAL LIB_${tmp} FORCE )
endif( ${_type} STREQUAL "SHARED" )
# disallow target without sources
if( NOT _sources )
message( FATAL_ERROR "\nTarget [$_target] have no sources." )
endif( NOT _sources )
# processing different types of sources
__tde_internal_process_sources( _sources ${_sources} )
# set automoc
if( _automoc )
tde_automoc( ${_sources} )
endif( _automoc )
# add target
add_library( ${_target} ${_type} ${_exclude_from_all} ${_sources} )
# we assume that modules have no prefix and no version
# also, should not link
if( ${_type} STREQUAL "MODULE" )
set_target_properties( ${_target} PROPERTIES PREFIX "" )
unset( _version )
set( _shouldnotlink yes )
endif( ${_type} STREQUAL "MODULE" )
# set real name of target
set_target_properties( ${_target} PROPERTIES OUTPUT_NAME ${_arg_target} )
# set -fPIC flag for static libraries
if( _static_pic )
set_target_properties( ${_target} PROPERTIES COMPILE_FLAGS -fPIC )
endif( _static_pic )
# set version
if( _version )
if( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )
# OpenBSD: _soversion and _version both contains only major and minor
string( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$" _dummy "${_version}" )
set( _version "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" )
set( _soversion "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" )
else( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )
# General (Linux) case: _soversion contains only the major number of version
string( REGEX MATCH "^[0-9]+" _soversion ${_version} )
endif( ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD" )
set_target_properties( ${_target} PROPERTIES VERSION ${_version} SOVERSION ${_soversion} )
endif( _version )
# set interface libraries (only for shared)
unset( _shared_libs )
if( NOT ${_type} STREQUAL "STATIC" )
foreach( _lib ${_link} )
#get_target_property( _lib_type ${_lib} TYPE )
#if( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" )
if( NOT ${_lib} MATCHES ".+-static" )
list( APPEND _shared_libs ${_lib} )
endif( NOT ${_lib} MATCHES ".+-static" )
#endif( NOT "STATIC_LIBRARY" STREQUAL "${_lib_type}" )
endforeach( _lib )
endif( NOT ${_type} STREQUAL "STATIC" )
# set embedded archives
if( _embed )
list( INSERT _link 0 -Wl,-whole-archive ${_embed} -Wl,-no-whole-archive )
endif( _embed )
# set link libraries
if( _link )
if( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" )
# hack for broken CMake 2.8.12.0
set_target_properties( ${_target} PROPERTIES LINK_LIBRARIES "${_link}" )
else( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" )
target_link_libraries( ${_target} ${_link} )
endif( _embed AND ${CMAKE_VERSION} VERSION_EQUAL "2.8.12.0" )
endif( )
if( _shared_libs )
set_target_properties( ${_target} PROPERTIES
LINK_INTERFACE_LIBRARIES "${_shared_libs}"
INTERFACE_LINK_LIBRARIES "${_shared_libs}" )
endif( _shared_libs )
# set dependencies
if( _dependencies )
add_dependencies( ${_target} ${_dependencies} )
endif( _dependencies )
# if destination directory is set
if( _destination )
# we export only shared libs (no static, no modules);
# also, do not export targets marked as "NO_EXPORT" (usually for tdeinit)
if( "SHARED" STREQUAL ${_type} AND NOT _no_export )
# get target properties: output name, version, soversion
get_target_property( _output ${_target} LOCATION )
get_filename_component( _output ${_output} NAME )
get_target_property( _version ${_target} VERSION )
get_target_property( _soversion ${_target} SOVERSION )
if( _version )
set( _location "${_destination}/${_output}.${_version}" )
set( _soname "${_output}.${_soversion}" )
else( )
set( _location "${_destination}/${_output}" )
set( _soname "${_output}" )
endif( )
configure_file( ${CMAKE_SOURCE_DIR}/cmake/modules/template_export_library.cmake "${PROJECT_BINARY_DIR}/export-${_target}.cmake" @ONLY )
endif( )
# install target
install( TARGETS ${_target} DESTINATION ${_destination} )
# install .la files for dynamic libraries
if( NOT "STATIC" STREQUAL ${_type} AND NOT _no_libtool_file )
tde_install_libtool_file( ${_target} ${_destination} )
endif( )
endif( _destination )
# embed name and metadata
set( ELF_EMBEDDING_METADATA "\"${_target}\" \"${_description}\" \"${_license}\" \"${_copyright}\" \"${_authors}\" \"${_product}\" \"${_organization}\" \"${_version}\" \"${_datetime}\" \"x-sharedlib\" \"${TDE_SCM_MODULE_NAME}\" \"${TDE_SCM_MODULE_REVISION}\" \"${_notes}\"" )
separate_arguments( ELF_EMBEDDING_METADATA )
if( TDELFEDITOR_EXECUTABLE AND _soname )
if( _version )
add_custom_command(
TARGET ${_target}
POST_BUILD