]> granicus.if.org Git - fortune-mod/blob - fortune-mod/CMakeLists.txt
Silence compile-time or run-time warnings.
[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 # see: https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html
11 SET (IS_CROSS "${CMAKE_CROSSCOMPILING}")
12
13 INCLUDE(FindPkgConfig)
14
15 SET (PKGDATADIR_SUBDIR "fortune-mod")
16 SET (RELATIVE_PKGDATADIR "${RELATIVE_DATADIR}/${PKGDATADIR_SUBDIR}")
17 SET (PKGDATADIR "${DATADIR}/${PKGDATADIR_SUBDIR}")
18
19 # Introduces VERSION , CPACK_PACKAGE_VERSION_MAJOR,
20 # CPACK_PACKAGE_VERSION_MAJOR, and CPACK_PACKAGE_VERSION_PATCH
21 READ_VERSION_FROM_VER_TXT()
22
23 # This is the equivalent to perform a "make dist"/"make distdir" etc.
24 SET(CPACK_PACKAGE_NAME "fortune-mod")
25 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fortune-mod")
26 SET(CPACK_PACKAGE_VENDOR "Shlomi Fish")
27 SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
28 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.txt")
29
30
31 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
32
33 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
34 SET(CPACK_SOURCE_GENERATOR "TXZ")
35
36 SET (base_with_ver "fortune-mod-[0-9]+\\\\.[0-9]+\\\\.[0-9]+")
37
38 SET(CPACK_SOURCE_IGNORE_FILES
39     "/\\\\.deps/"
40     "/\\\\.git/"
41     "/\\\\.tidyall\\\\.d/"
42     "/t/valgrind[0-9]+\\\\.t$"
43     "/tags$"
44     "\\\\.pyc$"
45     "~$"
46     # "/(build|BUILD|B)/"
47 )
48
49 IF(WIN32 AND NOT UNIX)
50     # There is a bug in NSI that does not handle full unix paths properly. Make
51     # sure there is at least one set of four (4) backlasshes.
52     SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\\\dondorf-king.bmp")
53     SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\fortune.exe")
54     SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\github.com\\\\shlomif\\\\fortune-mod")
55     SET(CPACK_NSIS_URL_INFO_ABOUT  "http:\\\\\\\\github.com\\\\shlomif\\\\fortune-mod")
56     SET(CPACK_NSIS_DISPLAY_NAME "fortune-mod")
57     SET(CPACK_NSIS_CONTACT "shlomif@shlomifish.org")
58     SET(CPACK_NSIS_MODIFY_PATH ON)
59     # Setting for NSIS :
60     SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\fc-solve.ico")
61     SET(CPACK_NSIS_MUI_UNIICON ${CPACK_NSIS_MUI_ICON})
62     SET(CPACK_PACKAGE_ICON ${CPACK_NSIS_MUI_ICON})
63     SET(CPACK_NSIS_MODIFY_PATH "ON")
64 ELSE()
65   SET(CPACK_STRIP_FILES "fortune")
66   SET(CPACK_SOURCE_STRIP_FILES "")
67 ENDIF()
68
69 SET(CPACK_PACKAGE_EXECUTABLES
70     "fortune" "The fortune-mod program"
71 )
72
73 ### This is to set the RPATH correctly, so when installed under a prefix
74 ### the executables will find the libraries.
75 ###
76 ### See:
77 ###
78 ### http://www.cmake.org/Wiki/CMake_RPATH_handling
79 ###
80 ### (Taken from that wiki page)
81
82 # use, i.e. don't skip the full RPATH for the build tree
83 SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
84
85 # when building, don't use the install RPATH already
86 # (but later on when installing)
87 SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
88
89 # the RPATH to be used when installing
90 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
91
92 # add the automatically determined parts of the RPATH
93 # which point to directories outside the build tree to the install RPATH
94 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
95
96 SET (WITH_TEST_SUITE CACHE BOOL "")
97 SET (NO_OFFENSIVE CACHE BOOL "Exclude the offensive option.")
98 SET (LOCALDIR "${CMAKE_INSTALL_PREFIX}/local/share/games/fortunes" CACHE STRING "LOCALDIR fortunes dir")
99 SET (LOCALODIR "${LOCALDIR}/off" CACHE STRING "offensive fortunes localdir")
100 SET (COOKIEDIR "${CMAKE_INSTALL_PREFIX}/share/games/fortunes" CACHE STRING  "cookie dir not under /usr/local")
101 SET (OCOOKIEDIR "${COOKIEDIR}/off" CACHE STRING "offensive cookie dir not under /usr/local")
102
103 SHLOMIF_ADD_COMMON_C_FLAGS()
104
105 # add_flags("-Weverything" "-Wno-language-extension-token" "-Wno-padded")
106
107 SHLOMIF_FINALIZE_FLAGS()
108
109 INCLUDE ("${CMAKE_SOURCE_DIR}/cmake/rinutils_bootstrap.cmake")
110
111 RINUTILS_SET_UP_FLAGS()
112
113 IF ("$ENV{FCS_CLANG}")
114     ADD_DEFINITIONS("-Weverything -Wno-language-extension-token -Wno-padded -Wno-gnu-statement-expression -Wno-unused-parameter -Wno-vla -Wno-cast-align -Wno-used-but-marked-unused -Wno-cast-qual -Wno-comma -Wno-disabled-macro-expansion -Wno-extra-semi-stmt -Wno-documentation-unknown-command -Wno-documentation -Wno-documentation-deprecated-sync -Wno-pass-failed -Wno-implicit-fallthrough")
115     # ADD_DEFINITIONS("-Weverything")
116 ENDIF ()
117
118 IF ($ENV{FCS_GCC})
119     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")
120     # -Wimplicit-fallthrough=5
121     # -Wno-vla-larger-than
122     # -Wsuggest-attribute=const
123     # -Wstringop-overflow=2
124
125     IF (NOT IS_DEBUG)
126         ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
127     ELSE ()
128         ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
129     ENDIF ()
130         ADD_DEFINITIONS("-O1")
131 ENDIF ()
132
133 # Either or both of CheckIncludeFile
134 # and CheckIncludeFiles may be needed for
135 # CHECK_INCLUDE_FILES and CHECK_INCLUDE_FILE
136 INCLUDE(CheckIncludeFile)
137 INCLUDE(CheckIncludeFiles)
138 SET(_r "stdbool.h" "stdio.h" "recode.h")
139 CHECK_INCLUDE_FILES("${_r}" HAVE_RECODE_H)
140 IF (NOT HAVE_RECODE_H)
141     IF (NOT WIN32)
142         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")
143     ENDIF ()
144 ENDIF ()
145
146 # So it can find config.h
147 INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
148
149 MACRO(my_exe exe c_file dir)
150     SET(_files "${c_file}")
151     if (WIN32)
152         list(APPEND _files "util/getopt.c")
153     endif()
154     ADD_EXECUTABLE("${exe}" "${c_file}")
155     set(_libs)
156     if ("${exe}" STREQUAL "fortune")
157         if (HAVE_RECODE_H)
158             list(APPEND _libs "recode")
159         endif()
160     endif()
161     if (WIN32)
162         # See https://stackoverflow.com/questions/15119639/how-to-link-winsock-in-cmake
163         list(APPEND _libs intl regex wsock32 ws2_32)
164     endif()
165     TARGET_LINK_LIBRARIES("${exe}" ${_libs})
166     if (NOT ("${dir}" STREQUAL "null"))
167         INSTALL(TARGETS "${exe}" RUNTIME DESTINATION "${dir}")
168     endif()
169 ENDMACRO()
170
171 my_exe(
172     "fortune"
173     "fortune/fortune.c"
174     "games"
175 )
176
177 my_exe(
178     "strfile"
179     "util/strfile.c"
180     "bin"
181 )
182
183 # Build but not install.
184 my_exe("randstr" "util/randstr.c" "null")
185 my_exe(
186     "unstr"
187     "util/unstr.c"
188     "bin"
189 )
190
191 my_exe(
192     "rot"
193     "util/rot.c"
194     "bin"
195 )
196
197 SET (_my_man_page_dir "${CMAKE_CURRENT_BINARY_DIR}/manpages")
198 SET (_my_man_page "${_my_man_page_dir}/fortune.6")
199 SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/process-fortune-man-template.pl")
200 SET (_my_args)
201 LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" "--ocookiedir" "${OCOOKIEDIR}" "--output" "${_my_man_page}")
202 IF (NO_OFFENSIVE)
203     LIST(APPEND _my_args "--without-offensive")
204     SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_with_offensive.template.man")
205 ELSE()
206     SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_without_offensive.template.man")
207 ENDIF()
208 LIST(APPEND _my_args "--input" "${_MY_IN}")
209
210 ADD_CUSTOM_COMMAND(
211     OUTPUT "${_my_man_page}"
212     COMMAND "${PERL_EXECUTABLE}"
213     ARGS "${_my_man_gen}" ${_my_args}
214     DEPENDS "${_my_man_gen}" "${_MY_IN}"
215 )
216 SET (_my_man_pages_list)
217
218 LIST(APPEND _my_man_pages_list "${_my_man_page}")
219
220 INSTALL_RENAME_MAN("fortune.6" "6" "fortune" "${_my_man_page_dir}")
221
222 SET (_util_dir "${CMAKE_CURRENT_SOURCE_DIR}/util")
223 MACRO(_fortune__generate_docbook basename offensive_flags)
224
225     SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/fortune")
226     SET (_dest_basename "${basename}.template")
227     SET (_my_man_page "${_my_man_page_dir}/${_dest_basename}.man")
228     SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml")
229     SET (_my_man_prog "${_my_man_page_dir}/gen-fortune-docbook-page.pl")
230     SET (_my_args "${_my_man_prog}" "--output" "${_my_man_docbook}" --cookiedir "[[cookiedir_placeholder]]" --ocookiedir "[[ocookiedir_placeholder]]" ${offensive_flags})
231     ADD_CUSTOM_COMMAND(
232         OUTPUT "${_my_man_docbook}"
233         COMMAND "${PERL_EXECUTABLE}"
234         ARGS ${_my_args}
235         DEPENDS "${_my_man_prog}"
236     )
237
238     LIST(APPEND _my_man_pages_list "${_my_man_docbook}")
239     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")
240     ADD_CUSTOM_COMMAND(
241         OUTPUT "${_my_man_page}"
242         COMMAND "${PERL_EXECUTABLE}"
243         ARGS ${_my_args}
244         DEPENDS "${_my_man_docbook}"
245     )
246
247     LIST(APPEND _my_man_pages_list "${_my_man_page}")
248 ENDMACRO()
249
250 _fortune__generate_docbook("fortune_with_offensive" "")
251 _fortune__generate_docbook("fortune_without_offensive" "--without-offensive")
252
253 MACRO(_fortune__generate_manpage basename)
254
255     SET (_my_man_page_dir "${CMAKE_CURRENT_SOURCE_DIR}/util")
256     SET (_my_man_page "${_my_man_page_dir}/${basename}.man")
257     SET (_my_man_docbook "${_my_man_page_dir}/${basename}.docbook5.xml")
258     SET (_my_args "-I${_util_dir}" "${_util_dir}/fortmod_gen_manpage.pl" "--src-dir" "${CMAKE_CURRENT_SOURCE_DIR}" "--basename=${basename}")
259     ADD_CUSTOM_COMMAND(
260         OUTPUT "${_my_man_page}"
261         COMMAND "${PERL_EXECUTABLE}"
262         ARGS ${_my_args}
263         DEPENDS "${_my_man_docbook}"
264     )
265
266     LIST(APPEND _my_man_pages_list "${_my_man_page}")
267 ENDMACRO()
268
269 _fortune__generate_manpage("strfile")
270 INSTALL_RENAME_MAN("strfile.man" "1" "strfile" "${_my_man_page_dir}")
271 _fortune__generate_manpage("randstr")
272
273 ADD_CUSTOM_TARGET(
274     generate_man_page
275     ALL DEPENDS ${_my_man_pages_list}
276 )
277
278 INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/util")
279
280 IF(WIN32 AND NOT UNIX)
281     FOREACH (var "LOCALODIR" "LOCALDIR" "OCOOKIEDIR" "COOKIEDIR")
282         string(REPLACE "\\" "/" "${var}" "${${var}}")
283     ENDFOREACH()
284 ENDIF()
285
286 IF (NO_OFFENSIVE)
287     ADD_DEFINITIONS("-DNO_OFFENSIVE=1")
288 ENDIF()
289
290 CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
291
292 IF (HAVE_REGEX_H)
293     ADD_DEFINITIONS("-DHAVE_REGEX_H")
294     ADD_DEFINITIONS("-DPOSIX_REGEX")
295 ENDIF()
296
297 ADD_DEFINITIONS("-DHAVE_STDBOOL")
298 SET (COOKIES
299     art
300     ascii-art
301     computers
302     cookie
303     definitions
304     disclaimer
305     drugs
306     education
307     ethnic
308     food
309     fortunes
310     goedel
311     humorists
312     kids
313     law
314     literature
315     love
316     magic
317     medicine
318     men-women
319     miscellaneous
320     news
321     people
322     pets
323     platitudes
324     politics
325     pratchett
326     riddles
327     rules-of-acquisition
328     science
329     songs-poems
330     sports
331     startrek
332     tao
333     translate-me
334     wisdom
335     work
336     linux
337     perl
338     knghtbrd
339     paradoxum
340     zippy
341     debian
342 )
343
344 SET (OFFENSIVE_COOKIES
345     art
346     astrology
347     atheism
348     black-humor
349     cookie
350     debian
351     definitions
352     drugs
353     ethnic
354     fortunes
355     hphobia
356     knghtbrd
357     limerick
358     linux
359     misandry
360     miscellaneous
361     misogyny
362     politics
363     privates
364     racism
365     religion
366     riddles
367     sex
368     songs-poems
369     vulgarity
370     zippy
371 )
372
373 ADD_SUBDIRECTORY("datfiles")
374
375 string (REPLACE ";" " " COOKIES_STR "${COOKIES}")
376 ADD_CUSTOM_TARGET(
377     "check"
378     "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}" "--cookies" "${COOKIES_STR}"
379 )
380
381 # Rebuild config.h if ver.txt has changed.
382 ADD_CUSTOM_COMMAND(
383     OUTPUT "config.h.in"
384     DEPENDS "ver.txt"
385     COMMAND "touch"
386     ARGS "config.h.in"
387 )
388
389 SET(AUTOGENERATED_CONFIG_H "config.h was auto-generated from config.h.in . Do not modify directly")
390
391 CONFIGURE_FILE(
392     ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
393     ${CMAKE_CURRENT_BINARY_DIR}/config.h
394 )
395
396 INCLUDE(CPack)