Skip to content

Add CMake support for building and linking against CaDiCaL using the IPASIR interface #6075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ set(enable_cbmc_tests on CACHE BOOL "Whether CBMC tests should be enabled")

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

if(${enable_cbmc_tests})
Expand Down
21 changes: 21 additions & 0 deletions COMPILING.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,27 @@ Note that at the time of writing this has been tested to work with the CaDiCaL
the IPASIR headers, which is needed for the cbmc includes of `ipasir.h`. The
compiled binary will be placed in `cbmc/src/cbmc/cbmc`.

---

It's also possible to build CBMC using CaDiCaL through IPASIR via `cmake`,
controlled with the flag `-Dsat_impl=ipasir-cadical`, like so:

```sh
$ cmake -Bbuild_ipasir -S. -Dsat_impl=ipasir-cadical
```

An advanced user may also take a more adventurous route, trying to link
CBMC against any solver supporthing the IPASIR interface. To do that,
an invocation like this is needed:

```sh
$ cmake -Bbuild_ipasir -S . -Dsat_impl=ipasir-custom -DIPASIR=<source_location> -DIPASIR_LIB=<lib_location>
```

with `<source_location>` being the absolute path to the folder containing
the solver implementation and `<lib_location>` being the absolute path that
contains a precompiled static library of the solver (`.a` file).

#### Compiling with Riss via IPASIR

The [Riss](https://github.com/conp-solutions/riss) solver supports the
Expand Down
64 changes: 64 additions & 0 deletions src/solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ set(booleforce_source
set(minibdd_source
${CMAKE_CURRENT_SOURCE_DIR}/bdd/miniBDD/example.cpp
)
set(ipasir_source
${CMAKE_CURRENT_SOURCE_DIR}/sat/satcheck_ipasir.cpp
)


file(GLOB_RECURSE sources "*.cpp" "*.h")
list(REMOVE_ITEM sources
Expand All @@ -51,6 +55,7 @@ list(REMOVE_ITEM sources
${lingeling_source}
${booleforce_source}
${minibdd_source}
# ${ipasir_source}
)

add_library(solvers ${sources})
Expand Down Expand Up @@ -128,6 +133,65 @@ elseif("${sat_impl}" STREQUAL "cadical")
)

target_link_libraries(solvers cadical)
elseif("${sat_impl}" STREQUAL "ipasir-cadical")
message(STATUS "Building with IPASIR solver linking against: CaDiCaL")

download_project(PROJ cadical
URL https://github.com/arminbiere/cadical/archive/rel-1.4.0.tar.gz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses CaDiCaL 1.4.0 and the non-IPASIR path uses CaDiCaL 1.3.0, can these by made the same version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have it on my todo list, though it needs to be submitted as a different PR - I prefer PRs to be isolated to single feature changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have the commit accomplishing this at tautschnig@330542a, but thus far held back on creating a PR as performance needs to be evaluated (I vaguely recall a regression).

PATCH_COMMAND true
COMMAND ./configure CXX=g++
URL_MD5 9bad586a82995a1d95d1197d445a353a
)

message(STATUS "Building CaDiCaL")
execute_process(COMMAND make WORKING_DIRECTORY ${cadical_SOURCE_DIR})

target_compile_definitions(solvers PUBLIC
SATCHECK_IPASIR HAVE_IPASIR IPASIR=${cadical_SOURCE_DIR}/src
)

add_library(cadical_ipasir STATIC IMPORTED)
set_property(TARGET cadical_ipasir
PROPERTY IMPORTED_LOCATION ${cadical_SOURCE_DIR}/build/libcadical.a
)

target_include_directories(solvers
PUBLIC
${cadical_SOURCE_DIR}/src
)
target_link_libraries(solvers cadical_ipasir)
elseif("${sat_impl}" STREQUAL "ipasir-custom")
message(STATUS "Building with IPASIR solver linking: custom solver provided")

if (NOT DEFINED IPASIR)
message(FATAL_ERROR
"IPASIR solver source code not provided. Please use -DIPASIR=<location> "
"with <location> being the path to the IPASIR solver source code."
)
endif()

if (NOT DEFINED IPASIR_LIB)
message(FATAL_ERROR
"IPASIR solver library not provided. Please use -DIPASIR_LIB=<location> "
"with <location> being the path to the IPASIR solver precompiled static "
"library."
)
endif()

target_compile_definitions(solvers PUBLIC
SATCHECK_IPASIR HAVE_IPASIR IPASIR=${IPASIR}
)

add_library(ipasir_custom STATIC IMPORTED)
set_property(TARGET ipasir_custom
PROPERTY IMPORTED_LOCATION ${IPASIR_LIB}
)

target_include_directories(solvers
PUBLIC
${IPASIR}
)
target_link_libraries(solvers ipasir_custom pthread)
endif()

if(CMAKE_USE_CUDD)
Expand Down