Skip to content

Commit aed55c8

Browse files
committed
Reworked the way C/C++ header files are used and installed
1 parent 5cbb137 commit aed55c8

21 files changed

+78
-83
lines changed

include/Includes/pysfml/audio.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
cimport sfml as sf
99
from pysfml.system cimport Int16
1010

11-
cdef extern from "pysfml/audio.h":
11+
cdef extern from "pysfml/audio/audio.h":
1212

1313
cdef class Chunk[type PyChunkType, object PyChunkObject]:
1414
cdef class sfml.audio.Chunk [object PyChunkObject]:
1515
cdef Int16* m_samples
1616
cdef size_t m_sampleCount
1717
cdef bint delete_this
1818

19-
cdef extern from "pysfml/audio_api.h":
19+
cdef extern from "pysfml/audio/audio_api.h":
2020
cdef void import_sfml__audio()
2121

2222
cdef object create_chunk()

include/Includes/pysfml/graphics.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cimport sfml as sf
99
from pysfml.system cimport Vector2
1010
from pysfml.system cimport NumericObject
1111

12-
cdef extern from "pysfml/graphics.h":
12+
cdef extern from "pysfml/graphics/graphics.h":
1313
cdef class sfml.graphics.Rect [object PyRectObject]:
1414
cdef sf.Rect[NumericObject] *p_this
1515

@@ -49,7 +49,7 @@ cdef extern from "pysfml/graphics.h":
4949
cdef class sfml.graphics.RenderStates [object PyRenderStatesObject]:
5050
pass
5151

52-
cdef extern from "pysfml/graphics_api.h":
52+
cdef extern from "pysfml/graphics/graphics_api.h":
5353
cdef void import_sfml__graphics()
5454

5555
cdef Color wrap_color(sf.Color *p)

include/Includes/pysfml/network.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
cimport sfml as sf
99

10-
cdef extern from "pysfml/network_api.h":
10+
cdef extern from "pysfml/network/network_api.h":
1111
cdef void import_sfml__network()

include/Includes/pysfml/system.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
cimport sfml as sf
99

10-
cdef extern from "pysfml/NumericObject.hpp":
10+
cdef extern from "pysfml/system/NumericObject.hpp":
1111
cdef cppclass NumericObject:
1212
NumericObject()
1313
NumericObject(object)
1414

1515
object get()
1616
void set(object)
1717

18-
cdef extern from "pysfml/system.h":
18+
cdef extern from "pysfml/system/system.h":
1919
cdef class sfml.system.Vector2 [object PyVector2Object]:
2020
cdef sf.Vector2[NumericObject] *p_this
2121

@@ -25,7 +25,7 @@ cdef extern from "pysfml/system.h":
2525
cdef class sfml.system.Time [object PyTimeObject]:
2626
cdef sf.Time *p_this
2727

28-
cdef extern from "pysfml/system_api.h":
28+
cdef extern from "pysfml/system/system_api.h":
2929
int import_sfml__system()
3030

3131
object popLastErrorMessage()

include/Includes/pysfml/window.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
cimport sfml as sf
99
from sfml cimport Uint8
1010

11-
cdef extern from "pysfml/window.h":
11+
cdef extern from "pysfml/window/window.h":
1212
cdef class sfml.window.VideoMode [object PyVideoModeObject]:
1313
cdef sf.VideoMode *p_this
1414
cdef bint delete_this
@@ -29,7 +29,7 @@ cdef extern from "pysfml/window.h":
2929
cdef bint m_visible
3030
cdef bint m_vertical_synchronization
3131

32-
cdef extern from "pysfml/window_api.h":
32+
cdef extern from "pysfml/window/window_api.h":
3333
cdef void import_sfml__window()
3434

3535
cdef VideoMode wrap_videomode(sf.VideoMode *p, bint d)

setup.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,57 @@
1616
arch = "x64"
1717

