forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
46 lines (42 loc) · 1.76 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
# Setup SWIG
find_package(SWIG REQUIRED)
include(UseSWIG)
# Setup Python
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
set_property(SOURCE linear_solver.i PROPERTY CPLUSPLUS ON)
list(APPEND CMAKE_SWIG_FLAGS "-module;pywraplp")
# outdir for .py file
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/..)
# outdir for .so file
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
# Second, for multi-config builds (e.g. msvc)
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_CURRENT_BINARY_DIR}/..)
endforeach()
if(${CMAKE_VERSION} VERSION_GREATER 3.8.2)
swig_add_library(pywraplp TYPE SHARED LANGUAGE python SOURCES linear_solver.i)
else()
swig_add_module(pywraplp python linear_solver.i)
endif()
# ${SWIG_MODULE_<name>_REAL_NAME} will resolve to _<name>.so TARGET
target_include_directories(${SWIG_MODULE_pywraplp_REAL_NAME} PRIVATE
${PYTHON_INCLUDE_DIRS})
target_link_libraries(${SWIG_MODULE_pywraplp_REAL_NAME} PRIVATE
ortools::ortools ${PYTHON_LIBRARIES})
if(UNIX)
if(NOT APPLE)
set_target_properties(${SWIG_MODULE_pywraplp_REAL_NAME} PROPERTIES
INSTALL_RPATH "$ORIGIN/../../:$ORIGIN")
else()
set_target_properties(${SWIG_MODULE_pywraplp_REAL_NAME} PROPERTIES
SUFFIX ".so"
INSTALL_RPATH "@loader_path/../..;@loader_path")
set_property(TARGET ${SWIG_MODULE_pywraplp_REAL_NAME} APPEND PROPERTY
LINK_FLAGS "-flat_namespace -undefined suppress")
endif()
endif()