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