summaryrefslogtreecommitdiffstats
path: root/kmm-macros.cmake
blob: 4e507236f7effae065789bfd3f1184b5f90c7e95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#################################################
#                                               #
#  Auxiliary macros for KMyMoney                #
#                                               #
#################################################

include( TDEMacros )


#################################################
#####
##### kmm_install_includes
#####
##### The macro is used to determine the headers that are installed,
##### while the symlinks in the binary include directory are created.
#####
##### Syntax:
#####   kmm_install_includes(
#####     [FILES] include_name [include_name]
#####     [DESTINATION subdir]
#####   )

macro( kmm_install_includes )

  unset( _files )
  unset( _dest )
  set( _var _files )

  foreach( _arg ${ARGN} )

    # found directive "FILES"
    if( "+${_arg}" STREQUAL "+FILES" )
      unset( _files )
      set( _var _files )
      set( _directive 1 )
    endif( )

    # found directive "DESTINATION"
    if( "+${_arg}" STREQUAL "+DESTINATION" )
      unset( _dest )
      set( _var _dest )
      set( _directive 1 )
    endif( )

    # collect data
    if( _directive )
      unset( _directive )
    elseif( _var )
      list( APPEND ${_var} ${_arg} )
    endif( )

  endforeach( )

  # determine destination directory
  if( NOT IS_ABSOLUTE "${_dest}" )
    set( _dest "${INCLUDE_INSTALL_DIR}/${_dest}" )
  endif()
  file( RELATIVE_PATH _dest_sub "${INCLUDE_INSTALL_DIR}" "${_dest}" )
  file( MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_dest_sub}" )

  # process files
  foreach( _file IN LISTS _files )
    if( NOT TARGET kmm-includes )
      add_custom_target( kmm-includes
        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
        COMMENT "Prepare includes..." )
    endif()

    get_filename_component( _source_name "${_file}" NAME )
    get_filename_component( _source_file "${_file}" ABSOLUTE )
    file( RELATIVE_PATH _target_name "${CMAKE_SOURCE_DIR}" "${_source_file}" )
    string( REPLACE "/" "+" _target_name "${_target_name}" )

    file( RELATIVE_PATH _link_source "${CMAKE_BINARY_DIR}/include/${_dest_sub}" ${_source_file} )
    file( RELATIVE_PATH _link_dest "${INCLUDE_INSTALL_DIR}" "${_dest}/${_source_name}" )

    add_custom_command(
      OUTPUT ${CMAKE_BINARY_DIR}/include/${_link_dest}
      COMMAND
        ${CMAKE_COMMAND} -E create_symlink
        ${_link_source} ${CMAKE_BINARY_DIR}/include/${_link_dest}
      COMMENT "Include file ${_link_dest}"
      DEPENDS ${_source_file}
    )
    add_custom_target( ${_target_name}
      DEPENDS ${CMAKE_BINARY_DIR}/include/${_link_dest}
    )
    add_dependencies( kmm-includes ${_target_name} )

    install( FILES ${_file} DESTINATION ${_dest} )
  endforeach( _file )

endmacro( kmm_install_includes )