996
|
1 # cfunge - A standard-conforming Befunge93/98/109 interpreter in C.
|
|
2 # Copyright (C) 2008 Arvid Norlander <anmaster AT tele2 DOT se>
|
|
3 #
|
|
4 # This program is free software: you can redistribute it and/or modify
|
|
5 # it under the terms of the GNU General Public License as published by
|
|
6 # the Free Software Foundation, either version 3 of the License, or
|
|
7 # (at the proxy's option) any later version. Arvid Norlander is a
|
|
8 # proxy who can decide which future versions of the GNU General Public
|
|
9 # License can be used.
|
|
10 #
|
|
11 # This program is distributed in the hope that it will be useful,
|
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 # GNU General Public License for more details.
|
|
15 #
|
|
16 # You should have received a copy of the GNU General Public License
|
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
|
19 project(CFUNGE C)
|
|
20
|
|
21 cmake_minimum_required(VERSION 2.6)
|
|
22
|
|
23 mark_as_advanced(
|
|
24 CMAKE_BACKWARDS_COMPATIBILITY
|
|
25 EXECUTABLE_OUTPUT_PATH
|
|
26 LIBRARY_OUTPUT_PATH
|
|
27 LIBRT_LOCATION
|
|
28 BOEHM_INCLUDE_DIR
|
|
29 BOEHM_LIBRARY_GC
|
|
30 CURSES_CURSES_H_PATH
|
|
31 CURSES_FORM_LIBRARY
|
|
32 CURSES_HAVE_CURSES_H
|
|
33 USE_CLOCK_GETTIME
|
|
34 ENABLE_FLOATS
|
|
35 ENABLE_TURT
|
|
36 USE_MUDFLAP
|
|
37 USE_WERROR
|
|
38 USE_VALGRIND
|
|
39 )
|
|
40
|
|
41 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
|
|
42 set(CMAKE_MODULE_PATH
|
|
43 ${CMAKE_SOURCE_DIR}/cmake/modules
|
|
44 ${CMAKE_MODULE_PATH}
|
|
45 )
|
|
46
|
|
47 # Set default build type.
|
|
48 if (NOT CMAKE_BUILD_TYPE)
|
|
49 set(CMAKE_BUILD_TYPE Release CACHE STRING
|
|
50 "Choose the type of build, options are: None(CMAKE_C_FLAGS only used) Debug Release RelWithDebInfo MinSizeRel."
|
|
51 FORCE)
|
|
52 endif (NOT CMAKE_BUILD_TYPE)
|
|
53
|
|
54 # http://www.cmake.org/pipermail/cmake/2007-October/016786.html
|
|
55 set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
|
56
|
|
57 # Common cmake macros
|
|
58 include(FindPkgConfig)
|
|
59 include(CheckCCompilerFlag)
|
|
60 include(CheckFunctionExists)
|
|
61 include(CheckLibraryExists)
|
|
62 include(CheckIncludeFile)
|
|
63
|
|
64 # Cfunge specific macros.
|
|
65 include(CfungeCheckCflag)
|
|
66 include(CfungeCheckFunction)
|
|
67 include(CfungeRequireFunction)
|
|
68 include(CfungeRequireInclude)
|
|
69 include(CfungeRequireMultipleIncludes)
|
|
70 include(CfungeCheckLibraryFunction)
|
|
71 include(CfungeCheckLinkerFlag)
|
|
72 include(CfungeCheckWarningFlags)
|
|
73 include(CfungeSetBuildInfoFlags)
|
|
74 include(MacroAddLinkFlags)
|
|
75
|
|
76 set(MAN_INSTALL_PREFIX
|
|
77 "${CMAKE_INSTALL_PREFIX}/share/man"
|
|
78 CACHE PATH "Where to install man page."
|
|
79 )
|
|
80
|
|
81
|
|
82
|
|
83 ################################################################################
|
|
84 # Options to enable optional dependencies.
|
|
85 option(USE_GC "If this is enabled, use Boehm-GC." OFF)
|
|
86 if(USE_GC)
|
|
87 pkg_check_modules(BOEHMGC REQUIRED bdw-gc>=7.0)
|
|
88
|
|
89 find_path(BOEHM_INCLUDE_DIR gc/gc.h
|
|
90 ${BOEHMGC_INCLUDE_DIRS}
|
|
91 )
|
|
92
|
|
93 find_library(BOEHM_LIBRARY_GC NAMES gc
|
|
94 PATHS
|
|
95 ${BOEHMGC_LIBRARY_DIRS}
|
|
96 )
|
|
97 include_directories(${BOEHM_INCLUDE_DIR})
|
|
98 link_directories(${BOEHMGC_LIBRARY_DIRS})
|
|
99 add_definitions(-DCFUN_USE_GC)
|
|
100 endif(USE_GC)
|
|
101
|
|
102 option(USE_NCURSES "Should we (try to) enable fingerprints needing ncurses?" ON)
|
|
103
|
|
104 option(USE_CLOCK_GETTIME "Try to use clock_gettime() instead of gettimeofday(). (Recommended.)" ON)
|
|
105
|
|
106 option(ENABLE_FLOATS "Enable all fingerprints using floating point. (Recommended.)" ON)
|
|
107 if (NOT ENABLE_FLOATS)
|
|
108 add_definitions(-DCFUN_NO_FLOATS)
|
|
109 endif (NOT ENABLE_FLOATS)
|
|
110
|
|
111 option(ENABLE_TURT "Enable TURT. (Recommended.)" ON)
|
|
112 if (NOT ENABLE_TURT)
|
|
113 add_definitions(-DCFUN_NO_TURT)
|
|
114 endif (NOT ENABLE_TURT)
|
|
115
|
|
116
|
|
117
|
|
118 ################################################################################
|
|
119 # Other options
|
|
120
|
|
121 option(EXACT_BOUNDS "Handle shrinking bounds (slower and most programs don't need it, but follows the standard more closely)." ON)
|
|
122 if(EXACT_BOUNDS)
|
|
123 add_definitions(-DCFUN_EXACT_BOUNDS)
|
|
124 endif(EXACT_BOUNDS)
|
|
125
|
|
126 option(USE_64BIT "Use 64-bit funge space cells (if off: use 32-bit)." ON)
|
|
127 if(USE_64BIT)
|
|
128 add_definitions(-DUSE64)
|
|
129 else(USE_64BIT)
|
|
130 add_definitions(-DUSE32)
|
|
131 endif(USE_64BIT)
|
|
132
|
|
133 option(CONCURRENT_FUNGE "Enable support for concurrent funge." ON)
|
|
134 if(CONCURRENT_FUNGE)
|
|
135 add_definitions(-DCONCURRENT_FUNGE)
|
|
136 endif(CONCURRENT_FUNGE)
|
|
137
|
|
138 option(ENABLE_TRACE "Enable support for tracing the execution (recommended)." ON)
|
|
139 if(NOT ENABLE_TRACE)
|
|
140 add_definitions(-DDISABLE_TRACE)
|
|
141 endif(NOT ENABLE_TRACE)
|
|
142
|
|
143 option(HARDENED "If this is enabled, and GCC is used, enable stack smash protection (slows down though) and some other features." OFF)
|
|
144 if (HARDENED)
|
|
145 add_definitions(-D_FORTIFY_SOURCE=2)
|
|
146 # Slows down though.
|
|
147 CFUNGE_CHECK_CFLAG(fstack-protector -fstack-protector)
|
|
148 endif (HARDENED)
|
|
149
|
|
150
|
|
151
|
|
152 ################################################################################
|
|
153 # Options for cfunge developers debugging cfunge.
|
|
154
|
|
155 option(USE_MUDFLAP "Enable mudflap pointer debugging library (does not work with Boehm-GC), needs GCC." OFF)
|
|
156 if(USE_MUDFLAP)
|
|
157 if (USE_GC)
|
|
158 message(FATAL_ERROR "You can't use mudflap and Boehm GC at the same time")
|
|
159 endif (USE_GC)
|
|
160 add_definitions(-fmudflap)
|
|
161 endif(USE_MUDFLAP)
|
|
162
|
|
163 option(USE_VALGRIND "Add special source annotations for the memory debugger valgrind (does not work with Boehm-GC)." OFF)
|
|
164 if(USE_VALGRIND)
|
|
165 if (USE_GC)
|
|
166 message(FATAL_ERROR "You can't use valgrind and Boehm GC at the same time")
|
|
167 endif (USE_GC)
|
|
168 add_definitions(-DENABLE_VALGRIND)
|
|
169 endif(USE_VALGRIND)
|
|
170
|
|
171 option(USE_WERROR "Should we build with -Werror" OFF)
|
|
172 if(USE_WERROR)
|
|
173 if (CMAKE_COMPILER_IS_GNUCC)
|
|
174 CFUNGE_CHECK_CFLAG(Werror -Werror)
|
|
175 endif (CMAKE_COMPILER_IS_GNUCC)
|
|
176 endif(USE_WERROR)
|
|
177
|
|
178
|
|
179
|
|
180 ################################################################################
|
|
181 # Compiler defines.
|
|
182 CFUNGE_CHECK_CFLAG(std_c99 -std=c99)
|
|
183 # Feature test macros for exposing relevant definitions in headers.
|
|
184 add_definitions(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600)
|
|
185
|
|
186
|
|
187
|
|
188 ################################################################################
|
|
189 # Check that certain system headers exist.
|
|
190
|
|
191 # These are C99 required ones
|
|
192 CFUNGE_REQUIRE_INCLUDE(stddef.h)
|
|
193 CFUNGE_REQUIRE_INCLUDE(stdbool.h)
|
|
194 CFUNGE_REQUIRE_INCLUDE(stdint.h)
|
|
195 CFUNGE_REQUIRE_INCLUDE(limits.h)
|
|
196 CFUNGE_REQUIRE_INCLUDE(inttypes.h)
|
|
197
|
|
198 # POSIX.1-2001 requires these:
|
|
199 CFUNGE_REQUIRE_INCLUDE(arpa/inet.h)
|
|
200 CFUNGE_REQUIRE_INCLUDE(unistd.h)
|
|
201 CFUNGE_REQUIRE_INCLUDE(fcntl.h)
|
|
202 CFUNGE_REQUIRE_INCLUDE(sys/types.h)
|
|
203 CFUNGE_REQUIRE_INCLUDE(sys/socket.h)
|
|
204 CFUNGE_REQUIRE_INCLUDE(netinet/in.h)
|
|
205 # Some includes must be checked together.
|
|
206 CFUNGE_REQUIRE_MULTIPLE_INCLUDES("sys/types.h;netinet/tcp.h" "netinet/tcp.h")
|
|
207 CFUNGE_REQUIRE_INCLUDE(netdb.h)
|
|
208 CFUNGE_REQUIRE_INCLUDE(regex.h)
|
|
209
|
|
210 # Optional in POSIX, we need it
|
|
211 CFUNGE_REQUIRE_INCLUDE(sys/mman.h)
|
|
212
|
|
213
|
|
214
|
|
215 ################################################################################
|
|
216 # Existance of various functions
|
|
217 # Some are sanity checks (required in standards), some are required by cfunge
|
|
218 # but optional in standards, some are optionally used by cfunge.
|
|
219 #
|
|
220 # All those in the second category are optional in POSIX.1-2001 but required in
|
|
221 # POSIX.1-2008
|
|
222 #
|
|
223 # We don't check functions that exist in C89.
|
|
224
|
|
225 # Sanity checks: Required by POSIX.1-2001.
|
|
226 CFUNGE_REQUIRE_FUNCTION(dup2)
|
|
227 CFUNGE_REQUIRE_FUNCTION(fcntl)
|
|
228 CFUNGE_REQUIRE_FUNCTION(fork)
|
|
229 CFUNGE_REQUIRE_FUNCTION(gettimeofday)
|
|
230 CFUNGE_REQUIRE_FUNCTION(mkdir)
|
|
231 CFUNGE_REQUIRE_FUNCTION(regcomp)
|
|
232 CFUNGE_REQUIRE_FUNCTION(rmdir)
|
|
233 # Sanity checks: Some networking functions (required by POSIX.1-2001)
|
|
234 CFUNGE_REQUIRE_FUNCTION(getaddrinfo)
|
|
235 CFUNGE_REQUIRE_FUNCTION(freeaddrinfo)
|
|
236 CFUNGE_REQUIRE_FUNCTION(poll)
|
|
237 CFUNGE_REQUIRE_FUNCTION(socket)
|
|
238
|
|
239 # Required: These are optional in POSIX.1-2001 but we need them.
|
|
240 CFUNGE_REQUIRE_FUNCTION(mmap)
|
|
241 CFUNGE_REQUIRE_FUNCTION(munmap)
|
|
242 # Required: We require the XSI extension strdup():
|
|
243 CFUNGE_REQUIRE_FUNCTION(strdup)
|
|
244
|
|
245 # Optional: Some optional ones (in POSIX.1-2001) that we use if found.
|
|
246 # random() and srandom() are XSI extensions, we fall back on rand/srand if they
|
|
247 # aren't available.
|
|
248 CFUNGE_CHECK_FUNCTION(random)
|
|
249 CFUNGE_CHECK_FUNCTION(srandom)
|
|
250
|
|
251 if (ENABLE_FLOATS)
|
|
252 # Optional: C99 requires these but we fall back on double versions since many
|
|
253 # systems still lack the long double versions.
|
|
254 set(CMAKE_REQUIRED_LIBRARIES "-lm")
|
|
255 CFUNGE_CHECK_FUNCTION(acosl)
|
|
256 CFUNGE_CHECK_FUNCTION(asinl)
|
|
257 CFUNGE_CHECK_FUNCTION(atanl)
|
|
258 CFUNGE_CHECK_FUNCTION(cosl)
|
|
259 CFUNGE_CHECK_FUNCTION(floorl)
|
|
260 CFUNGE_CHECK_FUNCTION(powl)
|
|
261 CFUNGE_CHECK_FUNCTION(roundl)
|
|
262 CFUNGE_CHECK_FUNCTION(sinl)
|
|
263 CFUNGE_CHECK_FUNCTION(sqrtl)
|
|
264 CFUNGE_CHECK_FUNCTION(tanl)
|
|
265 endif (ENABLE_FLOATS)
|
|
266
|
|
267
|
|
268
|
|
269 ################################################################################
|
|
270 # Warnings
|
|
271 CFUNGE_CHECK_WARNING_FLAGS()
|
|
272
|
|
273
|
|
274
|
|
275 ################################################################################
|
|
276 # Stuff for debug/non-debug builds
|
|
277 # No case insensitive string copmpare, lets convert to upper-case.
|
|
278 # NOTE: CMAKE_BUILD_TYPE_UPPERCASE is used in CFUNGE_SET_BUILD_INFO_FLAGS() too.
|
|
279 string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPERCASE)
|
|
280 if (CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
|
|
281 add_definitions(-DGC_DEBUG)
|
|
282 add_definitions(-DDEBUG)
|
|
283 else (CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
|
|
284 add_definitions(-DNDEBUG)
|
|
285 remove_definitions(-DGC_DEBUG)
|
|
286 remove_definitions(-DDEBUG)
|
|
287 CFUNGE_CHECK_CFLAG(fvisibility_hidden -fvisibility=hidden)
|
|
288 CFUNGE_CHECK_CFLAG(fno-ident -fno-ident)
|
|
289 endif (CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")
|
|
290
|
|
291
|
|
292
|
|
293 ################################################################################
|
|
294 # Includes
|
|
295 include_directories(${CFUNGE_SOURCE_DIR}/src/)
|
|
296
|
|
297
|
|
298
|
|
299 ################################################################################
|
|
300 # Targets
|
|
301 FILE(GLOB CFUNGE_SOURCES RELATIVE ${CFUNGE_SOURCE_DIR}
|
|
302 lib/libghthash/*.c
|
|
303 lib/genx/*.c
|
|
304 lib/stringbuffer/*.c
|
|
305 src/*.c
|
|
306 src/funge-space/*.c
|
|
307 src/instructions/*.c
|
|
308 src/fingerprints/*.c
|
|
309 src/fingerprints/*/*.c
|
|
310 )
|
|
311
|
|
312 add_executable(cfunge ${CFUNGE_SOURCES})
|
|
313
|
|
314 # Try various nice linker flags.
|
|
315 CFUNGE_CHECK_LINKER_FLAG(cfunge Wl_O1 -Wl,-O1)
|
|
316 CFUNGE_CHECK_LINKER_FLAG(cfunge Wl_as-needed -Wl,--as-needed)
|
|
317 CFUNGE_CHECK_LINKER_FLAG(cfunge Wl_warn-common -Wl,--warn-common)
|
|
318 if (HARDENED)
|
|
319 CFUNGE_CHECK_LINKER_FLAG(cfunge Wl_z_relro -Wl,-z,relro)
|
|
320 CFUNGE_CHECK_LINKER_FLAG(cfunge Wl_z_now -Wl,-z,now)
|
|
321 endif (HARDENED)
|
|
322
|
|
323
|
|
324
|
|
325 ################################################################################
|
|
326 # Check for ncurses - needs to be done late due to libraries.
|
|
327 # Quite a mess yes.
|
|
328 if (USE_NCURSES)
|
|
329 set(CURSES_NEED_NCURSES TRUE)
|
|
330 find_package(Curses)
|
|
331 CHECK_INCLUDE_FILE(term.h HAVE_TERM_H)
|
|
332 if (CURSES_FOUND AND HAVE_TERM_H AND CURSES_HAVE_CURSES_H)
|
|
333 # HACK: We should use ${CURSES_LIBRARIES} here, but that breaks static
|
|
334 # builds as it contains the full path to ncurses.so
|
|
335 target_link_libraries(cfunge ncurses)
|
|
336 add_definitions(-DHAVE_NCURSES)
|
|
337 else (CURSES_FOUND AND HAVE_TERM_H AND CURSES_HAVE_CURSES_H)
|
|
338 message(STATUS "ncurses and/or term.h not found: disabling the TERM fingrprint.")
|
|
339 endif (CURSES_FOUND AND HAVE_TERM_H AND CURSES_HAVE_CURSES_H)
|
|
340 endif (USE_NCURSES)
|
|
341
|
|
342
|
|
343
|
|
344 ################################################################################
|
|
345 # Check for clock_gettime() - needs to be done late due to possible libraries.
|
|
346 #
|
|
347 # clock_gettime is complex to check for since it can be in libc (FreeBSD) or in
|
|
348 # librt (Linux).
|
|
349 if (USE_CLOCK_GETTIME)
|
|
350 CFUNGE_CHECK_FUNCTION(clock_gettime)
|
|
351 if (NOT CFUNGE_HAVE_clock_gettime)
|
|
352 find_library(LIBRT_LOCATION
|
|
353 NAMES rt)
|
|
354 if (NOT ${LIBRT_LOCATION} STREQUAL "LIBRT_LOCATION-NOTFOUND")
|
|
355 get_filename_component(LIBRT_PATH ${LIBRT_LOCATION} PATH)
|
|
356 CFUNGE_CHECK_LIBRARY_FUNCTION(cfunge rt clock_gettime ${LIBRT_PATH})
|
|
357 endif (NOT ${LIBRT_LOCATION} STREQUAL "LIBRT_LOCATION-NOTFOUND")
|
|
358 endif (NOT CFUNGE_HAVE_clock_gettime)
|
|
359 endif (USE_CLOCK_GETTIME)
|
|
360
|
|
361
|
|
362
|
|
363 ################################################################################
|
|
364 # Linking libraries
|
|
365
|
|
366 # Need -lm for some fingerprints.
|
|
367 if (ENABLE_FLOATS)
|
|
368 target_link_libraries(cfunge m)
|
|
369 endif (ENABLE_FLOATS)
|
|
370
|
|
371 if(USE_GC)
|
|
372 target_link_libraries(cfunge ${BOEHM_LIBRARY_GC})
|
|
373 endif(USE_GC)
|
|
374
|
|
375 if(USE_MUDFLAP)
|
|
376 MACRO_ADD_LINK_FLAGS(cfunge "-fmudflap")
|
|
377 target_link_libraries(cfunge mudflap)
|
|
378 endif(USE_MUDFLAP)
|
|
379
|
|
380
|
|
381
|
|
382 ################################################################################
|
|
383 # Build info
|
|
384 CFUNGE_SET_BUILD_INFO_FLAGS()
|
|
385
|
|
386
|
|
387
|
|
388 ################################################################################
|
|
389 # Generate man page
|
|
390 add_custom_target(build-man
|
|
391 help2man -N "--name=A fast Befunge93/98/109 interpreter in C" --help-option=-h --version-option=-V --include doc/cfunge-man.in --include doc/cfunge-man-fingerprints.in ${CFUNGE_BINARY_DIR}/cfunge > doc/cfunge.1
|
|
392 DEPENDS cfunge
|
|
393 WORKING_DIRECTORY ${CFUNGE_SOURCE_DIR}
|
|
394 COMMENT "Generating man page..."
|
|
395 VERBATIM
|
|
396 )
|
|
397
|
|
398
|
|
399
|
|
400 ################################################################################
|
|
401 # Installation
|
|
402 install(TARGETS cfunge
|
|
403 RUNTIME DESTINATION bin
|
|
404 )
|
|
405 install(FILES doc/cfunge.1
|
|
406 DESTINATION ${MAN_INSTALL_PREFIX}/man1
|
|
407 )
|