]> granicus.if.org Git - fortune-mod/blob - fortune-mod/CMakeLists.txt
debian package
[fortune-mod] / fortune-mod / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.2)
2
3 project(fortune-mod)
4
5 INCLUDE ("${CMAKE_SOURCE_DIR}/cmake/shlomif_common_bootstrap.cmake")
6 SHLOMIF_COMMON_SETUP("${private_mod_path}")
7
8 CMAKE_POLICY(SET CMP0054 NEW)
9
10 INCLUDE(FindPkgConfig)
11
12 SET (PKGDATADIR_SUBDIR "fortune-mod")
13 SET (RELATIVE_PKGDATADIR "${RELATIVE_DATADIR}/${PKGDATADIR_SUBDIR}")
14 SET (PKGDATADIR "${DATADIR}/${PKGDATADIR_SUBDIR}")
15
16 # Introduces VERSION , CPACK_PACKAGE_VERSION_MAJOR,
17 # CPACK_PACKAGE_VERSION_MAJOR, and CPACK_PACKAGE_VERSION_PATCH
18 READ_VERSION_FROM_VER_TXT()
19
20 # This is the equivalent to perform a "make dist"/"make distdir" etc.
21 SET(CPACK_PACKAGE_NAME "fortune-mod")
22 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fortune-mod")
23 SET(CPACK_PACKAGE_VENDOR "Shlomi Fish")
24 SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
25 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.txt")
26
27
28 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
29
30 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
31 SET(CPACK_SOURCE_GENERATOR "TXZ")
32
33 SET (base_with_ver "fortune-mod-[0-9]+\\\\.[0-9]+\\\\.[0-9]+")
34
35 SET(CPACK_SOURCE_IGNORE_FILES
36     "/.deps/"
37     "/\\\\.git/"
38     "/\\\\.tidyall\\\\.d/"
39     "~$"
40     "\\\\.pyc$"
41     "/tags$"
42     "/(build|BUILD|B)/"
43 )
44
45 IF(WIN32 AND NOT UNIX)
46     # There is a bug in NSI that does not handle full unix paths properly. Make
47     # sure there is at least one set of four (4) backlasshes.
48     SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\dondorf-king.bmp")
49     SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\fortune.exe")
50     SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\github.com\\\\shlomif\\\\fortune-mod")
51     SET(CPACK_NSIS_URL_INFO_ABOUT  "http:\\\\\\\\github.com\\\\shlomif\\\\fortune-mod")
52     SET(CPACK_NSIS_DISPLAY_NAME "fortune-mod")
53     SET(CPACK_NSIS_CONTACT "shlomif@shlomifish.org")
54     SET(CPACK_NSIS_MODIFY_PATH ON)
55     # Setting for NSIS :
56     SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\fc-solve.ico")
57     SET(CPACK_NSIS_MUI_UNIICON ${CPACK_NSIS_MUI_ICON})
58     SET(CPACK_PACKAGE_ICON ${CPACK_NSIS_MUI_ICON})
59     SET(CPACK_NSIS_MODIFY_PATH "ON")
60 ELSE()
61   SET(CPACK_STRIP_FILES "fortune")
62   SET(CPACK_SOURCE_STRIP_FILES "")
63 ENDIF()
64
65 SET(CPACK_PACKAGE_EXECUTABLES
66     "fortune" "The fortune-mod program"
67 )
68
69 ### This is to set the RPATH correctly, so when installed under a prefix
70 ### the executables will find the libraries.
71 ###
72 ### See:
73 ###
74 ### http://www.cmake.org/Wiki/CMake_RPATH_handling
75 ###
76 ### (Taken from that wiki page)
77
78 # use, i.e. don't skip the full RPATH for the build tree
79 SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
80
81 # when building, don't use the install RPATH already
82 # (but later on when installing)
83 SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
84
85 # the RPATH to be used when installing
86 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
87
88 # add the automatically determined parts of the RPATH
89 # which point to directories outside the build tree to the install RPATH
90 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
91
92 SET (WITH_TEST_SUITE CACHE BOOL "")
93 SET (NO_OFFENSIVE CACHE BOOL "Exclude the offensive option.")
94 SET (LOCALDIR "${CMAKE_INSTALL_PREFIX}/local/share/games/fortunes" CACHE STRING "LOCALDIR fortunes dir")
95 SET (LOCALODIR "${LOCALDIR}/off" CACHE STRING "offensive fortunes localdir")
96 SET (COOKIEDIR "${CMAKE_INSTALL_PREFIX}/share/games/fortunes" CACHE STRING  "cookie dir not under /usr/local")
97 SET (OCOOKIEDIR "${COOKIEDIR}/off" CACHE STRING "offensive cookie dir not under /usr/local")
98
99 SHLOMIF_ADD_COMMON_C_FLAGS()
100
101 # add_flags("-Weverything" "-Wno-language-extension-token" "-Wno-padded")
102
103 SHLOMIF_FINALIZE_FLAGS()
104
105
106 # Clone the rinutils repository with the appropriate tag.
107 SET (rinutils_dir "rinutils")
108 SET (rinutils_dir_absolute "${CMAKE_CURRENT_SOURCE_DIR}/${rinutils_dir}")
109 SET (rinutils_inc_dir "${rinutils_dir_absolute}/rinutils/include")
110 IF (NOT EXISTS "${rinutils_inc_dir}")
111     EXECUTE_PROCESS(
112         COMMAND "git" "clone" "-b" "0.6.0" "https://github.com/shlomif/rinutils.git" "${rinutils_dir}"
113         WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
114     )
115 ELSE ()
116     IF (NOT EXISTS "${rinutils_inc_dir}")
117         EXECUTE_PROCESS(
118             COMMAND "git" "submodule" "update" "--init"
119             WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
120         )
121     ENDIF ()
122 ENDIF ()
123
124 find_package(Rinutils QUIET)
125 IF ("${Rinutils_FOUND}")
126     INCLUDE_DIRECTORIES(AFTER ${RINUTILS_INCLUDE_DIR} ${RINUTILS_INCLUDE_DIRS})
127 ELSE ()
128     IF (NOT EXISTS "${rinutils_inc_dir}")
129         MESSAGE(FATAL_ERROR "Could not find rinutils anywhere - it should have been bundled in the releases' source tarball.\nYou can try installing it from a source release or from its repository: https://github.com/shlomif/rinutils\n\nAlso see: https://github.com/shlomif/fortune-mod/issues/44")
130     ENDIF ()
131     INCLUDE_DIRECTORIES(AFTER "${rinutils_inc_dir}")
132 ENDIF ()
133 IF ("$ENV{FCS_GCC}")
134     ADD_DEFINITIONS("-W -Wabi=11 -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbad-function-cast -Wbool-compare -Wbool-operation -Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdangling-else -Wdate-time -Wdeprecated -Wdeprecated-declarations -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wduplicate-decl-specifier -Wempty-body -Wendif-labels -Wenum-compare -Wexpansion-to-defined -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Whsa -Wignored-attributes -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wincompatible-pointer-types -Winit-self -Winline -Wint-conversion -Wint-in-bool-context -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wjump-misses-init -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnested-externs -Wnonnull -Wnonnull-compare -Wnull-dereference -Wodr -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-compare -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wpsabi -Wrestrict -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshadow -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-aliasing -Wstrict-prototypes  -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-unreachable -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvla -Wvolatile-register-var -Wwrite-strings -Walloc-size-larger-than=9223372036854775807 -Warray-bounds=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wnormalized=nfc -Wshift-overflow=2  -Wunused-const-variable=2 -Wstrict-overflow=1  -Wno-switch-default -Wno-vla -Wno-inline  -Wno-jump-misses-init -Wno-unsafe-loop-optimizations")
135     # -Wimplicit-fallthrough=5
136     # -Wno-vla-larger-than
137     # -Wsuggest-attribute=const
138     # -Wstringop-overflow=2
139
140     IF (NOT IS_DEBUG)
141         ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
142     ELSE ()
143         ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
144     ENDIF ()
145         ADD_DEFINITIONS("-O1")
146 ENDIF ()
147
148 INCLUDE(CheckIncludeFile)
149 SET(_r "stdbool.h" "stdio.h" "recode.h")
150 CHECK_INCLUDE_FILES("${_r}" HAVE_RECODE_H)
151 IF (NOT "${HAVE_RECODE_H}")
152     IF (NOT WIN32)
153         MESSAGE(WARNING "Cannot find recode.h anywhere; it is usually unnecessary, but you may opt to install a source release tarball of the recode library from https://github.com/rrthomas/recode")
154     ENDIF ()
155 ENDIF ()
156
157 # So it can find config.h
158 INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
159
160 MACRO(my_exe exe c_file dir)
161     SET(_files "${c_file}")
162     if (WIN32)
163         list(APPEND _files "util/getopt.c")
164     endif()
165     ADD_EXECUTABLE("${exe}" "${c_file}")
166     set(_libs)
167     if ("${exe}" STREQUAL "fortune")
168         if (HAVE_RECODE_H)
169             list(APPEND _libs "recode")
170         endif()
171     endif()
172     if (WIN32)
173         # See https://stackoverflow.com/questions/15119639/how-to-link-winsock-in-cmake
174         list(APPEND _libs intl regex wsock32 ws2_32)
175     endif()
176     TARGET_LINK_LIBRARIES("${exe}" ${_libs})
177     if (NOT ("${dir}" STREQUAL "null"))
178         INSTALL(TARGETS "${exe}" RUNTIME DESTINATION "${dir}")
179     endif()
180 ENDMACRO()
181
182 my_exe(
183     "fortune"
184     "fortune/fortune.c"
185     "games"
186 )
187
188 my_exe(
189     "strfile"
190     "util/strfile.c"
191     "bin"
192 )
193
194 # Build but not install.
195 my_exe("randstr" "util/randstr.c" "null")
196 my_exe(
197     "unstr"
198     "util/unstr.c"
199     "bin"
200 )
201
202 my_exe(
203     "rot"
204     "util/rot.c"
205     "bin"
206 )
207
208 SET (_my_man_page_dir "${CMAKE_CURRENT_BINARY_DIR}/manpages")
209 SET (_my_man_page "${_my_man_page_dir}/fortune.6")
210 SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/process-fortune-man-template.pl")
211 SET (_my_args)
212 LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" "--ocookiedir" "${OCOOKIEDIR}" "--output" "${_my_man_page}")
213 IF ("${NO_OFFENSIVE}")
214     LIST(APPEND _my_args "--without-offensive")
215     SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_with_offensive.template.man")
216 ELSE()
217     SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_without_offensive.template.man")
218 ENDIF()
219 LIST(APPEND _my_args "--input" "${_MY_IN}")
220
221 ADD_CUSTOM_COMMAND(
222     OUTPUT "${_my_man_page}"
223     COMMAND "${PERL_EXECUTABLE}"
224     ARGS "${_my_man_gen}" ${_my_args}
225     DEPENDS "${_my_man_gen}" "${_MY_IN}"
226 )
227 SET (_my_man_pages_list)
228
229 LIST(APPEND _my_man_pages_list "${_my_man_page}")
230
231 INSTALL_RENAME_MAN("fortune.6" "6" "fortune" "${_my_man_page_dir}")
232
233 SET (_util_dir "${CMAKE_CURRENT_SOURCE_DIR}/util")
234 MACRO(_fortune__generate_docbook basename offensive_flags)
235
236     SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/fortune")
237     SET (_dest_basename "${basename}.template")
238     SET (_my_man_page "${_my_man_page_dir}/${_dest_basename}.man")
239     SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml")
240     SET (_my_man_prog "${_my_man_page_dir}/gen-fortune-docbook-page.pl")
241     SET (_my_args "${_my_man_prog}" "--output" "${_my_man_docbook}" --cookiedir "[[cookiedir_placeholder]]" --ocookiedir "[[ocookiedir_placeholder]]" ${offensive_flags})
242     ADD_CUSTOM_COMMAND(
243         OUTPUT "${_my_man_docbook}"
244         COMMAND "${PERL_EXECUTABLE}"
245         ARGS ${_my_args}
246         DEPENDS "${_my_man_prog}"
247     )
248
249     LIST(APPEND _my_man_pages_list "${_my_man_docbook}")
250     SET (_my_args "-I${_util_dir}" "${_util_dir}/fortmod_gen_manpage.pl" "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}" "--basename=${basename}" "--dest-basename=${_dest_basename}" "--out-section=6" "--out-basename=fortune" "--subdir=fortune")
251     ADD_CUSTOM_COMMAND(
252         OUTPUT "${_my_man_page}"
253         COMMAND "${PERL_EXECUTABLE}"
254         ARGS ${_my_args}
255         DEPENDS "${_my_man_docbook}"
256     )
257
258     LIST(APPEND _my_man_pages_list "${_my_man_page}")
259 ENDMACRO()
260
261 _fortune__generate_docbook("fortune_with_offensive" "")
262 _fortune__generate_docbook("fortune_without_offensive" "--without-offensive")
263
264 MACRO(_fortune__generate_manpage basename)
265
266     SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/util")
267     SET (_my_man_page "${_my_man_page_dir}/${basename}.man")
268     SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml")
269     SET (_my_args "-I${_util_dir}" "${_util_dir}/fortmod_gen_manpage.pl" "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}" "--basename=${basename}")
270     ADD_CUSTOM_COMMAND(
271         OUTPUT "${_my_man_page}"
272         COMMAND "${PERL_EXECUTABLE}"
273         ARGS ${_my_args}
274         DEPENDS "${_my_man_docbook}"
275     )
276
277     LIST(APPEND _my_man_pages_list "${_my_man_page}")
278 ENDMACRO()
279
280 _fortune__generate_manpage("strfile")
281 INSTALL_RENAME_MAN("strfile.man" "1" "strfile" "${_my_man_page_dir}")
282 _fortune__generate_manpage("randstr")
283
284 ADD_CUSTOM_TARGET(
285     generate_man_page
286     ALL DEPENDS ${_my_man_pages_list}
287 )
288
289 INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/util")
290
291 IF(WIN32 AND NOT UNIX)
292     FOREACH (var "LOCALODIR" "LOCALDIR" "OCOOKIEDIR" "COOKIEDIR")
293         string(REPLACE "\\" "/" "${var}" "${${var}}")
294     ENDFOREACH()
295 ENDIF()
296
297 IF ("${NO_OFFENSIVE}")
298     ADD_DEFINITIONS("-DNO_OFFENSIVE=1")
299 ENDIF()
300
301 CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
302
303 IF ("${HAVE_REGEX_H}")
304     ADD_DEFINITIONS("-DHAVE_REGEX_H")
305     ADD_DEFINITIONS("-DPOSIX_REGEX")
306 ENDIF()
307
308 ADD_DEFINITIONS("-DHAVE_STDBOOL")
309 SET (COOKIES
310     art
311     ascii-art
312     computers
313     cookie
314     definitions
315     disclaimer
316     drugs
317     education
318     ethnic
319     food
320     fortunes
321     goedel
322     humorists
323     kids
324     law
325     linuxcookie
326     literature
327     love
328     magic
329     medicine
330     men-women
331     miscellaneous
332     news
333     people
334     pets
335     platitudes
336     politics
337     pratchett
338     riddles
339     science
340     songs-poems
341     sports
342     startrek
343     tao
344     translate-me
345     wisdom
346     work
347     linux
348     perl
349     knghtbrd
350     paradoxum
351     zippy
352     debian
353 )
354
355 SET (OFFENSIVE_COOKIES
356     art
357     astrology
358     atheism
359     black-humor
360     cookie
361     debian
362     definitions
363     drugs
364     ethnic
365     fortunes
366     hphobia
367     knghtbrd
368     limerick
369     linux
370     misandry
371     miscellaneous
372     misogyny
373     politics
374     privates
375     racism
376     religion
377     riddles
378     sex
379     songs-poems
380     vulgarity
381     zippy
382 )
383
384 ADD_SUBDIRECTORY("datfiles")
385
386 string (REPLACE ";" " " COOKIES_STR "${COOKIES}")
387 ADD_CUSTOM_TARGET(
388     "check"
389     "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}" "--cookies" "${COOKIES_STR}"
390 )
391
392 # Rebuild config.h if ver.txt has changed.
393 ADD_CUSTOM_COMMAND(
394     OUTPUT "config.h.in"
395     DEPENDS "ver.txt"
396     COMMAND "touch"
397     ARGS "config.h.in"
398 )
399
400 SET(AUTOGENERATED_CONFIG_H "config.h was auto-generated from config.h.in . Do not modify directly")
401
402 CONFIGURE_FILE(
403     ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
404     ${CMAKE_CURRENT_BINARY_DIR}/config.h
405 )
406
407 INCLUDE(CPack)