forked from symengine/symengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
792 lines (668 loc) · 26 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 2.8.5)
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_SOURCE_DIR}/cmake/UserOverride.cmake)
project(symengine)
set(SYMENGINE_MAJOR_VERSION 0)
set(SYMENGINE_MINOR_VERSION 5)
set(SYMENGINE_PATCH_VERSION 0)
set(SYMENGINE_VERSION ${SYMENGINE_MAJOR_VERSION}.${SYMENGINE_MINOR_VERSION}.${SYMENGINE_PATCH_VERSION})
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(CheckCXXCompilerFlag)
# Make sure that CMAKE_BUILD_TYPE is either Debug or Release:
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Build type (Debug, Release)" FORCE)
endif ()
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "Release"))
message("${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')")
endif ()
set(BUILD_FOR_DISTRIBUTION no
CACHE BOOL "Building SymEngine for a distribution")
#Boost.multiprecision build segfaults if -O3 optimization is on
#which it is by default for cmake Release mode. Remove -O3 from flags.
if (("${INTEGER_CLASS}" MATCHES "boostmp") AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
string(REPLACE "-O3" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
endif()
# Enable C++11 support in all compilers. SymEngine will not compile unless
# the C++11 support is enabled.
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Intel")
set(CXX11_OPTIONS "-std=c++11")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
# pgcpp
set(CXX11_OPTIONS "--gnu --c++11 -D__GXX_EXPERIMENTAL_CXX0X__")
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CXX11_OPTIONS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CXX11_OPTIONS}")
# Add proper -fPIC and MINGW handling
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (NOT MINGW)
set(common "-fPIC")
else()
set(common "-D_hypot=hypot -Doff64_t=_off64_t")
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(common "${common} -DMS_WIN64")
endif()
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${common}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${common}")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(common "-fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${common}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${common}")
endif ()
# Check c++11 support
try_compile(CXX11 "${CMAKE_CURRENT_BINARY_DIR}/cxx" "${CMAKE_SOURCE_DIR}/cmake/checkcxx11.cpp"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_CXX_FLAGS_RELEASE}" OUTPUT_VARIABLE CXX11_ERROR_LOG)
if (NOT ${CXX11})
message(FATAL_ERROR "Compiler does not support C++11 constructs. \n"
"CXX11 Error Log : \n${CXX11_ERROR_LOG}")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
CHECK_CXX_COMPILER_FLAG("-Wno-implicit-fallthrough" NO_WARN_IMPLICIT_FALL_THROUGH_FLAG)
endif()
# check if linker supports exclude-libs
if (NOT(MSVC))
try_compile(EXCLUDE_LIBS "${CMAKE_CURRENT_BINARY_DIR}/cxx" "${CMAKE_SOURCE_DIR}/cmake/checkcxx11.cpp"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_CXX_FLAGS_RELEASE}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${GMP_INCLUDE_DIRS}"
CMAKE_FLAGS "-DLINK_LIBRARIES=-Wl,--exclude-libs,ALL"
OUTPUT_VARIABLE EXCLUDE_LIBS_ERROR_LOG)
endif()
if (${EXCLUDE_LIBS})
message(STATUS "Linker supports --exclude-libs")
else()
message(STATUS "Linker does not support --exclude-libs")
endif()
include(CheckTypeSize)
check_type_size("long double" SYMENGINE_SIZEOF_LONG_DOUBLE)
set(HAVE_GCC_ABI_DEMANGLE yes
CACHE BOOL "Build with C++ name demangling support")
set(HAVE_C_FUNCTION_NOT_FUNC no
CACHE BOOL "C compiler supports __FUNCTION__ but not __func__")
set(HAVE_DEFAULT_CONSTRUCTORS yes
CACHE BOOL "C++ compiler supports default constructors")
set(HAVE_SYMENGINE_NOEXCEPT yes
CACHE BOOL "C++ compiler supports noexcept specifier")
set(HAVE_SYMENGINE_IS_CONSTRUCTIBLE yes
CACHE BOOL "C++ compiler supports std::is_constructible")
set(HAVE_SYMENGINE_RESERVE yes
CACHE BOOL "C++ compiler supports std::unordered_map<>::reserve()")
if (MSVC)
# MSVC doesn't have cxxabi.h
set(HAVE_GCC_ABI_DEMANGLE no)
# MSVC only supports __func__ in a C++ mode, not a C mode
set(HAVE_C_FUNCTION_NOT_FUNC yes)
# MSVC does not support =default for constructors
set(HAVE_DEFAULT_CONSTRUCTORS no)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
set(HAVE_DEFAULT_CONSTRUCTORS no)
set(HAVE_SYMENGINE_RESERVE no)
endif()
try_compile(HAVE_SYMENGINE_STD_TO_STRING "${CMAKE_CURRENT_BINARY_DIR}/cxx" "${CMAKE_SOURCE_DIR}/cmake/checkstdtostring.cpp"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_CXX_FLAGS_RELEASE}")
if ((CMAKE_CXX_COMPILER_ID MATCHES Clang) AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
try_compile(CHECK_CLANG "${CMAKE_CURRENT_BINARY_DIR}/cxx" "${CMAKE_SOURCE_DIR}/cmake/checkclang.cpp")
if (NOT ${CHECK_CLANG})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D__extern_always_inline=inline" )
endif()
endif()
# Cotire
if ((CMAKE_VERSION VERSION_GREATER 2.8.11) AND
(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|MSVC"))
set(WITH_COTIRE yes CACHE BOOL "Use cotire to speed up build")
else()
set(WITH_COTIRE no CACHE BOOL "Use cotire to speed up build")
endif()
set(INTEGER_CLASS "gmp"
CACHE STRING "Integer class for symengine. Either gmp, gmpxx, flint or piranha")
# Virtual TypeID
set(WITH_VIRTUAL_TYPEID no CACHE BOOL "Use virtual TypeID getter")
set(WITH_SYMENGINE_VIRTUAL_TYPEID False)
# Piranha
set(WITH_PIRANHA no CACHE BOOL "Build with Piranha")
# FLINT
set(WITH_FLINT no CACHE BOOL "Build with Flint")
set(HAVE_SYMENGINE_FLINT False)
# Boost
set(WITH_BOOST no CACHE BOOL "Build with Boost")
set(HAVE_SYMENGINE_GMP yes)
if ("${INTEGER_CLASS}" MATCHES "boostmp")
set(SYMENGINE_INTEGER_CLASS "BOOSTMP")
set(WITH_BOOST yes)
set(HAVE_SYMENGINE_GMP no)
elseif ("${INTEGER_CLASS}" MATCHES "piranha")
set(SYMENGINE_INTEGER_CLASS "PIRANHA")
set(WITH_PIRANHA yes)
elseif ("${INTEGER_CLASS}" MATCHES "flint")
set(SYMENGINE_INTEGER_CLASS "FLINT")
set(WITH_FLINT yes)
elseif ("${INTEGER_CLASS}" MATCHES "gmpxx")
if (WITH_PIRANHA)
message(WARNING "SymEngine can't be built with both INTEGER_CLASS=gmpxx and WITH_PIRANHA=yes")
set(SYMENGINE_INTEGER_CLASS "GMP")
else()
set(SYMENGINE_INTEGER_CLASS "GMPXX")
set(WITH_GMPXX yes)
endif()
else()
set(SYMENGINE_INTEGER_CLASS "GMP")
endif()
# GMP
if (HAVE_SYMENGINE_GMP)
find_package(GMP REQUIRED)
include_directories(SYSTEM ${GMP_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GMP_TARGETS})
set(PKGS ${PKGS} "GMP")
# Check gmpxx
if (NOT(MSVC) AND WITH_GMPXX)
try_compile(GMPXX "${CMAKE_CURRENT_BINARY_DIR}/cxx" "${CMAKE_SOURCE_DIR}/cmake/checkgmpxx.cpp"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${CMAKE_CXX_FLAGS_RELEASE}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${GMP_INCLUDE_DIRS}"
CMAKE_FLAGS "-DLINK_LIBRARIES=${GMP_LIBRARIES}"
OUTPUT_VARIABLE GMPXX_ERROR_LOG)
if (NOT ${GMPXX})
message(FATAL_ERROR "GMP library being linked is not supported by CMAKE_CXX_COMPILER used. \n"
"Recompile GMP with C++ support using ${CMAKE_CXX_COMPILER}, remove CMakeCache.txt and try again.\n"
"Error Log : \n${GMPXX_ERROR_LOG}")
endif()
endif()
endif()
set(MSVC_USE_MT yes CACHE BOOL "Use MT flags when compiling in MSVC")
set(MSVC_WARNING_LEVEL 1 CACHE STRING "MSVC warning level")
if (MSVC)
if (MSVC_USE_MT)
foreach(CompilerFlag CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE)
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
foreach(CompilerFlag CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE)
set(${CompilerFlag} "${${CompilerFlag}} /W${MSVC_WARNING_LEVEL}")
endforeach()
endif()
if (BUILD_SHARED_LIBS)
if (WIN32)
if (MSVC)
# Use CMake 3.4 feature
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS yes)
else()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols")
endif()
endif()
endif()
# ECM
set(WITH_ECM no
CACHE BOOL "Build with ECM (libecm-dev) support")
if (WITH_ECM)
find_package(ECM REQUIRED)
include_directories(SYSTEM ${ECM_INCLUDE_DIRS})
set(LIBS ${LIBS} ${ECM_TARGETS})
set(HAVE_SYMENGINE_ECM yes)
set(PKGS ${PKGS} "ECM")
endif()
# PRIMESIEVE
set(WITH_PRIMESIEVE no
CACHE BOOL "Build with Primesieve")
if (WITH_PRIMESIEVE)
find_package(PRIMESIEVE REQUIRED)
include_directories(SYSTEM ${PRIMESIEVE_INCLUDE_DIRS})
set(LIBS ${LIBS} ${PRIMESIEVE_TARGETS})
set(HAVE_SYMENGINE_PRIMESIEVE yes)
set(PKGS ${PKGS} "PRIMESIEVE")
endif()
# ARB
set(WITH_ARB no
CACHE BOOL "Build with Arb")
set(HAVE_SYMENGINE_ARB False)
# MPFR
set(WITH_MPFR no
CACHE BOOL "Build with MPFR")
set(HAVE_SYMENGINE_MPFR False)
# MPC
set(WITH_MPC no
CACHE BOOL "Build with MPC")
set(HAVE_SYMENGINE_MPC False)
# Virtual TypeID
if (WITH_VIRTUAL_TYPEID)
set(WITH_SYMENGINE_VIRTUAL_TYPEID True)
endif()
# Parser
set(WITH_GENERATE_PARSER no CACHE BOOL "Generate parser files")
if (WITH_GENERATE_PARSER)
find_program(BISON_EXECUTABLE bison)
find_program(RE2C_EXECUTABLE re2c)
if ("${BISON_EXECUTABLE}" STREQUAL "BISON_EXECUTABLE-NOTFOUND")
message(FATAL_ERROR "bison not found!")
endif()
if ("${RE2C_EXECUTABLE}" STREQUAL "RE2C_EXECUTABLE-NOTFOUND")
message(FATAL_ERROR "re2c not found!")
endif()
endif()
if (WITH_FLINT)
find_package(FLINT REQUIRED)
include_directories(SYSTEM ${FLINT_INCLUDE_DIRS})
set(LIBS ${LIBS} ${FLINT_TARGETS})
set(HAVE_SYMENGINE_FLINT True)
set(PKGS ${PKGS} "FLINT")
# Workaround for https://github.com/fredrik-johansson/arb/issues/24
include_directories(SYSTEM ${FLINT_INCLUDE_DIRS}/flint)
set(WITH_MPFR yes)
endif()
if (WITH_ARB)
find_package(FLINT REQUIRED)
include_directories(SYSTEM ${FLINT_INCLUDE_DIRS})
set(LIBS ${LIBS} ${FLINT_TARGETS})
set(PKGS ${PKGS} "FLINT")
# Workaround for https://github.com/fredrik-johansson/arb/issues/24
include_directories(SYSTEM ${FLINT_INCLUDE_DIRS}/flint)
set(WITH_FLINT yes)
set(HAVE_SYMENGINE_FLINT True)
set(WITH_MPFR yes)
find_package(ARB REQUIRED)
include_directories(SYSTEM ${ARB_INCLUDE_DIRS})
set(LIBS ${LIBS} ${ARB_TARGETS})
set(HAVE_SYMENGINE_ARB True)
set(PKGS ${PKGS} "ARB")
endif()
if (WITH_MPC)
find_package(MPC REQUIRED)
include_directories(SYSTEM ${MPC_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MPC_TARGETS})
set(HAVE_SYMENGINE_MPC True)
set(WITH_MPFR yes)
set(PKGS ${PKGS} "MPC")
endif()
# PTHREAD
set(WITH_PTHREAD no
CACHE BOOL "Build with PTHREAD")
if (WITH_PIRANHA)
set(WITH_PTHREAD yes)
set(WITH_MPFR yes)
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
find_package(PIRANHA REQUIRED)
include_directories(SYSTEM ${PIRANHA_INCLUDE_DIRS})
set(HAVE_SYMENGINE_PIRANHA yes)
set(PKGS ${PKGS} "PIRANHA")
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} serialization iostreams)
set(WITH_BOOST yes)
endif()
if (WITH_PTHREAD)
find_package(PTHREAD REQUIRED)
include_directories(SYSTEM ${PTHREAD_INCLUDE_DIRS})
set(LIBS ${LIBS} ${PTHREAD_TARGETS})
set(HAVE_SYMENGINE_PTHREAD yes)
set(PKGS ${PKGS} "PTHREAD")
endif()
if (WITH_MPFR)
find_package(MPFR REQUIRED)
include_directories(SYSTEM ${MPFR_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MPFR_TARGETS})
set(HAVE_SYMENGINE_MPFR True)
set(PKGS ${PKGS} "MPFR")
endif()
# PTHREAD
set(WITH_PTHREAD no
CACHE BOOL "Build with PTHREAD")
if (WITH_PIRANHA)
set(WITH_PTHREAD yes)
set(WITH_MPFR yes)
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
find_package(PIRANHA REQUIRED)
include_directories(SYSTEM ${PIRANHA_INCLUDE_DIRS})
set(HAVE_SYMENGINE_PIRANHA yes)
set(PKGS ${PKGS} "PIRANHA")
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} serialization iostreams)
set(WITH_BOOST yes)
endif()
# LLVM
set(WITH_LLVM no
CACHE BOOL "Build with LLVM")
if (WITH_LLVM)
set(SYMENGINE_LLVM_COMPONENTS asmparser core executionengine instcombine mcjit native nativecodegen scalaropts vectorize support transformutils)
find_package(LLVM REQUIRED ${SYMENGINE_LLVM_COMPONENTS})
set(LLVM_MINIMUM_REQUIRED_VERSION "3.8")
if (LLVM_PACKAGE_VERSION LESS ${LLVM_MINIMUM_REQUIRED_VERSION})
message(FATAL_ERROR "LLVM version found ${LLVM_PACKAGE_VERSION} is too old.
Require at least ${LLVM_MINIMUM_REQUIRED_VERSION}")
endif()
foreach(LLVM_FLAG ${LLVM_DEFINITIONS})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${LLVM_FLAG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${LLVM_FLAG}")
endforeach()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
llvm_map_components_to_libnames(llvm_libs_direct ${SYMENGINE_LLVM_COMPONENTS})
llvm_expand_dependencies(llvm_libs ${llvm_libs_direct})
if (BUILD_SHARED_LIBS)
set(SYMENGINE_LLVM_LINK_DOWNSTREAM_DEFAULT False)
foreach(LLVM_LIB ${llvm_libs})
get_target_property(${LLVM_LIB}_IMPORT_LOCATION ${LLVM_LIB} LOCATION)
if (NOT "${${LLVM_LIB}_IMPORT_LOCATION}" MATCHES "NOTFOUND")
if (NOT "${${LLVM_LIB}_IMPORT_LOCATION}" MATCHES ".a$|.lib$")
set(SYMENGINE_LLVM_LINK_DOWNSTREAM_DEFAULT True)
endif()
endif()
endforeach()
else()
set(SYMENGINE_LLVM_LINK_DOWNSTREAM_DEFAULT True)
endif()
set(SYMENGINE_LLVM_LINK_DOWNSTREAM ${SYMENGINE_LLVM_LINK_DOWNSTREAM_DEFAULT}
CACHE INTERNAL "Link to llvm in SymEngineConfig.cmake")
if (NOT SYMENGINE_LLVM_LINK_DOWNSTREAM)
unset(SYMENGINE_LLVM_COMPONENTS)
endif ()
set(LIBS ${LIBS} ${llvm_libs})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
set(HAVE_SYMENGINE_LLVM yes)
set(PKGS ${PKGS} "LLVM")
endif()
# BENCHMARKS
set(BUILD_BENCHMARKS yes
CACHE BOOL "Build SymEngine benchmarks")
set(BUILD_BENCHMARKS_NONIUS no
CACHE BOOL "Build SymEngine Nonius benchmarks")
if (BUILD_BENCHMARKS)
if (BUILD_BENCHMARKS_NONIUS)
if(NOT WIN32)
set(WITH_PTHREAD yes)
endif()
set(WITH_BOOST yes)
endif()
endif()
if (WITH_BOOST)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
set(HAVE_SYMENGINE_BOOST yes)
endif()
# BFD
set(WITH_BFD no
CACHE BOOL "Build with BFD (binutils-dev) support")
if (WITH_BFD)
find_package(BFD REQUIRED)
find_package(LINKH REQUIRED)
include_directories(SYSTEM ${BFD_INCLUDE_DIRS} ${LINKH_INCLUDE_DIRS})
set(LIBS ${LIBS} ${BFD_TARGETS})
set(HAVE_TEUCHOS_BFD yes)
set(HAVE_TEUCHOS_LINK yes)
set(HAVE_TEUCHOS_EXECINFO yes)
find_package(EXECINFO REQUIRED)
include_directories(SYSTEM ${EXECINFO_INCLUDE_DIRS})
set(LIBS ${LIBS} ${EXECINFO_TARGETS})
set(PKGS ${PKGS} "BFD" "LINKH" "EXECINFO")
endif()
# TCMalloc
set(WITH_TCMALLOC no
CACHE BOOL "Build with TCMalloc linked")
if (WITH_TCMALLOC)
find_package(TCMALLOC REQUIRED)
set(LIBS ${LIBS} ${TCMALLOC_TARGETS})
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
endif()
set(PKGS ${PKGS} "TCMALLOC")
endif()
# Doxygen
set(BUILD_DOXYGEN no
CACHE BOOL "Create C++ API Doxgyen documentation.")
if (BUILD_DOXYGEN)
find_package(Doxygen REQUIRED)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
add_custom_target(doc ALL
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
COMMENT "Generating API documentation with Doxygen" VERBATIM)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc/html/ DESTINATION doc)
endif(DOXYGEN_FOUND)
endif()
# SYMENGINE_ASSERT
set(WITH_SYMENGINE_ASSERT no
CACHE BOOL "Enable SYMENGINE_ASSERT macro")
# SYMENGINE_THREAD_SAFE
set(WITH_SYMENGINE_THREAD_SAFE "${BUILD_FOR_DISTRIBUTION}"
CACHE BOOL "Enable SYMENGINE_THREAD_SAFE support")
# TESTS
set(BUILD_TESTS yes
CACHE BOOL "Build SymEngine tests")
# Teuchos
set(WITH_SYMENGINE_TEUCHOS no
CACHE BOOL "Build with teuchos")
# OpenMp
set(WITH_OPENMP no
CACHE BOOL "Build with OpenMP")
if (WITH_OPENMP)
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} ${OpenMP_CXX_FLAGS}")
set(WITH_SYMENGINE_THREAD_SAFE yes)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang|GNU)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -Wno-unknown-pragmas")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# In Debug mode we use Teuchos::RCP and enable debugging checks that make
# the usage 100% safe, as long as the Teuchos guidelines are followed.
set(WITH_SYMENGINE_RCP_DEFAULT no) # Use the Teuchos::RCP
set(HAVE_TEUCHOS_DEBUG yes) # Enable safety checks
set(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING yes) # Enable safety checks
set(WITH_SYMENGINE_ASSERT yes) # Also enable assertions
else ()
set(WITH_SYMENGINE_RCP_DEFAULT yes)
endif()
# SYMENGINE_RCP
set(WITH_SYMENGINE_RCP ${WITH_SYMENGINE_RCP_DEFAULT}
CACHE BOOL "Enable SYMENGINE_RCP support")
if (WITH_COVERAGE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
endif()
if ((NOT WITH_SYMENGINE_RCP) OR HAVE_TEUCHOS_BFD)
set(WITH_SYMENGINE_TEUCHOS yes)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
## References:
## cmake --help-policy CMP0042
set(CMAKE_MACOSX_RPATH ON)
endif()
if(CMAKE_INSTALL_RPATH_USE_LINK_PATH)
## References:
## https://cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
endif()
enable_testing()
add_subdirectory(symengine)
set(SymEngine_DIR ${PROJECT_BINARY_DIR} CACHE BOOL "SymEngine Build Directory")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
set(DEF_INSTALL_CMAKE_DIR_REL ..)
else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/symengine)
set(DEF_INSTALL_CMAKE_DIR_REL ../../..)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for CMake files")
if (TARGET teuchos)
set(SYMENGINE_TARGETS symengine teuchos)
else()
set(SYMENGINE_TARGETS symengine)
endif()
export(TARGETS ${SYMENGINE_TARGETS} FILE "${PROJECT_BINARY_DIR}/SymEngineTargets.cmake")
foreach(PKG ${PKGS})
set(SYMENGINE_PKG_FINDS "${SYMENGINE_PKG_FINDS}\nset(SYMENGINE_${PKG}_LIBRARIES ${${PKG}_LIBRARIES})")
set(SYMENGINE_PKG_FINDS "${SYMENGINE_PKG_FINDS}\nset(SYMENGINE_${PKG}_INCLUDE_DIRS ${${PKG}_INCLUDE_DIRS})")
set(SYMENGINE_PKG_FINDS "${SYMENGINE_PKG_FINDS}\nset(HAVE_SYMENGINE_${PKG} True)")
endforeach()
# ... for the build tree
set(CONF_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
if (TARGET teuchos)
set(CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/symengine/utilities/teuchos ${PROJECT_BINARY_DIR}/symengine/utilities/teuchos)
endif()
set(SYMENGINE_BUILD_TREE yes)
configure_file(cmake/SymEngineConfig.cmake.in
"${PROJECT_BINARY_DIR}/SymEngineConfig.cmake" @ONLY)
# ... for the install tree
set(SYMENGINE_BUILD_TREE no)
configure_file(cmake/SymEngineConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SymEngineConfig.cmake" @ONLY)
#include(CMakePackageConfigHelpers)
#write_basic_package_version_file(
# "${CMAKE_CURRENT_BINARY_DIR}/SymEngineConfigVersion.cmake"
# VERSION ${SYMENGINE_VERSION}
# COMPATIBILITY AnyNewerVersion
#)
configure_file(cmake/SymEngineConfigVersion.cmake.in SymEngineConfigVersion.cmake @ONLY)
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/SymEngineConfig.cmake"
${PROJECT_BINARY_DIR}/SymEngineConfigVersion.cmake
#cmake/FindFLINT.cmake
#cmake/FindARB.cmake
#cmake/FindBFD.cmake
#cmake/FindECM.cmake
#cmake/FindEXECINFO.cmake
#cmake/FindFLINT.cmake
#cmake/FindGMP.cmake
#cmake/FindLINKH.cmake
#cmake/FindMPC.cmake
#cmake/FindMPFR.cmake
#cmake/FindPIRANHA.cmake
#cmake/FindPRIMESIEVE.cmake
#cmake/FindPTHREAD.cmake
#cmake/FindTCMALLOC.cmake
#cmake/LibFindMacros.cmake
DESTINATION ${INSTALL_CMAKE_DIR})
install(EXPORT SymEngineTargets DESTINATION ${INSTALL_CMAKE_DIR})
file(COPY ${symengine_SOURCE_DIR}/cmake/ DESTINATION ${symengine_BINARY_DIR}/cmake)
if (BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
# At the end we print a nice summary
message("--------------------------------------------------------------------------------")
message("")
message("+-------------------------------+")
message("| Configuration results SUMMARY |")
message("+-------------------------------+")
message("")
message("CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message("CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")
message("CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message("CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message("BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
message("INTEGER_CLASS : ${SYMENGINE_INTEGER_CLASS}")
message("HAVE_SYMENGINE_GMP: ${HAVE_SYMENGINE_GMP}")
message("WITH_SYMENGINE_ASSERT: ${WITH_SYMENGINE_ASSERT}")
message("WITH_SYMENGINE_RCP: ${WITH_SYMENGINE_RCP}")
message("WITH_SYMENGINE_TEUCHOS: ${WITH_SYMENGINE_TEUCHOS}")
if (NOT WITH_SYMENGINE_RCP)
message("HAVE_TEUCHOS_DEBUG: ${HAVE_TEUCHOS_DEBUG}")
message("HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING: ${HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING}")
endif ()
message("WITH_COTIRE: ${WITH_COTIRE}")
message("WITH_GENERATE_PARSER: ${WITH_GENERATE_PARSER}")
message("HAVE_GCC_ABI_DEMANGLE: ${HAVE_GCC_ABI_DEMANGLE}")
message("HAVE_C_FUNCTION_NOT_FUNC: ${HAVE_C_FUNCTION_NOT_FUNC}")
message("HAVE_DEFAULT_CONSTRUCTORS: ${HAVE_DEFAULT_CONSTRUCTORS}")
message("HAVE_SYMENGINE_NOEXCEPT: ${HAVE_SYMENGINE_NOEXCEPT}")
message("HAVE_SYMENGINE_IS_CONSTRUCTIBLE: ${HAVE_SYMENGINE_IS_CONSTRUCTIBLE}")
message("HAVE_SYMENGINE_RESERVE: ${HAVE_SYMENGINE_RESERVE}")
message("HAVE_SYMENGINE_STD_TO_STRING: ${HAVE_SYMENGINE_STD_TO_STRING}")
message("WITH_SYMENGINE_THREAD_SAFE: ${WITH_SYMENGINE_THREAD_SAFE}")
message("BUILD_TESTS: ${BUILD_TESTS}")
message("BUILD_BENCHMARKS: ${BUILD_BENCHMARKS}")
message("BUILD_BENCHMARKS_NONIUS: ${BUILD_BENCHMARKS_NONIUS}")
message("WITH_GMP: ${HAVE_SYMENGINE_GMP}")
if (HAVE_SYMENGINE_GMP)
message("GMP_INCLUDE_DIRS: ${GMP_INCLUDE_DIRS}")
message("GMP_LIBRARIES: ${GMP_LIBRARIES}")
endif()
message("WITH_BFD: ${WITH_BFD}")
if (WITH_BFD)
message("BFD_INCLUDE_DIRS: ${BFD_INCLUDE_DIRS}")
message("BFD_LIBRARIES: ${BFD_LIBRARIES}")
message("LINKH_INCLUDE_DIRS: ${LINKH_INCLUDE_DIRS}")
message("EXECINFO_INCLUDE_DIRS: ${EXECINFO_INCLUDE_DIRS}")
endif()
message("WITH_ECM: ${WITH_ECM}")
if (WITH_ECM)
message("ECM_INCLUDE_DIRS: ${ECM_INCLUDE_DIRS}")
message("ECM_LIBRARIES: ${ECM_LIBRARIES}")
endif()
message("WITH_PRIMESIEVE: ${WITH_PRIMESIEVE}")
if (WITH_PRIMESIEVE)
message("PRIMESIEVE_INCLUDE_DIRS: ${PRIMESIEVE_INCLUDE_DIRS}")
message("PRIMESIEVE_LIBRARIES: ${PRIMESIEVE_LIBRARIES}")
endif()
message("WITH_FLINT: ${WITH_FLINT}")
if (WITH_FLINT)
message("FLINT_INCLUDE_DIRS: ${FLINT_INCLUDE_DIRS}")
message("FLINT_LIBRARIES: ${FLINT_LIBRARIES}")
endif()
message("WITH_ARB: ${WITH_ARB}")
if (WITH_ARB)
message("ARB_INCLUDE_DIRS: ${ARB_INCLUDE_DIRS}")
message("ARB_LIBRARIES: ${ARB_LIBRARIES}")
message("FLINT_INCLUDE_DIRS: ${FLINT_INCLUDE_DIRS}")
message("FLINT_LIBRARIES: ${FLINT_LIBRARIES}")
endif()
message("WITH_MPFR: ${WITH_MPFR}")
if (WITH_MPFR)
message("MPFR_INCLUDE_DIRS: ${MPFR_INCLUDE_DIRS}")
message("MPFR_LIBRARIES: ${MPFR_LIBRARIES}")
endif()
message("WITH_PIRANHA: ${WITH_PIRANHA}")
if (WITH_PIRANHA)
message("PIRANHA_INCLUDE_DIRS: ${PIRANHA_INCLUDE_DIRS}")
endif()
message("WITH_LLVM: ${WITH_LLVM}")
if (WITH_LLVM)
message("LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")
endif()
message("WITH_BOOST: ${WITH_BOOST}")
if (WITH_BOOST)
message("BOOST_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message("BOOST_LIBRARIES: ${Boost_LIBRARIES}")
endif()
message("WITH_PTHREAD: ${WITH_PTHREAD}")
if (WITH_PTHREAD)
message("PTHREAD_INCLUDE_DIRS: ${PTHREAD_INCLUDE_DIRS}")
message("PTHREAD_LIBRARIES: ${PTHREAD_LIBRARIES}")
endif()
message("WITH_MPC: ${WITH_MPC}")
if (WITH_MPC)
message("MPC_INCLUDE_DIRS: ${MPC_INCLUDE_DIRS}")
message("MPC_LIBRARIES: ${MPC_LIBRARIES}")
endif()
message("WITH_TCMALLOC: ${WITH_TCMALLOC}")
if (WITH_TCMALLOC)
message("TCMALLOC_LIBRARIES: ${TCMALLOC_LIBRARIES}")
endif()
message("WITH_OPENMP: ${WITH_OPENMP}")
message("WITH_VIRTUAL_TYPEID: ${WITH_VIRTUAL_TYPEID}")
message("")
message("--------------------------------------------------------------------------------")
message("")