Skip to content

Commit 01d3110

Browse files
author
wonder
committed
CMake: improved build of python bindings
- all intermediate files are out of source - bindings are built only when libs are changed, not everytime git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6503 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 68a20f0 commit 01d3110

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

python/CMakeLists.txt

+32-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11

2+
IF (WIN32)
3+
SET(BINDINGS_CORE_LIB ${CMAKE_CURRENT_BINARY_DIR}/core/core.pyd)
4+
SET(BINDINGS_GUI_LIB ${CMAKE_CURRENT_BINARY_DIR}/gui/gui.pyd)
5+
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.dll)
6+
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.dll)
7+
ELSE (WIN32)
8+
SET(BINDINGS_CORE_LIB ${CMAKE_CURRENT_BINARY_DIR}/core/core.so)
9+
SET(BINDINGS_GUI_LIB ${CMAKE_CURRENT_BINARY_DIR}/gui/gui.so)
10+
SET(QGIS_CORE_LIB ${CMAKE_BINARY_DIR}/src/core/libqgis_core.so)
11+
SET(QGIS_GUI_LIB ${CMAKE_BINARY_DIR}/src/gui/libqgis_gui.so)
12+
ENDIF (WIN32)
13+
14+
SET (BINDINGS_LIBS ${BINDING_CORE_LIB} ${BINDINGS_GUI_LIB})
15+
16+
SET (BINDINGS_CORE_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/core/Makefile)
17+
SET (BINDINGS_GUI_MAKEFILE ${CMAKE_CURRENT_BINARY_DIR}/gui/Makefile)
218

3-
ADD_CUSTOM_TARGET (python ALL DEPENDS run_sip compile_python_core compile_python_gui)
419

20+
# 'python' target will force to build bindings libs for core and gui
21+
ADD_CUSTOM_TARGET (python ALL DEPENDS ${BINDINGS_CORE_LIB} ${BINDINGS_GUI_LIB})
22+
23+
# don't run python before the libs are built
524
ADD_DEPENDENCIES (python qgis_core qgis_gui)
625

26+
727
# Step 1: during configuration
828
# create file configure.py from configure.py.in
929
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/configure.py.in
10-
${CMAKE_CURRENT_SOURCE_DIR}/configure.py)
30+
${CMAKE_CURRENT_BINARY_DIR}/configure.py)
1131

1232
# Step 2: during make
1333
# run python configure.py
14-
ADD_CUSTOM_COMMAND(OUTPUT run_sip PRE_BUILD
34+
# it will run SIP utility to generate sources and will prepare makefiles
35+
# should be run everytime core or gui library has been changed
36+
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_CORE_MAKEFILE} ${BINDINGS_GUI_MAKEFILE} PRE_BUILD
1537
COMMAND ${PYTHON_EXECUTABLE}
16-
ARGS ${CMAKE_CURRENT_SOURCE_DIR}/configure.py)
38+
ARGS ${CMAKE_CURRENT_BINARY_DIR}/configure.py
39+
DEPENDS ${QGIS_CORE_LIB} ${QGIS_GUI_LIB})
1740

1841
# Step 3: run make in core and gui subdirs
19-
ADD_CUSTOM_COMMAND(OUTPUT compile_python_core PRE_LINK
42+
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_CORE_LIB} PRE_LINK
2043
COMMAND ${CMAKE_MAKE_PROGRAM}
2144
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/core
22-
DEPENDS run_sip)
23-
ADD_CUSTOM_COMMAND(OUTPUT compile_python_gui PRE_LINK
45+
DEPENDS ${BINDINGS_CORE_MAKEFILE})
46+
ADD_CUSTOM_COMMAND(OUTPUT ${BINDINGS_GUI_LIB} PRE_LINK
2447
COMMAND ${CMAKE_MAKE_PROGRAM}
2548
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gui
26-
DEPENDS run_sip)
49+
DEPENDS ${BINDINGS_GUI_MAKEFILE})
2750

2851

2952
# python's site-packages dir: bindings will be installed here
@@ -43,12 +66,5 @@ ENDIF (UNIX)
4366
EXEC_PROGRAM(${PYTHON_EXECUTABLE} ARGS -c "\"${CMD}\"" OUTPUT_VARIABLE SITE_PKG_PATH)
4467

4568
# Step 4: install built libs to python's site packages
46-
IF (WIN32)
47-
SET(BINDINGS_LIBS ${CMAKE_CURRENT_BINARY_DIR}/core/core.pyd
48-
${CMAKE_CURRENT_BINARY_DIR}/gui/gui.pyd)
49-
ELSE (WIN32)
50-
SET(BINDINGS_LIBS ${CMAKE_CURRENT_BINARY_DIR}/core/core.so
51-
${CMAKE_CURRENT_BINARY_DIR}/gui/gui.so)
52-
ENDIF (WIN32)
69+
INSTALL(FILES __init__.py ${CMAKE_CURRENT_BINARY_DIR}/qgisconfig.py ${BINDINGS_LIBS} DESTINATION ${SITE_PKG_PATH}/qgis)
5370

54-
INSTALL(FILES __init__.py qgisconfig.py ${BINDINGS_LIBS} DESTINATION ${SITE_PKG_PATH}/qgis)

python/configure.py.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if not os.path.isdir("./gui"):
2020

2121
# The name of the SIP build file generated by SIP and used by the build
2222
# system.
23-
build_file_core = python_path + "/core/core.sbf"
24-
build_file_gui = python_path + "/gui/gui.sbf"
23+
build_file_core = src_path + "/python/core/core.sbf"
24+
build_file_gui = src_path + "/python/gui/gui.sbf"
2525

2626
# Get the SIP configuration information.
2727
config = PyQt4.pyqtconfig.Configuration()
@@ -99,7 +99,7 @@ for mk in [ makefile_core, makefile_gui ]:
9999
src_path+"/src/core/renderer",
100100
src_path+"/src/core/spatialindex",
101101
src_path+"/src/core/symbology",
102-
src_path,
102+
build_path, # qgsconfig.h, qgssvnversion.h
103103
gdal_inc_dir]
104104
mk.extra_cxxflags = ["-DCORE_EXPORT="]
105105

@@ -140,7 +140,7 @@ content = {
140140

141141
# This creates the qgisconfig.py module from the qgisconfig.py.in
142142
# template and the dictionary.
143-
sipconfig.create_config_module(python_path+"/qgisconfig.py", python_path+"/qgisconfig.py.in", content)
143+
sipconfig.create_config_module(build_path+"/python/qgisconfig.py", src_path+"/python/qgisconfig.py.in", content)
144144

145145
print "Done"
146146

0 commit comments

Comments
 (0)