File: CMakeLists.txt

package info (click to toggle)
mathgl 2.4.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 32,488 kB
  • sloc: cpp: 81,486; ansic: 3,138; pascal: 1,562; python: 37; makefile: 17; sh: 7
file content (802 lines) | stat: -rw-r--r-- 28,649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
cmake_minimum_required(VERSION 3.1.0)
if(POLICY CMP0043)
    cmake_policy(SET CMP0043 OLD)
endif()

project( MathGL2 )

set(mgl_clean_files )
set(MGL_DEP_LIBS)
add_definitions(-DMGL_SRC)

# Set these on command-line
# set(PY3VERSION_DOTTED 3.6)
# set(PY3VERSION_NODOT  36)

#add_definitions(-DZLIB_WINAPI)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${MathGL2_SOURCE_DIR}/scripts)

if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are:
		None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(MathGL_VERSION_MAJOR 2)
set(MathGL_VERSION_MINOR 4)
set(MathGL_PATCH_VERSION 2)
set(MathGL_VERSION ${MathGL_VERSION_MAJOR}.${MathGL_VERSION_MINOR}.${MathGL_PATCH_VERSION})
set(MathGL_SOVERSION 7.5.0)
string(TIMESTAMP MathGL_DATE UTC)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
	option(enable-lcov "Enable coverage." OFF)
	if(enable-lcov)
		include(CodeCoverage)
		APPEND_COVERAGE_COMPILER_FLAGS()
	endif(enable-lcov)
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
	unset(enable-lcov CACHE)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")

#set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
set(MathGL_INSTALL_LIB_DIR "lib" CACHE PATH "Installation directory for libraries")
set(MathGL_INSTALL_BIN_DIR "bin" CACHE PATH "Installation directory for executables")
set(MathGL_INSTALL_INCLUDE_DIR "include" CACHE PATH "Installation directory for headers")
if(WIN32 AND NOT CYGWIN)
  set(DEF_INSTALL_CMAKE_DIR cmake)
else()
  set(DEF_INSTALL_CMAKE_DIR lib/cmake/mathgl)
