-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
171 lines (156 loc) · 6.9 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
cmake_minimum_required(VERSION 3.5)
file(READ "libclingo-dl/clingo-dl.h" main)
string(REGEX MATCH "#define CLINGODL_VERSION \"([^\"]*)\"" clingov ${main})
project(CLINGODL 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()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# 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)
option(CLINGODL_MANAGE_RPATH "set rpath if not installed into system directory" ON)
option(CLINGODL_BUILD_TESTS "build tests" OFF)
option(CLINGODL_BUILD_SHARED "build clingo-dl library shared" ON)
option(CLINGODL_CROSSCHECK "enable additional state checking" OFF)
option(CLINGODL_USE_LOCAL_CATCH
"Advanced option to build against bundled or installed catch."
ON)
option(CLINGODL_PROFILE "profile clingo-dl" OFF)
set(PYCLINGODL_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(PYCLINGODL_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(PYCLINGODL_PIP_PATH "" CACHE STRING "path to clingo pip package")
set(PYCLINGODL_SUFFIX "" CACHE STRING "suffix for python module")
set(PYCLINGODL_INSTALL_DIR "" CACHE STRING "path where to install python module")
mark_as_advanced(CLINGODL_BUILD_STATIC)
mark_as_advanced(CLINGODL_BUILD_SHARED)
mark_as_advanced(CLINGODL_CROSSCHECK)
mark_as_advanced(PYCLINGODL_PIP_PATH)
mark_as_advanced(PYCLINGODL_SUFFIX)
mark_as_advanced(PYCLINGODL_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 CLINGODL_BUILD_SHARED)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()
if (CLINGODL_BUILD_TESTS)
enable_testing()
endif()
if (CLINGODL_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()
add_subdirectory(third_party)
if (PYCLINGODL_ENABLE)
if(NOT PYCLINGODL_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 (PYCLINGODL_ENABLE STREQUAL "require" OR PYCLINGODL_ENABLE STREQUAL "pip")
set(_args ${_args} REQUIRED)
endif()
find_package(Python COMPONENTS ${_args})
else()
set(_args)
if (PYCLINGODL_ENABLE STREQUAL "require" OR PYCLINGODL_ENABLE STREQUAL "pip")
set(_args ${_args} REQUIRED)
endif()
if (PYCLINGODL_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 (PYCLINGODL_ENABLE STREQUAL "pip")
if (NOT CLINGODL_BUILD_SHARED)
message(FATAL_ERROR "building against the pip package requires CLINGODL_BUILD_SHARED.")
endif()
add_library(libclingo INTERFACE)
if (NOT PYCLINGODL_PIP_PATH)
execute_process(COMMAND ${Python_EXECUTABLE} ${CLINGODL_SOURCE_DIR}/cmake/python-site.py clingo OUTPUT_VARIABLE PYCLINGODL_PIP_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
file(TO_CMAKE_PATH "${PYCLINGODL_PIP_PATH}" _PYCLINGODL_PIP_PATH)
target_include_directories(libclingo INTERFACE "${_PYCLINGODL_PIP_PATH}")
if (WIN32)
target_link_libraries(libclingo INTERFACE "${_PYCLINGODL_PIP_PATH}/import__clingo.lib")
elseif (APPLE)
target_link_options(libclingo INTERFACE "-undefined" "dynamic_lookup")
endif()
if (CLINGODL_BUILD_TESTS)
add_subdirectory(app/lib)
endif()
add_subdirectory(libclingo-dl)
add_subdirectory(libpyclingo-dl)
else()
find_package(Clingo REQUIRED)
add_subdirectory(libclingo-dl)
if (PYCLINGODL_ENABLE)
add_subdirectory(libpyclingo-dl)
endif()
add_subdirectory(app)
endif()