Builds using cmake instead of the python setuptools implicit build
| 117 | |
| 118 | __metaclass__ = type |
| 119 | class BuildCMakeExt(build_ext, object): |
| 120 | """ |
| 121 | Builds using cmake instead of the python setuptools implicit build |
| 122 | """ |
| 123 | def run(self): |
| 124 | """ |
| 125 | Perform build_cmake before doing the 'normal' stuff |
| 126 | """ |
| 127 | for extension in self.extensions: |
| 128 | self.build_cmake(extension) |
| 129 | super(BuildCMakeExt, self).run() |
| 130 | |
| 131 | def build_cmake(self, extension): |
| 132 | """ |
| 133 | The steps required to build the extension |
| 134 | """ |
| 135 | self.announce("Preparing the build environment", level=3) |
| 136 | build_dir = os.path.join(self.build_temp) |
| 137 | extension_path = os.path.abspath(os.path.dirname(self.get_ext_fullpath(extension.name))) |
| 138 | os.makedirs(build_dir) |
| 139 | os.makedirs(extension_path) |
| 140 | python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1]) |
| 141 | |
| 142 | # Now that the necessary directories are created, build |
| 143 | self.announce("Configuring cmake project", level=3) |
| 144 | cmake_args = ['-DPYTHON_EXECUTABLE=' + sys.executable, |
| 145 | '-DUSE_OCV_BGFG=ON', |
| 146 | '-DUSE_OCV_KCF=ON', |
| 147 | '-DSILENT_WORK=ON', |
| 148 | '-DBUILD_EXAMPLES=OFF', |
| 149 | '-DBUILD_ASYNC_DETECTOR=OFF', |
| 150 | '-DBUILD_CARS_COUNTING=OFF', |
| 151 | '-DBUILD_YOLO_LIB=OFF', |
| 152 | '-DBUILD_YOLO_TENSORRT=OFF', |
| 153 | '-DMTRACKER_PYTHON=ON'] |
| 154 | if not os.path.exists(self.build_temp): |
| 155 | os.makedirs(self.build_temp) |
| 156 | self.spawn(['cmake', '-H'+extension.sourcedir, '-B'+self.build_temp]+ cmake_args) |
| 157 | |
| 158 | self.announce("Building binaries", level=3) |
| 159 | self.spawn(["cmake", "--build", self.build_temp, |
| 160 | "--config", "Release", '--', '-j8']) |
| 161 | |
| 162 | # Build finished, now copy the files into the copy directory |
| 163 | # The copy directory is the parent directory of the extension (.pyd) |
| 164 | self.announce("Moving built python module", level=3) |
| 165 | |
| 166 | bin_dir = "build" # self.build_temp |
| 167 | self.distribution.bin_dir = bin_dir |
| 168 | list_bin = os.listdir(bin_dir) |
| 169 | print("bin_dir:", bin_dir, ", extension_path:", extension_path, ", list_bin:", list_bin) |
| 170 | pyd_path = [] |
| 171 | for _pyd in list_bin: |
| 172 | print("_pyd:", _pyd) |
| 173 | if os.path.isfile(os.path.join(bin_dir, _pyd)) and os.path.splitext(_pyd)[0].startswith(PACKAGE_NAME) and os.path.splitext(_pyd)[1] in [".pyd", ".so"]: |
| 174 | pyd_path.append(os.path.join(bin_dir, _pyd)) |
| 175 | print("pyd_path:", pyd_path) |
| 176 | pyd_path = pyd_path[0] |
nothing calls this directly
no outgoing calls
no test coverage detected