diff --git a/SConstruct b/SConstruct index 9ba4c1f..a0bbddc 100644 --- a/SConstruct +++ b/SConstruct @@ -1,154 +1,154 @@ from __future__ import print_function import os, sys from version import write_info_file # Compilation colors colors = {} colors['cyan'] = '\033[96m' colors['purple'] = '\033[95m' colors['blue'] = '\033[94m' colors['green'] = '\033[92m' colors['yellow'] = '\033[93m' colors['red'] = '\033[91m' colors['end'] = '\033[0m' # Inherit all environment variables (for CXX detection, etc.) main_env = Environment(ENV = os.environ) main_env['COLOR_DICT'] = colors # Compiler detection compiler_default = 'g++' if 'CXX' in os.environ: compiler_default = os.environ['CXX'] # Build variables vars = Variables('build-setup.conf') vars.Add(EnumVariable('build_type', 'Build type', 'release', allowed_values=('release', 'profiling', 'debug'), ignorecase=2)) vars.Add('prefix', 'Prefix where to install', '/usr/local') vars.Add('CXX', 'Compiler', compiler_default) vars.Add(BoolVariable('timer', 'Activate the timer possibilities', False)) vars.Add(BoolVariable('verbose', 'Activate verbosity', False)) vars.Add(BoolVariable('build_doc', 'Build documentation', False)) vars.Add(BoolVariable('color', 'Color the non-verbose compilation output', False)) vars.Update(main_env) Help(vars.GenerateHelpText(main_env)) # Save all options, not just those that differ from default with open('build-setup.conf', 'w') as setup: for key in vars.keys(): setup.write("{} = '{}'\n".format(key, main_env[key])) # instead of #vars.Save('build-setup.conf', main_env) build_type = main_env['build_type'] build_dir = 'build-' + main_env['build_type'] print("Building in " + build_dir) verbose = main_env['verbose'] # Remove colors if not set if not main_env['color']: for key in colors: colors[key] = '' if not verbose: main_env['SHCXXCOMSTR'] = unicode('{0}[Compiling] {1}$SOURCE{2}'.format(colors['green'], colors['blue'], colors['end'])) main_env['SHLINKCOMSTR'] = unicode('{0}[Linking] {1}$TARGET{2}'.format(colors['purple'], colors['blue'], colors['end'])) main_env['SWIGCOMSTR'] = unicode('{0}[Swig] {1}$SOURCE{2}'.format(colors['yellow'], colors['blue'], colors['end'])) # Include paths main_env.AppendUnique(CPPPATH=['#/src', '#/src/core', - '#/src/surface', - '#/src/bem', - '#/src/python', - '#/python']) + '#/src/surface', + '#/src/bem', + '#/src/python', + '#/python']) # Treating Intel compiler for OpenMP if main_env['CXX'] != 'icpc': omp_libs = ['gomp'] omp_flag = '-fopenmp' else: omp_libs = [''] omp_flag = '-qopenmp' main_env.AppendUnique(LIBS=omp_libs) main_env.AppendUnique(LINKFLAGS=[omp_flag]) # Flags and options main_env.AppendUnique(CXXFLAGS=['-std=c++11', '-Wall', omp_flag]) # Adding compile flags defined in evironment if 'CXXFLAGS' in os.environ: main_env.AppendUnique(CXXFLAGS = Split(os.environ['CXXFLAGS'])) if main_env['timer']: main_env.AppendUnique(CPPDEFINES=['USING_TIMER']) cxxflags_dict = { "debug":Split("-g -O0 -DTAMAAS_DEBUG"), "profiling":Split("-g -pg -O2"), "release":Split("-O3") } shlinkflags_dict = { "debug":[], "profiling":['-pg'], "release":[] } main_env.AppendUnique(CXXFLAGS=cxxflags_dict[build_type]) main_env.AppendUnique(SHLINKFLAGS=shlinkflags_dict[build_type]) main_env['LIBPATH'] = [os.path.abspath(os.path.join(build_dir,'src'))] main_env['RPATH'] = "$LIBPATH" fftw_include = "" fftw_library = "" # If FFTW is provided by module system (on clusters) if 'FFTW_ROOT' in main_env['ENV']: fftw_include = os.path.join(main_env['ENV']['FFTW_ROOT'], 'include') fftw_library = os.path.join(main_env['ENV']['FFTW_ROOT'], 'lib') main_env = main_env.Clone( tools = [fftw], FFTW_LIBRARY_WISH = ['main', 'omp'], FFTW_INCLUDE_DIR = fftw_include, FFTW_LIBRARY_DIR = fftw_library, ) # Writing information file write_info_file("src/tamaas_info.cpp") Export('main_env') # Compiling sources SConscript('src/SConscript',variant_dir=os.path.join(build_dir,'src'),duplicate=False) # Building python wrapper SConscript('python/SConscript',variant_dir=os.path.join(build_dir,'python'),duplicate=False) # Copying tests SConscript('tests/SConscript',variant_dir=os.path.join(build_dir,'tests'),duplicate=False) # Building documentation if main_env['build_doc']: SConscript('doc/SConscript', variant_dir=os.path.join(build_dir, 'doc'), duplicate=False) # Saving the env file env_content = """export PYTHONPATH=$PYTHONPATH:{0}/python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{0}/src""" with open(os.path.join(build_dir, 'tamaas_environement.sh'), 'w') as env_file: env_file.write(env_content.format(os.path.abspath(build_dir))) diff --git a/python/SConscript b/python/SConscript index 234716a..e0c9efe 100644 --- a/python/SConscript +++ b/python/SConscript @@ -1,38 +1,49 @@ -Import('main_env') -import distutils.sysconfig from os.path import abspath -from numpy.distutils.misc_util import get_numpy_include_dirs as numpy_dirs from distutils.version import StrictVersion +from subprocess import check_output, STDOUT + +Import('main_env') env_swig = main_env.Clone( - tools = ['swig'], - SWIG = 'swig', - SHLIBPREFIX = '', + tools=['swig'], + SWIG='swig', + SHLIBPREFIX='', ) if env_swig['SWIGVERSION'] is None: print "Could not find swig version" print env_swig.Dictionary() print env_swig.Environment Exit(1) if StrictVersion(env_swig['SWIGVERSION']) < StrictVersion("3.0"): print "Swig version {} is not supported by tamaas".format(env_swig['SWIGVERSION']) Exit(1) -env_swig.AppendUnique(CPPPATH=[distutils.sysconfig.get_python_inc(), numpy_dirs()]) +# Check user's prefered version +version_out = check_output(["python", "--version"], stderr=STDOUT).split(' ') +version = StrictVersion(version_out[-1]) +python3 = version >= StrictVersion("3.0") + +# Run scons_versions.py to get versions corresponding to prefered python install, and not scons's +includes = check_output(["python", "../../python/scons_includes.py"]).split('\n') + +env_swig.AppendUnique(CPPPATH=includes) env_swig.AppendUnique(SWIGPATH=['$CPPPATH']) env_swig.AppendUnique(SWIGFLAGS=['-python', '-c++']) +if python3: + env_swig.AppendUnique(SWIGFLAGS=['-py3']) + verbose = main_env['verbose'] if not verbose: env_swig.AppendUnique(SWIGFLAGS=['-w325', '-w315']) - env_swig.AppendUnique(CXXFLAGS=['-Wno-maybe-uninitialized']) # for some warning in wrapper code + env_swig.AppendUnique(CXXFLAGS=['-Wno-maybe-uninitialized']) # for some warning in wrapper code env_swig.SharedLibrary( - target = '_tamaas.so', - source = ['tamaas.i'], - LIBS = ['Tamaas'], - RPATH = [abspath('../src')] + target='_tamaas.so', + source=['tamaas.i'], + LIBS=['Tamaas'], + RPATH=[abspath('../src')] ) diff --git a/python/scons_includes.py b/python/scons_includes.py new file mode 100644 index 0000000..3c83882 --- /dev/null +++ b/python/scons_includes.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# coding: utf-8 +# ----------------------------------------------------------------------------- +# @author Lucas Frérot +# +# @section LICENSE +# +# Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de +# Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des +# Solides) +# +# Tamaas is free software: you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Tamaas. If not, see . +# ----------------------------------------------------------------------------- + +from __future__ import print_function +import distutils.sysconfig as dsys +from numpy.distutils.misc_util import get_numpy_include_dirs as numpy_dirs + +print(dsys.get_python_inc()) +for d in numpy_dirs(): + print(d)