endif()
set(MathGL_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach(p LIB BIN INCLUDE CMAKE)
  set(var MathGL_INSTALL_${p}_DIR)
  if(NOT IS_ABSOLUTE "${${var}}")
    set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  endif()
endforeach()

macro(mgl_po_src)
    set(l_files )
    foreach(src_file ${ARGN})
        get_filename_component(fp ${src_file} ABSOLUTE)
        file(RELATIVE_PATH rel ${CMAKE_SOURCE_DIR} ${fp})
        list(APPEND l_files "${rel}")
    endforeach(src_file ${ARGN})
    set(po_files ${po_files} ${l_files} PARENT_SCOPE)
endmacro(mgl_po_src)

function(mgl_add_lib mgl_tmp_lib)
       if(${mgl_tmp_lib} MATCHES mgl)
               set(mgllib mgl)
               set(mgllib2 mgl2)
       else(${mgl_tmp_lib} MATCHES mgl)
               set(mgllib mgl-${mgl_tmp_lib})
               set(mgllib2 mgl2-${mgl_tmp_lib})
       endif(${mgl_tmp_lib} MATCHES mgl)
       set(mgl_src_lst ${ARGV})
       list(REMOVE_AT mgl_src_lst 0)
       add_library(${mgllib} SHARED ${mgl_src_lst})
       add_library(${mgllib}-static STATIC ${mgl_src_lst})
       set_target_properties(${mgllib} PROPERTIES SOVERSION ${MathGL_SOVERSION})
       set_target_properties(${mgllib} PROPERTIES DEFINE_SYMBOL "mgl_EXPORTS")
       set_target_properties(${mgllib} PROPERTIES C_VISIBILITY_PRESET hidden)
       set_target_properties(${mgllib} PROPERTIES CXX_VISIBILITY_PRESET hidden)
       set_target_properties(${mgllib} PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
       target_compile_definitions(${mgllib}-static PUBLIC MGL_STATIC_DEFINE)
       if(MSVC)
	   set(mgl_lib_static "-static")
           if(CMAKE_BUILD_TYPE STREQUAL "Debug")
               set(mgl_lib_end "d")
	   else(CMAKE_BUILD_TYPE STREQUAL "Debug")
               set(mgl_lib_end)
           endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
       elseif(MSVC)
	   set(mgl_lib_static)
           set_target_properties(${mgllib} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
	   set_target_properties(${mgllib}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
       endif(MSVC)
       if(enable-mgl2)
               set_target_properties(${mgllib} PROPERTIES OUTPUT_NAME "${mgllib2}${mgl_lib_end}")
               set_target_properties(${mgllib}-static PROPERTIES OUTPUT_NAME "${mgllib2}${mgl_lib_static}${mgl_lib_end}")
       else(enable-mgl2)
               set_target_properties(${mgllib} PROPERTIES OUTPUT_NAME "${mgllib}${mgl_lib_end}")
               set_target_properties(${mgllib}-static PROPERTIES OUTPUT_NAME "${mgllib}${mgl_lib_static}${mgl_lib_end}")
       endif(enable-mgl2)

       install(
               TARGETS ${mgllib} ${mgllib}-static
               EXPORT MathGLTargets
               RUNTIME DESTINATION ${MathGL_INSTALL_BIN_DIR}
               ARCHIVE DESTINATION ${MathGL_INSTALL_LIB_DIR}
               LIBRARY DESTINATION ${MathGL_INSTALL_LIB_DIR}
       )
endfunction(mgl_add_lib mgl_tmp_lib)

MACRO(MGL_DEPENDENT_OPTION option doc default depends1 force1 depends2 force2)
  IF(${option}_ISSET MATCHES "^${option}_ISSET$")
    SET(${option}_AVAILABLE 1)
    IF(${force1})
    FOREACH(d ${depends1})
      STRING(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
      IF(${CMAKE_DEPENDENT_OPTION_DEP})
      ELSE(${CMAKE_DEPENDENT_OPTION_DEP})
          SET(${option}_AVAILABLE 0)
          SET(depends1_AVAILABLE 1)
      ENDIF(${CMAKE_DEPENDENT_OPTION_DEP})
    ENDFOREACH(d)
    ENDIF(${force1})
    IF(${force2})
    FOREACH(d ${depends2})
      STRING(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
      IF(${CMAKE_DEPENDENT_OPTION_DEP})
      ELSE(${CMAKE_DEPENDENT_OPTION_DEP})
          SET(${option}_AVAILABLE 0)
          SET(depends2_AVAILABLE 1)
      ENDIF(${CMAKE_DEPENDENT_OPTION_DEP})
    ENDFOREACH(d)
    ENDIF(${force2})
    IF(${option}_AVAILABLE)
      OPTION(${option} "${doc}" "${default}")
      SET(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
    ELSE(${option}_AVAILABLE)
      IF(${option} MATCHES "^${option}$")
      ELSE(${option} MATCHES "^${option}$")
        SET(${option} "${${option}}" CACHE INTERNAL "${doc}")
      ENDIF(${option} MATCHES "^${option}$")
        IF(depends1_AVAILABLE)
          SET(${option} OFF)
        ELSEIF(depends2_AVAILABLE)
          SET(${option} ON)
        ENDIF(depends1_AVAILABLE)
    ENDIF(${option}_AVAILABLE)
  ELSE(${option}_ISSET MATCHES "^${option}_ISSET$")
    SET(${option} "${${option}_ISSET}")
  ENDIF(${option}_ISSET MATCHES "^${option}_ISSET$")
ENDMACRO(MGL_DEPENDENT_OPTION)
include(CMakeDependentOption)

string(TIMESTAMP MGL_NIGHT "%d.%m.%y")

if(WIN32)
	option(enable-dep-dll "Enable copying off all dependent dll libraries to the install directory" OFF)
endif(WIN32)

option(enable-double "Enable double precision in MathGL library" ON)
option(enable-mpi "Enable mpi" ON)
option(enable-opengl "Enable OpenGL support" ON)
option(enable-all-docs "Enable all documentation building")
#option(enable-doc "Enable documentation building")
option(enable-all "Enable all core features")
option(enable-all-widgets "Enable all Widgets")
option(enable-all-swig "Enable all SWIG based interfaces")
option(enable-rvalue "Enable move constructor support (need C++11)" OFF)
option(enable-pthread "Enable POSIX threads support" ON)
if(MSVC)
	option(enable-pthr-widget "Enable POSIX threads for widgets" OFF)
else(MSVC)
	option(enable-pthr-widget "Enable POSIX threads for widgets" ON)
endif(MSVC)
option(enable-openmp "Enable OpenMP support" OFF)

if(enable-pthread AND enable-openmp)
	message(SEND_ERROR "You can't enable POSIX threads and OpenMP at the same time!")
endif(enable-pthread AND enable-openmp)

option(enable-lgpl "Enable only LGPL part of MathGL")
option(enable-mgl2 "Use names 'libmgl2-*' instead of 'libmgl-*'")
option(enable-ltdl "Enable loading modules support" ON)
option(enable-doc-site "Enable HTML documentation for website")
#CMAKE_DEPENDENT_OPTION(enable-doc-site "Enable HTML documentation for website" OFF "NOT enable-all-docs" ON)
CMAKE_DEPENDENT_OPTION(enable-doc-html "Enable HTML documentation" OFF "NOT enable-all-docs" ON)
CMAKE_DEPENDENT_OPTION(enable-doc-info "Enable INFO documentation" OFF "NOT enable-all-docs" ON)
CMAKE_DEPENDENT_OPTION(enable-doc-pdf-ru "Enable Russian PDF documentation" OFF "NOT enable-all-docs" ON)
CMAKE_DEPENDENT_OPTION(enable-doc-pdf-en "Enable English PDF documentation" OFF "NOT enable-all-docs" ON)
#CMAKE_DEPENDENT_OPTION(enable-doc-prc "Enable PDF samples for HTML docs" OFF "NOT enable-all-docs" ON)
#CMAKE_DEPENDENT_OPTION(enable-doc-json "Enable JSON samples for HTML docs" OFF "NOT enable-all-docs" ON)
option(enable-texi2html "Use texi2html (obsolete package) instead of texi2any" OFF)
CMAKE_DEPENDENT_OPTION(enable-mgltex "Enable installation of mgltex package (MGL scripts in LATEX document)" OFF "NOT enable-lgpl" OFF)

CMAKE_DEPENDENT_OPTION(enable-zlib "Enable zlib support" ON "NOT enable-all" ON)
CMAKE_DEPENDENT_OPTION(enable-png "Enable png support" ON "NOT enable-all" ON)
CMAKE_DEPENDENT_OPTION(enable-jpeg "Enable jpeg support" ON "NOT enable-all" ON)
MGL_DEPENDENT_OPTION(enable-gsl "Enable gsl support" ON "NOT enable-lgpl" ON "NOT enable-all" ON)
MGL_DEPENDENT_OPTION(enable-hdf4 "Enable hdf4 support" ON "NOT enable-lgpl" ON "NOT enable-all" ON)
MGL_DEPENDENT_OPTION(enable-hdf5 "Enable hdf5 support" ON "NOT enable-lgpl" ON "NOT enable-all" ON)
CMAKE_DEPENDENT_OPTION(enable-pdf "Enable pdf support" ON "NOT enable-all" ON)
CMAKE_DEPENDENT_OPTION(enable-gif "Enable gif support" ON "NOT enable-all" ON)
CMAKE_DEPENDENT_OPTION(enable-glut "Enable glut support" ON "NOT enable-all-widgets" ON)
CMAKE_DEPENDENT_OPTION(enable-fltk "Enable fltk widget" ON "NOT enable-all-widgets" ON)
CMAKE_DEPENDENT_OPTION(enable-wx "Enable wxWidget widget" ON "NOT enable-all-widgets" ON)
CMAKE_DEPENDENT_OPTION(enable-qt4 "Enable Qt4 widget" OFF "NOT enable-all-widgets" ON)
CMAKE_DEPENDENT_OPTION(enable-qt4asqt "Set Qt4 as default libmgl-qt" OFF "enable-qt4" OFF)
CMAKE_DEPENDENT_OPTION(enable-qt5 "Enable Qt5 widget" ON "NOT enable-all-widgets" ON)
CMAKE_DEPENDENT_OPTION(enable-qt5asqt "Set Qt5 as default libmgl-qt" ON "enable-qt5" OFF)

# msvc fwprintf print char* for the specifier of "%s" format
if(MSVC AND MSVC_VERSION GREATER 1899)
	SET(CMAKE_CXX_FLAGS "/EHsc -D_CRT_STDIO_ISO_WIDE_SPECIFIERS ${CMAKE_CXX_FLAGS}")
	SET(CMAKE_C_FLAGS "-D_CRT_STDIO_ISO_WIDE_SPECIFIERS ${CMAKE_C_FLAGS}")
endif(MSVC AND MSVC_VERSION GREATER 1899)

include(CheckCXXSourceCompiles)

if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
	set(CMAKE_REQUIRED_FLAGS -msse2 -mfpmath=sse)
	CHECK_CXX_SOURCE_COMPILES("
		int main(void){}" mgl_sse)
	if(mgl_sse)
		SET(CMAKE_CXX_FLAGS "-msse2 -mfpmath=sse ${CMAKE_CXX_FLAGS}")
		SET(CMAKE_C_FLAGS "-msse2 -mfpmath=sse ${CMAKE_C_FLAGS}")
	endif(mgl_sse)
	unset(CMAKE_REQUIRED_FLAGS)
endif(${CMAKE_SIZEOF_VOID_P} EQUAL 4)

if(enable-qt4 OR enable-qt5)
	set(QT_ENABLED ON)
	if(enable-qt4asqt AND enable-qt5asqt)
		message(SEND_ERROR "You cannot make Qt4 and Qt5 as qt at the same time.")
	endif(enable-qt4asqt AND enable-qt5asqt)
	if(enable-qt4 AND NOT enable-qt5)
		set(enable-qt4asqt TRUE)
	endif(enable-qt4 AND NOT enable-qt5)
	if(enable-qt5 AND NOT enable-qt4)
		set(enable-qt5asqt TRUE)
	endif(enable-qt5 AND NOT enable-qt4)
# 	if(NOT enable-opengl)
# 		message(SEND_ERROR "You cannot build MathGL with Qt4 or Qt5 without OpenGL enabled.")
# 	endif(NOT enable-opengl)
endif(enable-qt4 OR enable-qt5)

CMAKE_DEPENDENT_OPTION(enable-json-sample "Enable JSON sample (WebKit variant is the default)." ON "QT_ENABLED" ON)
CMAKE_DEPENDENT_OPTION(enable-json-sample-we "Enable JSON sample (WebEngine variant)." ON "enable-json-sample" ON)
MGL_DEPENDENT_OPTION(enable-python "Enable python interface" ON "NOT enable-lgpl" ON "NOT enable-all-swig" ON)
MGL_DEPENDENT_OPTION(enable-lua "Enable Lua (v.5.1) interface" OFF "NOT enable-lgpl" ON "NOT enable-all-swig" ON)
MGL_DEPENDENT_OPTION(enable-octave "Enable octave interface" ON "NOT enable-lgpl" ON "NOT enable-all-swig" ON)
MGL_DEPENDENT_OPTION(enable-octave-install "Octave interface will install for all users" ON "NOT enable-lgpl" ON "NOT enable-all-swig" ON)

include_directories( ${MathGL2_SOURCE_DIR}/include ${MathGL2_BINARY_DIR}/include)
set(MGL_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/include/mgl2")
set(MGL_CGI_PATH_INSTALL "share/mathgl" CACHE STRING "Set CGI install directory")
set(MGL_CGI_PATH "${CMAKE_INSTALL_PREFIX}/${MGL_CGI_PATH_INSTALL}")
set(MGL_DEF_FONT "STIX" CACHE STRING "Set default font name")

if(NOT WIN32)
#	set(MGL_CGI_PATH "${CMAKE_INSTALL_PREFIX}/share/mathgl")
	set(MGL_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/mathgl")
	set(MGL_DOC_PATH "${CMAKE_INSTALL_PREFIX}/share/doc/mathgl")
	set(MGL_MAN_PATH "${CMAKE_INSTALL_PREFIX}/share/man")
	set(MGL_INFO_PATH "${CMAKE_INSTALL_PREFIX}/share/info")
	set(MGL_FONT_PATH "${MGL_DATA_PATH}/fonts")
else(NOT WIN32)
	set(MGL_FONT_PATH "${CMAKE_INSTALL_PREFIX}/fonts")
endif(NOT WIN32)

include(CheckFunctionExists)
include(CMakePushCheckState)
include(TestBigEndian)

TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
if(WORDS_BIGENDIAN)
	ADD_DEFINITIONS(-DWORDS_BIGENDIAN)
endif(WORDS_BIGENDIAN)

CHECK_FUNCTION_EXISTS(sin MGL_SIN)
CHECK_FUNCTION_EXISTS(memrchr HAVE_MEMRCHR)
if(NOT MGL_SIN)
	cmake_push_check_state()
	set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
	CHECK_FUNCTION_EXISTS(sin MGL_SIN_M)
	cmake_pop_check_state()
	if(MGL_SIN_M)
		set(M_LIB m)
	elseif(MGL_SIN_M)
		message(SEND_ERROR "Math library not found")
	endif(MGL_SIN_M)
endif(NOT MGL_SIN)
set(MGL_DEP_LIBS ${M_LIB} ${MGL_DEP_LIBS})

if(HAVE_MEMRCHR)
	ADD_DEFINITIONS(-DHAVE_MEMRCHR)
endif(HAVE_MEMRCHR)

include(CheckTypeSize)
check_type_size("long" SIZEOF_LONG)

#unset(MGL_HAVE_C99_COMPLEX)
CHECK_CXX_SOURCE_COMPILES(
"#include <complex>
#include <complex.h>
int main(int argc, char *args[])
{std::complex<double> c(2.0, 1.0);
double _Complex i=1.0i;
double _Complex *a = reinterpret_cast<double _Complex *>(&c);
std::complex<double> b(*a);return 0;}" MGL_HAVE_C99_COMPLEX)
if(NOT MGL_HAVE_C99_COMPLEX)
	set(MGL_HAVE_C99_COMPLEX 0)
endif(NOT MGL_HAVE_C99_COMPLEX)

#unset(MGL_HAVE_NAN_INF)
CHECK_CXX_SOURCE_COMPILES(
"#include <math.h>
int main(){double a=NAN, b=INFINITY;return 0;}" MGL_HAVE_NAN_INF)
if(NOT MGL_HAVE_NAN_INF)
	set(MGL_HAVE_NAN_INF 0)
endif(NOT MGL_HAVE_NAN_INF)

#unset(MGL_HAVE_ATTRIBUTE)
CHECK_CXX_SOURCE_COMPILES(
"int __attribute__((pure)) test1() {return 0;}
int __attribute__((const)) test2(int x) {return x*x;}
int main(int argc, char* argv[]) {return 0;}" MGL_HAVE_ATTRIBUTE)
if(NOT MGL_HAVE_ATTRIBUTE)
	set(MGL_HAVE_ATTRIBUTE 0)
endif(NOT MGL_HAVE_ATTRIBUTE)

if(NOT MSVC AND enable-rvalue)
	SET(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}")
	unset(MGL_HAVE_RVAL CACHE)
	CHECK_CXX_SOURCE_COMPILES(
	"struct test { test() {} test(test&& a){} };
	int main() { test t;	return 0; }" MGL_HAVE_RVAL)
	if(NOT MGL_HAVE_RVAL)
		message(SEND_ERROR "Couldn't enable rvalue.")
#		set(MGL_HAVE_RVAL 0)
	endif(NOT MGL_HAVE_RVAL)
else(NOT MSVC AND enable-rvalue)
	set(MGL_HAVE_RVAL 0)
endif(NOT MSVC AND enable-rvalue)



CHECK_CXX_SOURCE_COMPILES(
"#include <getopt.h>
int main(int argc, char *args[]) {
int ch = getopt(argc, args, \"1:2:3:4:5:6:7:8:9:hno:L:C:A:s:S:q:\"); return 0; }" MGL_HAVE_GETOPT)
if(NOT MGL_HAVE_GETOPT)
	include_directories(${MathGL2_SOURCE_DIR}/addons/getopt)
	set(getopt_lib-static getopt-static)
endif(NOT MGL_HAVE_GETOPT)

if(enable-double)
	set(MGL_USE_DOUBLE 1)
else(enable-double)
	set(MGL_USE_DOUBLE 0)
endif(enable-double)

if(enable-qt4 OR enable-qt5)
	set(MGL_HAVE_QT 1)
endif(enable-qt4 OR enable-qt5)

if(enable-mpi)
	set(MGL_HAVE_MPI 1)
	find_package(MPI REQUIRED)
	set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
	set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
	include_directories(${MPI_INCLUDE_PATH})
else(enable-mpi)
	set(MGL_HAVE_MPI 0)
endif(enable-mpi)

if(enable-pthr-widget OR enable-pthread)
	if(enable-pthread)
		set(MGL_HAVE_PTHREAD 1)
	else(enable-pthread)
		set(MGL_HAVE_PTHREAD 0)
	endif(enable-pthread)
	# cmake v.3.1
	set(MGL_HAVE_PTHR_WIDGET 1)
	set(CMAKE_THREAD_PREFER_PTHREAD ON)
	set(THREADS_PREFER_PTHREAD_FLAG ON)
	find_package(Threads REQUIRED)
	# was for v.2.8.12
	#	include(FindThreads)
	if(NOT CMAKE_USE_PTHREADS_INIT)
		message(SEND_ERROR "Couldn't find POSIX threads library.")
	endif(NOT CMAKE_USE_PTHREADS_INIT)
	# cmake v.3.1
	set(MGL_DEP_LIBS Threads::Threads ${MGL_DEP_LIBS})
	# was for v.2.8.12
	#	set(MGL_DEP_LIBS ${CMAKE_THREAD_LIBS_INIT} ${MGL_DEP_LIBS})
else(enable-pthr-widget OR enable-pthread)
	set(MGL_HAVE_PTHR_WIDGET 0)
	set(MGL_HAVE_PTHREAD 0)
endif(enable-pthr-widget OR enable-pthread)

if(enable-openmp)
        find_package(OpenMP)
        if(OPENMP_FOUND)
                set(MGL_HAVE_OMP 1)
                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
                set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
        else(OPENMP_FOUND)
                message(SEND_ERROR "Couldn't find OpenMP. You can enable POSIX threads instead.")
                set(MGL_HAVE_OMP 0)
        endif(OPENMP_FOUND)
else(enable-openmp)
        set(MGL_HAVE_OMP 0)
endif(enable-openmp)

if(enable-gsl)
	set(MGL_HAVE_GSL 1)
	find_library(GSL_LIB gsl)
	find_library(GSL_CBLAS_LIB gslcblas)
	find_path(GSL_INCLUDE_DIR gsl/gsl_fft_complex.h)
	if(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR)
		message(SEND_ERROR "${GSL_LIB}")
		message(SEND_ERROR "${GSL_CBLAS_LIB}")
		message(SEND_ERROR "${GSL_INCLUDE_DIR}")
		message(SEND_ERROR "Couldn't find GSL libraries.")
	else(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR)
		set(CMAKE_REQUIRED_INCLUDES ${GSL_INCLUDE_DIR})
		set(CMAKE_REQUIRED_LIBRARIES ${GSL_LIB} ${GSL_CBLAS_LIB})
		CHECK_CXX_SOURCE_COMPILES("#include <gsl/gsl_multifit_nlin.h>
		int main(){gsl_multifit_fdfsolver *s=0;gsl_matrix *J = 0;
		gsl_multifit_fdfsolver_jac(s, J);}" MGL_HAVE_GSL2)
		unset(CMAKE_REQUIRED_INCLUDES)
		unset(CMAKE_REQUIRED_LIBRARIES)
	endif(NOT GSL_LIB OR NOT GSL_CBLAS_LIB OR NOT GSL_INCLUDE_DIR)
	set(MGL_DEP_LIBS ${GSL_LIB} ${GSL_CBLAS_LIB} ${MGL_DEP_LIBS})
	include_directories(${GSL_INCLUDE_DIR})
else(enable-gsl)
	set(MGL_HAVE_GSL 0)
endif(enable-gsl)

if(enable-all OR enable-ltdl)
	set(MGL_HAVE_LTDL 1)
	find_library(LTDL_LIB ltdl)
	find_path(LTDL_INCLUDE_DIR ltdl.h)
	if(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR)
		message(SEND_ERROR "${LTDL_LIB}")
		message(SEND_ERROR "${LTDL_INCLUDE_DIR}")
		message(SEND_ERROR "Couldn't find LTDL library.")
	endif(NOT LTDL_LIB OR NOT LTDL_INCLUDE_DIR)
	set(MGL_DEP_LIBS ${LTDL_LIB} ${MGL_DEP_LIBS})
	include_directories(${LTDL_INCLUDE_DIR})
else(enable-all OR enable-ltdl)
	set(MGL_HAVE_LTDL 0)
endif(enable-all OR enable-ltdl)

if(enable-hdf4)
	set(MGL_HAVE_HDF4 1)
	find_library(HDF4_LIB NAMES df hdf)
	find_library(HDF4MF_LIB mfhdf)
	find_path(HDF4_INCLUDE_DIR mfhdf.h PATH_SUFFIXES hdf)
	if(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR)
		message(SEND_ERROR "${HDF4_LIB}")
		message(SEND_ERROR "${HDF4MF_LIB}")
		message(SEND_ERROR "${HDF4_INCLUDE_DIR}")
		message(SEND_ERROR "Couldn't find HDF4 libraries.")
	endif(NOT HDF4_LIB OR NOT HDF4MF_LIB OR NOT HDF4_INCLUDE_DIR)
	set(MGL_DEP_LIBS ${HDF4MF_LIB} ${HDF4_LIB} ${MGL_DEP_LIBS})
	include_directories(${HDF4_INCLUDE_DIR})
else(enable-hdf4)
	set(MGL_HAVE_HDF4 0)
endif(enable-hdf4)

if(enable-hdf5)
	set(MGL_HAVE_HDF5 1)
	find_package(HDF5)
	if(NOT HDF5_FOUND)
		find_package(HDF5 NAMES hdf5 COMPONENTS C shared static)
		if(NOT HDF5_FOUND)
			message(SEND_ERROR "Couldn't find HDF5 library.")
		endif(NOT HDF5_FOUND)
	endif(NOT HDF5_FOUND)
	set(MGL_DEP_LIBS ${HDF5_LIBRARIES} ${HDF5_C_SHARED_LIBRARY} ${MGL_DEP_LIBS})
	include_directories(${HDF5_INCLUDE_DIRS})
else(enable-hdf5)
	set(MGL_HAVE_HDF5 0)
endif(enable-hdf5)

if(enable-jpeg)
	set(MGL_HAVE_JPEG 1)
	include(FindJPEG)
	if(NOT JPEG_FOUND)
		message(SEND_ERROR "Couldn't find JPEG library.")
	endif(NOT JPEG_FOUND)
	set(MGL_DEP_LIBS ${JPEG_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${JPEG_INCLUDE_DIR})
else(enable-jpeg)
	set(MGL_HAVE_JPEG 0)
endif(enable-jpeg)


if(enable-zlib)
	set(MGL_HAVE_ZLIB 1)
	include(FindZLIB)
	if(NOT ZLIB_FOUND)
		message(SEND_ERROR "Couldn't find ZLib library.")
	endif(NOT ZLIB_FOUND)
	set(MGL_DEP_LIBS ${ZLIB_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${ZLIB_INCLUDE_DIR})
else(enable-zlib)
	set(MGL_HAVE_ZLIB 0)
endif(enable-zlib)

if(enable-png)
	set(MGL_HAVE_PNG 1)
	if(NOT MGL_HAVE_ZLIB)
		message(SEND_ERROR "You have to enable ZLib if you plan to use PNG export.")
	endif(NOT MGL_HAVE_ZLIB)
	include(FindPNG)
	if(NOT PNG_FOUND)
		message(SEND_ERROR "Couldn't find PNG library.")
	endif(NOT PNG_FOUND)
	set(MGL_DEP_LIBS ${PNG_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${PNG_INCLUDE_DIR})
else(enable-png)
	set(MGL_HAVE_PNG 0)
endif(enable-png)


if(enable-pdf)
	set(MGL_HAVE_PDF 1)
	if(NOT MGL_HAVE_PNG)
		message(SEND_ERROR "You have to enable PNG if you plan to use PDF export.")
	endif(NOT MGL_HAVE_PNG)
	find_library(HPDF_LIB hpdf)
	if(NOT HPDF_LIB)
		message(SEND_ERROR "Couldn't find libHaru or libhpdf.")
	endif(NOT HPDF_LIB)
	find_path(HPDF_INCLUDE_DIR hpdf_u3d.h)
	if(NOT HPDF_INCLUDE_DIR)
		message(SEND_ERROR "Couldn't find headers of 3d-enabled version of libhpdf.")
	endif(NOT HPDF_INCLUDE_DIR)
	include_directories(${HPDF_INCLUDE_DIR})
	set(MGL_DEP_LIBS ${HPDF_LIB} ${MGL_DEP_LIBS})
else(enable-pdf)
	set(MGL_HAVE_PDF 0)
endif(enable-pdf)

if(enable-gif)
	set(MGL_HAVE_GIF 1)
	include(FindGIF)
	if(NOT GIF_FOUND)
		message(SEND_ERROR "Couldn't find GIF library.")
	endif(NOT GIF_FOUND)
	set(MGL_DEP_LIBS ${GIF_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${GIF_INCLUDE_DIR})
else(enable-gif)
	set(MGL_HAVE_GIF 0)
endif(enable-gif)

if(enable-opengl)
	set(MGL_HAVE_OPENGL 1)
	include(FindOpenGL)
	if(NOT OPENGL_FOUND)
		message(SEND_ERROR "Couldn't find OpenGL libraries.")
	endif(NOT OPENGL_FOUND)
	set(MGL_DEP_LIBS ${OPENGL_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${OPENGL_INCLUDE_DIR} )
else(enable-opengl)
	set(MGL_HAVE_OPENGL 0)
endif(enable-opengl)

if(enable-glut)
	set(MGL_HAVE_GLUT 1)
	if(NOT MGL_HAVE_OPENGL)
		message(SEND_ERROR "You have to enable OpenGL if you plan to use GLUT.")
	endif(NOT MGL_HAVE_OPENGL)
	include(FindGLUT)
	if(NOT GLUT_FOUND)
		message(SEND_ERROR "Couldn't find GLUT library.")
	endif(NOT GLUT_FOUND)
else(enable-glut)
	set(MGL_HAVE_GLUT 0)
endif(enable-glut)

if(enable-fltk)
	set(MGL_HAVE_FLTK 1)
	FIND_PACKAGE(FLTK)
	if(NOT FLTK_FOUND)
		message(SEND_ERROR "Couldn't find FLTK library.")
	else(NOT FLTK_FOUND)
		include_directories(${FLTK_INCLUDE_DIR})
		CHECK_CXX_SOURCE_COMPILES(
		"#include <FL/Fl_Copy_Surface.H>
		int main(){return 0;}" MGL_HAVE_FL_COPY)
	endif(NOT FLTK_FOUND)
	if(NOT MGL_HAVE_FL_COPY)
		set(MGL_HAVE_FL_COPY 0)
	endif(NOT MGL_HAVE_FL_COPY)
else(enable-fltk)
	set(MGL_HAVE_FLTK 0)
endif(enable-fltk)

if(enable-wx)
	set(MGL_HAVE_WX 1)
	FIND_PACKAGE(wxWidgets COMPONENTS base core gl)
	if(NOT wxWidgets_FOUND)
		message(SEND_ERROR "Couldn't find wxWidgets library.")
	endif(NOT wxWidgets_FOUND)
else(enable-wx)
	set(MGL_HAVE_WX 0)
endif(enable-wx)


find_program(findxgettext xgettext)
find_program(findmsgmerge msgmerge)
find_program(findmsgfmt msgfmt)
find_program(findmsgcat msgcat)
if(NOT findmsgfmt OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat )
	message("Building of translation files was disabled, because xgettext, msgmerge, msgcat or msgfmt was not found. Current translations will be just coped.")
	set(USE_GETTEXT 0)
else(NOT findmsgfmt  OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat )
	set(USE_GETTEXT 1)
endif(NOT findmsgfmt  OR NOT findxgettext OR NOT findmsgmerge OR NOT findmsgcat )
find_package(Intl)
if(NOT Intl_FOUND)
	set(MGL_USE_LIBINTL 0)
	message("Gettext and translations was fully disabled, because libintl was not found.")
else(NOT Intl_FOUND)
	set(MGL_USE_LIBINTL 1)
	set(MGL_DEP_LIBS ${Intl_LIBRARIES} ${MGL_DEP_LIBS})
	include_directories(${Intl_INCLUDE_DIRS})
endif(NOT Intl_FOUND)
set(po_files )
if(WIN32)
	set(USE_GETTEXT 0)
	set(MGL_USE_LIBINTL 0)
endif(WIN32)

if(enable-doc-info)
	set(MGL_HAVE_DOC_INFO 1)
	find_program(findmi makeinfo)
	if(NOT findmi)
		message(SEND_ERROR "Couldn't find makeinfo needed for documentation building.")
	endif(NOT findmi)
else(enable-doc-info)
	set(MGL_HAVE_DOC_INFO 0)
endif(enable-doc-info)

if(enable-doc-html OR enable-doc-site)
	if(enable-texi2html)
		find_program(findth texi2html)
		if(NOT findth)
			message(SEND_ERROR "Couldn't find texi2html needed for documentation building.")
		endif(NOT findth)
	else(enable-texi2html)
		find_program(findth texi2any)
		if(NOT findth)
			message(SEND_ERROR "Couldn't find texi2any needed for documentation building.")
		endif(NOT findth)
	endif(enable-texi2html)
endif(enable-doc-html OR enable-doc-site)

if(enable-texi2html)
	set(site_en ${CMAKE_BINARY_DIR}/texinfo/doc_en/doc_en.html)
	set(site_ru ${CMAKE_BINARY_DIR}/texinfo/doc_ru/doc_ru.html)
	set(th_opt )
else(enable-texi2html)
	set(th_opt --html)
	set(site_en ${CMAKE_BINARY_DIR}/texinfo/doc_en/index.html)
	set(site_ru ${CMAKE_BINARY_DIR}/texinfo/doc_ru/index.html)
endif(enable-texi2html)

if(enable-doc-html)
	set(MGL_HAVE_DOC_HTML 1)
else(enable-doc-html)
	set(MGL_HAVE_DOC_HTML 0)
endif(enable-doc-html)

if(enable-doc-site)
	set(MGL_HAVE_DOC_SITE 1)
else(enable-doc-site)
	set(MGL_HAVE_DOC_SITE 0)
endif(enable-doc-site)

if(enable-doc-pdf-ru)
	set(MGL_HAVE_DOC_PDF_RU 1)
	find_program(findtp texi2pdf)
	if(NOT findtp)
		message(SEND_ERROR "Couldn't find texi2pdf needed for documentation building.")
	endif(NOT findtp)
else(enable-doc-pdf-ru)
	set(MGL_HAVE_DOC_PDF_RU 0)
endif(enable-doc-pdf-ru)

if(enable-doc-pdf-en)
	set(MGL_HAVE_DOC_PDF_EN 1)
	find_program(findtp texi2pdf)
	if(NOT findtp)
		message(SEND_ERROR "Couldn't find texi2pdf needed for documentation building.")
	endif(NOT findtp)
else(enable-doc-pdf-en)
	set(MGL_HAVE_DOC_PDF_EN 0)
endif(enable-doc-pdf-en)

if(enable-doc-site)
	set(MGL_HAVE_DOC_JSON 1)
else(enable-doc-site)
	set(MGL_HAVE_DOC_JSON 0)
endif(enable-doc-site)

if(enable-doc-site)
	set(MGL_HAVE_DOC_PRC 1)
	if(NOT enable-pdf)
		message(SEND_ERROR "You need to enable pdf support for MathGL.")
	endif(NOT enable-pdf)
else(enable-doc-site)
	set(MGL_HAVE_DOC_PRC 0)
endif(enable-doc-site)

if(UNIX)
	add_definitions(-DNO_COLOR_ARRAY)
endif(UNIX)

if(WIN32)
	add_definitions(-DWIN32)
endif(WIN32)

if(NOT MGL_HAVE_GETOPT)
	add_subdirectory( addons/getopt )
endif(NOT MGL_HAVE_GETOPT)

add_subdirectory( src )
add_subdirectory( widgets )
add_subdirectory( include )
if(NOT enable-lgpl)
	if(MGL_HAVE_QT)
		add_subdirectory( udav )
		if(enable-json-sample)
			add_subdirectory( json )
		endif(enable-json-sample)
	endif(MGL_HAVE_QT)
	if(enable-python OR enable-lua OR enable-octave)
		add_subdirectory( lang )
	endif(enable-python OR enable-lua OR enable-octave)
add_subdirectory( utils )
add_subdirectory( examples )
if(NOT WIN32)
	add_subdirectory( fonts )
endif(NOT WIN32)
add_subdirectory( mgllab )
endif(NOT enable-lgpl)

if(NOT MSVC AND NOT BORLAND)

	if(MGL_HAVE_DOC_HTML OR MGL_HAVE_DOC_SITE OR MGL_HAVE_DOC_INFO OR MGL_HAVE_DOC_PDF_RU OR MGL_HAVE_DOC_PDF_EN )
		add_subdirectory( texinfo )
	endif(MGL_HAVE_DOC_HTML OR MGL_HAVE_DOC_SITE OR MGL_HAVE_DOC_INFO OR MGL_HAVE_DOC_PDF_RU OR MGL_HAVE_DOC_PDF_EN )

endif(NOT MSVC AND NOT BORLAND)

if(enable-mgltex)
	add_subdirectory( mgltex )
endif(enable-mgltex)

if(MGL_USE_LIBINTL)
	if(USE_GETTEXT)
		set(mgl_tl_list )
		add_custom_command(OUTPUT mathgl.pot
			COMMAND ${findxgettext} -s --keyword=_ -C -c --package-name=MathGL2 --package-version=${MathGL_VERSION} -o ${MathGL2_BINARY_DIR}/mathgl.pot ${po_files}
			WORKING_DIRECTORY ${MathGL2_SOURCE_DIR}/
			DEPENDS ${po_files} )
		set(mgl_clean_files mathgl.pot ${mgl_clean_files})
		foreach(tl ru es) # en)
			add_custom_command(OUTPUT mathgl_${tl}.po.done
				COMMAND ${findmsgmerge} -U mathgl_${tl}.po ${MathGL2_BINARY_DIR}/mathgl.pot
				COMMAND ${CMAKE_COMMAND} -E touch ${MathGL2_BINARY_DIR}/mathgl_${tl}.po.done
				WORKING_DIRECTORY ${MathGL2_SOURCE_DIR}/
				DEPENDS mathgl.pot mathgl_${tl}.po)
			add_custom_command(OUTPUT mathgl_${tl}.mo
				COMMAND ${findmsgfmt} -o mathgl_${tl}.mo ${MathGL2_SOURCE_DIR}/mathgl_${tl}.po
				DEPENDS mathgl_${tl}.po.done)
			install( FILES ${MathGL2_BINARY_DIR}/mathgl_${tl}.mo DESTINATION "${CMAKE_INSTALL_PREFIX}/share/locale/${tl}/LC_MESSAGES/" RENAME mathgl.mo )
			set(mgl_tl_list mathgl_${tl}.mo ${mgl_tl_list})
			set(mgl_clean_files mathgl_${tl}.mo mathgl_${tl}.po.done ${mgl_clean_files})
		endforeach(tl)
		add_custom_target(mgl_translations ALL DEPENDS ${mgl_tl_list})
	else(USE_GETTEXT)
		foreach(tl ru es) # en)
			install( FILES ${MathGL2_SOURCE_DIR}/translations/mathgl_${tl}.mo DESTINATION "${CMAKE_INSTALL_PREFIX}/share/locale/${tl}/LC_MESSAGES/" RENAME mathgl.mo )
		endforeach(tl)
	endif(USE_GETTEXT)
endif(MGL_USE_LIBINTL)

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${mgl_clean_files}")

# WARNING!!! DO NOT ADD ANYTHING AFTER THIS LINE!
add_subdirectory ( scripts )