Lines 1-163
Link Here
|
1 |
# - Try to find the a valid boost+python combination |
|
|
2 |
# Once done this will define |
3 |
# |
4 |
# BOOST_PYTHON_FOUND - system has a valid boost+python combination |
5 |
# BOOST_PYTHON_INCLUDES - the include directory for boost+python |
6 |
# BOOST_PYTHON_LIBS - the needed libs for boost+python |
7 |
|
8 |
# Copyright (c) 2006, Pino Toscano, <toscano.pino@tiscali.it> |
9 |
# |
10 |
# Redistribution and use is allowed according to the terms of the BSD license. |
11 |
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. |
12 |
|
13 |
if(BOOST_PYTHON_INCLUDES AND BOOST_PYTHON_LIBS) |
14 |
# Already in cache, be silent |
15 |
set(BOOST_PYTHON_FIND_QUIETLY TRUE) |
16 |
endif(BOOST_PYTHON_INCLUDES AND BOOST_PYTHON_LIBS) |
17 |
|
18 |
# some needed includes |
19 |
include(CheckCXXSourceCompiles) |
20 |
include(CheckIncludeFileCXX) |
21 |
include(CheckLibraryExists) |
22 |
|
23 |
find_package(PkgConfig) |
24 |
|
25 |
# reset vars |
26 |
set(BOOST_PYTHON_INCLUDES) |
27 |
set(BOOST_PYTHON_LIBS) |
28 |
|
29 |
# handy arrays |
30 |
set(PYTHON_VERSIONS "python;python2.7;python2.6;python2.5;python2.4;python2.3;python2.2") |
31 |
set(PYTHON_INCLUDE_DIRS "/usr/include/$pyver;/usr/local/include/$pyver;/usr/$pyver/include;/usr/local/$pyver/include;$prefix/include/$pyver;$prefix/$pyver/include") |
32 |
set(PYTHON_LIBRARY_DIRS "/usr/lib${LIB_SUFFIX};/usr/local/lib${LIB_SUFFIX};/usr/lib${LIB_SUFFIX}/$pyver/config") |
33 |
set(PYTHON_LIBS "boost_python-gcc-mt;boost_python-mt;boost_python-gcc-mt-1_33;boost_python-gcc-mt-1_33_1;boost_python;boost_python-gcc-mt-1_32;boost_python") |
34 |
|
35 |
if(WIN32) |
36 |
set(PythonLibs_FIND_VERSION 2.7.0) |
37 |
find_package(PythonLibs) |
38 |
find_package(Boost COMPONENTS python QUIET) |
39 |
if(PYTHONLIBS_FOUND AND Boost_FOUND) |
40 |
set(BOOST_PYTHON_INCLUDES ${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIR}) |
41 |
set(BOOST_PYTHON_LIBS ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES}) |
42 |
endif(PYTHONLIBS_FOUND AND Boost_FOUND) |
43 |
else(WIN32) |
44 |
# 1st: check for boost/shared_ptr.hpp |
45 |
check_include_file_cxx(boost/shared_ptr.hpp HAVE_BOOST_SHARED_PTR_HPP) |
46 |
|
47 |
if(HAVE_BOOST_SHARED_PTR_HPP) |
48 |
|
49 |
# try pkg-config next |
50 |
set(_found FALSE) |
51 |
foreach(_pyver ${PYTHON_VERSIONS}) |
52 |
if(NOT _found) |
53 |
pkg_check_modules(_python QUIET ${_pyver}) |
54 |
if (_python_FOUND) |
55 |
find_package(Boost 1.33 COMPONENTS python) |
56 |
if (Boost_PYTHON_FOUND) |
57 |
set(_found TRUE) |
58 |
set(BOOST_PYTHON_INCLUDES "${_python_INCLUDE_DIRS};${Boost_INCLUDE_DIRS}") |
59 |
set(BOOST_PYTHON_LIBS "${_python_LDFLAGS} ${Boost_PYTHON_LIBRARY}") |
60 |
endif(Boost_PYTHON_FOUND) |
61 |
endif(_python_FOUND) |
62 |
endif(NOT _found) |
63 |
endforeach(_pyver ${PYTHON_VERSIONS}) |
64 |
|
65 |
endif(HAVE_BOOST_SHARED_PTR_HPP) |
66 |
|
67 |
if(HAVE_BOOST_SHARED_PTR_HPP AND NOT _found) |
68 |
# save the old flags and setting the new ones |
69 |
set(_save_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) |
70 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}") |
71 |
|
72 |
foreach(_pyver ${PYTHON_VERSIONS}) |
73 |
if(NOT _found) |
74 |
foreach(_pydir ${PYTHON_INCLUDE_DIRS}) |
75 |
|
76 |
if(NOT _found) |
77 |
string(REPLACE "$pyver" "${_pyver}" _pydir ${_pydir}) |
78 |
string(REPLACE "$prefix" "${CMAKE_INSTALL_PREFIX}" _pydir ${_pydir}) |
79 |
|
80 |
if(EXISTS ${_pydir}) |
81 |
if(EXISTS ${_pydir}/Python.h) |
82 |
|
83 |
foreach(_pylibdir ${PYTHON_LIBRARY_DIRS}) |
84 |
|
85 |
if(NOT _found) |
86 |
string(REPLACE "$pyver" ${_pyver} _pylibdir ${_pylibdir}) |
87 |
|
88 |
foreach(_pblib ${PYTHON_LIBS}) |
89 |
|
90 |
if(NOT _found) |
91 |
|
92 |
set(CMAKE_REQUIRED_FLAGS "-L${_pylibdir}") |
93 |
set(CMAKE_REQUIRED_INCLUDES ${_pydir}) |
94 |
set(CMAKE_REQUIRED_LIBRARIES ${_pblib} ${_pyver}) |
95 |
|
96 |
check_cxx_source_compiles(" |
97 |
#include <boost/python.hpp> |
98 |
const char* greet() { return \"Hello world!\"; } |
99 |
BOOST_PYTHON_MODULE(hello) { boost::python::def(\"greet\", greet); } |
100 |
|
101 |
int main() { return 0; } |
102 |
|
103 |
// some vars, in case of the compilation fail... |
104 |
// python include dir: ${_pydir} |
105 |
// python lib dir: ${_pylibdir} |
106 |
// boost python lib: ${_pblib} |
107 |
|
108 |
" boost_python_${_pylibdir}_${_pydir}_${_pblib}_compile ) |
109 |
|
110 |
set(CMAKE_REQUIRED_FLAGS) |
111 |
set(CMAKE_REQUIRED_INCLUDES) |
112 |
set(CMAKE_REQUIRED_LIBRARIES) |
113 |
|
114 |
if(boost_python_${_pylibdir}_${_pydir}_${_pblib}_compile) |
115 |
|
116 |
set(_found TRUE) |
117 |
|
118 |
set(BOOST_PYTHON_INCLUDES ${_pydir}) |
119 |
set(BOOST_PYTHON_LIBS "-l${_pyver} -L${_pylibdir} -l${_pblib}") |
120 |
|
121 |
endif(boost_python_${_pylibdir}_${_pydir}_${_pblib}_compile) |
122 |
|
123 |
endif(NOT _found) |
124 |
|
125 |
endforeach(_pblib ${PYTHON_LIBS}) |
126 |
|
127 |
endif(NOT _found) |
128 |
|
129 |
endforeach(_pylibdir ${PYTHON_LIBRARY_DIRS}) |
130 |
|
131 |
endif(EXISTS ${_pydir}/Python.h) |
132 |
endif(EXISTS ${_pydir}) |
133 |
|
134 |
endif(NOT _found) |
135 |
|
136 |
endforeach(_pydir ${PYTHON_INCLUDE_DIRS}) |
137 |
|
138 |
endif(NOT _found) |
139 |
|
140 |
endforeach(_pyver ${PYTHON_VERSIONS}) |
141 |
|
142 |
set(CMAKE_CXX_FLAGS ${_save_CMAKE_CXX_FLAGS}) |
143 |
|
144 |
endif(HAVE_BOOST_SHARED_PTR_HPP AND NOT _found) |
145 |
endif(WIN32) |
146 |
|
147 |
if(BOOST_PYTHON_INCLUDES AND BOOST_PYTHON_LIBS) |
148 |
set(BOOST_PYTHON_FOUND TRUE) |
149 |
endif(BOOST_PYTHON_INCLUDES AND BOOST_PYTHON_LIBS) |
150 |
|
151 |
if(BOOST_PYTHON_FOUND) |
152 |
if(NOT BoostPython_FIND_QUIETLY) |
153 |
message(STATUS "Found Boost+Python: libs ${BOOST_PYTHON_LIBS}, headers ${BOOST_PYTHON_INCLUDES}") |
154 |
endif(NOT BoostPython_FIND_QUIETLY) |
155 |
set(KIG_ENABLE_PYTHON_SCRIPTING 1) |
156 |
else (BOOST_PYTHON_FOUND) |
157 |
if (BoostPython_FIND_REQUIRED) |
158 |
message(FATAL_ERROR "Could NOT find Boost+Python") |
159 |
endif(BoostPython_FIND_REQUIRED) |
160 |
set(KIG_ENABLE_PYTHON_SCRIPTING 0) |
161 |
endif(BOOST_PYTHON_FOUND) |
162 |
|
163 |
mark_as_advanced(BOOST_PYTHON_INCLUDES BOOST_PYTHON_LIBS) |