QueueCommand::QueueCommand(int kind) : m_projectOnly(false) , m_kind(kind) , m_cleanLog(true) , m_checkBuildSuccess(false) { // Fill with default values if ( clCxxWorkspaceST::Get()->IsOpen() ) { m_project = clCxxWorkspaceST::Get()->GetActiveProjectName(); BuildConfigPtr buildPtr = clCxxWorkspaceST::Get()->GetProjBuildConf(m_project, ""); wxASSERT_MSG( buildPtr, "No active project" ); // If a 'Build' or 'Clean' kinds where requested // and the project build configuration is Custom build // change the kind to CustomBuild and set the proper build // targets if ( m_kind == kBuild && buildPtr->IsCustomBuild() ) { // change the type to CustomBuild m_kind = kCustomBuild; SetCustomBuildTarget("Build"); } else if ( m_kind == kClean && buildPtr->IsCustomBuild() ) { // change the type to CustomBuild m_kind = kCustomBuild; SetCustomBuildTarget("Clean"); } else { m_configuration = buildPtr->GetName(); } } }
void ClangCodeCompletion::OnBuildStarting(clBuildEvent& e) { e.Skip(); CHECK_CLANG_ENABLED_RET(); // Determine the compilation database CompilationDatabase cdb; cdb.Open(); cdb.Close(); // Set the compilation database environment variable ::wxSetEnv(wxT("CL_COMPILATION_DB"), cdb.GetFileName().GetFullPath()); // If this is NOT a custom project, set the CXX and CC environment wxString project = e.GetProjectName(); wxString config = e.GetConfigurationName(); BuildConfigPtr bldConf = WorkspaceST::Get()->GetProjBuildConf(project, config); if( bldConf && !bldConf->IsCustomBuild()) { wxString cxx = bldConf->GetCompiler()->GetTool(wxT("CXX")); wxString cc = bldConf->GetCompiler()->GetTool(wxT("CC")); cxx.Prepend(wxT("codelitegcc ")); cc.Prepend(wxT("codelitegcc ")); ::wxSetEnv("CXX", cxx); ::wxSetEnv("CC" , cc); } }
wxArrayString Project::GetIncludePaths() { wxArrayString paths; BuildMatrixPtr matrix = WorkspaceST::Get()->GetBuildMatrix(); if(!matrix) { return paths; } wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); wxString projectSelConf = matrix->GetProjectSelectedConf(workspaceSelConf, GetName()); BuildConfigPtr buildConf = WorkspaceST::Get()->GetProjBuildConf(this->GetName(), projectSelConf); // for non custom projects, take the settings from the build configuration if(buildConf && !buildConf->IsCustomBuild()) { // Get the include paths and add them wxString projectIncludePaths = buildConf->GetIncludePath(); wxArrayString projectIncludePathsArr = wxStringTokenize(projectIncludePaths, wxT(";"), wxTOKEN_STRTOK); for(size_t i=0; i<projectIncludePathsArr.GetCount(); i++) { wxFileName fn; if(projectIncludePathsArr.Item(i) == wxT("..")) { fn = wxFileName(GetFileName().GetPath(), wxT("")); fn.RemoveLastDir(); } else if(projectIncludePathsArr.Item(i) == wxT(".")) { fn = wxFileName(GetFileName().GetPath(), wxT("")); } else { fn = projectIncludePathsArr.Item(i); if(fn.IsRelative()) { fn.MakeAbsolute(GetFileName().GetPath()); } } paths.Add( fn.GetFullPath() ); } // get the compiler options and add them wxString projectCompileOptions = buildConf->GetCompileOptions(); wxArrayString projectCompileOptionsArr = wxStringTokenize(projectCompileOptions, wxT(";"), wxTOKEN_STRTOK); for(size_t i=0; i<projectCompileOptionsArr.GetCount(); i++) { wxString cmpOption (projectCompileOptionsArr.Item(i)); cmpOption.Trim().Trim(false); // expand backticks, if the option is not a backtick the value remains // unchanged wxArrayString includePaths = DoBacktickToIncludePath(cmpOption); if(includePaths.IsEmpty() == false) paths.insert(paths.end(), includePaths.begin(), includePaths.end()); } } return paths; }
void PSCustomBuildPage::Load(BuildConfigPtr buildConf) { m_checkEnableCustomBuild->SetValue(buildConf->IsCustomBuild()); m_textCtrlCustomBuildWD->SetValue(buildConf->GetCustomBuildWorkingDir()); m_dvListCtrlTargets->DeleteAllItems(); wxVector<wxVariant> cols; cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_BUILD); cols.push_back(buildConf->GetCustomBuildCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_CLEAN); cols.push_back(buildConf->GetCustomCleanCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_REBUILD); cols.push_back(buildConf->GetCustomRebuildCmd()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_COMPILE_SINGLE_FILE); cols.push_back(buildConf->GetSingleFileBuildCommand()); m_dvListCtrlTargets->AppendItem(cols); cols.clear(); cols.push_back(ProjectCustomBuildTragetDlg::CUSTOM_TARGET_PREPROCESS_FILE); cols.push_back(buildConf->GetPreprocessFileCommand()); m_dvListCtrlTargets->AppendItem(cols); // Initialize the custom build targets std::map<wxString, wxString> targets = buildConf->GetCustomTargets(); std::map<wxString, wxString>::iterator titer = targets.begin(); for(; titer != targets.end(); ++titer) { if(ProjectCustomBuildTragetDlg::IsPredefinedTarget(titer->first)) continue; cols.clear(); cols.push_back(titer->first); cols.push_back(titer->second); m_dvListCtrlTargets->AppendItem(cols); } m_dlg->SetCustomBuildEnabled(m_checkEnableCustomBuild->IsChecked()); }
void clCxxWorkspace::CreateCompileCommandsJSON(JSONElement& compile_commands) const { BuildMatrixPtr matrix = clCxxWorkspaceST::Get()->GetBuildMatrix(); if(!matrix) return; wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); clCxxWorkspace::ProjectMap_t::const_iterator iter = m_projects.begin(); for(; iter != m_projects.end(); ++iter) { BuildConfigPtr buildConf = iter->second->GetBuildConfiguration(); if(buildConf && buildConf->IsProjectEnabled() && !buildConf->IsCustomBuild() && buildConf->IsCompilerRequired()) { iter->second->CreateCompileCommandsJSON(compile_commands); } } }
void BatchBuildDlg::GetBuildInfoList(std::list<QueueCommand>& buildInfoList) { bool clean_log(true); for (unsigned int i=0; i<m_checkListConfigurations->GetCount(); i++) { if (m_checkListConfigurations->IsChecked(i)) { wxString text = m_checkListConfigurations->GetString(i); wxString project = text.BeforeFirst(wxT('|')); wxString config = text.AfterFirst(wxT('|')); project.Trim().Trim(false); config.Trim().Trim(false); // get the selected configuration to be built BuildConfigPtr bldConf = WorkspaceST::Get()->GetProjBuildConf(project, config); if (bldConf) { QueueCommand buildInfo(project, config, true, m_cmd); // handle custom build projects properly if (bldConf->IsCustomBuild()) { buildInfo.SetKind(QueueCommand::kCustomBuild); switch (m_cmd) { case QueueCommand::kBuild: buildInfo.SetCustomBuildTarget(wxT("Build")); break; case QueueCommand::kClean: buildInfo.SetCustomBuildTarget(wxT("Clean")); break; } } buildInfo.SetCleanLog(clean_log); buildInfoList.push_back(buildInfo); clean_log = false; } } } }
wxArrayString PluginManager::GetProjectCompileFlags(const wxString& projectName, bool isCppFile) { if(IsWorkspaceOpen() == false) return wxArrayString(); wxArrayString args; // Next apppend the user include paths wxString errMsg; // First, we need to find the currently active workspace configuration BuildMatrixPtr matrix = GetWorkspace()->GetBuildMatrix(); if(!matrix) { return wxArrayString(); } wxString workspaceSelConf = matrix->GetSelectedConfigurationName(); // Now that we got the selected workspace configuration, extract the related project configuration ProjectPtr proj = GetWorkspace()->FindProjectByName(projectName, errMsg); if(!proj) { return args; } wxString projectSelConf = matrix->GetProjectSelectedConf(workspaceSelConf, proj->GetName()); BuildConfigPtr dependProjbldConf = GetWorkspace()->GetProjBuildConf(proj->GetName(), projectSelConf); if(dependProjbldConf && dependProjbldConf->IsCustomBuild() == false) { // Get the include paths and add them wxString projectIncludePaths = dependProjbldConf->GetIncludePath(); wxArrayString projectIncludePathsArr = wxStringTokenize(projectIncludePaths, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectIncludePathsArr.GetCount(); i++) { args.Add(wxString::Format(wxT("-I%s"), projectIncludePathsArr[i].c_str())); } // get the compiler options and add them wxString projectCompileOptions = dependProjbldConf->GetCompileOptions(); wxArrayString projectCompileOptionsArr = wxStringTokenize(projectCompileOptions, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectCompileOptionsArr.GetCount(); i++) { wxString cmpOption(projectCompileOptionsArr.Item(i)); cmpOption.Trim().Trim(false); wxString tmp; // Expand backticks / $(shell ...) syntax supported by codelite if(cmpOption.StartsWith(wxT("$(shell "), &tmp) || cmpOption.StartsWith(wxT("`"), &tmp)) { cmpOption = tmp; tmp.Clear(); if(cmpOption.EndsWith(wxT(")"), &tmp) || cmpOption.EndsWith(wxT("`"), &tmp)) { cmpOption = tmp; } if(m_backticks.find(cmpOption) == m_backticks.end()) { // Expand the backticks into their value wxArrayString outArr; // Apply the environment before executing the command EnvSetter setter(EnvironmentConfig::Instance(), NULL, projectName); ProcUtils::SafeExecuteCommand(cmpOption, outArr); wxString expandedValue; for(size_t j = 0; j < outArr.size(); j++) { expandedValue << outArr.Item(j) << wxT(" "); } m_backticks[cmpOption] = expandedValue; cmpOption = expandedValue; } else { cmpOption = m_backticks.find(cmpOption)->second; } } args.Add(cmpOption); } // get the compiler preprocessor and add them as well wxString projectPreps = dependProjbldConf->GetPreprocessor(); wxArrayString projectPrepsArr = wxStringTokenize(projectPreps, wxT(";"), wxTOKEN_STRTOK); for(size_t i = 0; i < projectPrepsArr.GetCount(); i++) { args.Add(wxString::Format(wxT("-D%s"), projectPrepsArr[i].c_str())); } } return args; }
bool CodeCompletionManager::GetDefinitionsAndSearchPaths(LEditor* editor, wxArrayString& searchPaths, wxArrayString& definitions) { // Sanity CHECK_PTR_RET_FALSE(editor); if(editor->GetProjectName().IsEmpty()) return false; if(!WorkspaceST::Get()->IsOpen()) return false; // Support only C/C++ files if(!FileExtManager::IsCxxFile(editor->GetFileName().GetFullName())) return false; // Get the file's project and get the build configuration settings // for it ProjectPtr proj = WorkspaceST::Get()->GetProject(editor->GetProjectName()); CHECK_PTR_RET_FALSE(proj); BuildConfigPtr buildConf = proj->GetBuildConfiguration(); CHECK_PTR_RET_FALSE(buildConf); CompilerPtr compiler = buildConf->GetCompiler(); CHECK_PTR_RET_FALSE(compiler); if(buildConf->IsCustomBuild()) { // Custom builds are handled differently CompilationDatabase compileDb; compileDb.Open(); if(compileDb.IsOpened()) { // we have compilation database for this workspace wxString compileLine, cwd; compileDb.CompilationLine(editor->GetFileName().GetFullPath(), compileLine, cwd); CL_DEBUG("Pre Processor dimming: %s\n", compileLine); CompilerCommandLineParser cclp(compileLine, cwd); searchPaths = cclp.GetIncludes(); // get the mcros definitions = cclp.GetMacros(); } else { // we will probably will fail... return false; } } else { // get the include paths based on the project settings (this is per build configuration) searchPaths = proj->GetIncludePaths(); CL_DEBUG("CxxPreProcessor will use the following include paths:"); CL_DEBUG_ARR(searchPaths); // get the compiler include paths // wxArrayString compileIncludePaths = compiler->GetDefaultIncludePaths(); // includePaths.insert(includePaths.end(), compileIncludePaths.begin(), compileIncludePaths.end()); definitions = proj->GetPreProcessors(); CL_DEBUG("CxxPreProcessor will use the following macros:"); CL_DEBUG_ARR(definitions); } // Append the compiler builtin macros wxArrayString builtinMacros = compiler->GetBuiltinMacros(); definitions.insert(definitions.end(), builtinMacros.begin(), builtinMacros.end()); return true; }
bool CodeCompletionManager::GetDefinitionsAndSearchPaths(clEditor* editor, wxArrayString& searchPaths, wxArrayString& definitions) { // Sanity CHECK_PTR_RET_FALSE(editor); if(editor->GetProjectName().IsEmpty()) return false; if(!clCxxWorkspaceST::Get()->IsOpen()) return false; // Support only C/C++ files if(!FileExtManager::IsCxxFile(editor->GetFileName().GetFullName())) return false; // Get the file's project and get the build configuration settings // for it ProjectPtr proj = clCxxWorkspaceST::Get()->GetProject(editor->GetProjectName()); CHECK_PTR_RET_FALSE(proj); BuildConfigPtr buildConf = proj->GetBuildConfiguration(); CHECK_PTR_RET_FALSE(buildConf); CompilerPtr compiler = buildConf->GetCompiler(); CHECK_PTR_RET_FALSE(compiler); #if 0 if(buildConf->IsCustomBuild()) { definitions = proj->GetPreProcessors(); CL_DEBUG("CxxPreProcessor will use the following macros:"); CL_DEBUG_ARR(definitions); // Custom builds are handled differently CompilationDatabase compileDb; compileDb.Open(); if(compileDb.IsOpened()) { // we have compilation database for this workspace wxString compileLine, cwd; compileDb.CompilationLine(editor->GetFileName().GetFullPath(), compileLine, cwd); CL_DEBUG("Pre Processor dimming: %s\n", compileLine); CompilerCommandLineParser cclp(compileLine, cwd); searchPaths = cclp.GetIncludes(); // get the mcros definitions << cclp.GetMacros(); } } #endif // get the include paths based on the project settings (this is per build configuration) searchPaths = proj->GetIncludePaths(); CL_DEBUG("CxxPreProcessor will use the following include paths:"); CL_DEBUG_ARR(searchPaths); // get the compiler include paths // wxArrayString compileIncludePaths = compiler->GetDefaultIncludePaths(); // includePaths.insert(includePaths.end(), compileIncludePaths.begin(), compileIncludePaths.end()); definitions = proj->GetPreProcessors(); // get macros out of workspace wxString strWorkspaceMacros = clCxxWorkspaceST::Get()->GetParserMacros(); wxArrayString workspaceMacros = wxStringTokenize(strWorkspaceMacros, wxT("\n\r"), wxTOKEN_STRTOK); for(size_t i = 0; i < workspaceMacros.GetCount(); i++) definitions.Add(workspaceMacros.Item(i).Trim().Trim(false).c_str()); CL_DEBUG("CxxPreProcessor will use the following macros:"); CL_DEBUG_ARR(definitions); // Append the compiler builtin macros wxArrayString builtinMacros = compiler->GetBuiltinMacros(); definitions.insert(definitions.end(), builtinMacros.begin(), builtinMacros.end()); return true; }
void ContinuousBuild::DoBuild(const wxString& fileName) { PRINT_MESSAGE(wxT("DoBuild\n")); // Make sure a workspace is opened if (!m_mgr->IsWorkspaceOpen()) { PRINT_MESSAGE(wxT("No workspace opened!\n")); return; } // Filter non source files FileExtManager::FileType type = FileExtManager::GetType(fileName); switch(type) { case FileExtManager::TypeSourceC: case FileExtManager::TypeSourceCpp: case FileExtManager::TypeResource: break; default: { PRINT_MESSAGE(wxT("Non source file\n")); return; } } wxString projectName = m_mgr->GetProjectNameByFile(fileName); if(projectName.IsEmpty()) { PRINT_MESSAGE(wxT("Project name is empty\n")); return; } wxString errMsg; ProjectPtr project = m_mgr->GetSolution()->FindProjectByName(projectName, errMsg); if(!project){ PRINT_MESSAGE(wxT("Could not find project for file\n")); return; } // get the selected configuration to be build BuildConfigPtr bldConf = m_mgr->GetSolution()->GetProjBuildConf( project->GetName(), wxEmptyString ); if ( !bldConf ) { PRINT_MESSAGE(wxT("Failed to locate build configuration\n")); return; } BuilderPtr builder = m_mgr->GetBuildManager()->GetBuilder( wxT( "GNU makefile for g++/gcc" ) ); if(!builder){ PRINT_MESSAGE(wxT("Failed to located builder\n")); return; } // Only normal file builds are supported if(bldConf->IsCustomBuild()){ PRINT_MESSAGE(wxT("Build is custom. Skipping\n")); return; } // get the single file command to use wxString cmd = builder->GetSingleFileCmd(projectName, bldConf->GetName(), fileName); WrapInShell(cmd); if( m_buildProcess.IsBusy() ) { // add the build to the queue if (m_files.Index(fileName) == wxNOT_FOUND) { m_files.Add(fileName); // update the UI m_view->AddFile(fileName); } return; } PRINT_MESSAGE(wxString::Format(wxT("cmd:%s\n"), cmd.c_str())); if(!m_buildProcess.Execute(cmd, fileName, project->GetFileName().GetPath(), this)) return; // Set some messages m_mgr->SetStatusMessage(wxString::Format(wxT("Compiling %s..."), wxFileName(fileName).GetFullName().c_str()), 0); // Add this file to the UI queue m_view->AddFile(fileName); }
wxString MacroManager::DoExpand( const wxString& expression, IManager* manager, const wxString& project, bool applyEnv, const wxString& confToBuild) { wxString expandedString(expression); clCxxWorkspace* workspace = clCxxWorkspaceST::Get(); if(!manager) { manager = clGetManager(); } size_t retries = 0; wxString dummyname, dummfullname; while((retries < 5) && FindVariable(expandedString, dummyname, dummyname)) { ++retries; DollarEscaper de(expandedString); if(workspace) { expandedString.Replace(wxT("$(WorkspaceName)"), workspace->GetName()); ProjectPtr proj = workspace->GetProject(project); if(proj) { wxString prjBuildWd; wxString prjRunWd; wxString project_name(proj->GetName()); // make sure that the project name does not contain any spaces project_name.Replace(wxT(" "), wxT("_")); BuildConfigPtr bldConf = workspace->GetProjBuildConf(proj->GetName(), confToBuild); if(bldConf) { bool isCustom = bldConf->IsCustomBuild(); expandedString.Replace(wxT("$(ProjectOutputFile)"), bldConf->GetOutputFileName()); // An alias expandedString.Replace(wxT("$(OutputFile)"), bldConf->GetOutputFileName()); // When custom build project, use the working directory set in the // custom build tab, otherwise use the project file's path prjBuildWd = isCustom ? bldConf->GetCustomBuildWorkingDir() : proj->GetFileName().GetPath(); prjRunWd = bldConf->GetWorkingDirectory(); } expandedString.Replace(wxT("$(ProjectWorkingDirectory)"), prjBuildWd); expandedString.Replace(wxT("$(ProjectRunWorkingDirectory)"), prjRunWd); expandedString.Replace(wxT("$(ProjectPath)"), proj->GetFileName().GetPath()); expandedString.Replace(wxT("$(WorkspacePath)"), workspace->GetWorkspaceFileName().GetPath()); expandedString.Replace(wxT("$(ProjectName)"), project_name); if(bldConf) { expandedString.Replace(wxT("$(IntermediateDirectory)"), bldConf->GetIntermediateDirectory()); expandedString.Replace(wxT("$(ConfigurationName)"), bldConf->GetName()); expandedString.Replace(wxT("$(OutDir)"), bldConf->GetIntermediateDirectory()); } if(expandedString.Find(wxT("$(ProjectFiles)")) != wxNOT_FOUND) expandedString.Replace(wxT("$(ProjectFiles)"), proj->GetFiles()); if(expandedString.Find(wxT("$(ProjectFilesAbs)")) != wxNOT_FOUND) expandedString.Replace(wxT("$(ProjectFilesAbs)"), proj->GetFiles(true)); } } if(manager) { IEditor* editor = manager->GetActiveEditor(); if(editor) { wxFileName fn(editor->GetFileName()); expandedString.Replace(wxT("$(CurrentFileName)"), fn.GetName()); wxString fpath(fn.GetPath()); fpath.Replace(wxT("\\"), wxT("/")); expandedString.Replace(wxT("$(CurrentFilePath)"), fpath); expandedString.Replace(wxT("$(CurrentFileExt)"), fn.GetExt()); expandedString.Replace(wxT("$(CurrentFileFullName)"), fn.GetFullName()); wxString ffullpath(fn.GetFullPath()); ffullpath.Replace(wxT("\\"), wxT("/")); expandedString.Replace(wxT("$(CurrentFileFullPath)"), ffullpath); expandedString.Replace(wxT("$(CurrentSelection)"), editor->GetSelection()); if(expandedString.Find(wxT("$(CurrentSelectionRange)")) != wxNOT_FOUND) { int start = editor->GetSelectionStart(), end = editor->GetSelectionEnd(); wxString output = wxString::Format(wxT("%i:%i"), start, end); expandedString.Replace(wxT("$(CurrentSelectionRange)"), output); } } } // exapand common macros wxDateTime now = wxDateTime::Now(); expandedString.Replace(wxT("$(User)"), wxGetUserName()); expandedString.Replace(wxT("$(Date)"), now.FormatDate()); if(manager && applyEnv) { expandedString.Replace(wxT("$(CodeLitePath)"), manager->GetInstallDirectory()); // Apply the environment and expand the variables EnvSetter es(NULL, NULL, project, confToBuild); expandedString = manager->GetEnv()->ExpandVariables(expandedString, false); } } return expandedString; }