summaryrefslogtreecommitdiff
path: root/cmake/FindCaDiCaL.cmake
blob: 0c095a5291ceef898e157dfc96686bac20b32876 (plain)
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
###############################################################################
# Top contributors (to current version):
#   Gereon Kremer, Mathias Preiner
#
# This file is part of the cvc5 project.
#
# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
# in the top-level source directory and their institutional affiliations.
# All rights reserved.  See the file COPYING in the top-level source
# directory for licensing information.
# #############################################################################
#
# Find CaDiCaL
# CaDiCaL_FOUND - system has CaDiCaL lib
# CaDiCaL_INCLUDE_DIR - the CaDiCaL include directory
# CaDiCaL_LIBRARIES - Libraries needed to use CaDiCaL
##

include(deps-helper)

find_path(CaDiCaL_INCLUDE_DIR NAMES cadical.hpp)
find_library(CaDiCaL_LIBRARIES NAMES cadical)

set(CaDiCaL_FOUND_SYSTEM FALSE)
if(CaDiCaL_INCLUDE_DIR AND CaDiCaL_LIBRARIES)
  set(CaDiCaL_FOUND_SYSTEM TRUE)

  # Unfortunately it is not part of the headers
  find_library(CaDiCaL_BINARY NAMES cadical)
  if(CaDiCaL_BINARY)
    execute_process(
      COMMAND ${CaDiCaL_BINARY} --version OUTPUT_VARIALE CaDiCaL_VERSION
    )
  else()
    set(CaDiCaL_VERSION "")
  endif()

  check_system_version("CaDiCaL")
endif()

if(NOT CaDiCaL_FOUND_SYSTEM)
  check_ep_downloaded("CaDiCaL-EP")
  if(NOT CaDiCaL-EP_DOWNLOADED)
    check_auto_download("CaDiCaL" "--no-cadical")
  endif()

  include(CheckSymbolExists)
  include(ExternalProject)

  set(CaDiCaL_VERSION "88623ef0866370448c34f6e320c148fc18e6f4cc")

  # avoid configure script and instantiate the makefile manually the configure
  # scripts unnecessarily fails for cross compilation thus we do the bare
  # minimum from the configure script here
  set(CXXFLAGS "-fPIC -O3 -DNDEBUG -DQUIET -std=c++11")
  # check for getc_unlocked
  check_symbol_exists("getc_unlocked" "cstdio" HAVE_UNLOCKED_IO)
  if(NOT HAVE_UNLOCKED_IO)
    set(CXXFLAGS "${CXXFLAGS} -DNUNLOCKED")
  endif()

  if("${CMAKE_GENERATOR}" STREQUAL "Unix Makefiles")
    # use $(MAKE) instead of "make" to allow for parallel builds
    set(make_cmd "$(MAKE)")
  else()
    # $(MAKE) does not work with ninja
    set(make_cmd "make")
  endif()

  ExternalProject_Add(
    CaDiCaL-EP
    ${COMMON_EP_CONFIG}
    BUILD_IN_SOURCE ON
    URL https://github.com/arminbiere/cadical/archive/${CaDiCaL_VERSION}.tar.gz
    URL_HASH SHA1=16ea51f0274d699f3d3c9e3be7083179eed83abf
    CONFIGURE_COMMAND mkdir -p <SOURCE_DIR>/build
    # avoid configure script, prepare the makefile manually
    COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/makefile.in
            <SOURCE_DIR>/build/makefile
    COMMAND
      sed -i.orig -e "s,@CXX@,${CMAKE_CXX_COMPILER}," -e
      "s,@CXXFLAGS@,${CXXFLAGS}," -e "s,@MAKEFLAGS@,,"
      <SOURCE_DIR>/build/makefile
    # This is a temporary patch until fixed upstream
    PATCH_COMMAND
      sed -i.orig
        "s,#include <vector>,#include <vector>\\\\n#include <cstddef>,"
        <SOURCE_DIR>/src/reap.hpp
    BUILD_COMMAND ${make_cmd} -C <SOURCE_DIR>/build libcadical.a
    INSTALL_COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/build/libcadical.a
                    <INSTALL_DIR>/lib/libcadical.a
    COMMAND ${CMAKE_COMMAND} -E copy <SOURCE_DIR>/src/cadical.hpp
            <INSTALL_DIR>/include/cadical.hpp
    BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libcadical.a
  )

  set(CaDiCaL_INCLUDE_DIR "${DEPS_BASE}/include/")
  set(CaDiCaL_LIBRARIES "${DEPS_BASE}/lib/libcadical.a")
endif()

set(CaDiCaL_FOUND TRUE)

add_library(CaDiCaL STATIC IMPORTED GLOBAL)
set_target_properties(
  CaDiCaL PROPERTIES IMPORTED_LOCATION "${CaDiCaL_LIBRARIES}"
)
set_target_properties(
  CaDiCaL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CaDiCaL_INCLUDE_DIR}"
)

if (WIN32)
  # The Windows version of CaDiCaL calls GetProcessMemoryInfo(), which is
  # defined in the Process Status API (psapi), so we declare it as a dependency
  # of the CaDiCaL library (without this, linking a static cvc5 executable
  # fails).
  set_target_properties(
    CaDiCaL PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES psapi
  )
endif ()

mark_as_advanced(CaDiCaL_FOUND)
mark_as_advanced(CaDiCaL_FOUND_SYSTEM)
mark_as_advanced(CaDiCaL_INCLUDE_DIR)
mark_as_advanced(CaDiCaL_LIBRARIES)

if(CaDiCaL_FOUND_SYSTEM)
  message(STATUS "Found CaDiCaL ${CaDiCaL_VERSION}: ${CaDiCaL_LIBRARIES}")
else()
  message(STATUS "Building CaDiCaL ${CaDiCaL_VERSION}: ${CaDiCaL_LIBRARIES}")
  add_dependencies(CaDiCaL CaDiCaL-EP)
endif()
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback