-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
215 lines (193 loc) · 8.47 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
cmake_minimum_required(VERSION 3.10)
file(READ "libclingo-lpx/clingo-lpx.h" main)
string(REGEX MATCH "#define CLINGOLPX_VERSION \"([^\"]*)\"" clingov ${main})
project(CLINGOLPX VERSION "${CMAKE_MATCH_1}" LANGUAGES C CXX)
if (POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected - using 'Release'")
set(CMAKE_BUILD_TYPE "Release")
endif()
# Enable folders in IDEs like Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
include(GNUInstallDirs)
include(CMakeDependentOption)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(CLINGOLPX_MANAGE_RPATH "set rpath if not installed into system directory" ON)
option(CLINGOLPX_BUILD_TESTS "build tests" OFF)
option(CLINGOLPX_BUILD_SHARED "build clingo-lpx library shared" ON)
option(CLINGOLPX_CROSSCHECK "enable additional state checking" OFF)
option(CLINGOLPX_PROFILE "Enable profiling using gperftools" OFF)
set(CLINGOLPX_MATH_LIBRARY "auto" CACHE STRING "math library: auto, imath, flint")
option(CLINGOLPX_USE_LOCAL_CATCH
"Advanced option to build against bundled or installed catch."
ON)
set(PYCLINGOLPX_ENABLE "auto" CACHE STRING "build with python support: OFF, auto, require, pip
auto: enable python support if python is available
require: enable python support and fails if python is not available
pip: enable python support and link against the clingo python module")
set(PYCLINGOLPX_INSTALL "prefix" CACHE STRING "configure where to install python module: user, system, prefix
user: install into user prefix
system: install into python library
prefix: install into install prefix")
set(PYCLINGOLPX_PIP_PATH "" CACHE STRING "path to clingo pip package")
set(PYCLINGOLPX_SUFFIX "" CACHE STRING "suffix for python module")
set(PYCLINGOLPX_INSTALL_DIR "" CACHE STRING "path where to install python module")
mark_as_advanced(CLINGOLPX_BUILD_STATIC)
mark_as_advanced(CLINGOLPX_BUILD_SHARED)
mark_as_advanced(CLINGOLPX_CROSSCHECK)
mark_as_advanced(CLINGOLPX_PROFILE)
mark_as_advanced(PYCLINGOLPX_PIP_PATH)
mark_as_advanced(PYCLINGOLPX_SUFFIX)
mark_as_advanced(PYCLINGOLPX_INSTALL_DIR)
if (MSVC)
set(VC_RELEASE_LINK_OPTIONS /LTCG)
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}")
SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}")
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}")
SET(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} ${VC_RELEASE_LINK_OPTIONS}")
endif()
if (POLICY CMP0063 AND CLINGOLPX_BUILD_SHARED)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()
if (CLINGOLPX_BUILD_TESTS)
enable_testing()
endif()
if (CLINGOLPX_MANAGE_RPATH)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemDir)
if ("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
endif()
if (NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if (NOT CMAKE_IMPORT_LIBRARY_PREFIX)
set(CMAKE_IMPORT_LIBRARY_PREFIX import_)
endif()
find_package(Threads)
try_compile(
CLINGOLPX_HAS_SHARED_MUTEX "${CMAKE_BINARY_DIR}/try_compile"
SOURCES "${CMAKE_SOURCE_DIR}/cmake/shared_mutex.cc"
LINK_LIBRARIES Threads::Threads)
if (NOT CLINGOLPX_HAS_SHARED_MUTEX)
message(WARNING "shared mutex support not available falling back to mutex")
endif()
if (CLINGOLPX_MATH_LIBRARY STREQUAL "imath" OR PYCLINGOLPX_ENABLE STREQUAL "pip")
set(_CLINGOLPX_MATH_LIBRARY "imath")
elseif (CLINGOLPX_MATH_LIBRARY STREQUAL "auto")
find_package(FLINT)
if (FLINT_FOUND)
set(_CLINGOLPX_MATH_LIBRARY "flint")
else()
set(_CLINGOLPX_MATH_LIBRARY "imath")
endif()
elseif (CLINGOLPX_MATH_LIBRARY STREQUAL "flint")
find_package(FLINT REQUIRED)
set(_CLINGOLPX_MATH_LIBRARY "flint")
else()
message(FATAL_ERROR "error unknown math library")
endif()
add_subdirectory(third_party)
add_library(MATH::MATH INTERFACE IMPORTED)
if (_CLINGOLPX_MATH_LIBRARY STREQUAL "flint")
set_property(TARGET MATH::MATH PROPERTY INTERFACE_COMPILE_DEFINITIONS CLINGOLPX_USE_FLINT)
set_property(TARGET MATH::MATH PROPERTY INTERFACE_LINK_LIBRARIES FLINT::FLINT)
elseif (_CLINGOLPX_MATH_LIBRARY STREQUAL "imath")
set_property(TARGET MATH::MATH PROPERTY INTERFACE_COMPILE_DEFINITIONS CLINGOLPX_USE_IMATH)
set_property(TARGET MATH::MATH PROPERTY INTERFACE_LINK_LIBRARIES libimath)
else()
endif()
if (CLINGOLPX_PROFILE)
find_package(Gperftools REQUIRED)
endif()
if (PYCLINGOLPX_ENABLE)
if(NOT PYCLINGOLPX_ENABLE STREQUAL "pip" AND (CMAKE_VERSION VERSION_GREATER "3.15.0" OR CMAKE_VERSION VERSION_EQUAL "3.15.0"))
if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
endif()
if(DEFINED PYTHON_INCLUDE_DIR AND NOT DEFINED Python_INCLUDE_DIR)
set(Python_INCLUDE_DIR "${PYTHON_INCLUDE_DIR}")
endif()
if(DEFINED PYTHON_LIBRARY AND NOT DEFINED Python_LIBRARY)
set(Python_LIBRARY "${PYTHON_LIBRARY}")
endif()
if (POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif()
set(_args Interpreter)
set(_args ${_args} Development)
if (PYCLINGOLPX_ENABLE STREQUAL "require" OR PYCLINGOLPX_ENABLE STREQUAL "pip")
set(_args ${_args} REQUIRED)
endif()
find_package(Python COMPONENTS ${_args})
else()
set(_args)
if (PYCLINGOLPX_ENABLE STREQUAL "require" OR PYCLINGOLPX_ENABLE STREQUAL "pip")
set(_args ${_args} REQUIRED)
endif()
if (PYCLINGOLPX_ENABLE STREQUAL "pip")
find_package(PythonExtensions ${_args})
else()
find_package(PythonInterp ${_args})
find_package(PythonLibs ${_args})
endif()
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
set(Python_VERSION_MAJOR "${PYTHON_VERSION_MAJOR}")
if (PYTHONLIBS_FOUND)
add_library(Python::Python INTERFACE IMPORTED)
add_library(Python::Module INTERFACE IMPORTED)
set(Python_Development_FOUND ON)
set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")
set(Python_VERSION "${PYTHONLIBS_VERSION_STRING}")
set_property(TARGET Python::Python PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PYTHON_INCLUDE_DIRS}")
set_property(TARGET Python::Module PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PYTHON_INCLUDE_DIRS}")
set_property(TARGET Python::Python PROPERTY INTERFACE_LINK_LIBRARIES "${PYTHON_LIBRARIES}")
if (MSVC)
set_property(TARGET Python::Module PROPERTY INTERFACE_LINK_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
endif()
endif()
endif()
if (PYCLINGOLPX_ENABLE STREQUAL "pip")
if (NOT CLINGOLPX_BUILD_SHARED)
message(FATAL_ERROR "building against the pip package requires CLINGOLPX_BUILD_SHARED.")
endif()
add_library(libclingo INTERFACE)
if (NOT PYCLINGOLPX_PIP_PATH)
execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGOLPX_SOURCE_DIR}/cmake/python-site.py clingo OUTPUT_VARIABLE PYCLINGOLPX_PIP_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
file(TO_CMAKE_PATH "${PYCLINGOLPX_PIP_PATH}" _PYCLINGOLPX_PIP_PATH)
target_include_directories(libclingo INTERFACE "${_PYCLINGOLPX_PIP_PATH}")
if (WIN32)
target_link_libraries(libclingo INTERFACE "${_PYCLINGOLPX_PIP_PATH}/import__clingo.lib")
elseif (APPLE)
target_link_options(libclingo INTERFACE "-undefined" "dynamic_lookup")
endif()
if (CLINGOLPX_BUILD_TESTS)
add_subdirectory(app/lib)
endif()
add_subdirectory(libclingo-lpx)
add_subdirectory(libpyclingo-lpx)
else()
find_package(Clingo REQUIRED)
add_subdirectory(libclingo-lpx)
if (PYCLINGOLPX_ENABLE)
add_subdirectory(libpyclingo-lpx)
endif()
add_subdirectory(app)
endif()