forked from aewallin/opencamlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonlib.cmake
More file actions
157 lines (143 loc) · 5.27 KB
/
pythonlib.cmake
File metadata and controls
157 lines (143 loc) · 5.27 KB
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
# find boost so we can get it's version
find_package(Boost)
# debugging
set(Boost_DEBUG ON)
# set additional versions, when using a old CMake version this can be handy to find a modern boost
# set(Boost_ADDITIONAL_VERSIONS 1.69.0)
# set boost architecture and namespace, this is needed to make cmake find boost when you didn't compile boost (using b2) with the --layout=system option.
# set(Boost_ARCHITECTURE "-x64")
# set(Boost_NAMESPACE "libboost")
if (WIN32)
# use static python lib
add_definitions(-DBOOST_PYTHON_STATIC_LIB)
# disable autolinking in boost
add_definitions( -DBOOST_ALL_NO_LIB ) # avoid LNK1104 on Windows: http://stackoverflow.com/a/28902261/122441
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
message(STATUS "CMake version < 3.12.0")
find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
if (UNIX AND NOT APPLE)
find_package(Boost COMPONENTS python${PYTHON_VERSION_SUFFIX})
if (PYTHON_VERSION_MAJOR EQUAL 3)
find_package(PythonInterp 3)
find_package(PythonLibs 3 REQUIRED)
else()
find_package(PythonInterp)
find_package(PythonLibs REQUIRED)
endif()
else()
find_package(Boost COMPONENTS python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR})
if (PYTHON_VERSION_MAJOR EQUAL 3)
find_package(PythonInterp 3)
find_package(PythonLibs 3 REQUIRED)
else()
find_package(PythonInterp)
find_package(PythonLibs REQUIRED)
endif()
endif()
else()
message("Python not found")
endif()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(0,0,\"/usr/local\")"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
) # on Ubuntu 11.10 this outputs: /usr/local/lib/python2.7/dist-packages
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(plat_specific=1,standard_lib=0,prefix=\"/usr/local\")"
OUTPUT_VARIABLE PYTHON_ARCH_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
message(STATUS "CMake version >= 3.12.0")
if (USE_PY_3)
find_package(Python3 COMPONENTS Interpreter Development)
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
set(PYTHON_SITE_PACKAGES ${Python3_SITELIB})
set(PYTHON_ARCH_PACKAGES ${Python3_SITEARCH})
find_package(Boost COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
else()
find_package(Python2 COMPONENTS Interpreter Development)
set(PYTHON_INCLUDE_DIRS ${Python2_INCLUDE_DIRS})
set(PYTHON_LIBRARIES ${Python2_LIBRARIES})
set(PYTHON_SITE_PACKAGES ${Python2_SITELIB})
set(PYTHON_ARCH_PACKAGES ${Python2_SITEARCH})
find_package(Boost COMPONENTS python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR})
endif()
endif()
message(STATUS "Boost_INCLUDE_DIR = ${Boost_INCLUDE_DIR}")
message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS = ${Boost_LIBRARY_DIRS}")
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
message(STATUS "PYTHON_SITE_PACKAGES = " ${PYTHON_SITE_PACKAGES})
message(STATUS "PYTHON_ARCH_PACKAGES = " ${PYTHON_ARCH_PACKAGES})
message(STATUS "PYTHON_INCLUDE_DIRS = ${PYTHON_INCLUDE_DIRS}")
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
message(STATUS "PYTHON_SITE_PACKAGES = ${PYTHON_SITE_PACKAGES}")
message(STATUS "PYTHON_ARCH_PACKAGES = ${PYTHON_ARCH_PACKAGES}")
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})
# include dirs
include_directories( ${OpenCamLib_SOURCE_DIR}/cutters )
include_directories( ${OpenCamLib_SOURCE_DIR}/geo )
include_directories( ${OpenCamLib_SOURCE_DIR}/algo )
include_directories( ${OpenCamLib_SOURCE_DIR}/dropcutter )
include_directories( ${OpenCamLib_SOURCE_DIR}/common )
include_directories( ${OpenCamLib_SOURCE_DIR} )
# this makes the ocl Python module
add_library(
ocl
MODULE
pythonlib/ocl_cutters.cpp
pythonlib/ocl_geometry.cpp
pythonlib/ocl_algo.cpp
pythonlib/ocl_dropcutter.cpp
pythonlib/ocl.cpp
)
target_link_libraries(
ocl
ocl_common
ocl_dropcutter
ocl_cutters
ocl_geo
ocl_algo
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
)
message(STATUS "linking python binary ocl.so with boost: " ${Boost_PYTHON_LIBRARY})
# this makes the lib name ocl.so and not libocl.so
set_target_properties(ocl PROPERTIES PREFIX "")
if (WIN32)
set_target_properties(ocl PROPERTIES SUFFIX ".pyd")
endif (WIN32)
# if (WIN32)
# set_target_properties(ocl PROPERTIES VERSION ${MY_VERSION})
# endif (WIN32)
if (APPLE AND NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
install(
TARGETS ocl
LIBRARY DESTINATION lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/ocl
)
# these are the python helper lib-files such as camvtk.py
install(
DIRECTORY lib/
DESTINATION lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/ocl
# PATTERN .svn EXCLUDE
)
else()
install(
TARGETS ocl
LIBRARY DESTINATION ${PYTHON_ARCH_PACKAGES}
)
# these are the python helper lib-files such as camvtk.py
install(
DIRECTORY lib/
DESTINATION ${PYTHON_SITE_PACKAGES}
# PATTERN .svn EXCLUDE
)
endif()