fix build under newer KConfig by bump cmake min version

This commit is contained in:
2024-09-04 19:01:58 +08:00
parent 727a2ec214
commit 9fb3681e3a
1022 changed files with 4414 additions and 1375 deletions

View File

@ -0,0 +1,144 @@
// Lexilla lexer library use example
/** @file CheckLexilla.c
** Check that Lexilla.h works.
**/
// Copyright 2021 by Neil Hodgson <neilh@scintilla.org>
// This file is in the public domain.
// If the public domain is not possible in your location then it can also be used under the same
// license as Scintilla. https://www.scintilla.org/License.txt
/* Build and run
Win32
gcc CheckLexilla.c -I ../../include -o CheckLexilla
CheckLexilla
CheckLexilla ../SimpleLexer/SimpleLexer.dll
Win32 Visual C++
cl CheckLexilla.c -I ../../include -Fe: CheckLexilla
CheckLexilla
CheckLexilla ../SimpleLexer/SimpleLexer.dll
macOS
clang CheckLexilla.c -I ../../include -o CheckLexilla
./CheckLexilla
./CheckLexilla ../SimpleLexer/SimpleLexer.dylib
Linux
gcc CheckLexilla.c -I ../../include -ldl -o CheckLexilla
./CheckLexilla
./CheckLexilla ../SimpleLexer/SimpleLexer.so
While principally meant for compilation as C to act as an example of using Lexilla
from C it can also be built as C++.
Warnings are intentionally shown for the deprecated typedef LexerNameFromIDFn when compiled with
GCC or Clang or as C++.
*/
#include <stdio.h>
#if defined(_WIN32)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#if defined(__cplusplus)
#include "ILexer.h"
#endif
#include "Lexilla.h"
#if defined(__cplusplus)
using namespace Lexilla;
#endif
#if defined(_WIN32)
typedef FARPROC Function;
typedef HMODULE Module;
#else
typedef void *Function;
typedef void *Module;
#endif
static Function FindSymbol(Module m, const char *symbol) {
#if defined(_WIN32)
return GetProcAddress(m, symbol);
#else
return dlsym(m, symbol);
#endif
}
int main(int argc, char *argv[]) {
char szLexillaPath[] = "../../bin/" LEXILLA_LIB LEXILLA_EXTENSION;
const char *libPath = szLexillaPath;
if (argc > 1) {
libPath = argv[1];
}
#if defined(_WIN32)
Module lexillaLibrary = LoadLibraryA(libPath);
#else
Module lexillaLibrary = dlopen(libPath, RTLD_LAZY);
#endif
printf("Opened %s -> %p.\n", libPath, lexillaLibrary);
if (lexillaLibrary) {
GetLexerCountFn lexerCount = (GetLexerCountFn)FindSymbol(lexillaLibrary, LEXILLA_GETLEXERCOUNT);
if (lexerCount) {
int nLexers = lexerCount();
printf("There are %d lexers.\n", nLexers);
GetLexerNameFn lexerName = (GetLexerNameFn)FindSymbol(lexillaLibrary, LEXILLA_GETLEXERNAME);
for (int i = 0; i < nLexers; i++) {
char name[100] = "";
lexerName(i, name, sizeof(name));
printf("%s ", name);
}
printf("\n");
GetLexerFactoryFn lexerFactory = (GetLexerFactoryFn)FindSymbol(lexillaLibrary, LEXILLA_GETLEXERFACTORY);
LexerFactoryFunction lexerFactory4 = lexerFactory(4); // 4th entry is "as" which is an object lexer so works
printf("Lexer factory 4 -> %p.\n", lexerFactory4);
CreateLexerFn lexerCreate = (CreateLexerFn)FindSymbol(lexillaLibrary, LEXILLA_CREATELEXER);
ILexer5 *lexerCpp = lexerCreate("cpp");
printf("Created cpp lexer -> %p.\n", lexerCpp);
LexerNameFromIDFn lexerNameFromID = (LexerNameFromIDFn)FindSymbol(lexillaLibrary, LEXILLA_LEXERNAMEFROMID);
if (lexerNameFromID) {
const char *lexerNameCpp = lexerNameFromID(3); // SCLEX_CPP=3
if (lexerNameCpp) {
printf("Lexer name 3 -> %s.\n", lexerNameCpp);
} else {
printf("Lexer name 3 not available.\n");
}
} else {
printf("Lexer name from ID not supported.\n");
}
GetLibraryPropertyNamesFn libraryProperties = (GetLibraryPropertyNamesFn)FindSymbol(lexillaLibrary, LEXILLA_GETLIBRARYPROPERTYNAMES);
if (libraryProperties) {
const char *names = libraryProperties();
printf("Property names '%s'.\n", names);
} else {
printf("Property names not supported.\n");
}
SetLibraryPropertyFn librarySetProperty = (SetLibraryPropertyFn)FindSymbol(lexillaLibrary, LEXILLA_SETLIBRARYPROPERTY);
if (librarySetProperty) {
librarySetProperty("key", "value");
} else {
printf("Set property not supported.\n");
}
GetNameSpaceFn libraryNameSpace = (GetLibraryPropertyNamesFn)FindSymbol(lexillaLibrary, LEXILLA_GETNAMESPACE);
if (libraryNameSpace) {
const char *nameSpace = libraryNameSpace();
printf("Name space '%s'.\n", nameSpace);
} else {
printf("Name space not supported.\n");
}
}
}
}

View File

