def build_extensions(self): from setup_util import cpp_flag, has_flag, detect_openmp # enable these options only for clang, OSX if sys.platform == 'darwin': import sysconfig compiler = os.path.basename(sysconfig.get_config_var("CC")) if 'clang' in str(compiler): self.c_opts['unix'] += [ '-stdlib=libc++', '-mmacosx-version-min=10.7' ] ct = self.compiler.compiler_type opts = self.c_opts.get(ct, []) if ct == 'unix': opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) opts.append(cpp_flag(self.compiler)) if has_flag(self.compiler, '-fvisibility=hidden'): opts.append('-fvisibility=hidden') elif ct == 'msvc': opts.append('/std:c++17') opts.append('/bigobj') opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version()) # setup OpenMP support openmp_enabled, additional_libs = detect_openmp(self.compiler) if openmp_enabled: warnings.warn('enabled openmp') if sys.platform == 'darwin': omp_compiler_args = ['-fopenmp=libiomp5'] else: omp_compiler_args = ['-fopenmp'] omp_libraries = ['-l%s' % l for l in additional_libs] omp_defines = [('USE_OPENMP', None)] # debug if self.debug: dbg_flag = ['-g'] else: dbg_flag = ['-g0', '-DNDEBUG'] for ext in self.extensions: if ext.language == 'c++': ext.extra_compile_args = opts + dbg_flag elif ext.language is None: # C ext.extra_compile_args += dbg_flag if openmp_enabled: ext.extra_compile_args += omp_compiler_args ext.extra_link_args += omp_libraries ext.define_macros += omp_defines build_ext.build_extensions(self)
def build_extensions(self): from setup_util import cpp_flag, has_flag, detect_openmp # enable these options only for clang, OSX if sys.platform == 'darwin': import sysconfig compiler = os.path.basename(sysconfig.get_config_var("CC")) if str(compiler).startswith('clang'): self.c_opts['unix'] += [ '-stdlib=libc++', '-mmacosx-version-min=10.7' ] # TODO: test self.compiler.linker_so[0] = self.compiler.linker_exe[0] ct = self.compiler.compiler_type opts = self.c_opts.get(ct, []) if ct == 'unix': opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) opts.append(cpp_flag(self.compiler)) if has_flag(self.compiler, '-fvisibility=hidden'): opts.append('-fvisibility=hidden') elif ct == 'msvc': opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version()) # setup OpenMP support openmp_enabled, needs_gomp = detect_openmp() if openmp_enabled: warnings.warn('enabled openmp') omp_compiler_args = ['-fopenmp'] omp_libraries = ['-lgomp'] if needs_gomp else [] omp_defines = [('USE_OPENMP', None)] # debug dbg_flag = ['-g0' if not self.debug else '-g'] for ext in self.extensions: if ext.language == 'c++': ext.extra_compile_args = opts + dbg_flag elif ext.language is None: # C ext.extra_compile_args += dbg_flag if openmp_enabled: ext.extra_compile_args += omp_compiler_args ext.extra_link_args += omp_libraries ext.define_macros += omp_defines build_ext.build_extensions(self)