-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
854 lines (713 loc) · 33.5 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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# AUTHORS: Dan Liew, Ryan Govostes, Mate Soos
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if(POLICY CMP0048)
#policy for VERSION in cmake 3.0
cmake_policy(SET CMP0048 NEW)
endif()
if(POLICY CMP0074)
#policy for <PackageName>_ROOT variables
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0092)
# Disable passing /W3 by default on MSVC
cmake_policy(SET CMP0092 NEW)
endif()
if(POLICY CMP0077)
# Allow to override options via regular variables
cmake_policy(SET CMP0077 NEW)
endif()
project(STP)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14)
include(GenerateExportHeader)
include(GNUInstallDirs)
include(FeatureSummary)
# Search paths for custom CMake modules
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
# Search for packages in the deps directory
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/deps/install")
# generate JSON file of compile commands -- useful for code extension
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(INCLUDEDIR include CACHE STRING "Output directory for include headers")
set(STP_TIMESTAMPS ON CACHE BOOL "Enable build with timestamps")
# -----------------------------------------------------------------------------
# Make RelWithDebInfo the default build type if otherwise not set
# -----------------------------------------------------------------------------
set(build_types Debug Release RelWithDebInfo MinSizeRel)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "You can choose the type of build, options are: ${build_types}")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Options are ${build_types}"
FORCE
)
# Provide drop down menu options in cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${build_types})
endif()
message(STATUS "Doing a ${CMAKE_BUILD_TYPE} build")
# -----------------------------------------------------------------------------
# Option to enable/disable assertions
# -----------------------------------------------------------------------------
# Filter out definition of NDEBUG from the default build configuration flags.
# We will add this ourselves if we want to disable assertions
foreach (build_config ${build_types})
string(TOUPPER ${build_config} upper_case_build_config)
foreach (language CXX C)
set(VAR_TO_MODIFY "CMAKE_${language}_FLAGS_${upper_case_build_config}")
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )"
" "
replacement
"${${VAR_TO_MODIFY}}"
)
#message("Original (${VAR_TO_MODIFY}) is ${${VAR_TO_MODIFY}} replacement is ${replacement}")
set(${VAR_TO_MODIFY} "${replacement}" CACHE STRING "Default flags for ${build_config} configuration" FORCE)
endforeach()
endforeach()
option(ENABLE_ASSERTIONS "Build with assertions enabled" ON)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(ENABLE_ASSERTIONS OFF)
endif()
if (ENABLE_ASSERTIONS)
# NDEBUG was already removed.
else()
# Note this definition doesn't appear in the cache variables.
add_definitions(-DNDEBUG)
endif()
add_feature_info(Assertions ENABLE_ASSERTIONS "Enables assertions")
# -----------------------------------------------------------------------------
# Enable LLVM sanitizations.
# Note that check_cxx_compiler_flag doesn't work, a fix is needed here
# -----------------------------------------------------------------------------
macro(add_cxx_flag flagname)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flagname}")
endmacro()
include(MacroPushRequiredVars)
option(SANITIZE "Use Clang sanitizers" OFF)
if (SANITIZE)
# Set in Cache so user can tweak it later
SET(CMAKE_CXX_COMPILER "clang++" CACHE FILEPATH "" FORCE)
message(STATUS "Forcing compiler: ${CMAKE_CXX_COMPILER}")
add_cxx_flag("-fsanitize=return")
add_cxx_flag("-fsanitize=bounds")
add_cxx_flag("-fsanitize=integer")
add_cxx_flag("-fsanitize=undefined")
add_cxx_flag("-fsanitize=float-divide-by-zero")
add_cxx_flag("-fsanitize=integer-divide-by-zero")
add_cxx_flag("-fsanitize=null")
add_cxx_flag("-fsanitize=unsigned-integer-overflow")
add_cxx_flag("-fsanitize=address")
add_cxx_flag("-Wno-bitfield-constant-conversion")
endif()
add_feature_info(Sanitizers SANITIZE "Enables Clang sanitizers, will force using clang++ as the compiler")
# -----------------------------------------------------------------------------
# Let the user decide if they want to build shared or static client library.
# STP will link against this client library
# -----------------------------------------------------------------------------
option(BUILD_SHARED_LIBS "Build the shared library" ON)
option(STATICCOMPILE "Compile static library and executable" OFF)
if (STATICCOMPILE)
set(BUILD_SHARED_LIBS OFF)
set(ENABLE_PYTHON_INTERFACE OFF)
endif()
add_feature_info(Static STATICCOMPILE "Compiles static library and executable")
if ((${CMAKE_SYSTEM_NAME} MATCHES "Windows") OR (NOT BUILD_SHARED_LIBS))
set(Boost_USE_STATIC_LIBS ON)
set(Minisat_USE_STATIC_LIBS ON)
endif()
if (NOT BUILD_SHARED_LIBS)
if (NOT MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static ")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
# removing -rdynamic that's automatically added
foreach (language CXX C)
set(VAR_TO_MODIFY "CMAKE_SHARED_LIBRARY_LINK_${language}_FLAGS")
string(REGEX REPLACE "(^| )-rdynamic($| )"
" "
replacement
"${${VAR_TO_MODIFY}}")
#message("Original (${VAR_TO_MODIFY}) is ${${VAR_TO_MODIFY}} replacement is ${replacement}")
set(${VAR_TO_MODIFY} "${replacement}" CACHE STRING "Default flags for ${build_config} configuration" FORCE)
endforeach()
endif()
else ()
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_LIBDIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")
if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_INSTALL_RPATH "@loader_path/../lib")
message(STATUS "Using RPATH for dynamic linking")
endif()
endif()
option(SUPPRESS_WARNINGS "Silence all warnings" OFF)
if (NOT MSVC)
add_compile_options( -g)
add_compile_options( -pthread )
add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:-O2>")
add_compile_options("$<$<CONFIG:RELEASE>:-O2>")
add_compile_options("$<$<CONFIG:RELEASE>:-g0>")
add_compile_options("$<$<CONFIG:DEBUG>:-O0>")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -O2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -O2")
endif()
else()
# see https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx for details
# /ZI = include debug info
# /Wall = all warnings
add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/O2>")
add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/ZI>")
add_compile_options("$<$<CONFIG:RELEASE>:/O2>")
add_compile_options("$<$<CONFIG:RELEASE>:/D>")
add_compile_options("$<$<CONFIG:RELEASE>:/NDEBUG>")
add_compile_options("$<$<CONFIG:DEBUG>:/Od>")
if (NOT BUILD_SHARED_LIBS)
# We statically link to reduce dependencies
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
# /MD -- Causes the application to use the multithread-specific
# and DLL-specific version of the run-time library.
# Defines _MT and _DLL and causes the compiler to place
# the library name MSVCRT.lib into the .obj file.
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
# /MDd -- Defines _DEBUG, _MT, and _DLL and causes the application to use the debug multithread-specific and DLL-specific version of the run-time library.
# It also causes the compiler to place the library name MSVCRTD.lib into the .obj file.
if(${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MDd")
endforeach(flag_var)
# Creates a multithreaded executable (static) file using LIBCMT.lib.
add_compile_options(/MT)
endif()
# buffers security check
add_compile_options(/GS)
# Proper warning level
if(SUPPRESS_WARNINGS)
add_compile_options(/W0)
else()
add_compile_options(/W1)
endif()
# Disable STL used in DLL-boundary warning
add_compile_options(/wd4251)
add_compile_options(/D_CRT_SECURE_NO_WARNINGS)
# Wall is MSVC's Weverything, so annoying unless used from the start
# and with judiciously used warning disables
# add_compile_options(/Wall)
# /Za = only ansi C98 & C++11
# /Za is not recommended for use, not tested, etc.
# see: http://stackoverflow.com/questions/5489326/za-compiler-directive-does-not-compile-system-headers-in-vs2010
# add_compile_options(/Za)
add_compile_options(/fp:precise)
# exception handling. s = The exception-handling model that catches C++ exceptions only and tells the compiler to assume that functions declared as extern "C" may throw an exception.
# exception handling. c = If used with s (/EHsc), catches C++ exceptions only and tells the compiler to assume that functions declared as extern "C" never throw a C++ exception.
add_compile_options(/EHsc)
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /PDBCOMPRESS")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:1572864")
#what does this do?
set(DEF_INSTALL_CMAKE_DIR CMake)
if (MSVC)
# Windows compatibility includes
set(STP_DEFS_COMM ${STP_DEFS_COMM} -D_CRT_SECURE_NO_WARNINGS)
set(STP_INCL_COMM windows/winports windows/winports/msc99hdr ${STP_INCL_COMM})
include_directories(${STP_INCL_COMM})
add_subdirectory(windows)
set(PLATFORM_COMPAT_LIBRARIES ${PLATFORM_COMPAT_LIBRARIES} windows_compat)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
# stack size of MSVC must be specified
string(REGEX REPLACE "/STACK:[0-9]+" "" CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:512000000")
# inline is not a keyword in visual studios old C version, allow its redefinition
add_definitions("-D_ALLOW_KEYWORD_MACROS")
endif()
endif()
# -----------------------------------------------------------------------------
# Set the appropriate build flags
# -----------------------------------------------------------------------------
include(CheckCXXCompilerFlag)
macro(add_cxx_flag_if_supported flagname)
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
if(HAVE_FLAG_${flagname})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flagname}")
endif()
endmacro()
check_cxx_compiler_flag("-std=c++11" HAVE_FLAG_STD_CPP11)
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(NOT MSVC)
if(SUPPRESS_WARNINGS)
add_cxx_flag_if_supported("-w")
else()
add_cxx_flag_if_supported("-Wall")
add_cxx_flag_if_supported("-Wextra")
add_cxx_flag_if_supported("-Wunused")
add_cxx_flag_if_supported("-pedantic")
add_cxx_flag_if_supported("-Wsign-compare")
add_cxx_flag_if_supported("-Wtype-limits")
add_cxx_flag_if_supported("-Wuninitialized")
add_cxx_flag_if_supported("-Wno-deprecated")
add_cxx_flag_if_supported("-Wstrict-aliasing")
add_cxx_flag_if_supported("-Wpointer-arith")
add_cxx_flag_if_supported("-Wheader-guard")
add_cxx_flag_if_supported("-Wpointer-arith")
add_cxx_flag_if_supported("-Wformat-nonliteral")
add_cxx_flag_if_supported("-Winit-self")
add_cxx_flag_if_supported("-Wparentheses")
add_cxx_flag_if_supported("-Wunreachable-code")
endif()
if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
add_cxx_flag_if_supported("-fno-omit-frame-pointer")
endif()
#if(NOT ENABLE_TESTING AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# almost working
# add_cxx_flag_if_supported("-fvisibility=hidden")
set(CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_LINKER_FLAGS} -Wl,--discard-all -Wl,--build-id=sha1")
endif()
# add_cxx_flag_if_supported("-flto") # slow compile and not enough benefits
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_definitions("-D__STDC_LIMIT_MACROS")
option(TUNE_NATIVE "Use -mtune=native" OFF)
if(TUNE_NATIVE)
add_cxx_flag_if_supported("-mtune=native")
endif()
option(COVERAGE "Build with coverage check" OFF)
if (COVERAGE)
add_cxx_flag("--coverage")
endif()
option(WERROR "Build with warnings as errors" OFF)
if (WERROR)
if (NOT MSVC)
message(STATUS "Enabling treating warnings as errors")
# Let's make things be errors -- we can't test for this
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
else()
message(STATUS "Warnings as errors is not enabled under MSVC")
endif()
endif()
option(USE_THREAD_LOCAL "Use thread-local storage when available" ON)
add_feature_info(ThreadLocal USE_THREAD_LOCAL "Enables use of thread-local storage when available")
if(WIN32)
set(FLEX_PATH_HINT "e:/cygwin/bin" CACHE STRING "Flex path hints, can be null if on your path")
set(BISON_PATH_HINT "e:/cygwin/bin" CACHE STRING "Bison path hints, can be null if on your path")
set(PERL_PATH_HINT "C:/Perl/bin" CACHE STRING "Perl path hints, can be null if on your pat")
set(PHINTS ${PERL_PATH_HINT} ${FLEX_PATH_HINT} ${BISON_PATH_HINT})
add_definitions(${STP_DEFS_COMM})
endif()
# -----------------------------------------------------------------------------
# Add GIT version
# -----------------------------------------------------------------------------
function(SetVersionNumber PREFIX VERSION_MAJOR VERSION_MINOR VERSION_PATCH)
set(${PREFIX}_VERSION_MAJOR ${VERSION_MAJOR} PARENT_SCOPE)
set(${PREFIX}_VERSION_MINOR ${VERSION_MINOR} PARENT_SCOPE)
set(${PREFIX}_VERSION_PATCH ${VERSION_PATCH} PARENT_SCOPE)
set(${PREFIX}_VERSION
"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
PARENT_SCOPE)
endfunction()
find_program (GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA)
MESSAGE(STATUS "GIT hash found: ${GIT_SHA}")
else()
set(GIT_SHA "GIT-hash-notfound")
endif()
set(STP_FULL_VERSION "2.3.3")
string(REPLACE "." ";" STP_FULL_VERSION_LIST ${STP_FULL_VERSION})
SetVersionNumber("PROJECT" ${STP_FULL_VERSION_LIST})
MESSAGE(STATUS "PROJECT_VERSION: ${PROJECT_VERSION}")
MESSAGE(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}")
MESSAGE(STATUS "PROJECT_VERSION_MINOR: ${PROJECT_VERSION_MINOR}")
MESSAGE(STATUS "PROJECT_VERSION_PATCH: ${PROJECT_VERSION_PATCH}")
# -----------------------------------------------------------------------------
# Write out the config.h
# -----------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/stp/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/stp/config.h"
)
# -----------------------------------------------------------------------------
# Set up includes
# -----------------------------------------------------------------------------
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
# FIXME: External library includes
include_directories(# For extlib-abc and extlib-constbv
${PROJECT_SOURCE_DIR}/lib
)
option(ONLY_SIMPLE "Only build very simplistic executable -- no Boost needed" OFF)
if (NOT ONLY_SIMPLE)
find_package( Boost 1.46 COMPONENTS program_options)
endif()
if(NOT Boost_FOUND)
set(ONLY_SIMPLE ON)
endif()
add_feature_info(SimpleOptions ONLY_SIMPLE "Simplifies command-line interface, only a few command-line options will be available")
# -----------------------------------------------------------------------------
# Find Riss
# -----------------------------------------------------------------------------
option(USE_RISS "Try to use Riss" OFF)
add_feature_info(Riss USE_RISS "Enables Riss solver")
if (USE_RISS)
add_definitions(-DUSE_RISS)
include_directories(${RISS_DIR}/) # should point to the base directory: ~/git/riss/
link_directories(${RISS_DIR}/build/lib) # should point to the base directory: ~/git/riss/build/lib
endif()
# -----------------------------------------------------------------------------
# Find CryptoMiniSat
# -----------------------------------------------------------------------------
option(NOCRYPTOMINISAT "Don't try to use cryptominisat" OFF)
if (NOT NOCRYPTOMINISAT)
set(cryptominisat5_DIR "" CACHE PATH "Path to directory containing cryptominisat5Config.cmake")
find_package(cryptominisat5 CONFIG)
if (cryptominisat5_FOUND AND HAVE_FLAG_STD_CPP11 AND (NOT NOCRYPTOMINISAT))
message(STATUS "CryptoMiniSat5 dynamic lib: ${CRYPTOMINISAT5_LIBRARIES}")
message(STATUS "CryptoMiniSat5 static lib: ${CRYPTOMINISAT5_STATIC_LIBRARIES}")
message(STATUS "CryptoMiniSat5 static lib deps: ${CRYPTOMINISAT5_STATIC_LIBRARIES_DEPS}")
message(STATUS "CryptoMiniSat5 include dirs: ${CRYPTOMINISAT5_INCLUDE_DIRS}")
add_definitions(-DUSE_CRYPTOMINISAT)
set(USE_CRYPTOMINISAT ON)
include_directories(SYSTEM ${CRYPTOMINISAT5_INCLUDE_DIRS})
else()
endif()
endif()
add_feature_info(CryptoMiniSat USE_CRYPTOMINISAT "Enables CryptoMiniSat solver, allows --cryptominisat5 option")
option(FORCE_CMS "Must build with CryptoMiniSat" OFF)
if (FORCE_CMS AND NOT USE_CRYPTOMINISAT)
message(FATAL_ERROR "CryptoMiniSat 5.x was not found but it was requested. Exiting.")
endif()
# -----------------------------------------------------------------------------
# Find UniGen
# -----------------------------------------------------------------------------
option(NOUNIGEN "Don't try to use UniSamp" OFF)
if (NOT NOUNIGEN)
set(unigen_DIR "" CACHE PATH "Path to directory containing unigenConfig.cmake") #AS: No clue
find_package(louvain_communities CONFIG)
if (louvain_communities_FOUND)
message(STATUS "Found Louvain Communities library")
message(STATUS "Louvain Communities dynamic lib: ${LOUVAIN_COMMUNITIES_LIBRARIES}")
message(STATUS "Louvain Communities include dirs: ${LOUVAIN_COMMUNITIES_INCLUDE_DIRS}")
else()
message(WARNING "Cannot find Louvain Communities libraries.")
endif()
find_package(arjun CONFIG)
if (arjun_FOUND)
message(STATUS "Found Arjun")
message(STATUS "Arjun dynamic lib : ${ARJUN_LIBRARIES}")
message(STATUS "Arjun include dirs: ${ARJUN_INCLUDE_DIRS}")
include_directories(SYSTEM ${ARJUN_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Cannot find Arjun. Please install it! Exiting.")
endif()
find_package(approxmc CONFIG REQUIRED)
message(STATUS "Found approxmc")
message(STATUS "ApproxMC dynamic lib: ${APPROXMC_LIBRARIES}")
message(STATUS "ApproxMC static lib: ${APPROXMC_STATIC_LIBRARIES}")
message(STATUS "ApproxMC static lib deps: ${APPROXMC_STATIC_LIBRARIES_DEPS}")
message(STATUS "ApproxMC include dirs: ${APPROXMC_INCLUDE_DIRS}")
include_directories(SYSTEM ${APPROXMC_INCLUDE_DIRS})
find_package(sbva CONFIG REQUIRED)
message(STATUS "Found sbva")
message(STATUS "sbva dynamic lib: ${SBVA_LIBRARIES}")
message(STATUS "sbva static lib: ${SBVA_STATIC_LIBRARIES}")
message(STATUS "sbva static lib deps: ${SBVA_STATIC_LIBRARIES_DEPS}")
message(STATUS "sbva include dirs: ${SBVA_INCLUDE_DIRS}")
include_directories(SYSTEM ${SBVA_INCLUDE_DIRS})
find_package(cmsgen CONFIG REQUIRED)
message(STATUS "Found cmsgen")
message(STATUS "CMSGen dynamic lib: ${CMSGEN_LIBRARIES}")
message(STATUS "CMSGen static lib: ${CMSGEN_STATIC_LIBRARIES}")
message(STATUS "CMSGen static lib deps: ${CMSGEN_STATIC_LIBRARIES_DEPS}")
message(STATUS "CMSGen include dirs: ${CMSGEN_INCLUDE_DIRS}")
include_directories(SYSTEM ${CMSGEN_INCLUDE_DIRS})
find_package(unigen CONFIG)
if (unigen_FOUND AND HAVE_FLAG_STD_CPP11 AND (NOT NOUNIGEN))
message(STATUS "UniGen dynamic lib: ${UNIGEN_LIBRARIES}")
message(STATUS "UniGen static lib: ${UNIGEN_STATIC_LIBRARIES}")
message(STATUS "UniGen static lib deps: ${UNIGEN_STATIC_LIBRARIES_DEPS}")
message(STATUS "UniGen include dirs: ${UNIGEN_INCLUDE_DIRS}")
add_definitions(-DUSE_UNIGEN)
set(USE_UNIGEN ON)
include_directories(SYSTEM ${UNIGEN_INCLUDE_DIRS})
else()
message(STATUS "UniGen NOT found")
endif()
endif()
add_feature_info(UniGen USE_UNIGEN "Enables Uniform Sampling, allows --unisamp option")
option(FORCE_UNIG "Must build with UniGen" OFF)
if (FORCE_UNIG AND NOT USE_UNIGEN)
message(FATAL_ERROR "UniSamp was not found but it was requested. Exiting.")
endif()
# -----------------------------------------------------------------------------
# Find ZLIB (needed for MiniSat)
# yes, we need to include the zlib header location or STP will not build
# thanks to MiniSat include-ing it n the header
# -----------------------------------------------------------------------------
find_package(ZLIB)
include_directories(${ZLIB_INCLUDE_DIR})
include_directories(${minisat_SOURCE_DIR})
# ----------
# manpage
# ----------
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_program(HELP2MAN_FOUND help2man)
if (HELP2MAN_FOUND)
if (NOT ONLY_SIMPLE)
ADD_CUSTOM_TARGET(man_stp
ALL
DEPENDS stp-bin
)
ADD_CUSTOM_COMMAND(
TARGET man_stp
COMMAND help2man
ARGS --name="Simple Theorem Prover SMT solver" --version-string=${STP_FULL_VERSION} --help-option="--help" $<TARGET_FILE:stp-bin> -o ${CMAKE_CURRENT_BINARY_DIR}/stp.1
)
INSTALL(
FILES ${CMAKE_CURRENT_BINARY_DIR}/stp.1
DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1)
message(STATUS "Manpage will be created and installed")
endif()
else()
MESSAGE(STATUS "Cannot find help2man, not creating manpage")
endif()
else()
MESSAGE(STATUS "Not on Linux, not creating manpage")
endif()
# -----------------------------------------------------------------------------
# Find Minisat
# -----------------------------------------------------------------------------
find_package(minisat)
set(MINISAT_INCLUDE_DIR "" CACHE PATH "MiniSat include directory")
set(MINISAT_LIBRARY "" CACHE PATH "MiniSat library directory")
if (minisat_FOUND)
message(STATUS "OK, found Minisat library under ${MINISAT_LIBRARIES} and Minisat include dirs under ${MINISAT_INCLUDE_DIRS}")
else()
message(STATUS "Not found using installed MiniSat, looking for built MiniSat")
find_package(minisat CONFIG)
if (minisat_FOUND)
message(STATUS "OK, found Minisat library under ${MINISAT_LIBRARIES} and Minisat include dirs under ${MINISAT_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "You must install minisat from https://github.com/stp/minisat")
endif()
endif()
include_directories(SYSTEM ${MINISAT_INCLUDE_DIRS})
set(LIBS ${LIBS} ${MINISAT_LIBRARIES})
# -----------------------------------------------------------------------------
# Find Parser and Lexer generators
# -----------------------------------------------------------------------------
# On macOS, search Homebrew for keg-only versions of Bison and Flex. Xcode does
# not provide new enough versions for us to use.
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
endif()
execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
endif()
endif()
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
if (BISON_VERSION VERSION_LESS "2.6")
message(FATAL_ERROR "STP requires Bison 2.6 or newer")
endif()
# required for genkinds.pl and a few other scripts
find_package(Perl REQUIRED)
# -----------------------------------------------------------------------------
# Query definitions
# -----------------------------------------------------------------------------
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
set(COMPILE_DEFINES)
foreach( d ${DirDefs} )
# message( STATUS "Found Define: " ${d} )
set(COMPILE_DEFINES "${COMPILE_DEFINES} -D${d}")
endforeach()
message(STATUS "All defines at startup: ${COMPILE_DEFINES}")
# -----------------------------------------------------------------------------
# Setup library build path (this is **not** the library install path)
# -----------------------------------------------------------------------------
if(WIN32)
# Create a single bin/ output directory so that DLL files can be
# readily found on DLL platforms.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
if(DEFINED CMAKE_CONFIGURATION_TYPES)
# Placing the binaries in ${CMAKE_*_OUTPUT_DIRECTORY} without regard to
# the debug/release/... configuration. This is needed for build systems
# where files for multiple configurations are kept within the same build
# directory (eg. MSBuild), since some targets (e.g. python-interface-tests)
# require the path to the stp library to be given in a configuration file.
# Note: the paths could be determined in a cleaner fashion by using generator
# expressions, which were used up to commit 1af1f5. However, that solution
# was not feasible, since CMake versions provided by recent Debian versions
# are buggy w.r.t. generator expressions.
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()
# -----------------------------------------------------------------------------
# Provide an export name to be used by targets that wish to export themselves.
# -----------------------------------------------------------------------------
set(STP_EXPORT_NAME "STPTargets")
# -----------------------------------------------------------------------------
# Testing and Python interface options
# -----------------------------------------------------------------------------
option(ENABLE_TESTING "Enable testing" OFF)
# try finding python if the user did not explicitly said that
# he/she does not want python bindings
if((NOT DEFINED ENABLE_PYTHON_INTERFACE) OR ENABLE_PYTHON_INTERFACE)
find_package (PythonInterp)
if(PYTHON_EXECUTABLE AND BUILD_SHARED_LIBS)
set(ENABLE_PYTHON_INTERFACE ON)
else()
set(ENABLE_PYTHON_INTERFACE OFF)
endif()
endif()
add_feature_info(PythonInterface ENABLE_PYTHON_INTERFACE "Enables Python interface")
# -----------------------------------------------------------------------------
# Compile all subdirs
# -----------------------------------------------------------------------------
message(STATUS "Final CXX flags ${CMAKE_CXX_FLAGS}")
option(BUILD_EXECUTABLES "Build executables" ON)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(bindings)
add_feature_info(Executables BUILD_EXECUTABLES "Enables executables compilation")
# -----------------------------------------------------------------------------
# Add uninstall target for makefiles
# -----------------------------------------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
# -----------------------------------------------------------------------------
# Add tests if required
# -----------------------------------------------------------------------------
if(ENABLE_TESTING AND NOT PYTHON_EXECUTABLE)
message(STATUS "Python interpreter cannot be found. Please install it to have the python interface and to enable testing")
set(ENABLE_TESTING OFF)
endif()
if(ENABLE_TESTING)
if (NOT BUILD_SHARED_LIBS)
set(ENABLE_TESTING OFF)
endif()
endif()
if(ENABLE_TESTING)
enable_testing()
set(UNIT_TEST_EXE_SUFFIX "Tests" CACHE STRING "Suffix for Unit test executable")
# add_custom_target(check
# COMMENT "top level target to invoke all other tests"
# )
add_subdirectory(tests)
endif()
add_feature_info(Tests ENABLE_TESTING "Enables tests")
# -----------------------------------------------------------------------------
# Print information about used features
# -----------------------------------------------------------------------------
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
# -----------------------------------------------------------------------------
# Export our targets so that other CMake based projects can interface with
# the build of STP in the build-tree
# -----------------------------------------------------------------------------
set(STP_TARGETS_FILENAME "STPTargets.cmake")
set(STP_CONFIG_FILENAME "STPConfig.cmake")
set(STP_CONFIG_VERSION_FILENAME "STPConfigVersion.cmake")
export(TARGETS stp
FILE "${PROJECT_BINARY_DIR}/${STP_TARGETS_FILENAME}")
# Create STPConfig file
set(EXPORT_TYPE "Build-tree")
set(CONF_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/include")
configure_file(STPConfig.cmake.in
"${PROJECT_BINARY_DIR}/${STP_CONFIG_FILENAME}" @ONLY
)
configure_file(STPConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/${STP_CONFIG_VERSION_FILENAME}" @ONLY
)
# Export this package to the CMake user package registry
# Now the user can just use find_package(STP) on their system
export(PACKAGE STP)
# -----------------------------------------------------------------------------
# Export our targets so that other CMake based projects can interface with
# the build of STP that is installed.
# -----------------------------------------------------------------------------
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/STP)
endif()
set(STP_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for STP CMake files"
)
# Create STPConfig file
set(EXPORT_TYPE "installed")
set(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
configure_file(STPConfig.cmake.in
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${STP_CONFIG_FILENAME}" @ONLY
)
install(FILES
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${STP_CONFIG_FILENAME}"
"${PROJECT_BINARY_DIR}/${STP_CONFIG_VERSION_FILENAME}"
DESTINATION "${STP_INSTALL_CMAKE_DIR}"
)
# Install the export set for use with the install-tree
install(EXPORT ${STP_EXPORT_NAME} DESTINATION
"${STP_INSTALL_CMAKE_DIR}"
)