Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa210d4

Browse files
authored
Merge pull request#2 from benjaminjack/revert-1-simplify-build-system-using-skbuild
Revert "setup: simplify build system using scikit-build"
2 parentsb978da8 +7ea8e23 commitaa210d4

File tree

2 files changed

+93
-16
lines changed

2 files changed

+93
-16
lines changed

‎CMakeLists.txt‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
cmake_minimum_required(VERSION 2.8.12)
2-
32
project(python_cpp_example)
43

54
SET(SOURCE_DIR"src/python_cpp_example")
@@ -15,9 +14,7 @@ SET(TESTS ${SOURCES}
1514
# Generate a test executable
1615
include_directories(lib/catch/include)
1716
add_executable("${PROJECT_NAME}_test"${TESTS})
18-
set_target_properties("${PROJECT_NAME}_test" PROPERTIESRUNTIME_OUTPUT_DIRECTORY${CMAKE_CURRENT_SOURCE_DIR}/tests/bin)
1917

2018
# Generate python module
2119
add_subdirectory(lib/pybind11)
22-
pybind11_add_module(python_cpp_example${SOURCES}"${SOURCE_DIR}/bindings.cpp")
23-
install(TARGETS python_cpp_exampleDESTINATION src/python_cpp_example)
20+
pybind11_add_module(python_cpp_example${SOURCES}"${SOURCE_DIR}/bindings.cpp")

‎setup.py‎

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,108 @@
11
#! /usr/bin/env python3
22

3-
from __future__importprint_function
4-
fromosimportsys,path
3+
importos
4+
importre
5+
importsys
6+
importsysconfig
7+
importplatform
8+
importsubprocess
59

6-
try:
7-
fromskbuildimportsetup
8-
exceptImportError:
9-
print('scikit-build is required to build from source.',file=sys.stderr)
10-
print('Please run:',file=sys.stderr)
11-
print('',file=sys.stderr)
12-
print(' python -m pip install scikit-build')
13-
sys.exit(1)
10+
fromdistutils.versionimportLooseVersion
11+
fromsetuptoolsimportsetup,Extension,find_packages
12+
fromsetuptools.command.build_extimportbuild_ext
13+
fromsetuptools.command.testimporttestasTestCommand
14+
fromshutilimportcopyfile,copymode
1415

15-
fromsetuptoolsimportfind_packages
16+
17+
classCMakeExtension(Extension):
18+
def__init__(self,name,sourcedir=''):
19+
Extension.__init__(self,name,sources=[])
20+
self.sourcedir=os.path.abspath(sourcedir)
21+
22+
23+
classCMakeBuild(build_ext):
24+
defrun(self):
25+
try:
26+
out=subprocess.check_output(['cmake','--version'])
27+
exceptOSError:
28+
raiseRuntimeError(
29+
"CMake must be installed to build the following extensions: "+
30+
", ".join(e.nameforeinself.extensions))
31+
32+
ifplatform.system()=="Windows":
33+
cmake_version=LooseVersion(re.search(r'version\s*([\d.]+)',
34+
out.decode()).group(1))
35+
ifcmake_version<'3.1.0':
36+
raiseRuntimeError("CMake >= 3.1.0 is required on Windows")
37+
38+
forextinself.extensions:
39+
self.build_extension(ext)
40+
41+
defbuild_extension(self,ext):
42+
extdir=os.path.abspath(
43+
os.path.dirname(self.get_ext_fullpath(ext.name)))
44+
cmake_args= ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY='+extdir,
45+
'-DPYTHON_EXECUTABLE='+sys.executable]
46+
47+
cfg='Debug'ifself.debugelse'Release'
48+
build_args= ['--config',cfg]
49+
50+
ifplatform.system()=="Windows":
51+
cmake_args+= ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
52+
cfg.upper(),
53+
extdir)]
54+
ifsys.maxsize>2**32:
55+
cmake_args+= ['-A','x64']
56+
build_args+= ['--','/m']
57+
else:
58+
cmake_args+= ['-DCMAKE_BUILD_TYPE='+cfg]
59+
build_args+= ['--','-j2']
60+
61+
env=os.environ.copy()
62+
env['CXXFLAGS']='{} -DVERSION_INFO=\\"{}\\"'.format(
63+
env.get('CXXFLAGS',''),
64+
self.distribution.get_version())
65+
ifnotos.path.exists(self.build_temp):
66+
os.makedirs(self.build_temp)
67+
subprocess.check_call(['cmake',ext.sourcedir]+cmake_args,
68+
cwd=self.build_temp,env=env)
69+
subprocess.check_call(['cmake','--build','.']+build_args,
70+
cwd=self.build_temp)
71+
# Copy *_test file to tests directory
72+
test_bin=os.path.join(self.build_temp,'python_cpp_example_test')
73+
self.copy_test_file(test_bin)
74+
print()# Add an empty line for cleaner output
75+
76+
defcopy_test_file(self,src_file):
77+
'''
78+
Copy ``src_file`` to ``dest_file`` ensuring parent directory exists.
79+
By default, message like `creating directory /path/to/package` and
80+
`copying directory /src/path/to/package -> path/to/package` are displayed on standard output. Adapted from scikit-build.
81+
'''
82+
# Create directory if needed
83+
dest_dir=os.path.join(os.path.dirname(
84+
os.path.abspath(__file__)),'tests','bin')
85+
ifdest_dir!=""andnotos.path.exists(dest_dir):
86+
print("creating directory {}".format(dest_dir))
87+
os.makedirs(dest_dir)
88+
89+
# Copy file
90+
dest_file=os.path.join(dest_dir,os.path.basename(src_file))
91+
print("copying {} -> {}".format(src_file,dest_file))
92+
copyfile(src_file,dest_file)
93+
copymode(src_file,dest_file)
1694

1795
setup(
1896
name='python_cpp_example',
19-
version='0.3',
97+
version='0.2',
2098
author='Benjamin Jack',
2199
author_email='benjamin.r.jack@gmail.com',
22100
description='A hybrid Python/C++ test project',
23101
long_description='',
24102
packages=find_packages('src'),
25103
package_dir={'':'src'},
104+
ext_modules=[CMakeExtension('python_cpp_example/python_cpp_example')],
105+
cmdclass=dict(build_ext=CMakeBuild),
26106
test_suite='tests',
27107
zip_safe=False,
28108
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp