Ejemplo n.º 1
0
void Gcc::refreshSettings()
{
    QStringList include_dirs;
    QStringList lib_dirs;
    QSettings settings(m_targetFile, QSettings::IniFormat);

    m_cflags.clear();
    m_lflags.clear();

    include_dirs = settings.value("Target/include_dirs").toString().split(' ', QString::SkipEmptyParts);
    lib_dirs = settings.value("Target/lib_dirs").toString().split(' ', QString::SkipEmptyParts);

    QStringListIterator i(include_dirs);
    while(i.hasNext()) {
        QDir includePath(i.next());
        if(includePath.isAbsolute())
            m_cflags << "-I" + includePath.path();
        else
            m_cflags << "-I" + QDir::currentPath() + "/" + includePath.path();
    }

    i = lib_dirs;
    while(i.hasNext()) {
        QDir libPath(i.next());
        if(libPath.isAbsolute())
            m_lflags << "-L" + libPath.path();
        else
            m_lflags << "-L" + QDir::currentPath() + "/" + libPath.path();
    }

    m_cflags << settings.value("Target/cflags").toString().split(' ', QString::SkipEmptyParts);
    m_lflags << settings.value("Target/lflags").toString().split(' ', QString::SkipEmptyParts);
}
Ejemplo n.º 2
0
void PageReader::include(const std::string& path)
{
	Poco::Path currentPath(_path);
	Poco::Path includePath(path);
	currentPath.resolve(includePath);
	
	_page.handler() << "\t// begin include " << currentPath.toString() << "\n";
	
	Poco::FileInputStream includeStream(currentPath.toString());
	PageReader includeReader(*this, currentPath.toString());
	includeReader.emitLineDirectives(_emitLineDirectives);
	includeReader.parse(includeStream);
	
	_page.handler() << "\t// end include " << currentPath.toString() << "\n";
}
Ejemplo n.º 3
0
void Gcc::refreshSettings()
{
	QStringList include_dirs;
	QStringList lib_dirs;
	QSettings settings(m_targetFile, QSettings::IniFormat);

	m_cflags.clear();
	m_lflags.clear();

	include_dirs = settings.value("Target/include_dirs").toString().split(' ', QString::SkipEmptyParts);
	lib_dirs = settings.value("Target/lib_dirs").toString().split(' ', QString::SkipEmptyParts);

	QStringListIterator i(include_dirs);
	while(i.hasNext()) {
		QDir includePath(i.next());
		if(includePath.isAbsolute())
			m_cflags << "-I" + includePath.path();
		else
			m_cflags << "-I" + QDir::currentPath() + "/" + includePath.path();
	}

	i = lib_dirs;
	while(i.hasNext()) {
		QDir libPath(i.next());
		if(libPath.isAbsolute())
			m_lflags << "-L" + libPath.path();
		else
			m_lflags << "-L" + QDir::currentPath() + "/" + libPath.path();
	}

	m_cflags << settings.value("Target/cflags").toString().split(' ', QString::SkipEmptyParts);
	m_lflags << settings.value("Target/lflags").toString().split(' ', QString::SkipEmptyParts);
	
#ifdef Q_OS_MAC
	if(QSysInfo::MacintoshVersion == QSysInfo::MV_TIGER) {
    m_cflags << "-isysroot" << "/Developer/SDKs/MacOSX10.4u.sdk";
    m_lflags << "-isysroot" << "/Developer/SDKs/MacOSX10.4u.sdk";
	}
#endif
}
Ejemplo n.º 4
0
wxArrayString Compiler::POSIXGetIncludePaths() const
{
    wxString command;
    command << GetTool("CXX") << " -v -x c++ /dev/null -fsyntax-only";

    wxString outputStr = ::wxShellExec(command, wxEmptyString);

    wxArrayString arr;
    wxArrayString outputArr = ::wxStringTokenize(outputStr, wxT("\n\r"), wxTOKEN_STRTOK);

    // Analyze the output
    bool collect(false);
    for(size_t i = 0; i < outputArr.GetCount(); i++) {
        if(outputArr[i].Contains(wxT("#include <...> search starts here:"))) {
            collect = true;
            continue;
        }

        if(outputArr[i].Contains(wxT("End of search list."))) {
            break;
        }

        if(collect) {

            wxString file = outputArr.Item(i).Trim().Trim(false);

            // on Mac, (framework directory) appears also,
            // but it is harmless to use it under all OSs
            file.Replace(wxT("(framework directory)"), wxT(""));
            file.Trim().Trim(false);

            wxFileName includePath(file, "");
            includePath.Normalize();

            arr.Add(includePath.GetPath());
        }
    }
    return arr;
}
Ejemplo n.º 5
0
bool FolderSelectionModel::setData(const QModelIndex& pIndex, const QVariant& pValue, int pRole) {
	if(!pIndex.isValid() || pIndex.column() != 0 || pRole != Qt::CheckStateRole) {
		return QFileSystemModel::setData(pIndex, pValue, pRole);
	}

	// here we ignore the check value, we treat it as a toggle
	// This is due to our using the Qt checking system in a virtual way
	const QString lPath = filePath(pIndex);
	const InclusionState lState = inclusionState(lPath);
	switch(lState) {
	case StateIncluded:
	case StateIncludeInherited:
		excludePath(lPath);
		break;
	default:
		includePath(lPath);
	}
	QModelIndex lRecurseIndex = pIndex;
	while(lRecurseIndex.isValid()) {
		emit dataChanged(lRecurseIndex, lRecurseIndex);
		lRecurseIndex = lRecurseIndex.parent();
	}
	return true;
}
GenerationDevice::GenerationDevice(const std::shared_ptr<DeviceConfig>& p_config, const std::shared_ptr<OpenclDevice>& p_device) throw (std::exception)
: m_config(p_config), m_device(p_device), m_context(0), m_commandQueue(0), m_bufferDevice(0), m_program(0), m_kernels{0, 0, 0}, m_available(true) {
	m_bufferCpu = new unsigned char[getMemorySize()];

	cl_int error;

	m_context = clCreateContext(0, 1, &m_device->getHandle(), NULL, NULL, &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL context");
	}

	m_commandQueue = clCreateCommandQueue(m_context, m_device->getHandle(), 0, &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL command queue");
	}

	m_bufferDevice = clCreateBuffer(m_context, CL_MEM_READ_WRITE, sizeof(unsigned char) * m_config->getGlobalWorkSize() * GEN_SIZE, 0, &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL GPU buffer");
	}

	std::string source(loadSource(KERNEL_PATH + "/nonce.cl"));
	const char* sources[] = {source.c_str()};
	std::size_t sourcesLength[] = {source.length()};
	m_program = clCreateProgramWithSource(m_context, 1, sources, sourcesLength, &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL program");
	}

	std::string includePath("-I " + KERNEL_PATH);
	error = clBuildProgram(m_program, 1, &m_device->getHandle(), includePath.c_str(), 0, 0);
	if(error != CL_SUCCESS) {
		std::size_t logSize;
		cl_int subError = clGetProgramBuildInfo(m_program, m_device->getHandle(), CL_PROGRAM_BUILD_LOG, 0, 0, &logSize);
		if(subError != CL_SUCCESS) {
			throw OpenclError(subError, "Unable to retrieve the OpenCL build info size");
		}

		std::unique_ptr<char[]> log(new char[logSize]);
		subError = clGetProgramBuildInfo(m_program, m_device->getHandle(), CL_PROGRAM_BUILD_LOG, logSize, (void*)log.get(), 0);
		if(subError != CL_SUCCESS) {
			throw OpenclError(subError, "Unable to retrieve the OpenCL build info");
		}

		std::ostringstream message;
		message << "Unable to build the OpenCL program" << std::endl;
		message << log.get();

		throw OpenclError(error, message.str());
	}

	m_kernels[0] = clCreateKernel(m_program, "nonce_step1", &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL step1 kernel");
	}

	error = clSetKernelArg(m_kernels[0], 0, sizeof(cl_mem), (void*)&m_bufferDevice);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to set the OpenCL step1 kernel arguments");
	}

	m_kernels[1] = clCreateKernel(m_program, "nonce_step2", &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL step2 kernel");
	}

	error = clSetKernelArg(m_kernels[1], 0, sizeof(cl_mem), (void*)&m_bufferDevice);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to set the OpenCL step2 kernel arguments");
	}

	m_kernels[2] = clCreateKernel(m_program, "nonce_step3", &error);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to create the OpenCL step3 kernel");
	}

	error = clSetKernelArg(m_kernels[2], 0, sizeof(cl_mem), (void*)&m_bufferDevice);
	if(error != CL_SUCCESS) {
		throw OpenclError(error, "Unable to set the OpenCL step3 kernel arguments");
	}
}
Ejemplo n.º 7
0
/**
 * tryFile is a pointer to a function that resolve_include() will use to
 * determine if a path references a real file.  ctx is a pointer to some context
 * information that will be passed through to tryFile.  (It's a hacky closure)
 */
