cmake/cython/setup.in.py
Go to the documentation of this file.
1 #
2 # This file was generated by jrl-cmakemodules, do not modify
3 #
4 
5 try:
6  from setuptools import setup
7  from setuptools import Extension
8 except ImportError:
9  from distutils.core import setup
10  from distutils.extension import Extension
11 
12 from Cython.Build import cythonize
13 
14 import hashlib
15 import os
16 import re
17 import sys
18 
19 try:
20  from numpy import get_include as numpy_get_include
21 except ImportError:
22 
23  def numpy_get_include():
24  return ""
25 
26 
27 win32_build = os.name == "nt"
28 linux_build = sys.platform.startswith("linux")
29 
30 sha512 = hashlib.sha512()
31 src_files = filter(
32  len, "@CYTHON_BINDINGS_SOURCES@;@CYTHON_BINDINGS_GENERATE_SOURCES@".split(";")
33 )
34 
35 
36 def absolute(src):
37  if os.path.isabs(src):
38  return src
39  else:
40  return "{}/{}".format("@CMAKE_CURRENT_SOURCE_DIR@", src)
41 
42 
43 src_files = map(absolute, src_files)
44 for f in src_files:
45  chunk = 2**12
46  with open(f, "r") as fd:
47  while True:
48  data = fd.read(chunk)
49  if data:
50  sha512.update(data.encode("ascii"))
51  else:
52  break
53 version_hash = sha512.hexdigest()[:7]
54 
55 
56 def get_lib_name(path):
57  ret = os.path.basename(path)
58  dot_idx = ret.find(".")
59  if dot_idx == -1:
60  return ret
61  return ret[0:dot_idx]
62 
63 
64 class pkg_config(object):
65  def __init__(self):
66  compile_args = "@CYTHON_BINDINGS_COMPILE_DEFINITIONS@"
67  self.compile_args = ["-D" + x for x in compile_args.split(";") if len(x)]
68  self.compile_args = list(set(self.compile_args))
69  include_dirs = "@CYTHON_BINDINGS_INCLUDE_DIRECTORIES@"
70  include_dirs += ";{}".format(numpy_get_include())
71  self.include_dirs = [x for x in include_dirs.split(";") if len(x)]
72  self.include_dirs.append("@CMAKE_CURRENT_SOURCE_DIR@/include")
73  self.include_dirs = list(set(self.include_dirs))
74  library_dirs = "@CYTHON_BINDINGS_LINK_FLAGS@"
75  self.library_dirs = [x for x in library_dirs.split(";") if len(x)]
76  self.libraries = [
77  re.sub("^lib", "", get_lib_name(lib))
78  for lib in "@CYTHON_BINDINGS_LIBRARIES@".split(";")
79  if len(lib)
80  ]
81  self.libraries = list(set(self.libraries))
82  self.library_dirs += [
83  os.path.dirname(lib)
84  for lib in "@CYTHON_BINDINGS_TARGET_FILES@".split(";")
85  if len(lib)
86  ]
87  self.library_dirs = list(set(self.library_dirs))
88  self.link_args = []
89  if linux_build:
90  for lib in self.libraries:
91  self.link_args += ["-Wl,--no-as-needed", "-l{}".format(lib)]
92  self.libraries = []
93  if not win32_build:
94  self.extra_objects = [
95  lib
96  for lib in "@CYTHON_BINDINGS_STATIC_LIBRARIES@".split(";")
97  if len(lib)
98  ]
99  else:
100  self.extra_objects = []
101 
102 
103 config = pkg_config()
104 
105 
106 def cxx_standard(value):
107  try:
108  return int(value)
109  except Exception:
110  return 0
111 
112 
114  if lhs == 98:
115  return 1
116  return lhs
117 
118 
119 cxx_standard = max(
120  map(cxx_standard, "0;@CYTHON_BINDINGS_CXX_STANDARD@".split(";")),
121  key=cxx_standard_cmp,
122 )
123 if cxx_standard != 0:
124  if not win32_build:
125  config.compile_args.append("-std=c++{}".format(cxx_standard))
126  # In C++17 the register keyword is unused and reserved,
127  # GCC still accepts it with a warning but clang errors by default
128  # It is used in Python 2.7 header file and so we need this flag
129  if cxx_standard >= 17:
130  config.compile_args.append("-Wno-register")
131  else:
132  if cxx_standard > 17:
133  config.compile_args.append("/std:c++latest")
134  elif cxx_standard == 17:
135  config.compile_args.append("/std:c++17")
136 
137 if win32_build:
138  config.compile_args.append("-DWIN32")
139  if "$<CONFIGURATION>".lower() == "debug":
140  config.compile_args += ["-Zi", "/Od"]
141  config.link_args += ["-debug"]
142 
143 
144 def GenExtension(name):
145  pyx_src = name.replace(".", "/")
146  pyx_src = pyx_src + ".pyx"
147  ext_src = pyx_src
148  return Extension(
149  name,
150  [ext_src],
151  extra_compile_args=config.compile_args,
152  include_dirs=config.include_dirs,
153  library_dirs=config.library_dirs,
154  libraries=config.libraries,
155  extra_link_args=config.link_args,
156  extra_objects=config.extra_objects,
157  )
158 
159 
160 extensions = [GenExtension(x) for x in "@CYTHON_BINDINGS_MODULES@".split(";")]
161 
162 extensions = cythonize(extensions)
163 
164 packages = [p.split(".")[0] for p in "@CYTHON_BINDINGS_MODULES@".split(";")]
165 package_data = {
166  p: list(
167  map(
168  lambda x: x.replace(p + "/", ""),
169  filter(
170  lambda x: x.startswith(p + "/"),
171  "@CYTHON_BINDINGS_EXPORT_SOURCES@".split(";"),
172  ),
173  )
174  )
175  for p in packages
176 }
177 
178 setup(
179  name="@CYTHON_BINDINGS_PACKAGE_NAME@",
180  version="@CYTHON_BINDINGS_VERSION@+{}".format(version_hash),
181  ext_modules=extensions,
182  packages=packages,
183  package_data=package_data,
184 )
setup
setup::GenExtension
def GenExtension(name)
setup::absolute
def absolute(src)
setup::get_lib_name
def get_lib_name(path)
set
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
setup::cxx_standard_cmp
def cxx_standard_cmp(lhs)
setup::cxx_standard
cxx_standard
Definition: models/example-robot-data/cmake/cython/setup.in.py:106
setup::numpy_get_include
def numpy_get_include()
Definition: cmake/cython/setup.in.py:23
append-urdf-model-with-another-model.open
open
Definition: append-urdf-model-with-another-model.py:78
boost::fusion::append
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:32
setup::pkg_config
Definition: cmake/cython/setup.in.py:64
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:181


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:32