forked from potassco/clingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
255 lines (234 loc) · 10.4 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
cmake_minimum_required(VERSION 3.1)
file(READ "libclingo/clingo.h" clingoh)
string(REGEX MATCH "#define CLINGO_VERSION \"([^\"]*)\"" clingov ${clingoh})
project(CLINGO 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()
include(GNUInstallDirs)
include(CMakeDependentOption)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(clingo_functions)
# Enable folders in IDEs like Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(CLINGO_BUILD_WEB "enable web target" OFF)
option(CLINGO_BUILD_STATIC "do not build shared libraries" OFF)
option(CLINGO_BUILD_WITH_PYTHON "enable python support" ON)
option(CLINGO_BUILD_WITH_LUA "enable lua support" ON)
option(CLINGO_BUILD_TESTS "build tests" OFF)
option(CLINGO_BUILD_EXAMPLES "build examples" OFF)
option(CLINGO_BUILD_APPS "build applications" ON)
option(CLINGO_MANAGE_RPATH "set rpath if not installed into system directory" ON)
CMAKE_DEPENDENT_OPTION(CLINGO_REQUIRE_PYTHON "fail if python support not found" OFF "CLINGO_BUILD_WITH_PYTHON" OFF)
CMAKE_DEPENDENT_OPTION(CLINGO_REQUIRE_LUA "fail if lua support not found" OFF "CLINGO_BUILD_WITH_LUA" OFF)
CMAKE_DEPENDENT_OPTION(CLINGO_BUILD_SHARED "build clingo library shared" ON "NOT CLINGO_BUILD_STATIC" OFF)
CMAKE_DEPENDENT_OPTION(CLINGO_BUILD_SHARED_INTERFACE "share symbols in dependents" OFF "CLINGO_BUILD_SHARED" OFF)
CMAKE_DEPENDENT_OPTION(CLINGO_BUILD_PY_SHARED "build pyclingo library shared" OFF "NOT CLINGO_BUILD_STATIC" OFF)
CMAKE_DEPENDENT_OPTION(CLINGO_BUILD_LUA_SHARED "build luaclingo library shared" OFF "NOT CLINGO_BUILD_STATIC" OFF)
option(CLINGO_INSTALL_LIB "install the clingo library" ${CLINGO_BUILD_SHARED})
option(PYCLINGO_USE_CFFI "build pyclingo using cffi" OFF)
option(PYCLINGO_FORCE_OLD_MODULE "force use of the old find_python module" OFF)
option(PYCLINGO_USER_INSTALL "install the python module in the user's site directory" ON)
option(PYCLINGO_DYNAMIC_LOOKUP "do not link to python library and pass linker option `-undefined link_dynamic`" ${APPLE})
CMAKE_DEPENDENT_OPTION(PYCLINGO_USE_INSTALL_PREFIX "install the python module under the install prefix" OFF "NOT PYCLINGO_USER_INSTALL" OFF)
set(CLINGO_CLINGOPATH "" CACHE STRING "global search directories for clingo's include statement")
set(CLINGO_USE_LIB OFF CACHE BOOL "advanced option to build python and lua modules against an existing libclingo")
set(CLINGO_BUILD_REVISION "" CACHE STRING "revision string to add to version information")
set(CLINGO_PYTHON_VERSION "" CACHE STRING "set this to find a specific python version")
set(CLINGO_LUA_VERSION "" CACHE STRING "set this to find a specific lua version")
mark_as_advanced(CLINGO_BUILD_WEB)
mark_as_advanced(CLINGO_BUILD_STATIC)
mark_as_advanced(CLINGO_BUILD_SHARED)
mark_as_advanced(CLINGO_BUILD_SHARED_INTERFACE)
mark_as_advanced(CLINGO_BUILD_PY_SHARED)
mark_as_advanced(CLINGO_BUILD_LUA_SHARED)
mark_as_advanced(CLINGO_USE_LIB)
mark_as_advanced(CLINGO_BUILD_REVISION)
mark_as_advanced(PYCLINGO_FORCE_OLD_MODULE)
# workaround to set custom ar and ranlib
if (CLINGO_CMAKE_AR)
set(CMAKE_AR "${CLINGO_CMAKE_AR}")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if (CLINGO_CMAKE_RANLIB)
set(CMAKE_RANLIB "${CLINGO_CMAKE_RANLIB}")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
endif()
if (CLINGO_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 (CLINGO_BUILD_WEB)
unset(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES)
unset(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES)
unset(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS)
unset(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS)
unset(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES)
unset(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES)
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()
# NOTE: searching for the interpreter first increases the chance
# that searching for the python libraries finds the matching libraries for the default python interpreter
# python is also used to run the tests
if(NOT PYCLINGO_FORCE_OLD_MODULE 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)
if (CLINGO_BUILD_WITH_PYTHON)
set(_args ${_args} Development)
if (CLINGO_REQUIRE_PYTHON)
set(_args ${_args} REQUIRED)
endif()
endif()
find_package(Python ${CLINGO_PYTHON_VERSION} COMPONENTS ${_args})
else()
find_package(PythonInterp)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
if (CLINGO_BUILD_WITH_PYTHON)
if (CLINGO_REQUIRE_PYTHON)
find_package(PythonLibs ${CLINGO_PYTHON_VERSION} REQUIRED)
else()
find_package(PythonLibs ${CLINGO_PYTHON_VERSION})
endif()
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 (CLINGO_BUILD_WITH_LUA)
if (CLINGO_REQUIRE_LUA)
find_package(Lua ${CLINGO_LUA_VERSION} REQUIRED)
else()
find_package(Lua ${CLINGO_LUA_VERSION})
endif()
if(LUA_FOUND)
add_library(Lua::Lua INTERFACE IMPORTED)
set_property(TARGET Lua::Lua PROPERTY INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}")
set_property(TARGET Lua::Lua PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}")
endif()
endif()
find_package(BISON "2.5")
find_package(RE2C "0.13")
if (PYCLINGO_USE_CFFI AND Python_Development_FOUND)
# When using CFFI the clingo module has to be compiled with -pthread to
# avoid linker errors
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
if (POLICY CMP0063 AND (CLINGO_BUILD_SHARED OR Python_Development_FOUND OR LUA_FOUND))
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()
enable_testing()
# NOTE: assumes that submodule has been initialized
set(CLASP_BUILD_APP ${CLINGO_BUILD_APPS} CACHE BOOL "")
if (CLINGO_USE_LIB)
set(clingo_library_targets)
add_library(libclingo INTERFACE IMPORTED)
set_property(TARGET libclingo PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CLINGO_SOURCE_DIR}/libclingo")
set_property(TARGET libclingo PROPERTY INTERFACE_LINK_LIBRARIES "clingo")
else()
if (NOT CLINGO_BUILD_SHARED_INTERFACE)
list(APPEND clingo_library_targets libclingo)
endif()
set(clingo_library_targets libgringo libpotassco libclasp libreify)
if (NOT CLINGO_BUILD_SHARED)
set(CLASP_INSTALL_LIB ${CLINGO_INSTALL_LIB} CACHE BOOL "")
endif()
set(CLASP_USE_LOCAL_LIB_POTASSCO ON CACHE BOOL "" FORCE)
add_subdirectory(clasp)
add_subdirectory(libreify)
add_subdirectory(libgringo)
add_subdirectory(libclingo)
endif()
if (Python_Development_FOUND)
if (PYCLINGO_USE_CFFI)
add_subdirectory(libpyclingo_cffi)
list(APPEND clingo_library_targets libpyclingo)
else()
add_subdirectory(libpyclingo)
list(APPEND clingo_library_targets libpyclingo)
list(APPEND clingo_library_targets libpyclingom)
endif()
else()
add_library(libpyclingo INTERFACE IMPORTED)
add_library(libpyclingom INTERFACE IMPORTED)
endif()
if (LUA_FOUND)
add_subdirectory(libluaclingo)
list(APPEND clingo_library_targets libluaclingo)
else()
add_library(libluaclingo INTERFACE IMPORTED)
endif()
if (CLINGO_BUILD_APPS AND NOT CLINGO_USE_LIB)
add_subdirectory(app/reify)
add_subdirectory(app/gringo)
add_subdirectory(app/clingo)
endif()
if (CLINGO_BUILD_EXAMPLES)
add_subdirectory(examples/c)
add_subdirectory(examples/cc)
endif()
if (NOT CLINGO_BUILD_STATIC AND Python_Development_FOUND)
if (PYCLINGO_USE_CFFI)
add_subdirectory(app/pyclingo_cffi)
else()
add_subdirectory(app/pyclingo)
endif()
endif()
if (NOT CLINGO_BUILD_STATIC AND LUA_FOUND)
add_subdirectory(app/luaclingo)
endif()
if (CLINGO_BUILD_WEB)
add_subdirectory(app/web)
endif()
if (NOT CLINGO_BUILD_STATIC AND (CLINGO_BUILD_SHARED OR Python_Development_FOUND OR LUA_FOUND))
foreach(target ${clingo_library_targets})
set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endforeach()
endif()