mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-21 17:35:55 +01:00
eclipse: add generation of editor language settings
Add automatic generation of editor language settings for C and C++, so the automatic code correction uses the correct compiler and compiler flags, including for example the correct C/C++ standard so construct from such standards are correctly managed by the IDE. Correct compiler and flags are automatically generated using the build environment data gathered during configure phase. The playground example has been modified to contain some code that is standard specific to demonstrate the new feature when run under Eclipse.
This commit is contained in:
parent
664513aa44
commit
229bf15ab2
@ -1,9 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <pkg1/exLibC/exLibC.hpp>
|
||||
|
||||
int check_smaller(int value) {
|
||||
const char* foo = u8"bar"; // u8 is C++17 only
|
||||
std::cout << __cplusplus << std::endl; // Check version of C++ standard
|
||||
|
||||
if (value < HELLO_LIMIT) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -2,12 +2,15 @@
|
||||
# encoding: utf-8
|
||||
|
||||
def options(opt):
|
||||
# We are using C++
|
||||
opt.load('compiler_cxx')
|
||||
# We are using C and C++
|
||||
opt.load('compiler_c compiler_cxx')
|
||||
|
||||
def configure(conf):
|
||||
# We are using C++
|
||||
conf.load('compiler_cxx')
|
||||
# We are using C and C++
|
||||
conf.load('compiler_c compiler_cxx')
|
||||
# Force some standards to see that IDE will follow them
|
||||
conf.env.CXXFLAGS=['-std=c++17']
|
||||
conf.env.CFLAGS=['-std=c17']
|
||||
|
||||
def build(bld):
|
||||
bld.shlib(source='exLibC/src/exLibC.cpp', includes='exLibC/src/include', target='exampleLibC', export_includes='exLibC/src/include/')
|
||||
|
@ -25,6 +25,8 @@ cdt_core = oe_cdt + '.core'
|
||||
cdt_bld = oe_cdt + '.build.core'
|
||||
extbuilder_dir = '.externalToolBuilders'
|
||||
extbuilder_name = 'Waf_Builder.launch'
|
||||
settings_dir = '.settings'
|
||||
settings_name = 'language.settings.xml'
|
||||
|
||||
class eclipse(Build.BuildContext):
|
||||
cmd = 'eclipse'
|
||||
@ -156,6 +158,61 @@ class eclipse(Build.BuildContext):
|
||||
project = self.impl_create_javaproject(javasrcpath, javalibpath)
|
||||
self.write_conf_to_xml('.classpath', project)
|
||||
|
||||
# Create editor language settings to have correct standards applied in IDE, as per project configuration
|
||||
try:
|
||||
os.mkdir(settings_dir)
|
||||
except OSError:
|
||||
pass # Ignore if dir already exists
|
||||
|
||||
lang_settings = Document()
|
||||
project = lang_settings.createElement('project')
|
||||
|
||||
# Language configurations for C and C++ via cdt
|
||||
if hasc:
|
||||
configuration = self.add(lang_settings, project, 'configuration',
|
||||
{'id' : 'org.eclipse.cdt.core.default.config.1', 'name': 'Default'})
|
||||
|
||||
extension = self.add(lang_settings, configuration, 'extension', {'point': 'org.eclipse.cdt.core.LanguageSettingsProvider'})
|
||||
|
||||
provider = self.add(lang_settings, extension, 'provider',
|
||||
{ 'copy-of': 'extension',
|
||||
'id': 'org.eclipse.cdt.ui.UserLanguageSettingsProvider'})
|
||||
|
||||
provider = self.add(lang_settings, extension, 'provider-reference',
|
||||
{ 'id': 'org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider',
|
||||
'ref': 'shared-provider'})
|
||||
|
||||
provider = self.add(lang_settings, extension, 'provider-reference',
|
||||
{ 'id': 'org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider',
|
||||
'ref': 'shared-provider'})
|
||||
|
||||
# C and C++ are kept as separated providers so appropriate flags are used also in mixed projects
|
||||
if self.env.CC:
|
||||
provider = self.add(lang_settings, extension, 'provider',
|
||||
{ 'class': 'org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector',
|
||||
'console': 'false',
|
||||
'id': 'org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector.1',
|
||||
'keep-relative-paths' : 'false',
|
||||
'name': 'CDT GCC Built-in Compiler Settings',
|
||||
'parameter': '%s %s ${FLAGS} -E -P -v -dD "${INPUTS}"'%(self.env.CC[0],' '.join(self.env['CFLAGS'])),
|
||||
'prefer-non-shared': 'true' })
|
||||
|
||||
self.add(lang_settings, provider, 'language-scope', { 'id': 'org.eclipse.cdt.core.gcc'})
|
||||
|
||||
if self.env.CXX:
|
||||
provider = self.add(lang_settings, extension, 'provider',
|
||||
{ 'class': 'org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector',
|
||||
'console': 'false',
|
||||
'id': 'org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector.2',
|
||||
'keep-relative-paths' : 'false',
|
||||
'name': 'CDT GCC Built-in Compiler Settings',
|
||||
'parameter': '%s %s ${FLAGS} -E -P -v -dD "${INPUTS}"'%(self.env.CXX[0],' '.join(self.env['CXXFLAGS'])),
|
||||
'prefer-non-shared': 'true' })
|
||||
self.add(lang_settings, provider, 'language-scope', { 'id': 'org.eclipse.cdt.core.g++'})
|
||||
|
||||
lang_settings.appendChild(project)
|
||||
self.write_conf_to_xml('%s%s%s'%(settings_dir, os.path.sep, settings_name), lang_settings)
|
||||
|
||||
def impl_create_project(self, executable, appname, hasc, hasjava, haspython, waf_executable):
|
||||
doc = Document()
|
||||
projectDescription = doc.createElement('projectDescription')
|
||||
@ -348,6 +405,12 @@ class eclipse(Build.BuildContext):
|
||||
|
||||
self.add(doc, storageModule, 'project', {'id': '%s.null.1'%appname, 'name': appname})
|
||||
|
||||
storageModule = self.add(doc, cproject, 'storageModule',
|
||||
{'moduleId': 'org.eclipse.cdt.core.LanguageSettingsProviders'})
|
||||
|
||||
storageModule = self.add(doc, cproject, 'storageModule',
|
||||
{'moduleId': 'scannerConfiguration'})
|
||||
|
||||
doc.appendChild(cproject)
|
||||
return doc
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user