String resolve_include(const String& file, const char* currentDir,
                       bool (*tryFile)(const String& file, void*), void* ctx) {
  const char* c_file = file.data();

  if (!File::IsPlainFilePath(file)) {
    // URIs don't have an include path
    if (tryFile(file, ctx)) {
      return file;
    }

  } else if (c_file[0] == '/') {
    String can_path(FileUtil::canonicalize(file.c_str(), file.size()),
                    AttachString);

    if (tryFile(can_path, ctx)) {
      return can_path;
    }

  } else if ((c_file[0] == '.' && (c_file[1] == '/' || (
    c_file[1] == '.' && c_file[2] == '/')))) {

    String path(String(g_context->getCwd() + "/" + file));
    String can_path(FileUtil::canonicalize(path.c_str(), path.size()),
                    AttachString);

    if (tryFile(can_path, ctx)) {
      return can_path;
    }

  } else {
    auto includePaths = ThreadInfo::s_threadInfo.getNoCheck()->
      m_reqInjectionData.getIncludePaths();
    unsigned int path_count = includePaths.size();

    for (int i = 0; i < (int)path_count; i++) {
      String path("");
      String includePath(includePaths[i]);

      if (includePath[0] != '/') {
        path += (g_context->getCwd() + "/");
      }

      path += includePath;

      if (path[path.size() - 1] != '/') {
        path += "/";
      }

      path += file;
      String can_path(FileUtil::canonicalize(path.c_str(), path.size()),
                      AttachString);

      if (tryFile(can_path, ctx)) {
        return can_path;
      }
    }

    if (currentDir[0] == '/') {
      String path(currentDir);
      path += "/";
      path += file;
      String can_path(FileUtil::canonicalize(path.c_str(), path.size()),
                      AttachString);

      if (tryFile(can_path, ctx)) {
        return can_path;
      }
    } else {
      String path(g_context->getCwd() + "/" + currentDir + file);
      String can_path(FileUtil::canonicalize(path.c_str(), path.size()),
                      AttachString);

      if (tryFile(can_path, ctx)) {
        return can_path;
      }
    }
  }

  return String();
}
Ejemplo n.º 8
0
void IncludePathLocator::Locate(wxArrayString& paths, wxArrayString &excludePaths, bool thirdPartyLibs, const wxString &tool) {
	// Common compiler paths - should be placed at top of the include path!
	wxString tmpfile1 = wxFileName::CreateTempFileName(wxT("codelite"));
	wxString command;
	wxString tmpfile = tmpfile1;
	tmpfile += wxT(".cpp");

	wxString bin = tool;
	if(bin.IsEmpty()) {
		bin = wxT("gcc");
	}

	wxRenameFile(tmpfile1, tmpfile);

	// GCC prints parts of its output to stdout and some to stderr
	// redirect all output to stdout
#if defined(__WXMAC__) || defined(__WXGTK__)
	// Mac does not like the standard command
	command = wxString::Format(wxT("%s -v -x c++ /dev/null -fsyntax-only"), bin.c_str());
#else
	command = wxString::Format(wxT("%s -v -x c++ %s -fsyntax-only"), bin.c_str(), tmpfile.c_str());
#endif

	wxString outputStr = wxShellExec(command, wxEmptyString);
	wxRemoveFile( tmpfile );

	wxArrayString outputArr = wxStringTokenize(outputStr, wxT("\n\r"), wxTOKEN_STRTOK);
	// Analyze the output
	bool collect(false);
	for(size_t i=0; i<outputArr.GetCount(); i++) {
		if(outputArr[i].Contains(wxT("#include <...> search starts here:"))) {
			collect = true;
			continue;
		}

		if(outputArr[i].Contains(wxT("End of search list."))) {
			break;
		}

		if(collect) {

			wxString file = outputArr.Item(i).Trim().Trim(false);

			// on Mac, (framework directory) appears also,
			// but it is harmless to use it under all OSs
			file.Replace(wxT("(framework directory)"), wxT(""));
			file.Trim().Trim(false);

			wxFileName includePath(file, wxT(""));
			includePath.Normalize();

			paths.Add( includePath.GetPath() );
		}
	}

	if(thirdPartyLibs) {
		// try to locate QMAKE
		wxFileConfig  qmakeConf(wxEmptyString, wxEmptyString, m_mgr->GetStartupDirectory() + wxT("/config/qmake.ini"));
		wxString      groupName;
		long          index(0);
		wxArrayString out;
		wxString      qmake(wxT("qmake"));

		if (qmakeConf.GetFirstGroup(groupName, index)) {
			// we got qmake configuration, use it instead of the default qmake command
			qmake = qmakeConf.Read(groupName + wxT("/qmake"));
		}

		// Run: qmake -query QT_INSTALL_PREFIX
		wxString cmd;
		cmd << qmake << wxT(" -query QT_INSTALL_PREFIX");

#ifdef __WXGTK__
		cmd << wxT(" 2>/dev/null");
#endif

		out = ExecCommand(cmd);

		if (out.IsEmpty() == false ) {

			wxString qt_output (out.Item(0));
			qt_output.Trim().Trim(false);

#if defined(__WXGTK__)||defined(__WXMAC__)
			wxString pathQt4, pathQt3, pathQt;
			pathQt4 << qt_output << wxFileName::GetPathSeparator() << wxT("include") << wxFileName::GetPathSeparator() << wxT("qt4");
			pathQt3 << qt_output << wxFileName::GetPathSeparator() << wxT("include") << wxFileName::GetPathSeparator() << wxT("qt3");
			pathQt  << qt_output << wxFileName::GetPathSeparator() << wxT("include");

			if (wxDir::Exists( pathQt4 )) {
				wxString tmpPath;

				tmpPath = pathQt4 + wxT("/QtCore");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

				tmpPath = pathQt4 + wxT("/QtGui");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

				tmpPath = pathQt4 + wxT("/QtXml");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

			} else if (wxDir::Exists( pathQt3 ) ) {

				wxString tmpPath;

				tmpPath = pathQt3 + wxT("/QtCore");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

				tmpPath = pathQt3 + wxT("/QtGui");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

				tmpPath = pathQt3 + wxT("/QtXml");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

			} else if (wxDir::Exists( pathQt ) ) {

				wxString tmpPath;

				tmpPath = pathQt + wxT("/QtCore");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );

				tmpPath = pathQt + wxT("/QtGui");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( pathQt );

				tmpPath = pathQt + wxT("/QtXml");
				if(wxFileName::DirExists(tmpPath))
					paths.Add( tmpPath );
			}

#else // __WXMSW__
			wxString pathWin;
			pathWin << qt_output << wxFileName::GetPathSeparator() << wxT("include") << wxFileName::GetPathSeparator();
			if (wxDir::Exists( pathWin )) {

				wxString tmpPath;

				tmpPath = pathWin + wxT("QtCore");
				if(wxFileName::DirExists(tmpPath)) {
					wxFileName fn(tmpPath, wxT(""));
					paths.Add( fn.GetPath() );
				}

				tmpPath = pathWin + wxT("QtGui");
				if(wxFileName::DirExists(tmpPath)) {
					wxFileName fn(tmpPath, wxT(""));
					paths.Add( fn.GetPath() );
				}

				tmpPath = pathWin + wxT("QtXml");
				if(wxFileName::DirExists(tmpPath)) {
					wxFileName fn(tmpPath, wxT(""));
					paths.Add( fn.GetPath() );
				}
			}
#endif
		}

		// Try wxWidgets
#ifdef __WXMSW__
		// On Windows, just read the content of the WXWIN environment variable
		wxString wxwin;
		if (wxGetEnv(wxT("WX_INCL_HOME"), &wxwin)) {
			// we got the path to the installation of wxWidgets
			if (wxDir::Exists(wxwin)) {
				paths.Add( wxwin );
				excludePaths.Add( wxwin + wxT("\\univ") );
				excludePaths.Add( wxwin + wxT("\\unix") );
			}
		}
#else
		// run wx-config and parse the output
		out.Clear();
		out = ExecCommand(wxT("wx-config --cxxflags 2>/dev/null"));
		if (out.IsEmpty() == false) {
			wxString line ( out.Item(0) );
			int where = line.Find(wxT(" -I"));
			while (where != wxNOT_FOUND) {
				line = line.Mid(where + 3);
				paths.Add( line.BeforeFirst(wxT(' ')) );
				where = line.Find(wxT(" -I"));
			}
		}
#endif
	}
}
bool U2D3DXEffectShader::LoadResource()
{
	U2ASSERT(0 == m_pD3DEffect);

	HRESULT hr;
	
	IDirect3DDevice9* pD3DDev = m_pRenderer->GetD3DDevice();
	U2ASSERT(pD3DDev);

	U2FilePath fPath;		
	TCHAR fullPath[MAX_PATH];
	// StackString Memory Leak...
	U2DynString includePath(FX_SHADER_PATH);
	includePath += _T("\\2.0");

	fPath.ConvertToAbs(fullPath, MAX_PATH * sizeof(TCHAR) , m_szFilename.Str(), includePath);		

	U2File* pFile = U2File::GetFile(fullPath, U2File::READ_ONLY);
	if(!pFile)
	{
		U2_DELETE pFile;
		return false;
	}

	uint32 uBuffLen = pFile->GetfileSize();
	if(uBuffLen == 0)
	{
		U2_DELETE pFile;
		return false;
	}

	unsigned char* pBuffer = U2_ALLOC(unsigned char, uBuffLen);
	pFile->Read(pBuffer, uBuffLen);

	U2_DELETE pFile;

	ID3DXBuffer* pErrorBuffer = NULL;

#ifdef DEBUG_SHADER
	DWORD compileFlags = D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
		| D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT | D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT ;	
#else
	DWORD compileFlags = D3DXSHADER_USE_LEGACY_D3DX9_31_DLL;
#endif

	//U2DynString includePath(FX_SHADER_PATH);
	//includePath += _T("\\2.0");
	
	U2D3DXEffectShaderInclude includeHandler(includePath);

	ID3DXEffectPool* pEffectPool = m_pRenderer->GetD3DEffectPool();
	U2ASSERT(pEffectPool);

	// get the highest supported shader profiles
//	LPCSTR vsProfile, psProfile;
//#ifdef UNICODE 
//	 vsProfile = ToUnicode( D3DXGetVertexShaderProfile(pD3DDev) );
//	 psProfile = ToUnicode( D3DXGetPixelShaderProfile(pD3DDev) );
//#else 
//	vsProfile = D3DXGetVertexShaderProfile(pD3DDev);
//	psProfile = D3DXGetPixelShaderProfile(pD3DDev);
//#endif
	LPCSTR vsProfile = D3DXGetVertexShaderProfile(pD3DDev);
	LPCSTR psProfile = D3DXGetPixelShaderProfile(pD3DDev);

	if (0 == vsProfile)
	{
		FDebug("Invalid Vertex Shader profile! Fallback to vs_2_0!\n");
		vsProfile = "vs_2_0";
	}

	if (0 == psProfile)
	{
		FDebug("Invalid Pixel Shader profile! Fallback to ps_2_0!\n");
		psProfile = "ps_2_0";
	}

	// create macro definitions for shader compiler
	D3DXMACRO defines[] = {
		{ "VS_PROFILE", vsProfile },
		{ "PS_PROFILE", psProfile },
		{ 0, 0 },
	};

	// create effect
	if (compileFlags)
	{
		hr = D3DXCreateEffectFromFile(
			pD3DDev,            // pDevice
			fullPath,   // File name
			defines,            // pDefines
			&includeHandler,    // pInclude
			compileFlags,       // Flags
			pEffectPool,         // pPool
			&m_pD3DEffect,    // ppEffect
			&pErrorBuffer);      // ppCompilationErrors
	}
	else
	{
		hr = D3DXCreateEffect(
			pD3DDev,            // pDevice
			pBuffer,             // pFileData
			uBuffLen,           // DataSize
			defines,            // pDefines
			&includeHandler,    // pInclude
			compileFlags,       // Flags
			pEffectPool,         // pPool
			&(m_pD3DEffect),    // ppEffect
			&pErrorBuffer);      // ppCompilationErrors
	}

	U2_FREE(pBuffer);
	pBuffer = NULL;

	if (FAILED(hr))
	{
		FDebug("nD3D9Shader: failed to load fx file '%s' with:\n\n%s\n",
			fullPath,
			pErrorBuffer ? pErrorBuffer->GetBufferPointer() : "No D3DX error message.");
		if (pErrorBuffer)
		{
			pErrorBuffer->Release();
		}
		return false;
	}
	U2ASSERT(m_pD3DEffect);

	m_bValidated = false;
	m_bNotValidate = false;

	this->ValidateEffect();

	return true;
}