1 cmake_minimum_required(VERSION 3.2)
3 INCLUDE ("${CMAKE_SOURCE_DIR}/cmake/shlomif_common_bootstrap.cmake")
4 SHLOMIF_COMMON_SETUP("${private_mod_path}")
6 CMAKE_POLICY(SET CMP0054 NEW)
8 SET (PKGDATADIR_SUBDIR "fortune-mod")
9 SET (RELATIVE_PKGDATADIR "${RELATIVE_DATADIR}/${PKGDATADIR_SUBDIR}")
10 SET (PKGDATADIR "${DATADIR}/${PKGDATADIR_SUBDIR}")
12 # Introduces VERSION , CPACK_PACKAGE_VERSION_MAJOR,
13 # CPACK_PACKAGE_VERSION_MAJOR, and CPACK_PACKAGE_VERSION_PATCH
14 READ_VERSION_FROM_VER_TXT()
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")
24 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY} ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
26 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
28 SET (base_with_ver "fortune-mod-[0-9]+\\\\.[0-9]+\\\\.[0-9]+")
30 SET(CPACK_SOURCE_IGNORE_FILES
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)
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")
55 SET(CPACK_STRIP_FILES "fortune")
56 SET(CPACK_SOURCE_STRIP_FILES "")
59 SET(CPACK_PACKAGE_EXECUTABLES
60 "fortune" "The fortune-mod program"
63 ### This is to set the RPATH correctly, so when installed under a prefix
64 ### the executables will find the libraries.
68 ### http://www.cmake.org/Wiki/CMake_RPATH_handling
70 ### (Taken from that wiki page)
72 # use, i.e. don't skip the full RPATH for the build tree
73 SET(CMAKE_SKIP_BUILD_RPATH FALSE)
75 # when building, don't use the install RPATH already
76 # (but later on when installing)
77 SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
79 # the RPATH to be used when installing
80 SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
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)
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")
93 SHLOMIF_ADD_COMMON_C_FLAGS()
95 # add_flags("-Weverything" "-Wno-language-extension-token" "-Wno-padded")
97 SHLOMIF_FINALIZE_FLAGS()
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}"
105 INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/${rinutils}/rinutils/include")
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
115 ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
117 ADD_DEFINITIONS("-D_FORTIFY_SOURCE=2")
119 ADD_DEFINITIONS("-O1")
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")
129 # So it can find config.h
130 INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
132 MACRO(my_exe exe c_file dir)
133 SET(_files "${c_file}")
135 list(APPEND _files "util/getopt.c")
137 ADD_EXECUTABLE("${exe}" "${c_file}")
139 if ("${exe}" STREQUAL "fortune")
140 list(APPEND _libs "recode")
143 # See https://stackoverflow.com/questions/15119639/how-to-link-winsock-in-cmake
144 list(APPEND _libs intl regex wsock32 ws2_32)
146 TARGET_LINK_LIBRARIES("${exe}" ${_libs})
147 if (NOT ("${dir}" STREQUAL "null"))
148 INSTALL(TARGETS "${exe}" RUNTIME DESTINATION "${dir}")
164 # Build but not install.
165 my_exe("randstr" "util/randstr.c" "null")
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")
181 LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" "--ocookiedir" "${OCOOKIEDIR}" "--output" "${_my_man_page}")
182 IF ("${NO_OFFENSIVE}")
183 LIST(APPEND _my_args "--without-offensive")
187 OUTPUT "${_my_man_page}"
188 COMMAND "${PERL_EXECUTABLE}"
189 ARGS "${_my_man_gen}" ${_my_args}
190 DEPENDS "${_my_man_gen}"
195 ALL DEPENDS "${_my_man_page}"
197 INSTALL_RENAME_MAN("strfile.man" "1" "strfile" "util")
198 INSTALL_RENAME_MAN("fortune.6" "6" "fortune" "fortune")
200 INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/util")
202 IF(WIN32 AND NOT UNIX)
203 FOREACH (var "LOCALODIR" "LOCALDIR" "OCOOKIEDIR" "COOKIEDIR")
204 string(REPLACE "\\" "/" "${var}" "${var}")
208 IF ("${NO_OFFENSIVE}")
209 ADD_DEFINITIONS("-DNO_OFFENSIVE=1")
212 CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
214 IF ("${HAVE_REGEX_H}")
215 ADD_DEFINITIONS("-DHAVE_REGEX_H")
216 ADD_DEFINITIONS("-DPOSIX_REGEX")
219 ADD_DEFINITIONS("-DHAVE_STDBOOL")
266 SET (OFFENSIVE_COOKIES
295 ADD_SUBDIRECTORY("datfiles")
297 string (REPLACE ";" " " COOKIES_STR "${COOKIES}")
300 "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}" "--cookies" "${COOKIES_STR}"
303 # Rebuild config.h if ver.txt has changed.
311 SET(AUTOGENERATED_CONFIG_H "config.h was auto-generated from config.h.in . Do not modify directly")
314 ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
315 ${CMAKE_CURRENT_BINARY_DIR}/config.h