summaryrefslogtreecommitdiffstats
path: root/doc/man/CMakeLists.txt
blob: cc9e9ce23e394d2348126379946711084f28808a (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

file( GLOB_RECURSE _man_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} * )
unset( _dirs )
foreach( _man_file IN LISTS _man_files )
  get_filename_component( _dir ${_man_file} PATH )
  list( APPEND _dirs ${_dir} )
endforeach()
if( _dirs )
  list( SORT _dirs )
  list( REMOVE_DUPLICATES _dirs )
endif()

string( REGEX REPLACE "[ \r\n\t]+" ";" _linguas "$ENV{LINGUAS}" )

foreach( _dir IN LISTS _dirs )
  string( REGEX REPLACE "/.*" "" _lang ${_dir} )
  if( ${_lang} STREQUAL "en" OR
      "${_linguas}" MATCHES "^;*$" OR
      ";${_linguas};" MATCHES ";${_lang};" )

    file( GLOB_RECURSE _man_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${_lang}/* )
    foreach( _man_file IN LISTS _man_files )
      if( ${_man_file} MATCHES "\\.[0-9]$" )
        string( REGEX REPLACE ".*\\.([0-9])$" "\\1" _man_section "${_man_file}" )
        list( APPEND _man_files_${_man_section} "${_man_file}" )
        list( APPEND _man_sections "${_man_section}" )
      endif()
    endforeach()
    if( ${_lang} STREQUAL "en" )
      set( _lang_dir "" )
    else()
      set( _lang_dir "/${_lang}" )
    endif()
    foreach( _man_section IN LISTS _man_sections )
      install(
          FILES ${_man_files_${_man_section}}
          DESTINATION ${MAN_INSTALL_DIR}${_lang_dir}/man${_man_section}
          COMPONENT doc
      )
    endforeach()
  endif()
endforeach()