-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
255 lines (223 loc) · 7.75 KB
/
CMakeLists.txt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
cmake_minimum_required(VERSION 2.8.4)
# project informations
project(dfc C)
set(PACKAGE ${CMAKE_PROJECT_NAME})
set(VERSION_MAJOR 3)
set(VERSION_MINOR 1)
set(VERSION_PATCH 1)
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_REVISION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# prepend "-" to version_revision
if(VERSION_REVISION)
set(VERSION_REVISION "-${VERSION_REVISION}")
endif()
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_REVISION})
# supported platforms
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(BSD true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
set(BSD true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "kFreeBSD")
set(LINUX true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(BSD true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
set(BSD true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(BSD true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(SOLARIS true)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "GNU")
set(LINUX true)
else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()
# useful defines
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin/${CMAKE_BUILD_TYPE})
set(MAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/man)
set(CONF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/conf)
set(PO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/po)
include_directories("src")
# defines for installation
if(DEFINED PREFIX)
set(PREFIX ${PREFIX} CACHE PATH "install prefix")
set(CMAKE_INSTALL_PREFIX ${PREFIX})
else()
set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "install prefix")
endif()
# use a sysconfdir if specified
if(DEFINED SYSCONFDIR)
set(SYSCONFDIR ${SYSCONFDIR} CACHE PATH "config directory")
else()
set(SYSCONFDIR ${PREFIX}/etc CACHE PATH "config directory")
endif()
# share directory
if(DEFINED SHAREDIR)
set(SHAREDIR ${SHAREDIR} CACHE PATH "share directory")
else()
set(SHAREDIR ${PREFIX}/share CACHE PATH "share directory")
endif()
# locale
if(DEFINED LOCALEDIR)
set(LOCALEDIR ${LOCALEDIR} CACHE PATH "locale directory")
else()
set(LOCALEDIR ${SHAREDIR}/locale CACHE PATH "locale directory")
endif()
# if XDG Config Dir is specified, use it
if(DEFINED XDG_CONFIG_DIR)
set(XDG_CONFIG_DIR ${XDG_CONFIG_DIR} CACHE PATH "xdg config directory")
else()
set(XDG_CONFIG_DIR ${SYSCONFDIR}/xdg CACHE PATH "xdf config directory")
endif()
# man path
if(DEFINED MAN_PATH)
set(MAN_PATH ${MAN_PATH} CACHE PATH "manpage directory")
else()
set(MAN_PATH ${SHAREDIR}/man CACHE PATH "manpage directory")
endif()
# doc path
if(DEFINED DOC_PATH)
set(DFC_DOC_PATH ${DFC_DOC_PATH} CACHE PATH "doc directory")
else()
set(DFC_DOC_PATH ${SHAREDIR}/doc/${PACKAGE} CACHE PATH "doc directory")
endif()
# Check for libintl
find_package(Libintl)
if (LIBINTL_FOUND)
option(NLS_ENABLED "Translation support with gettext" on)
else()
option(NLS_ENABLED "Translation support with gettext" off)
endif()
option(LFS_ENABLED "Enable macros for Large File Source. Required on 32-bit systems but should not cause any problems if defined on non 32-bit systems anyway, thus enabled by default." on)
# set compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
if(LINUX)
ADD_DEFINITIONS(-D_XOPEN_SOURCE=600)
elseif(SOLARIS)
ADD_DEFINITIONS(-D__EXTENSIONS__)
endif()
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wsign-conversion HAS_WSIGN_CONVERSION)
check_c_compiler_flag(-Wdouble-promotion HAS_WDOUBLE_PROMOTION)
check_c_compiler_flag(-Wlogical-op HAS_WLOGICAL_OP)
check_c_compiler_flag(-Wjump-misses-init HAS_WJUMP_MISSES_INIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wconversion -Wstrict-prototypes -Wcast-qual -Wcast-align -Wshadow -Wredundant-decls -Wundef -Wfloat-equal -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wpointer-arith -Wbad-function-cast -Wnested-externs -Wold-style-definition -Wformat=2 -Winit-self -Wwrite-strings -Wmissing-prototypes -pipe")
if(HAS_WSIGN_CONVERSION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-conversion")
endif()
if(HAS_WDOUBLE_PROMOTION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wdouble-promotion")
endif()
if(HAS_WLOGICAL_OP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
endif()
if(HAS_WJUMP_MISSES_INIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wjump-misses-init")
endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g3 -ggdb3 -Wpadded -Wpacked")
if(CMAKE_COMPILER_IS_GNUCC)
# gcc warns about strftime format when using std=c99. According to
# strftime(3), it is safe to remove this warning
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-y2k")
endif()
# platform specific source files
if(BSD)
set(SERVICE_SRC_FILE "${SOURCE_DIR}/platform/services-bsd.c")
elseif(LINUX)
set(SERVICE_SRC_FILE "${SOURCE_DIR}/platform/services-linux.c")
elseif(SOLARIS)
set(SERVICE_SRC_FILE "${SOURCE_DIR}/platform/services-solaris.c")
else()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif()
set(EXECUTABLE_NAME ${CMAKE_PROJECT_NAME})
SET(SRCS
${SOURCE_DIR}/dotfile.c
${SOURCE_DIR}/dfc.c
${SOURCE_DIR}/list.c
${SOURCE_DIR}/util.c
${SOURCE_DIR}/export/csv.c
${SOURCE_DIR}/export/html.c
${SOURCE_DIR}/export/json.c
${SOURCE_DIR}/export/tex.c
${SOURCE_DIR}/export/text.c
${SERVICE_SRC_FILE}
)
add_executable(
${EXECUTABLE_NAME}
${SRCS}
)
if(LFS_ENABLED)
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64)
endif()
if(NLS_ENABLED)
add_definitions(-DNLS_ENABLED)
# load gettext module for translation
set(GettextTranslate_ALL true)
set(GettextTranslate_GMO_BINARY true)
include(GettextTranslate)
add_subdirectory(po)
include_directories(${LIBINTL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${LIBINTL_LIBRARIES})
endif()
# link libraries
target_link_libraries(${EXECUTABLE_NAME} m)
add_definitions(-DPACKAGE="${PACKAGE}" -DVERSION="${VERSION}" -DLOCALEDIR="${LOCALEDIR}")
set(DFC_DOC_FILES
AUTHORS.md
CHANGELOG.md
HACKING.md
LICENSE
README.md
TRANSLATORS.md
)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
set(DFC_SYSCONFDIR ${XDG_CONFIG_DIR}/${PACKAGE})
file(STRINGS ${PO_DIR}/LINGUAS LINGUAS REGEX "^[^#].*")
string(REGEX MATCHALL "[^ ]+" languages ${LINGUAS})
# rule to generate a source tarball
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}")
set(CPACK_SOURCE_IGNORE_FILES
"~$"
".directory"
".swp$"
"^${PROJECT_SOURCE_DIR}/.git/"
"^${PROJECT_SOURCE_DIR}/build/"
"${PROJECT_SOURCE_DIR}/.gitignore$"
"${PROJECT_SOURCE_DIR}/po/dfc.pot$"
"${PROJECT_SOURCE_DIR}/res/"
"${CPACK_SOURCE_IGNORE_FILES}")
include(CPack)
add_custom_target(dist
COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
# installation
install(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION bin)
install(FILES ${MAN_DIR}/dfc.1 DESTINATION ${MAN_PATH}/man1)
install(FILES ${CONF_DIR}/dfcrc DESTINATION ${DFC_SYSCONFDIR})
if(NLS_ENABLED)
foreach(lang ${languages})
install(FILES ${MAN_DIR}/${lang}/${PACKAGE}.1 DESTINATION ${MAN_PATH}/${lang}/man1)
install(FILES ${CONF_DIR}/${lang}/dfcrc DESTINATION ${DFC_SYSCONFDIR}/${lang})
endforeach()
endif()
install(FILES ${DFC_DOC_FILES} DESTINATION ${DFC_DOC_PATH})
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)