1
# cmake/modules/plplot.cmake
3
# Copyright (C) 2006 Alan W. Irwin
5
# This file is part of PLplot.
7
# PLplot is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU Library General Public License as published
9
# by the Free Software Foundation; version 2 of the License.
11
# PLplot 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 Library General Public License for more details.
16
# You should have received a copy of the GNU Library General Public License
17
# along with the file PLplot; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
# Module for determining all configuration variables for PLplot.
22
# libraries are all shared by default
23
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
25
# Color maps (discrete and continuous) to use by default
26
if(NOT DEFAULT_CMAP0_FILE)
27
set(DEFAULT_CMAP0_FILE "cmap0_default.pal")
28
endif(NOT DEFAULT_CMAP0_FILE)
30
if(NOT DEFAULT_CMAP1_FILE)
31
set(DEFAULT_CMAP1_FILE "cmap1_default.pal")
32
endif(NOT DEFAULT_CMAP1_FILE)
34
# Set to ON if want to use general fill_intersection_polygon approach
35
# rather than the traditional code to fill the intersection of a
36
# polygon with the clipping limits. */
38
option(USE_FILL_INTERSECTION_POLYGON "use fill_intersection_polygon" OFF)
40
# Need these modules to do subsequent checks.
41
include(CheckIncludeFile)
42
include(CheckIncludeFiles)
43
include(CheckFunctionExists)
44
include(CheckSymbolExists)
45
include(CheckPrototypeExists)
47
# Useful functions go here.
49
function(TRANSFORM_VERSION numerical_result version)
50
# internal_version ignores everything in version after any character that
51
# is not 0-9 or ".". This should take care of the case when there is
52
# some non-numerical data in the patch version.
53
#message(STATUS "DEBUG: version = ${version}")
54
string(REGEX REPLACE "^([0-9.]+).*$" "\\1" internal_version ${version})
56
# internal_version is normally a period-delimited triplet string of the form
57
# "major.minor.patch", but patch and/or minor could be missing.
58
# Transform internal_version into a numerical result that can be compared.
59
string(REGEX REPLACE "^([0-9]*).+$" "\\1" major ${internal_version})
60
string(REGEX REPLACE "^[0-9]*\\.([0-9]*).*$" "\\1" minor ${internal_version})
61
string(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.([0-9]*)$" "\\1" patch ${internal_version})
63
if(NOT patch MATCHES "[0-9]+")
65
endif(NOT patch MATCHES "[0-9]+")
67
if(NOT minor MATCHES "[0-9]+")
69
endif(NOT minor MATCHES "[0-9]+")
71
if(NOT major MATCHES "[0-9]+")
73
endif(NOT major MATCHES "[0-9]+")
74
#message(STATUS "DEBUG: internal_version = ${internal_version}")
75
#message(STATUS "DEBUG: major = ${major}")
76
#message(STATUS "DEBUG: minor= ${minor}")
77
#message(STATUS "DEBUG: patch = ${patch}")
78
math(EXPR internal_numerical_result
79
"${major}*1000000 + ${minor}*1000 + ${patch}"
81
#message(STATUS "DEBUG: ${numerical_result} = ${internal_numerical_result}")
82
set(${numerical_result} ${internal_numerical_result} PARENT_SCOPE)
83
endfunction(TRANSFORM_VERSION)
85
# CMake-2.6.x duplicates this list so work around that bug by removing
87
if(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
88
list(REMOVE_DUPLICATES CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
89
endif(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
91
# Filter all CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES list elements from
93
function(filter_rpath rpath)
94
#message("DEBUG: ${rpath} = ${${rpath}}")
95
set(internal_rpath ${${rpath}})
97
list(REMOVE_DUPLICATES internal_rpath)
98
if(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
99
list(REMOVE_ITEM internal_rpath ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES})
100
endif(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
101
endif(internal_rpath)
102
#message("DEBUG: (filtered) ${rpath} = ${internal_rpath}")
103
set(${rpath} ${internal_rpath} PARENT_SCOPE)
104
endfunction(filter_rpath)
106
# =======================================================================
107
# Compilation and build options (PLFLT, install locations, and rpath)
108
# Note, must come before java since that depends on, e.g., LIB_DIR.
109
# =======================================================================
111
# WIN32 covers CYGWIN as well (and possibly MINGW, but we will make sure).
114
endif(WIN32 OR MINGW)
120
# Common CMakeLists.txt files are used to build the examples in the build
121
# tree and also to build the installed examples by the new CMake-based build
122
# system devoted to that purpose. Set this fundamental identification to
123
# distinguish the two cases.
126
option(BUILD_TEST "Compile examples in the build tree and enable ctest" OFF)
128
# Use bash when available for ctest and install tree test support
129
find_program(SH_EXECUTABLE bash)
130
find_program(SH_EXECUTABLE win-bash)
134
find_program(SH_EXECUTABLE sh)
136
message(STATUS "SH_EXECUTABLE = ${SH_EXECUTABLE}")
138
if(NOT SH_EXECUTABLE)
140
"WARNING: bash shell not found, ctest will not work properly"
142
endif(NOT SH_EXECUTABLE)
144
# Find diff and tail which are used to compare results from different
146
find_program(DIFF_EXECUTABLE diff)
147
find_program(TAIL_EXECUTABLE tail)
148
# On Linux find cmp which is faster than diff. N.B. other Unix systems may
149
# have a POSIX-compliant cmp but without the GNU extension available on
150
# Linux of the -i option which we use to skip the datestamp on PostScript
152
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
153
find_program(CMP_EXECUTABLE cmp)
156
endif(CMP_EXECUTABLE)
157
endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
159
option(PREBUILD_DIST "Pre-build all components required for distribution" OFF)
160
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
162
PREBUILD_DIST OFF CACHE INTERNAL
163
"Pre-build all components required for distribution"
165
endif(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
167
# create a devpackage file
168
option(DEVPAK "Create DevPackage" NO)
169
if(DEVPAK AND NOT WIN32)
170
message( STATUS "DevPackage only available for Win32. Set DEVPAK to OFF." )
172
endif(DEVPAK AND NOT WIN32)
173
if(DEVPAK AND BUILD_TEST)
174
message( STATUS "Examples are not build for DevPackage. Set BUILD_TEST to OFF." )
176
endif(DEVPAK AND BUILD_TEST)
179
# =======================================================================
181
# =======================================================================
183
# AC_HEADER_STDC is gross overkill since the current PLplot code only uses
184
# this for whether or not atexit can be used. But implement the full suite
185
# of AC_HEADER_STDC checks to keep the cmake version in synch with autotools
186
# and just in case some PLplot developer assumes the complete check for
187
# standard headers is done for a future programming change.
189
# From info autoconf....
190
# Define STDC_HEADERS if the system has ANSI C header files.
191
# Specifically, this macro checks for stdlib.h', stdarg.h',
192
# string.h', and float.h'; if the system has those, it probably
193
# has the rest of the ANSI C header files. This macro also checks
194
# whether string.h' declares memchr' (and thus presumably the
195
# other mem' functions), whether stdlib.h' declare free' (and
196
# thus presumably malloc' and other related functions), and whether
197
# the ctype.h' macros work on characters with the high bit set, as
200
message(STATUS "Checking whether system has ANSI C header files")
201
check_include_files("stdlib.h;stdarg.h;string.h;float.h" StandardHeadersExist)
202
if(StandardHeadersExist)
203
check_prototype_exists(memchr string.h memchrExists)
205
check_prototype_exists(free stdlib.h freeExists)
207
include(TestForHighBitCharacters)
208
if(CMAKE_HIGH_BIT_CHARACTERS)
209
message(STATUS "ANSI C header files - found")
210
set(STDC_HEADERS 1 CACHE INTERNAL "System has ANSI C header files")
211
endif(CMAKE_HIGH_BIT_CHARACTERS)
214
endif(StandardHeadersExist)
216
message(STATUS "ANSI C header files - not found")
217
set(STDC_HEADERS 0 CACHE INTERNAL "System has ANSI C header files")
218
endif(NOT STDC_HEADERS)
220
# AC_CHECK_HEADERS(unistd.h termios.h stdint.h)
221
check_include_files(unistd.h PL_HAVE_UNISTD_H)
222
check_include_files(termios.h HAVE_TERMIOS_H)
223
check_include_files(stdint.h PL_HAVE_STDINT_H)
224
check_include_file(crt_externs.h HAVE_CRT_EXTERNS_H)
227
include(TestForStandardHeaderwait)
229
# Reasonable approximation to AC_HEADER_DIRENT without the SCO stuff.
230
include(CheckDIRSymbolExists)
231
check_dirsymbol_exists("sys/types.h;dirent.h" HAVE_DIRENT_H)
232
if(NOT HAVE_DIRENT_H)
233
check_dirsymbol_exists("sys/types.h;sys/ndir.h" HAVE_SYS_NDIR_H)
234
if(NOT HAVE_SYS_NDIR_H)
235
check_dirsymbol_exists("sys/types.h;sys/dir.h" HAVE_SYS_DIR_H)
236
if(NOT HAVE_SYS_DIR_H)
237
check_dirsymbol_exists("sys/types.h;ndir.h" HAVE_NDIR_H)
238
if(NOT HAVE_NDIR_H AND UNIX)
240
"FATAL_ERROR for plplot.cmake: "
241
"DIR symbol must be defined by Unix system headers."
243
endif(NOT HAVE_NDIR_H AND UNIX)
244
endif(NOT HAVE_SYS_DIR_H)
245
endif(NOT HAVE_SYS_NDIR_H)
246
endif(NOT HAVE_DIRENT_H)
247
# Note the above tests #include <sys/types.h> to follow how
248
# AC_HEADER_DIRENT does its testing. Therefore, always do our
249
# own #defines that way for the cmake build system. Note, this
250
# sys/types.h requirement occurs for Mac OS X and possibly other systems.
251
# It is possible it will go away in the future, but we will follow whatever
252
# is done by AC_HEADER_DIRENT here until that changes.
253
set(NEED_SYS_TYPE_H ON)
255
#=======================================================================
257
#=======================================================================
259
# In the past, some X11 headers required "caddr_t" even on systems that
260
# claimed POSIX.1 compliance, which was illegal. This made it impossible
261
# to compile programs that included X11 headers if _POSIX_SOURCE was
262
# defined. We used to work around this potential problem by just defining
263
# caddr_t to 'char *' on all systems (unless it is set already), whether
264
# it was needed or not. Now we ignore the issue because we don't expect
265
# such broken X behaviour any more and because this kind of argument list
266
# for AC_CHECK_TYPE is now deprecated in the autoconf documentation.
268
# Do not implement the equivalent of this since commented out in the ABS
270
# AC_CHECK_TYPE(caddr_t, char *)
272
# Test signal handler return type (mimics AC_TYPE_SIGNAL)
273
include(TestSignalType)
275
include(CheckFunctionExists)
276
check_function_exists(popen HAVE_POPEN)
277
check_function_exists(usleep PL_HAVE_USLEEP)
278
check_function_exists(mkstemp PL_HAVE_MKSTEMP)
279
check_function_exists(mkstemp PL_HAVE_UNLINK)
280
check_function_exists(_NSGetArgc HAVE_NSGETARGC)
282
# Check for FP functions, including underscored version which
283
# are sometimes all that is available on windows
285
check_symbol_exists(finite "math.h" HAVE_FINITE_SYMBOL)
286
if(HAVE_FINITE_SYMBOL)
287
set(PL_HAVE_FINITE ON)
288
else(HAVE_FINITE_SYMBOL)
289
check_function_exists(finite HAVE_FINITE_FUNCTION)
290
if(HAVE_FINITE_FUNCTION)
291
set(PL_HAVE_FINITE ON)
292
else(HAVE_FINITE_FUNCTION)
293
check_symbol_exists(_finite "math.h" HAVE__FINITE_SYMBOL)
294
if(HAVE__FINITE_SYMBOL)
295
set(PL__HAVE_FINITE ON)
296
else(HAVE__FINITE_SYMBOL)
297
check_function_exists(_finite HAVE__FINITE_FUNCTION)
298
if(HAVE__FINITE_FUNCTION)
299
set(PL__HAVE_FINITE ON)
300
endif(HAVE__FINITE_FUNCTION)
301
endif(HAVE__FINITE_SYMBOL)
302
endif(HAVE_FINITE_FUNCTION)
303
endif(HAVE_FINITE_SYMBOL)
305
set(PL_HAVE_FINITE ON)
306
endif(PL__HAVE_FINITE)
308
check_symbol_exists(isnan "math.h" HAVE_ISNAN_SYMBOL)
309
if(HAVE_ISNAN_SYMBOL)
310
set(PL_HAVE_ISNAN ON)
311
else(HAVE_ISNAN_SYMBOL)
312
check_function_exists(isnan HAVE_ISNAN_FUNCTION)
313
if(HAVE_ISNAN_FUNCTION)
314
set(PL_HAVE_ISNAN ON)
315
else(HAVE_ISNAN_FUNCTION)
316
check_symbol_exists(_isnan "math.h" HAVE__ISNAN_SYMBOL)
317
if(HAVE__ISNAN_SYMBOL)
318
set(PL__HAVE_ISNAN ON)
319
else(HAVE__ISNAN_SYMBOL)
320
check_function_exists(_isnan HAVE__ISNAN_FUNCTION)
321
if(HAVE__ISNAN_FUNCTION)
322
set(PL__HAVE_ISNAN ON)
323
endif(HAVE__ISNAN_FUNCTION)
324
endif(HAVE__ISNAN_SYMBOL)
325
endif(HAVE_ISNAN_FUNCTION)
326
endif(HAVE_ISNAN_SYMBOL)
328
set(PL_HAVE_ISNAN ON)
329
endif(PL__HAVE_ISNAN)
331
check_symbol_exists(isinf "math.h" HAVE_ISINF_SYMBOL)
332
if(HAVE_ISINF_SYMBOL)
333
set(PL_HAVE_ISINF ON)
334
else(HAVE_ISINF_SYMBOL)
335
check_function_exists(isinf HAVE_ISINF_FUNCTION)
336
if(HAVE_ISINF_FUNCTION)
337
set(PL_HAVE_ISINF ON)
338
else(HAVE_ISINF_FUNCTION)
339
check_symbol_exists(_isinf "math.h" HAVE__ISINF_SYMBOL)
340
if(HAVE__ISINF_SYMBOL)
341
set(PL__HAVE_ISINF ON)
342
else(HAVE__ISINF_SYMBOL)
343
check_function_exists(_isinf HAVE__ISINF_FUNCTION)
344
if(HAVE__ISINF_FUNCTION)
345
set(PL__HAVE_ISINF ON)
346
endif(HAVE__ISINF_FUNCTION)
347
endif(HAVE__ISINF_SYMBOL)
348
endif(HAVE_ISINF_FUNCTION)
349
endif(HAVE_ISINF_SYMBOL)
351
set(PL_HAVE_ISINF ON)
352
endif(PL__HAVE_ISINF)
355
check_function_exists(snprintf PL_HAVE_SNPRINTF)
356
if(NOT PL_HAVE_SNPRINTF)
357
check_function_exists(_snprintf _PL_HAVE_SNPRINTF)
358
set(PL_HAVE_SNPRINTF ${_PL_HAVE_SNPRINTF} CACHE INTERNAL "Have function _sprintf")
359
endif(NOT PL_HAVE_SNPRINTF)
361
# =======================================================================
363
# =======================================================================
365
# Find swig. Required for python, java and Lua bindings.
366
# N.B. all version tests done below need experimental FindSWIG.cmake which
367
# is currently carried in this directory by PLplot, but which eventually
368
# should get into CMake.
371
message(STATUS "SWIG_VERSION = ${SWIG_VERSION}")
372
# Logic that depends on swig version
373
transform_version(NUMERICAL_SWIG_MINIMUM_VERSION "1.3.22")
374
transform_version(NUMERICAL_SWIG_VERSION "${SWIG_VERSION}")
375
if(NUMERICAL_SWIG_VERSION LESS "${NUMERICAL_SWIG_MINIMUM_VERSION}")
376
message(STATUS "WARNING: swig version too old. SWIG_FOUND set to OFF")
378
endif(NUMERICAL_SWIG_VERSION LESS "${NUMERICAL_SWIG_MINIMUM_VERSION}")
382
transform_version(NUMERICAL_NOPGCPP_MINIMUM_VERSION "1.3.30")
383
if(NUMERICAL_SWIG_VERSION LESS "${NUMERICAL_NOPGCPP_MINIMUM_VERSION}")
384
set(SWIG_JAVA_NOPGCPP OFF)
385
else(NUMERICAL_SWIG_VERSION LESS "${NUMERICAL_NOPGCPP_MINIMUM_VERSION}")
386
set(SWIG_JAVA_NOPGCPP ON)
387
endif(NUMERICAL_SWIG_VERSION LESS "${NUMERICAL_NOPGCPP_MINIMUM_VERSION}")
391
# Do not use "include(${SWIG_USE_FILE})" here since we want the option of
392
# using a locally modified version of UseSWIG.cmake if that exists rather
393
# than the official system version of that file.
397
# Find Perl. Required in several places in the build system (e.g.,
401
include(CheckPerlModules)
404
# =======================================================================
405
# pkg-config support as well as macros to put link flags in standard
406
# *.pc (pkg-config) form as well as standard fullpath form used by cmake.
407
# =======================================================================
410
# Find X headers, libraries, and library directory (required by xwin and
411
# cairo device drivers and also everything that is Tk related).
414
# Convert X11_LIBRARIES to full pathname in all cases (2.4 and 2.6).
415
cmake_link_flags(X11_LIBRARIES "${X11_LIBRARIES}")
418
# remove duplicates in the X11_INCLUDE_DIR list since those screw up
419
# certain of our modules and also slow down compilation if any of
420
# those duplicates leak through to the compile -I options.
421
list(SORT X11_INCLUDE_DIR)
422
set(copy_X11_INCLUDE_DIR ${X11_INCLUDE_DIR})
425
foreach(copy_listelement ${copy_X11_INCLUDE_DIR})
426
# need to get list elements corresponding to list indices.
427
list(LENGTH X11_INCLUDE_DIR listlength)
428
if(listindexplus LESS ${listlength})
429
list(GET X11_INCLUDE_DIR ${listindex} listelement)
430
list(GET X11_INCLUDE_DIR ${listindexplus} listelementplus)
431
else(listindexplus LESS ${listlength})
434
endif(listindexplus LESS ${listlength})
435
if(copy_listelement STREQUAL "${listelement}" AND
436
copy_listelement STREQUAL "${listelementplus}"
438
list(REMOVE_AT X11_INCLUDE_DIR ${listindex})
439
else(copy_listelement STREQUAL "${listelement}" AND
440
copy_listelement STREQUAL "${listelementplus}"
442
# update list indices
443
math(EXPR listindex "${listindex} + 1")
444
math(EXPR listindexplus "${listindex} + 1")
445
endif(copy_listelement STREQUAL "${listelement}" AND
446
copy_listelement STREQUAL "${listelementplus}"
448
endforeach(copy_listelement ${copy_X11_INCLUDE_DIR})
449
string(REGEX REPLACE ";" " -I" X11_COMPILE_FLAGS "-I${X11_INCLUDE_DIR}")
450
endif(X11_INCLUDE_DIR)
451
message(STATUS "X11_FOUND = ${X11_FOUND}")
452
message(STATUS "X11_INCLUDE_DIR = ${X11_INCLUDE_DIR}")
453
message(STATUS "X11_COMPILE_FLAGS = ${X11_COMPILE_FLAGS}")
454
message(STATUS "X11_LIBRARIES = ${X11_LIBRARIES}")
456
option(DEFAULT_NO_BINDINGS
457
"All language bindings are disabled by default"
460
# Temporary workaround for language support that is required.
461
include(language_support)
463
# Individual language support.
472
# OCaml support is included after the check for output drivers in order to
473
# check for extcairo support.
478
# =======================================================================
479
# additional library support
480
# =======================================================================
482
# On windows systems the math library is not separated so do not specify
483
# it unless you are on a non-windows system.
485
find_library(MATH_LIB NAMES m PATHS /usr/local/lib /usr/lib)
487
message(FATAL_ERROR "Cannot find required math library")
490
# Must come after MATH_LIB is defined (or not).
494
# =======================================================================
496
# =======================================================================
499
# =======================================================================
501
# =======================================================================
504
# =======================================================================
505
# OCaml support (after drivers to check for extcairo)
506
# =======================================================================
509
# =======================================================================
510
# Miscellaneous other features - including docbook documentation
511
# =======================================================================