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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
cmake_minimum_required(VERSION 2.6)

#definition du projet
project (d7c)

set(EXECUTABLE_OUTPUT_PATH bin)
set(package_name d7c)
set(package_version svn0.2)
set(email_report alexisis-pristontale@hotmail.com)


#recherche de getext
include(FindGettext)
find_package(Gettext)

if (NOT GETTEXT_FOUND)
  message(FATAL_ERROR "missing gettext : please install it")
endif (NOT GETTEXT_FOUND)

#verification des bibliothéques
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(UseLibraries)
USE_LIBRARIES(glib2 gcrypt ircclient)
if (NOT HAVE_glib2)
  message(FATAL_ERROR "missing glib2 : please install it")
endif (NOT HAVE_glib2)
if (NOT HAVE_gcrypt)
  message(FATAL_ERROR "missing gcrypt : please install it")
endif (NOT HAVE_gcrypt)
if (NOT HAVE_ircclient)
  message(FATAL_ERROR "missing libircclient : please install it")
endif (NOT HAVE_ircclient)

find_package(SQLite REQUIRED)
if (NOT SQLite_FOUND)
  message(FATAL_ERROR "missing sqlite3 : please install it")
endif (NOT SQLite_FOUND)

#inclusion des bibliothéques au projet
include_directories(
      ${USE_gcrypt_INCLUDE_DIR}
      ${USE_glib2_INCLUDE_DIR_1}
      ${USE_glib2_INCLUDE_DIR_2}
      ${USE_ircclient_INCLUDE_DIR}
      ${SQLITE_INCLUDE_DIRS}
)
link_directories(
      ${USE_gcrypt_LIBRARY}
      ${USE_glib2_LIBRARY}
      ${USE_ircclient_LIBRARY}
      ${SQLITE_LIBRARIES}
)


#identification des fichiers
file(
  GLOB_RECURSE
  sources_files
  src/*.[hc]
)
add_executable (
      d7c
      ${sources_files}    
)
target_link_libraries(
        d7c
        ${LIBRARIES}
        sqlite3
)

#mise a jour du fichier pot
file(
  GLOB_RECURSE
  po_files
  po/*.po
) 
add_custom_target(
      update_pot
      COMMAND xgettext -d ${package_name} -s -o
        ${package_name}.pot ./src/*.c -p ./po 
        --from-code=utf-8 -j 
        --keyword=_
        --package-name=${package_name}
        --package-version=${package_version} 
        --msgid-bugs-address=${email_report}
)

#creation des fichiers mo et mise a jour des fichiers po
#set(pot_file ./po/${package_name}.pot)
foreach (po_courrent ${po_files})
  get_filename_component(
    langue
    po_courent
    NAME_WE
  )
  set(mo_file /po/${langue}.mo)
  add_custom_command(
    TARGET update_pot
    COMMAND msgmerge --update ${po_files} ./po/${package_name}.pot
  )  
  add_custom_command(
    OUTPUT ${mo_file}
    COMMAND msgfmt -c ${po_current} -o ./po/${langue}.mo
    DEPENDS ${po_current}
  )
  install(
      FILES ${langue}.mo 
      DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/po/locale/${langue}/LC_MESSAGES
      RENAME ${package_name}.mo
  )
  set(pos_current ${pos_current} ${po_current})
endforeach (po_courrent) 
add_custom_target(build_mo ALL DEPENDS ${pos_current})

#ajout d'un fichier po
add_custom_target(
  create_po
  COMMAND msginit -l $(LANGUAGE) -o ./po/$(LANGUAGE).po -i ./po/${package_name}.pot
)