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
|
# Set the source file for langcomp to use C++ as well as set it's compile flags
set_source_files_properties(langcomp.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Generate langcomp and set it's linker flags
add_executable(langcomp langcomp.c)
set_target_properties(langcomp PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
# Get the location of the binary to use later
get_target_property(langcomp_BINARY langcomp LOCATION)
# Add the executable to the list of files for CPack to ignore
file(RELATIVE_PATH langcomp_BINARY_RELATIVE ${Anope_BINARY_DIR} ${langcomp_BINARY})
add_to_cpack_ignored_files("${langcomp_BINARY_RELATIVE}$" TRUE)
# Determine if langtool should be built
if(MSVC)
set(BUILD_LANGTOOL TRUE)
else(MSVC)
if(NOT GREP OR NOT PERL)
set(BUILD_LANGTOOL TRUE)
else(NOT GREP OR NOT PERL)
set(BUILD_LANGTOOL FALSE)
endif(NOT GREP OR NOT PERL)
endif(MSVC)
# If grep or perl don't exist on the system, build langtool to generate index and language.h
if(BUILD_LANGTOOL)
# Set the source file for langtool to use C++ as well as set it's compile flags
set_source_files_properties(langtool.c PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}")
# Generate langtool and set it's linker flags
add_executable(langtool langtool.c)
set_target_properties(langtool PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
# Get the location of the binary to use later)
get_target_property(langtool_BINARY langtool LOCATION)
# Add the executable to the list of files for CPack to ignore
file(RELATIVE_PATH langtool_BINARY_RELATIVE ${Anope_BINARY_DIR} ${langtool_BINARY})
add_to_cpack_ignored_files("${langtool_BINARY_RELATIVE}$" TRUE)
endif(BUILD_LANGTOOL)
# If grep exists (and we aren't using Visual Studio, it hates this), use it to generate the index file
if(NOT MSVC AND GREP)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index
COMMAND ${GREP} '^[A-Z]' ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l > ${CMAKE_CURRENT_BINARY_DIR}/index
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l
)
# Otherwise, use langtool to generate the index file
else(NOT MSVC AND GREP)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index
COMMAND ${langtool_BINARY} index ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l ${CMAKE_CURRENT_BINARY_DIR}/index
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/en_us.l DEPENDS langtool
)
endif(NOT MSVC AND GREP)
# Add the index file to the list of files for CPack to ignore
file(RELATIVE_PATH index_RELATIVE ${Anope_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/index)
add_to_cpack_ignored_files("${index_RELATIVE}$")
# Find all the *.l files within the current source directory, and sort the list
file(GLOB LANG_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.l")
sort_list(LANG_SRCS)
# Iterate through the language files
foreach(LANG_L ${LANG_SRCS})
# Convert the language file's extension to have no extension
STRING(REGEX REPLACE "\\.l$" "" LANG ${LANG_L})
# Add the language file to the list of compiled language files
append_to_list(LANGS ${CMAKE_CURRENT_BINARY_DIR}/${LANG})
# Generate a compiled language file using langcomp, as well as having a dependency on the index file being generated
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LANG}
COMMAND ${langcomp_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/${LANG_L} ${CMAKE_CURRENT_BINARY_DIR}/${LANG}
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${LANG_L} DEPENDS langcomp ${CMAKE_CURRENT_BINARY_DIR}/index
)
# Add the language file to the list of files for CPack to ignore
file(RELATIVE_PATH LANG_RELATIVE ${Anope_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${LANG})
add_to_cpack_ignored_files("${LANG_RELATIVE}$")
endforeach(LANG_L)
# If perl exists (and we aren't using Visual Studio, it hates this), use it to generate language.h
if(NOT MSVC AND PERL)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/language.h
COMMAND ${PERL} -e < ${CMAKE_CURRENT_BINARY_DIR}/index > ${CMAKE_CURRENT_BINARY_DIR}/language.h 'print STDERR \"Generating language.h... \"\; $$i=0\; while \(<>\) { chop\; printf \"\#define %-32s %d\\n\", $$_, $$i++\; } print \"\\n\#define NUM_STRINGS $$i\\n\"\; print STDERR \"$$i strings\\n\"\;'
MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/index
)
# Otherwise, use langtool to generate language.h
else(NOT MSVC AND PERL)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/language.h
COMMAND ${langtool_BINARY} language.h ${CMAKE_CURRENT_BINARY_DIR}/index ${CMAKE_CURRENT_BINARY_DIR}/language.h
MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/index DEPENDS langtool
)
endif(NOT MSVC AND PERL)
# Add language.h to the list of files for CPack to ignore
add_to_cpack_ignored_files("language.h$" TRUE)
# Add a custom target to depend on the language files and language.h
add_custom_target(language DEPENDS ${LANGS} ${CMAKE_CURRENT_BINARY_DIR}/language.h)
# If RUNGROUP was set, make the permissions be to have owner read/write as well as group read/write
if(RUNGROUP)
set(PERMS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
# Otherwise, only make the permissions be owner read/write
else(RUNGROUP)
set(PERMS OWNER_READ OWNER_WRITE)
endif(RUNGROUP)
# Set the language files to be installed to the languages directory under the data directory
install(FILES ${LANGS}
DESTINATION data/languages
PERMISSIONS ${PERMS}
)
# On non-Windows platforms, if RUNGROUP is set, change the permissions of the languages directory
if(NOT WIN32)
if(RUNGROUP)
install(CODE "execute_process(COMMAND ${CHMOD} 2770 \"\${CMAKE_INSTALL_PREFIX}/data/languages\")")
else(RUNGROUP)
install(CODE "execute_process(COMMAND ${CHMOD} 0700 \"\${CMAKE_INSTALL_PREFIX}/data/languages\")")
endif(RUNGROUP)
endif(NOT WIN32)
|