forked from niklasso/minisat
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCMakeLists.txt
238 lines (205 loc) · 7.83 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
#########################
# Important note: Minisat does not properly annotate its API with
# dllimport/dllexport, so the library build is forced to be static.
#########################
cmake_minimum_required(VERSION 3.5)
project(MiniSat VERSION 2.2 LANGUAGES CXX)
# Check if minisat is being used directly or via add_subdirectory, but allow overriding
if (NOT DEFINED MINISAT_MASTER_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MINISAT_MASTER_PROJECT ON)
else()
set(MINISAT_MASTER_PROJECT OFF)
endif()
endif ()
# options
option(MINISAT_BUILD_BINARIES "minisat: build binaries" ${MINISAT_MASTER_PROJECT})
option(MINISAT_BUILD_TESTING "Build and run MiniSat's tests" ON)
option(MINISAT_TEST_BENCHMARKS "Register benchmarks with CTest" OFF)
option(MINISAT_INSTALL "minisat: generate the install target" ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(GNUInstallDirs)
add_library(libminisat STATIC
# Impl files
minisat/core/OutOfMemoryException.cc
minisat/core/Solver.cc
minisat/core/SolverTypes.cc
minisat/core/ThrowOOMException.cc
minisat/utils/Options.cc
minisat/utils/System.cc
minisat/simp/SimpSolver.cc
# Header files for IDEs
minisat/core/Dimacs.h
minisat/core/OutOfMemoryException.h
minisat/core/Solver.h
minisat/core/SolverTypes.h
minisat/core/ThrowOOMException.h
minisat/mtl/Alg.h
minisat/mtl/Alloc.h
minisat/mtl/Heap.h
minisat/mtl/IntTypes.h
minisat/mtl/Map.h
minisat/mtl/Queue.h
minisat/mtl/Sort.h
minisat/mtl/Vec.h
minisat/mtl/XAlloc.h
minisat/utils/Options.h
minisat/utils/ParseUtils.h
minisat/utils/System.h
minisat/simp/SimpSolver.h
)
# Keep the library named as either libminisat.a or minisat.lib
# While having the target's logical name be distinct from minisat (the binary)
set_target_properties(libminisat
PROPERTIES
OUTPUT_NAME "minisat"
)
## Add a namespace alias.
# This is useful to abstract over use of the library as installed vs subdirectory build
add_library(MiniSat::libminisat ALIAS libminisat)
target_compile_features(libminisat
PUBLIC
cxx_attributes
cxx_defaulted_functions
cxx_deleted_functions
cxx_final
)
target_include_directories(libminisat
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set(targets libminisat)
if (MINISAT_BUILD_BINARIES OR (MINISAT_BUILD_TESTING AND BUILD_TESTING) OR (MINISAT_TEST_BENCHMARKS AND BUILD_TESTING))
# Also build two MiniSat executables
# NOTE: `minisat` is used in tests
add_executable(minisat
minisat/core/Main.cc
)
target_link_libraries(minisat libminisat)
add_executable(minisat-simp
minisat/simp/Main.cc
)
target_link_libraries(minisat-simp libminisat)
list(APPEND targets minisat minisat-simp)
endif()
# Workaround for libstdc++ + Clang + -std=gnu++11 bug.
set_target_properties(${targets}
PROPERTIES
CXX_EXTENSIONS OFF
)
foreach (target ${targets})
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
target_compile_options( ${target} PRIVATE -Wall -Wextra )
endif()
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options( ${target} PRIVATE /W4 /wd4267 )
target_compile_definitions( ${target} PRIVATE _CRT_SECURE_NO_WARNINGS )
endif()
endforeach()
###############
# Testing
##
include(CTest)
if (MINISAT_BUILD_TESTING AND BUILD_TESTING)
message(STATUS "Registering integration tests")
# Read all easy instances from a file
file(READ "${PROJECT_SOURCE_DIR}/tests/inputs/easy.txt" MINISAT_INTEGRATION_TESTS)
string(REGEX REPLACE ";" "\\\\;" MINISAT_INTEGRATION_TESTS "${MINISAT_INTEGRATION_TESTS}")
string(REGEX REPLACE "\n" ";" MINISAT_INTEGRATION_TESTS "${MINISAT_INTEGRATION_TESTS}")
# Add 1 test for each easy instance
foreach(INTEGRATION_TEST ${MINISAT_INTEGRATION_TESTS})
add_test(NAME "integration:${INTEGRATION_TEST}"
COMMAND minisat -verb=0 "tests/inputs/${INTEGRATION_TEST}"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
if ("${INTEGRATION_TEST}" MATCHES "^SAT")
# The output can contain multiple lines, so we cannot do a full-line match
# This means that we have to positive match SAT, but negative match UNSAT
# because SAT is a substring of UNSAT.
set_tests_properties("integration:${INTEGRATION_TEST}" PROPERTIES PASS_REGULAR_EXPRESSION "SAT\n"
FAIL_REGULAR_EXPRESSION "UNSAT\n")
else()
set_tests_properties("integration:${INTEGRATION_TEST}" PROPERTIES PASS_REGULAR_EXPRESSION "SAT\n")
endif()
set_tests_properties("integration:${INTEGRATION_TEST}" PROPERTIES
TIMEOUT 30
) # 30s timeout
endforeach(INTEGRATION_TEST)
endif() # TESTING
if (MINISAT_TEST_BENCHMARKS AND BUILD_TESTING)
message(STATUS "Registering benchmarks")
file(READ "${PROJECT_SOURCE_DIR}/tests/inputs/benchmarks.txt" MINISAT_BENCHMARKS)
string(REGEX REPLACE ";" "\\\\;" MINISAT_BENCHMARKS "${MINISAT_BENCHMARKS}")
string(REGEX REPLACE "\n" ";" MINISAT_BENCHMARKS "${MINISAT_BENCHMARKS}")
# Add 1 test for each easy instance
foreach(BENCHMARK ${MINISAT_BENCHMARKS})
add_test(NAME "benchmark:${BENCHMARK}"
COMMAND minisat -verb=0 "tests/inputs/${BENCHMARK}"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
if ("${BENCHMARK}" MATCHES "^SAT")
# The output can contain multiple lines, so we cannot do a full-line match
# This means that we have to positive match SAT, but negative match UNSAT
# because SAT is a substring of UNSAT.
set_tests_properties("benchmark:${BENCHMARK}" PROPERTIES PASS_REGULAR_EXPRESSION "SAT\n"
FAIL_REGULAR_EXPRESSION "UNSAT\n")
else()
set_tests_properties("benchmark:${BENCHMARK}" PROPERTIES PASS_REGULAR_EXPRESSION "SAT\n")
endif()
set_tests_properties("benchmark:${BENCHMARK}" PROPERTIES
TIMEOUT 86400
) # 1 day timeout
endforeach(BENCHMARK)
endif()
###############
# Installation
##
if (MINISAT_INSTALL)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/MiniSat)
install(
TARGETS
libminisat
EXPORT MiniSatTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if (MINISAT_BUILD_BINARIES)
install(
TARGETS
minisat
minisat-simp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
install(DIRECTORY minisat/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/minisat FILES_MATCHING PATTERN "*.h*")
install(EXPORT MiniSatTargets
FILE MiniSatTargets.cmake
NAMESPACE MiniSat::
DESTINATION ${INSTALL_CONFIGDIR}
)
#####################
# ConfigVersion file
##
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/MiniSatConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/CMake/MiniSatConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/MiniSatConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
## Install all the helper files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/MiniSatConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/MiniSatConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
endif()