def _find_include_directories(self, include_directories): env_dirs = self._env_include_directories() if not self.find_includes: return tools.unique(self._env_include_directories() + include_directories) all_found = True for include in self.find_includes: all_found = any( path.exists(dir_, include) for dir_ in env_dirs ) tools.debug("Search '%s':" % include, all_found) if not all_found: break if all_found: tools.debug("Include directories for", self.name, "found in env variables") return env_dirs tools.debug("Include directories for", self.name, "not found in env variables") results = [] include_directories += env_dirs for p in self.prefixes: include_directories.append(path.join(p, 'include')) if self.use_system_paths: include_directories += self.include_system_paths() tools.debug("Search include directories for library", self.name) dirs = [] for directory_name in self.include_directory_names: dirs.extend(path.join(dir_, directory_name) for dir_ in include_directories) include_directories = tools.unique(dirs) for include in self.find_includes: dirname, basename = path.split(include) name, ext = path.splitext(basename) found = False for dir_ in include_directories: tools.debug("Searching '%s' in directory '%s'" % (include, dir_)) files = tools.find_files( working_directory = path.join(dir_, dirname), name = name, extensions = [ext], recursive = False, ) if files: found = True tools.verbose("Found %s header '%s' in '%s'" % (self.name, include, dir_)) results.append(dir_) break if not found: tools.fatal( "Cannot find include file '%s' for library %s:" % (include, self.name), "\t* Set 'include_directories' when creating the library", "\t* Set the environment variable '%s_INCLUDE_DIRECTORY'" % self.name.upper(), "\t* Set the environment variable '%s_INCLUDE_DIRECTORIES'" % self.name.upper(), "\t* Set the environment variable '%s_PREFIX'" % self.name.upper(), "\t* Set the environment variable '%s_PREFIXES'" % self.name.upper(), "\t* Set the environment variable 'PREFIX'", "\t* Set the environment variable 'PREFIXES'", sep='\n' ) return results
def __init__(self, name, compiler, prefixes = [], include_directories = [], include_directory_names = [''], files = [], link_files = None, directories = [], binary_file_names = None, name_prefixes = ['lib', ''], name_suffixes = None, shared = None, preferred_shared = True, macosx_framework = False, search_macosx_framework_files = False, find_includes = [], use_system_paths = True, search_binary_files = True, only_one_binary_file = True, save_env_vars = True, system = False): self.name = name self.compiler = compiler self.env = self.compiler.build.env self.binary_file_names = binary_file_names self.name_suffixes = name_suffixes self.name_prefixes = name_prefixes self.compiler = compiler self.shared = shared self.preferred_shared = self.env_var( "SHARED", default = preferred_shared, ) self.macosx_framework = macosx_framework self.use_system_paths = use_system_paths self.only_one_binary_file = only_one_binary_file self.system = system if self.system: search_binary_files = False search_macosx_framework_files = False assert isinstance(find_includes, list) self.find_includes = find_includes assert len(include_directory_names) > 0 self.include_directory_names = include_directory_names self.prefixes = tools.unique(self._env_prefixes() + prefixes) self.libraries = [self] if self.macosx_framework and not search_macosx_framework_files: self.include_directories = [] self.directories = [] tools.debug("Files search for", self.name, "framework is not enabled.") return tools.debug(self.name, "library prefixes:", self.prefixes) self.include_directories = self._find_include_directories(include_directories) tools.debug(self.name, "library include directories:", self.include_directories) if search_binary_files: self._set_directories_and_files(directories) elif self.compiler.name == 'msvc' and self.system: self.files = [self.name + '.lib'] # + self.compiler.library_extension(self.shared)] self.directories = [] else: self.files = self._env_files() + files self.directories = self._env_directories() + directories if link_files is None: if self.compiler.name == 'msvc': self.link_files = [ (path.splitext(f)[0] + '.lib') for f in self.files ] else: self.link_files = files[:] else: self.link_files = link_files[:] tools.debug(self.name, "library directories:", self.directories) tools.verbose(self.name, "library files:", ', '.join(("'%s'" % f) for f in self.files)) if save_env_vars: self._save_env()
def main(build): build_type = build.env.get('BUILD_TYPE', 'DEBUG') build.env.BUILD_TYPE = build_type status("Configuring project", build.env.NAME, '(%s)' % build.env.VERSION_NAME, 'in', build.directory, '(%s)' % build_type) from configure.lang import cxx if build.env.BUILD_TYPE == 'DEBUG': defines = [ 'ETC_DEBUG', 'CUBE_DEBUG', 'CUBEAPP_DEBUG', ] optimization = cxx.compiler.Compiler.dont_optimize elif build.env.BUILD_TYPE == 'RELEASE': defines = ['NDEBUG'] if platform.IS_WINDOWS: defines.append(('_SCL_SECURE', '0')) optimization = cxx.compiler.Compiler.optimize_fastest else: raise Exception("Unknown build type '%s'" % build_type) defines += ['BOOST_ALL_NO_LIB', 'GLEW_NO_GLU', 'GLM_FORCE_RADIANS', ] if platform.IS_WINDOWS: defines.extend([ 'NOMINMAX' # ('_WIN32_WINNT', '0x0600'), # ('WINVER', '0x0600'), ]) #if platform.IS_LINUX: # defines += ['CUBE_WITH_GLX'] library_directories = [ #'/home/hotgloupi/sandbox/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/lib', #'/home/hotgloupi/sandbox/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf', #'/home/hotgloupi/sandbox/raspberry/root/usr/lib', #'/home/hotgloupi/sandbox/raspberry/root/usr/lib/arm-linux-gnueabihf', ] include_directories = [ path.join(build.directory, 'src'), # '/home/hotgloupi/sandbox/raspberry/root/usr/include', # '/home/hotgloupi/sandbox/raspberry/root/usr/include/arm-linux-gnueabihf', path.absolute(build.project.directory, 'src'), path.absolute(build.project.directory, 'src/glew'), ] compiler = cxx.find_compiler( build, position_independent_code = True, standard = 'c++11', defines = defines, library_directories = library_directories, include_directories = include_directories, static_libstd = False, hidden_visibility = (build_type != 'DEBUG'), optimization = optimization, #force_architecture = True, #target_architecture = '32bit', forbidden_warnings = ['return-type',] # additional_link_flags = { # 'gcc': ['-ldl', '-lpthread', '-lutil', '-lz', '-lX11', '-Xlinker', '-export-dynamic'], # } ) c_compiler = c.find_compiler( build, force_architecture = False, optimization = optimization ) status("Using %s as C++ compiler" % compiler) status("Using %s as C compiler" % c_compiler) freetype2 = build.add_dependency( c.libraries.FreetypeDependency, c_compiler, 'deps/freetype2' ) zlib = build.add_dependency( ZLibDependency, c_compiler, 'deps/zlib-1.2.8' ) bz2 = build.add_dependency( BZ2Dependency, c_compiler, 'deps/bzip2-1.0.6', ) if not platform.IS_WINDOWS: idn = build.add_dependency( IDNDependency, c_compiler, 'deps/libidn-1.28', ) else: idn = None curl = build.add_dependency( c.libraries.CURLDependency, c_compiler, "deps/curl-7.35.0", shared = False, #platform.IS_WINDOWS, with_ldap = False, with_ldaps = False, with_ftp = False, with_tftp = False, with_telnet = False, with_dict = False, with_file = False, with_cookies = True, idn = idn, ) bullet_physics = build.add_dependency( BulletPhysics, compiler, "deps/bullet-2.82-r2704", shared = False, #platform.IS_WINDOWS, ) librocket = build.add_dependency( LibRocketDependency, compiler, "deps/libRocket", c_compiler = c_compiler, freetype2 = freetype2, shared = False, #platform.IS_WINDOWS, ) if platform.IS_WINDOWS: python = c.libraries.PythonLibrary(c_compiler, shared = True) else: python = build.add_dependency( c.libraries.PythonDependency, c_compiler, 'deps/Python-v3.4.0', shared = False, version = (3, 4), pymalloc = False, with_valgrind_support = False, threads = False, ) boost = build.add_dependency( cxx.libraries.BoostDependency, compiler, 'deps/boost_1_57_0', version = (1, 57), python = python, export_python = True, components = [ 'format', 'timer', 'system', 'filesystem', 'python', 'signals2', 'thread', 'coroutine', 'context', ], #preferred_shared = False, # python3_shared = True, #thread_shared = True, ) glm = build.add_dependency(GLM, compiler, "deps/glm") # XXX needed ? compiler.include_directories.extend(tools.unique( sum((l.include_directories for l in boost.libraries), []) )) assimp = build.add_dependency( Assimp, compiler, 'deps/assimp', boost = boost, c_compiler = c_compiler, zlib = zlib, shared = False, #platform.IS_WINDOWS ) if platform.IS_OSX and platform.OSX_VERSION_MAJOR <= 10 and platform.OSX_VERSION_MINOR <= 6: sdl = c.libraries.SDLLibrary( c_compiler, macosx_framework = True, search_macosx_framework_files = True ) else: sdl = build.add_dependency( c.libraries.SDLDependency, c_compiler, 'deps/SDL', shared = platform.IS_WINDOWS, audio = False, haptic = False, # Fails on windows dynamic_api = False, ) sdl_image = build.add_dependency( c.libraries.SDLImageDependency, c_compiler, 'deps/SDL_image', sdl = sdl, shared = False ) #sdl = c.libraries.SDLLibrary( # compiler, # components=['image'], # shared=True #) opengl = c.libraries.OpenGLLibrary( compiler, system = True, shared = compiler.name != 'msvc' ) graphic_libraries = ( sdl.libraries + sdl_image.libraries + opengl.libraries + #assimp.libraries + freetype2.libraries + glm.libraries + bullet_physics.libraries + librocket.libraries ) #if not platform.IS_WINDOWS: # list(c.libraries.simple(s, compiler) for s in ['png', 'jpeg']) base_libraries = zlib.libraries + bz2.libraries if platform.IS_WINDOWS: base_libraries.extend( c.libraries.simple(name, compiler, system = True) for name in [ 'Shlwapi', 'ws2_32', 'Gdi32', 'mswsock', 'Dbghelp', 'winmm', 'version', 'imm32', 'Shell32', 'User32', 'Ole32', 'OleAut32', 'Advapi32', 'Kernel32', 'msvcrt', 'msvcprt', #'libcmt' ] ) else: # OSX and Linux if platform.IS_LINUX: base_libraries.extend( c.libraries.simple(name, compiler, system = True) for name in [ 'rt', 'util', ] ) # SDL audio disabled #base_libraries.extend( # c.libraries.simple(name, compiler, system = True) for name in ['audio',] #) elif platform.IS_MACOSX: base_libraries.extend( c.libraries.simple(name, compiler, macosx_framework = True) for name in [ 'ForceFeedback', 'IOKit', 'Cocoa', 'Carbon', 'CoreVideo' # 'AudioUnit', 'CoreAudio', 'AudioToolbox', # SDL Audio disabled ] ) libglew = compiler.link_static_library( 'libglew', ['src/glew/glew.c'], directory = 'release/lib', libraries = opengl.libraries, defines = ['GLEW_NO_GLU', 'GLEW_STATIC'], ) graphic_libraries.insert(0, libglew) precompiled_headers = [] with_pch = False if with_pch: precompiled_headers.append( compiler.generate_precompiled_header( "src/wrappers/stl.hpp", force_include = True, ) ) base_libraries.extend([ boost.component_library('filesystem'), boost.component_library('system'), boost.component_library('thread'), boost.component_library('coroutine'), boost.component_library('context'), ]) libetc = compiler.link_library( 'libetc', rglob("src/etc/*.cpp"), directory = 'release/lib', libraries = base_libraries + curl.libraries, defines = ['ETC_BUILD_DYNAMIC_LIBRARY', ('CURL_STATICLIB', 1)], shared = True, precompiled_headers = precompiled_headers, ) libetc_static = compiler.link_library( 'libetc-static', rglob("src/etc/*.cpp"), directory = 'release/lib', object_directory = 'etc-static', libraries = base_libraries + curl.libraries, defines = ['ETC_BUILD_STATIC_LIBRARY', ('CURL_STATICLIB', 1)], shared = False, position_independent_code = True, static_libstd = not platform.IS_MACOSX, precompiled_headers = precompiled_headers, ) ################### libcube if with_pch: precompiled_headers.extend([ compiler.generate_precompiled_header( "src/wrappers/boost/signals2.hpp", libraries = boost.libraries ), ]) libcube_libs = base_libraries + [libetc] + assimp.libraries + graphic_libraries libcube = compiler.link_dynamic_library( 'libcube', rglob("src/cube/*.cpp"), directory = 'release/lib', libraries = libcube_libs, precompiled_headers = precompiled_headers, defines = ['CUBE_BUILD_DYNAMIC_LIBRARY', 'ROCKET_STATIC_LIB'], ) if with_pch: precompiled_headers.extend([ compiler.generate_precompiled_header( "src/wrappers/boost/python.hpp", libraries = boost.libraries + python.libraries, ), ]) python_module_libraries = boost.libraries if platform.IS_WINDOWS: python_module_libraries.extend([libcube, libetc]) for binding in rglob("cube/*.py++", dir='src'): t = compiler.link_dynamic_library( path.splitext(path.basename(binding))[0], [binding], ext = python.ext, directory = path.dirname("release/lib/python", binding[4:]), libraries = python_module_libraries + base_libraries, include_directories = glm.libraries[0].include_directories, precompiled_headers = precompiled_headers, allow_unresolved_symbols = True, ) ################### libcubeapp libcubeapp = compiler.link_dynamic_library( 'libcubeapp', (src for src in rglob("src/cubeapp/*.cpp") if not src.endswith('main.cpp')), directory = 'release/lib', libraries = [libetc, libcube] + boost.libraries + glm.libraries, precompiled_headers = precompiled_headers, defines = ['CUBEAPP_BUILD_DYNAMIC_LIBRARY'], ) for binding in rglob("cubeapp/*.py++", dir='src'): compiler.link_dynamic_library( path.splitext(path.basename(binding))[0], [binding], ext = python.ext, directory = path.dirname("release/lib/python", binding[4:]), libraries=[libcubeapp, libcube, libetc] + graphic_libraries + boost.libraries + base_libraries, precompiled_headers = precompiled_headers, ) infinit_cube_libraries = [ libcubeapp, libcube, libetc, ] + graphic_libraries + boost.libraries + base_libraries cube_exe = compiler.link_executable( "8cube", ["src/cubeapp/main.cpp"], directory = "release/bin", libraries = infinit_cube_libraries, export_libraries = [boost.component_library('python')], ) if platform.IS_WINDOWS: seen = set() for lib in infinit_cube_libraries + assimp.libraries: if not isinstance(lib, Target): #print("lib %s" % lib.files, lib.shared, lib.system) if lib.shared and not lib.system: for f in lib.files: if f not in seen: seen.add(f) build.fs.copy(f, dest_dir = 'release/bin') else: if lib.shared: if lib.path not in seen: seen.add(lib.path) build.fs.copy(lib, dest_dir = 'release/bin') exts = ['py', 'bmp', 'ttf', 'rml'] for ext in exts: for src in rglob("cube/*.%s" % ext, dir = 'src'): build.fs.copy(src, 'release/lib/python/' + src[4:]) for src in rglob("cubeapp/*.%s" % ext, dir = 'src'): build.fs.copy(src, 'release/lib/python/' + src[4:]) import os for ext in exts: for src in rglob(path.join('share/games/default', '*.%s' % ext)): build.fs.copy(src, "release/" + src[6:]) # Default game launcher # # By default, it will launch the default game (named "default"). The # environment variable "GAME_ID" is used takes precedence over the default # game # compiler.link_executable( "launch", list(rglob("*.cpp", dir = "src/launch")), directory = 'release/bin', defines = [('GAME_ID', "default"), 'ETC_STATIC_LIBRARY'], static_libstd = not platform.IS_MACOSX and not platform.IS_WINDOWS, libraries = [libetc_static] + base_libraries + ( not platform.IS_WINDOWS and [c.libraries.simple('pthread', compiler, system = True)] or [] ) + curl.libraries ) tests = [ 'simple_window', 'cube/gl/shader_generator', ]