cmake find module for scintilla
This commit is contained in:
76
cmake/FindLexilla.cmake
Normal file
76
cmake/FindLexilla.cmake
Normal file
@@ -0,0 +1,76 @@
|
||||
# FindLexilla.cmake
|
||||
#
|
||||
# This module tries to find Lexilla, and if not found, fetches and builds it using FetchContent.
|
||||
# It also assumes Scintilla is available (either found or fetched).
|
||||
#
|
||||
# Once done this will define
|
||||
# Lexilla_FOUND - True if Lexilla was found
|
||||
# Lexilla_LIBRARIES - List of libraries to link against (e.g., lexilla)
|
||||
# Lexilla_INCLUDE_DIRS - The Lexilla include directories
|
||||
|
||||
# Check if Lexilla is already found or if we are in a NO_MODULE situation
|
||||
if(Lexilla_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.16) # FetchContent requires CMake 3.14+, using 3.16 for consistency
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
lexilla
|
||||
URL https://www.scintilla.org/lexilla546.zip
|
||||
URL_HASH SHA256=079857fe786a99d69452a4cbd75b3d7bb5826bf9543bfef2a79b82b599200bd0 # Placeholder, please update with actual SHA256
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(lexilla)
|
||||
|
||||
# Lexilla needs Scintilla headers, so ensure Scintilla is found/fetched
|
||||
find_package(Scintilla REQUIRED)
|
||||
|
||||
add_library(lexilla SHARED)
|
||||
|
||||
# Set C++ standard for this target
|
||||
target_compile_features(lexilla PUBLIC cxx_std_17)
|
||||
|
||||
file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS
|
||||
# main library binding
|
||||
"${lexilla_SOURCE_DIR}/include/Lexilla.h"
|
||||
"${lexilla_SOURCE_DIR}/src/Lexilla.cxx"
|
||||
# lexlib
|
||||
"${lexilla_SOURCE_DIR}/lexlib/*.h"
|
||||
"${lexilla_SOURCE_DIR}/lexlib/*.cxx"
|
||||
# lexers
|
||||
"${lexilla_SOURCE_DIR}/lexers/Lex*.cxx"
|
||||
)
|
||||
|
||||
target_sources(lexilla
|
||||
PRIVATE
|
||||
${SRCS}
|
||||
)
|
||||
|
||||
target_include_directories(lexilla
|
||||
PUBLIC
|
||||
"${lexilla_SOURCE_DIR}/include"
|
||||
"${lexilla_SOURCE_DIR}/lexlib"
|
||||
)
|
||||
|
||||
target_link_libraries(lexilla PUBLIC Scintilla::Scintilla)
|
||||
|
||||
# Set variables for find_package
|
||||
set(Lexilla_FOUND TRUE)
|
||||
set(Lexilla_INCLUDE_DIRS
|
||||
"${lexilla_SOURCE_DIR}/include"
|
||||
"${lexilla_SOURCE_DIR}/lexlib"
|
||||
)
|
||||
|
||||
# Create an ALIAS target for modern CMake consumption
|
||||
if(NOT TARGET Lexilla::Lexilla)
|
||||
add_library(Lexilla::Lexilla ALIAS lexilla)
|
||||
endif()
|
||||
|
||||
# Set variables for find_package (for backward compatibility)
|
||||
set(Lexilla_LIBRARIES Lexilla::Lexilla) # Point to the ALIAS target
|
||||
|
||||
# Mark as advanced so it doesn't show up in GUI by default
|
||||
mark_as_advanced(Lexilla_FOUND Lexilla_LIBRARIES Lexilla_INCLUDE_DIRS)
|
||||
113
cmake/FindScintilla.cmake
Normal file
113
cmake/FindScintilla.cmake
Normal file
@@ -0,0 +1,113 @@
|
||||
# FindScintilla.cmake
|
||||
#
|
||||
# This module tries to find Scintilla, and if not found, fetches and builds it using FetchContent.
|
||||
#
|
||||
# Once done this will define
|
||||
# Scintilla_FOUND - True if Scintilla was found
|
||||
# Scintilla_LIBRARIES - List of libraries to link against (e.g., scintilla-qt)
|
||||
# Scintilla_INCLUDE_DIRS - The Scintilla include directories
|
||||
|
||||
# Check if Scintilla is already found or if we are in a NO_MODULE situation
|
||||
if(Scintilla_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.16) # FetchContent requires CMake 3.14+, using 3.16 for consistency
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
scintilla
|
||||
URL https://www.scintilla.org/scintilla558.zip
|
||||
URL_HASH SHA256=d719ad721fda6cf54094d44c2f40a37b519bfcd36f485f69b88011cb439fb4ef # Placeholder, please update with actual SHA256
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(scintilla)
|
||||
|
||||
# Ensure Qt6 and Python3 are found for Scintilla's build
|
||||
find_package(Qt6 REQUIRED
|
||||
COMPONENTS Widgets Core5Compat
|
||||
)
|
||||
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
|
||||
# Run WidgetGen.py to generate ScintillaEdit.h and ScintillaEdit.cpp
|
||||
# This needs to be done before compiling the Qt wrapper
|
||||
add_custom_command(
|
||||
OUTPUT "${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.h"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.cpp"
|
||||
COMMAND ${CMAKE_COMMAND} -E chdir "${scintilla_SOURCE_DIR}/qt/ScintillaEdit"
|
||||
${Python3_EXECUTABLE} WidgetGen.py
|
||||
DEPENDS "${scintilla_SOURCE_DIR}/qt/ScintillaEdit/WidgetGen.py"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.h.template"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.cpp.template"
|
||||
COMMENT "Generating ScintillaEdit.h and ScintillaEdit.cpp"
|
||||
)
|
||||
|
||||
add_custom_target(scintilla-widgetgen
|
||||
DEPENDS
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.h"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.cpp"
|
||||
)
|
||||
|
||||
add_library(scintilla-qt SHARED)
|
||||
|
||||
set_target_properties(scintilla-qt PROPERTIES AUTOMOC ON)
|
||||
|
||||
# Set C++ standard for this target
|
||||
target_compile_features(scintilla-qt PUBLIC cxx_std_17)
|
||||
|
||||
file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS
|
||||
"${scintilla_SOURCE_DIR}/include/*.h"
|
||||
"${scintilla_SOURCE_DIR}/src/*.h"
|
||||
"${scintilla_SOURCE_DIR}/src/*.cxx"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEditBase/*.h"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEditBase/*.cpp"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/*.h"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/*.cpp"
|
||||
)
|
||||
|
||||
target_sources(scintilla-qt
|
||||
PRIVATE
|
||||
${SRCS}
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.h"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit/ScintillaEdit.cpp"
|
||||
)
|
||||
|
||||
add_dependencies(scintilla-qt scintilla-widgetgen)
|
||||
|
||||
target_compile_definitions(scintilla-qt
|
||||
PRIVATE
|
||||
-DSCINTILLA_QT=1 -DMAKING_LIBRARY=1
|
||||
)
|
||||
|
||||
target_include_directories(scintilla-qt
|
||||
PUBLIC
|
||||
"${scintilla_SOURCE_DIR}/include"
|
||||
"${scintilla_SOURCE_DIR}/src"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEditBase"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit"
|
||||
)
|
||||
|
||||
target_link_libraries(scintilla-qt
|
||||
PUBLIC
|
||||
Qt::Widgets Qt::Core5Compat
|
||||
)
|
||||
|
||||
# Create an ALIAS target for modern CMake consumption
|
||||
if(NOT TARGET Scintilla::Scintilla)
|
||||
add_library(Scintilla::Scintilla ALIAS scintilla-qt)
|
||||
endif()
|
||||
|
||||
# Set variables for find_package (for backward compatibility)
|
||||
set(Scintilla_FOUND TRUE)
|
||||
set(Scintilla_LIBRARIES Scintilla::Scintilla) # Point to the ALIAS target
|
||||
set(Scintilla_INCLUDE_DIRS
|
||||
"${scintilla_SOURCE_DIR}/include"
|
||||
"${scintilla_SOURCE_DIR}/src"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEditBase"
|
||||
"${scintilla_SOURCE_DIR}/qt/ScintillaEdit"
|
||||
)
|
||||
|
||||
# Mark as advanced so it doesn't show up in GUI by default
|
||||
mark_as_advanced(Scintilla_FOUND Scintilla_LIBRARIES Scintilla_INCLUDE_DIRS)
|
||||
Reference in New Issue
Block a user