Skip to content

Commit e2cb269

Browse files
authored
Merge pull request #6075 from NlightNFotis/cmake_ipasir
Add CMake support for building and linking against CaDiCaL using the IPASIR interface
2 parents df71f6f + 9bc54a2 commit e2cb269

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ set(enable_cbmc_tests on CACHE BOOL "Whether CBMC tests should be enabled")
8181

8282
set(sat_impl "minisat2" CACHE STRING
8383
"This setting controls the SAT library which is used. Valid values are
84-
'minisat2', 'glucose', or 'cadical'"
84+
'minisat2', 'glucose', 'cadical', 'ipasir-cadical' or 'ipasir-custom'"
8585
)
8686

8787
if(${enable_cbmc_tests})

COMPILING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,27 @@ Note that at the time of writing this has been tested to work with the CaDiCaL
462462
the IPASIR headers, which is needed for the cbmc includes of `ipasir.h`. The
463463
compiled binary will be placed in `cbmc/src/cbmc/cbmc`.
464464
465+
---
466+
467+
It's also possible to build CBMC using CaDiCaL through IPASIR via `cmake`,
468+
controlled with the flag `-Dsat_impl=ipasir-cadical`, like so:
469+
470+
```sh
471+
$ cmake -Bbuild_ipasir -S. -Dsat_impl=ipasir-cadical
472+
```
473+
474+
An advanced user may also take a more adventurous route, trying to link
475+
CBMC against any solver supporthing the IPASIR interface. To do that,
476+
an invocation like this is needed:
477+
478+
```sh
479+
$ cmake -Bbuild_ipasir -S . -Dsat_impl=ipasir-custom -DIPASIR=<source_location> -DIPASIR_LIB=<lib_location>
480+
```
481+
482+
with `<source_location>` being the absolute path to the folder containing
483+
the solver implementation and `<lib_location>` being the absolute path that
484+
contains a precompiled static library of the solver (`.a` file).
485+
465486
#### Compiling with Riss via IPASIR
466487

467488
The [Riss](https://github.com/conp-solutions/riss) solver supports the

src/solvers/CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ set(booleforce_source
3838
set(minibdd_source
3939
${CMAKE_CURRENT_SOURCE_DIR}/bdd/miniBDD/example.cpp
4040
)
41+
set(ipasir_source
42+
${CMAKE_CURRENT_SOURCE_DIR}/sat/satcheck_ipasir.cpp
43+
)
44+
4145

4246
file(GLOB_RECURSE sources "*.cpp" "*.h")
4347
list(REMOVE_ITEM sources
@@ -51,6 +55,7 @@ list(REMOVE_ITEM sources
5155
${lingeling_source}
5256
${booleforce_source}
5357
${minibdd_source}
58+
# ${ipasir_source}
5459
)
5560

5661
add_library(solvers ${sources})
@@ -128,6 +133,65 @@ elseif("${sat_impl}" STREQUAL "cadical")
128133
)
129134

130135
target_link_libraries(solvers cadical)
136+
elseif("${sat_impl}" STREQUAL "ipasir-cadical")
137+
message(STATUS "Building with IPASIR solver linking against: CaDiCaL")
138+
139+
download_project(PROJ cadical
140+
URL https://github.com/arminbiere/cadical/archive/rel-1.4.0.tar.gz
141+
PATCH_COMMAND true
142+
COMMAND ./configure CXX=g++
143+
URL_MD5 9bad586a82995a1d95d1197d445a353a
144+
)
145+
146+
message(STATUS "Building CaDiCaL")
147+
execute_process(COMMAND make WORKING_DIRECTORY ${cadical_SOURCE_DIR})
148+
149+
target_compile_definitions(solvers PUBLIC
150+
SATCHECK_IPASIR HAVE_IPASIR IPASIR=${cadical_SOURCE_DIR}/src
151+
)
152+
153+
add_library(cadical_ipasir STATIC IMPORTED)
154+
set_property(TARGET cadical_ipasir
155+
PROPERTY IMPORTED_LOCATION ${cadical_SOURCE_DIR}/build/libcadical.a
156+
)
157+
158+
target_include_directories(solvers
159+
PUBLIC
160+
${cadical_SOURCE_DIR}/src
161+
)
162+
target_link_libraries(solvers cadical_ipasir)
163+
elseif("${sat_impl}" STREQUAL "ipasir-custom")
164+
message(STATUS "Building with IPASIR solver linking: custom solver provided")
165+
166+
if (NOT DEFINED IPASIR)
167+
message(FATAL_ERROR
168+
"IPASIR solver source code not provided. Please use -DIPASIR=<location> "
169+
"with <location> being the path to the IPASIR solver source code."
170+
)
171+
endif()
172+
173+
if (NOT DEFINED IPASIR_LIB)
174+
message(FATAL_ERROR
175+
"IPASIR solver library not provided. Please use -DIPASIR_LIB=<location> "
176+
"with <location> being the path to the IPASIR solver precompiled static "
177+
"library."
178+
)
179+
endif()
180+
181+
target_compile_definitions(solvers PUBLIC
182+
SATCHECK_IPASIR HAVE_IPASIR IPASIR=${IPASIR}
183+
)
184+
185+
add_library(ipasir_custom STATIC IMPORTED)
186+
set_property(TARGET ipasir_custom
187+
PROPERTY IMPORTED_LOCATION ${IPASIR_LIB}
188+
)
189+
190+
target_include_directories(solvers
191+
PUBLIC
192+
${IPASIR}
193+
)
194+
target_link_libraries(solvers ipasir_custom pthread)
131195
endif()
132196

133197
if(CMAKE_USE_CUDD)

0 commit comments

Comments
 (0)