@ -0,0 +1,22 @@
.PHONY: all check clean
INCLUDES = -I ../../include
EXE = $(if $(windir),CheckLexilla.exe,CheckLexilla)
ifdef windir
RM = $(if $(wildcard $(dir $(SHELL))rm.exe), $(dir $(SHELL))rm.exe -f, del /q)
CC = gcc
else
LIBS += -ldl
endif
all: $(EXE)
check: $(EXE)
./$(EXE)
clean:
$(RM) $(EXE)
$(EXE): *.c
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $^ $(LIBS) $(LDLIBS) -o $@

View File

@ -0,0 +1,123 @@
// A simple lexer
/** @file SimpleLexer.cxx
** A lexer that follows the Lexilla protocol to allow it to be used from Lexilla clients like SciTE.
** The lexer applies alternating styles (0,1) to bytes of the text.
**/
// Copyright 2021 by Neil Hodgson <neilh@scintilla.org>
// This file is in the public domain.
// If the public domain is not possible in your location then it can also be used under the same
// license as Scintilla. https://www.scintilla.org/License.txt
// Windows/MSVC
// cl -std:c++17 -EHsc -LD -I ../../../scintilla/include -I ../../include -I ../../lexlib SimpleLexer.cxx ../../lexlib/*.cxx
// macOS/clang
// clang++ -dynamiclib --std=c++17 -I ../../../scintilla/include -I ../../include -I ../../lexlib SimpleLexer.cxx ../../lexlib/*.cxx -o SimpleLexer.dylib
// Linux/g++
// g++ -fPIC -shared --std=c++17 -I ../../../scintilla/include -I ../../include -I ../../lexlib SimpleLexer.cxx ../../lexlib/*.cxx -o SimpleLexer.so
/* It can be demonstrated in SciTE like this, substituting the actual shared library location as lexilla.path:
lexilla.path=.;C:\u\hg\lexilla\examples\SimpleLexer\SimpleLexer.dll
lexer.*.xx=simple
style.simple.1=fore:#FF0000
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <string_view>
#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"
// Lexilla.h should not be included here as it declares statically linked functions without the __declspec( dllexport )
#include "WordList.h"
#include "PropSetSimple.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
#include "LexerBase.h"
using namespace Scintilla;
using namespace Lexilla;
class LexerSimple : public LexerBase {
public:
LexerSimple() {
}
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override {
try {
Accessor astyler(pAccess, &props);
if (length > 0) {
astyler.StartAt(startPos);
astyler.StartSegment(startPos);
for (unsigned int k=0; k<length; k++) {
astyler.ColourTo(startPos+k, (startPos+k)%2);
}
}
astyler.Flush();
} catch (...) {
// Should not throw into caller as may be compiled with different compiler or options
pAccess->SetErrorStatus(SC_STATUS_FAILURE);
}
}
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override {
}
static ILexer5 *LexerFactorySimple() {
try {
return new LexerSimple();
} catch (...) {
// Should not throw into caller as may be compiled with different compiler or options
return nullptr;
}
}
};
#if defined(_WIN32)
#define EXPORT_FUNCTION __declspec(dllexport)
#define CALLING_CONVENTION __stdcall
#else
#define EXPORT_FUNCTION __attribute__((visibility("default")))
#define CALLING_CONVENTION
#endif
static const char *lexerName = "simple";
extern "C" {
EXPORT_FUNCTION int CALLING_CONVENTION GetLexerCount() {
return 1;
}
EXPORT_FUNCTION void CALLING_CONVENTION GetLexerName(unsigned int index, char *name, int buflength) {
*name = 0;
if ((index == 0) && (buflength > static_cast<int>(strlen(lexerName)))) {
strcpy(name, lexerName);
}
}
EXPORT_FUNCTION LexerFactoryFunction CALLING_CONVENTION GetLexerFactory(unsigned int index) {
if (index == 0)
return LexerSimple::LexerFactorySimple;
else
return 0;
}
EXPORT_FUNCTION Scintilla::ILexer5* CALLING_CONVENTION CreateLexer(const char *name) {
if (0 == strcmp(name, lexerName)) {
return LexerSimple::LexerFactorySimple();
}
return nullptr;
}
EXPORT_FUNCTION const char * CALLING_CONVENTION GetNameSpace() {
return "example";
}
}

View File

@ -0,0 +1,46 @@
.PHONY: all check clean
INCLUDES = -I ../../../scintilla/include -I ../../include -I ../../lexlib
BASE_FLAGS += --std=c++17
ifdef windir
SHAREDEXTENSION = dll
else
ifeq ($(shell uname),Darwin)
SHAREDEXTENSION = dylib
BASE_FLAGS += -arch arm64 -arch x86_64
LINK_FLAGS += -dynamiclib
else
BASE_FLAGS += -fPIC
SHAREDEXTENSION = so
endif
BASE_FLAGS += -fvisibility=hidden
endif
ifdef windir
RM = $(if $(wildcard $(dir $(SHELL))rm.exe), $(dir $(SHELL))rm.exe -f, del /q)
CXX = g++
endif
LIBRARY = SimpleLexer.$(SHAREDEXTENSION)
vpath %.cxx ../../lexlib
LEXLIB_SOURCES := $(sort $(notdir $(wildcard ../../lexlib/*.cxx)))
LEXLIB = $(LEXLIB_SOURCES:.cxx=.o)
%.o: %.cxx
$(CXX) $(INCLUDES) $(BASE_FLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
all: $(LIBRARY)
# make check requires CheckLexilla to have already been built
check: $(LIBRARY)
../CheckLexilla/CheckLexilla ./$(LIBRARY)
clean:
$(RM) *.o *obj *.lib *.exp $(LIBRARY)
$(LIBRARY): $(LEXLIB) *.cxx
$(CXX) $(INCLUDES) $(LINK_FLAGS) $(BASE_FLAGS) -shared $(CPPFLAGS) $(CXXFLAGS) $^ $(LIBS) $(LDLIBS) -o $@