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