1818
class CythonBuildExt(build_ext):
19-
""" Updated version of cython build_ext command to move
20-
the generated API headers to include/pysfml directory
19+
""" Updated version of cython build_ext command to deal with the
20+
generated API headers. C/C++ header files are all moved to the
21+
temporary build directory before being properly installed on
22+
the system.
2123
"""
2224

2325
def cython_sources(self, sources, extension):
26+
27+
# cythonize .pxd source files
2428
ret = build_ext.cython_sources(self, sources, extension)
2529

2630
# should result the module name; e.g, graphics[.pyx]
2731
module = os.path.basename(sources[0])[:-4]
2832

29-
# move its headers (foo.h and foo_api.h) to include/pysfml
30-
destination = os.path.join('include', 'pysfml')
31-
32-
filename = module + '.h'
33-
source = os.path.join('src', 'sfml', module, filename)
34-
if os.path.isfile(source):
35-
try:
36-
shutil.move(source, destination)
37-
except shutil.Error:
38-
pass
39-
40-
filename = module + '_api.h'
41-
source = os.path.join('src', 'sfml', module, filename)
42-
if os.path.isfile(source):
43-
try:
44-
shutil.move(source, destination)
45-
except shutil.Error:
46-
pass
33+
# prepare a list with all header files related to the module (*.hpp, *_api.h, *.h)
34+
header_files = glob(os.path.join('src', 'sfml', module, '*.hpp'))
4735

48-
return ret
36+
header_files.append(os.path.join('src', 'sfml', module, module + '.h'))
37+
header_files.append(os.path.join('src', 'sfml', module, module + '_api.h'))
38+
39+
# deal with exceptions
40+
if module == "network":
41+
header_files.remove(os.path.join('src', 'sfml', module, module + '.h'))
42+
header_files.remove(os.path.join('src', 'sfml', module, module + '_api.h'))
43+
44+
# create the temporary destination in the build directory
45+
destination = os.path.join(self.build_temp, 'include', 'pysfml', module)
46+
47+
if not os.path.exists(destination):
48+
os.makedirs(destination)
49+
50+
# move all header files to the build directory
51+
for header_file in header_files:
52+
if os.path.isfile(header_file):
53+
try:
54+
shutil.copy(header_file, destination)
55+
except shutil.Error:
56+
pass
57+
58+
# add the temporary header directory to compilation options
59+
self.compiler.include_dirs.append(os.path.join(self.build_temp, 'include'))
60+
61+
# update data_files to install the files on the system
4962

63+
# On Windows: C:\Python27\include\pysfml\*_api.h
64+
# On Unix: /usr/local/include/pysfml/*_api.h
65+
install_directory = os.path.join(sys.exec_prefix, 'include', 'pysfml', module)
66+
files_to_install = [os.path.join(self.build_temp, 'include', 'pysfml', module, os.path.basename(header_file)) for header_file in header_files]
67+
data_files.append((install_directory, files_to_install))
68+
69+
return ret
5070

5171
modules = ['system', 'window', 'graphics', 'audio', 'network']
5272

@@ -57,7 +77,6 @@ def cython_sources(self, sources, extension):
5777
include_path = os.path.join('include', 'pysfml')
5878
source_path = os.path.join('src', 'sfml')
5979

60-
6180
# clean the directory (remove generated C++ files by Cython)
6281
def remove_if_exist(filename):
6382
if os.path.isfile(filename):
@@ -86,7 +105,7 @@ def remove_if_exist(filename):
86105
extension = lambda name, files, libs: Extension(
87106
name='sfml.' + name,
88107
sources= [os.path.join('src', 'sfml', name, filename) for filename in files],
89-
include_dirs=['include', 'include/Includes'],
108+
include_dirs=['include/Includes'],
90109
language='c++',
91110
libraries=libs,
92111
extra_compile_args=['-fpermissive']
@@ -119,29 +138,10 @@ def remove_if_exist(filename):
119138

120139
major, minor, _, _ , _ = sys.version_info
121140

122-
files = []
123-
124-
# Install C headers
125-
c_api_headers = []
126-
c_api_headers.append(os.path.join(include_path, 'system.h'))
127-
c_api_headers.append(os.path.join(include_path, 'system_api.h'))
128-
c_api_headers.append(os.path.join(include_path, 'NumericObject.hpp'))
129-
c_api_headers.append(os.path.join(include_path, 'window.h'))
130-
c_api_headers.append(os.path.join(include_path, 'window_api.h'))
131-
c_api_headers.append(os.path.join(include_path, 'graphics.h'))
132-
c_api_headers.append(os.path.join(include_path, 'graphics_api.h'))
133-
c_api_headers.append(os.path.join(include_path, 'audio_api.h'))
134-
135-
if platform.system() == 'Windows':
136-
# On Windows: C:\Python27\include\pysfml\*_api.h
137-
files = [(sys.exec_prefix +'\\include\\pysfml', c_api_headers)]
138-
else:
139-
# On Unix: /usr/local/include/pysfml/*_api.h
140-
files = [(sys.exec_prefix + '/include/pysfml', c_api_headers)]
141-
141+
data_files = []
142142
if platform.system() == 'Windows':
143143
dlls = [("Lib\\site-packages\\sfml", glob('extlibs/sfml/bin/' + arch + '/*.dll'))]
144-
files += dlls
144+
data_files += dlls
145145

146146
with open('README.rst', 'r') as f:
147147
long_description = f.read()
@@ -153,7 +153,7 @@ def remove_if_exist(filename):
153153
ext_modules=ext_modules,
154154
package_dir={'': 'src'},
155155
packages=['sfml'],
156-
data_files=files,
156+
data_files=data_files,
157157
version='2.2.0',
158158
description='Python bindings for SFML',
159159
long_description=long_description,

src/sfml/audio/DerivableSoundRecorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* license.
88
*/
99

10-
#include "DerivableSoundRecorder.hpp"
10+
#include <pysfml/audio/DerivableSoundRecorder.hpp>
1111
#include <iostream>
1212

1313
DerivableSoundRecorder::DerivableSoundRecorder(void* pyobj):

src/sfml/audio/DerivableSoundRecorder.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
#include "Python.h"
1414
#include <SFML/Audio.hpp>
15-
#include "pysfml/audio_api.h"
16-
15+
#include <pysfml/audio/audio_api.h>
1716

1817
class DerivableSoundRecorder : public sf::SoundRecorder
1918
{

src/sfml/audio/DerivableSoundStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* license.
88
*/
99

10-
#include "DerivableSoundStream.hpp"
10+
#include <pysfml/audio/DerivableSoundStream.hpp>
1111

1212
DerivableSoundStream::DerivableSoundStream(void* pyobj):
1313
sf::SoundStream (),

src/sfml/audio/DerivableSoundStream.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
#include "Python.h"
1414
#include <SFML/Audio.hpp>
15-
#include "pysfml/NumericObject.hpp"
16-
#include "pysfml/audio_api.h"
17-
#include "pysfml/system_api.h"
15+
#include <pysfml/audio/audio_api.h>
16+
#include <pysfml/system/NumericObject.hpp>
17+
#include <pysfml/system/system_api.h>
1818

1919
class DerivableSoundStream : public sf::SoundStream
2020
{

0 commit comments

Comments
 (0)