From 9eb2598ea429b0c509266d7956b1a94148884668 Mon Sep 17 00:00:00 2001 From: xomx Date: Sun, 23 Mar 2025 08:38:40 +0100 Subject: [PATCH] Add version of external libraries (Scintilla/Lexilla/Boost) into Debug Info Dynamically collects all the version info needed and creates NppLibsVersion.h file by the help of a pre-build event. Fix https://community.notepad-plus-plus.org/topic/21513/determining-supporting-library-versions Fix #11466, close #16318 --- .gitignore | 1 + PowerEditor/gcc/makefile | 9 +++- PowerEditor/src/CMakeLists.txt | 9 ++++ PowerEditor/src/NppLibsVersionH-generator.bat | 47 +++++++++++++++++++ .../src/WinControls/AboutDlg/AboutDlg.cpp | 20 ++++++++ PowerEditor/visual.net/notepadPlus.Cpp.props | 3 ++ boostregex/boost/version.hpp | 32 +++++++++++++ boostregex/nppSpecifics.mak | 2 +- boostregex/nppSpecifics_mingw.mak | 2 +- scintilla/win32/Scintilla.vcxproj | 2 +- 10 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 PowerEditor/src/NppLibsVersionH-generator.bat create mode 100644 boostregex/boost/version.hpp diff --git a/.gitignore b/.gitignore index 2fd593972..8dd4fd53e 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,7 @@ PowerEditor/visual.net/ARM64 PowerEditor/src/tools/NppShell/build_ARM64 PowerEditor/src/tools/NppShell/build_Win32 PowerEditor/src/tools/NppShell/build_x64 +PowerEditor/src/NppLibsVersion.h # scintilla - generated files scintilla/bin/SciLexer.* diff --git a/PowerEditor/gcc/makefile b/PowerEditor/gcc/makefile index cc9ef1e3f..d680273fc 100644 --- a/PowerEditor/gcc/makefile +++ b/PowerEditor/gcc/makefile @@ -184,6 +184,7 @@ CPDIR := cp -r RMDIR := rm -rf CP := cp RM := rm -f +PREBUILD_EVENT_CMD := cmd //C "cd PowerEditor/src && NppLibsVersionH-generator.bat" normalize-path = $1 else ifneq "$(wildcard $(dir $(SHELL))ls.exe)" "" # a Windows system with a proper shell @@ -195,6 +196,7 @@ CPDIR := $(SHELL_DIRECTORY)cp.exe -r RMDIR := $(SHELL_DIRECTORY)rm.exe -rf CP := $(SHELL_DIRECTORY)cp.exe RM := $(SHELL_DIRECTORY)rm.exe -f +PREBUILD_EVENT_CMD := cmd //C "cd PowerEditor/src && NppLibsVersionH-generator.bat" normalize-path = $1 else # a standard Windows system @@ -203,6 +205,7 @@ CPDIR := xcopy /q /e /i /y RMDIR := rmdir /q /s CP := copy /y RM := del /q +PREBUILD_EVENT_CMD := cd ..\src && NppLibsVersionH-generator.bat normalize-path = $(subst /,\,$1) endif @@ -230,9 +233,13 @@ RC_TARGETS := $(patsubst %.rc,$(BUILD_DIRECTORY)/%.res,$(sort $(filter %.rc,$(GC SUBMAKEFLAGS += $(if $(NUMBER_OF_PROCESSORS),-j$(NUMBER_OF_PROCESSORS),) -all: $(SCINTILLA_TARGET) $(LEXILLA_TARGET) +all: pre-build-event $(SCINTILLA_TARGET) $(LEXILLA_TARGET) $(AT)$(MAKE) -f $(firstword $(MAKEFILE_LIST)) $(SUBMAKEFLAGS) binary +pre-build-event: + @echo Executing pre-build events... + $(AT)$(PREBUILD_EVENT_CMD) + $(BUILD_DIRECTORY): @echo + creating BUILD_DIRECTORY $@ $(AT)$(MKDIR) $(call normalize-path,$(sort $@ $(patsubst %/,%,$(dir $(CXX_TARGETS) $(RC_TARGETS))))) diff --git a/PowerEditor/src/CMakeLists.txt b/PowerEditor/src/CMakeLists.txt index be821a95b..ea2d3330f 100644 --- a/PowerEditor/src/CMakeLists.txt +++ b/PowerEditor/src/CMakeLists.txt @@ -423,6 +423,15 @@ find_library(LEXILLA_STATIC_LIBRARY REQUIRED ) +execute_process( + COMMAND cmd /C "cd ${CMAKE_SOURCE_DIR} && NppLibsVersionH-generator.bat" + RESULT_VARIABLE pre-build-result + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) +if(NOT pre-build-result EQUAL 0) + message(FATAL_ERROR "Pre-build event failed with exit code: ${pre-build-result}") +endif() + ADD_EXECUTABLE(notepad++ ${option} ${src_files} ${include_files} ${rcFiles}) diff --git a/PowerEditor/src/NppLibsVersionH-generator.bat b/PowerEditor/src/NppLibsVersionH-generator.bat new file mode 100644 index 000000000..709606602 --- /dev/null +++ b/PowerEditor/src/NppLibsVersionH-generator.bat @@ -0,0 +1,47 @@ +@echo off + +rem If this batch file is called from the Microsoft Visual Studio pre-build event, +rem then the current dir for this bat-file is set to Notepad++ solution/project dir. +rem Because in this batch file we have to go two dir-levels higher (for finding the files +rem from the external libraries) from both the solution/project dir and from the dir, +rem where this batch file is located, we can run this batch file ok also manually +rem and not only from that MSVS event. +set outputFile="..\..\PowerEditor\src\NppLibsVersion.h" + +if exist %outputFile% del %outputFile% + +rem First "for" finds and extracts specific one line string like "#define VERSION_SCINTILLA "5.5.4"". +rem Second "for" then uses regex to extract only the "..." version part substring from it. + +set sciVerStr="N/A" +for /F "delims=" %%a in ('findstr /L /C:"#define VERSION_SCINTILLA " "..\..\scintilla\win32\ScintRes.rc"') do ( + for %%b in (%%a) do ( + echo %%b | findstr /R "[0-9]*\.[0-9]*\." > nul 2>&1 && set sciVerStr=%%b + ) +) + +set lexVerStr="N/A" +for /F "delims=" %%a in ('findstr /L /C:"#define VERSION_LEXILLA " "..\..\lexilla\src\LexillaVersion.rc"') do ( + for %%b in (%%a) do ( + echo %%b | findstr /R "[0-9]*\.[0-9]*\." > nul 2>&1 && set lexVerStr=%%b + ) +) + +set boostRegexVerStr="N/A" +for /F "delims=" %%a in ('findstr /L /C:"#define BOOST_LIB_VERSION " "..\..\boostregex\boost\version.hpp"') do ( + for %%b in (%%a) do ( + echo %%b | findstr /R "[0-9]*_[0-9]*\" > nul 2>&1 && set boostRegexVerStr=%%b + ) +) + +rem At this point, we should have the quoted version strings collected: +echo Scintilla version detected: %sciVerStr% +echo Lexilla version detected: %lexVerStr% +echo Boost Regex version detected: %boostRegexVerStr% + +rem And finally create the output file: +echo // NppLibsVersion.h>%outputFile% +echo // - maintained by NppLibsVersionH-generator.bat>>%outputFile% +echo #define NPP_SCINTILLA_VERSION %sciVerStr%>>%outputFile% +echo #define NPP_LEXILLA_VERSION %lexVerStr%>>%outputFile% +echo #define NPP_BOOST_REGEX_VERSION %boostRegexVerStr%>>%outputFile% diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index 79b50251d..7f40089ef 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -18,6 +18,11 @@ #include "AboutDlg.h" #include "Parameters.h" #include "localization.h" +#if defined __has_include +#if __has_include ("NppLibsVersion.h") +#include "NppLibsVersion.h" +#endif +#endif using namespace std; @@ -197,6 +202,21 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _debugInfoStr += L"Built with : (unknown)\r\n"; #endif + // Scintilla/Lexilla version + _debugInfoStr += L"Scintilla/Lexilla included : "; + { + string strSciLexVer = NPP_SCINTILLA_VERSION; + strSciLexVer += "/"; + strSciLexVer += NPP_LEXILLA_VERSION; + _debugInfoStr += wmc.char2wchar(strSciLexVer.c_str(), CP_ACP); + } + _debugInfoStr += L"\r\n"; + + // Boost Regex version + _debugInfoStr += L"Boost Regex included : "; + _debugInfoStr += wmc.char2wchar(NPP_BOOST_REGEX_VERSION, CP_ACP); + _debugInfoStr += L"\r\n"; + // Binary path _debugInfoStr += L"Path : "; wchar_t nppFullPath[MAX_PATH]{}; diff --git a/PowerEditor/visual.net/notepadPlus.Cpp.props b/PowerEditor/visual.net/notepadPlus.Cpp.props index 320ee8dc8..dffcc7dbc 100644 --- a/PowerEditor/visual.net/notepadPlus.Cpp.props +++ b/PowerEditor/visual.net/notepadPlus.Cpp.props @@ -54,6 +54,9 @@ ..\src\dpiAware.manifest;%(AdditionalManifestFiles) + + call "..\..\PowerEditor\src\NppLibsVersionH-generator.bat" + diff --git a/boostregex/boost/version.hpp b/boostregex/boost/version.hpp new file mode 100644 index 000000000..989f25fa3 --- /dev/null +++ b/boostregex/boost/version.hpp @@ -0,0 +1,32 @@ +// Boost version.hpp configuration header file ------------------------------// + +// (C) Copyright John maddock 1999. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/config for documentation + +#ifndef BOOST_VERSION_HPP +#define BOOST_VERSION_HPP + +// +// Caution: this is the only Boost header that is guaranteed +// to change with every Boost release. Including this header +// will cause a recompile every time a new Boost version is +// used. +// +// BOOST_VERSION % 100 is the patch level +// BOOST_VERSION / 100 % 1000 is the minor version +// BOOST_VERSION / 100000 is the major version + +#define BOOST_VERSION 108500 + +// +// BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION +// but as a *string* in the form "x_y[_z]" where x is the major version +// number, y is the minor version number, and z is the patch level if not 0. +// This is used by to select which library version to link to. + +#define BOOST_LIB_VERSION "1_85" + +#endif diff --git a/boostregex/nppSpecifics.mak b/boostregex/nppSpecifics.mak index 0a692f9a6..37eb0c1e5 100644 --- a/boostregex/nppSpecifics.mak +++ b/boostregex/nppSpecifics.mak @@ -15,7 +15,7 @@ SRC_OBJS=\ INCLUDES=$(INCLUDES) -I../../boostregex -CXXFLAGS=$(CXXFLAGS) -DSCI_OWNREGEX +CXXFLAGS=$(CXXFLAGS) -DSCI_OWNREGEX -DBOOST_REGEX_STANDALONE $(DIR_O)\UTF8DocumentIterator.obj:: ../../boostregex/UTF8DocumentIterator.cxx diff --git a/boostregex/nppSpecifics_mingw.mak b/boostregex/nppSpecifics_mingw.mak index dfd4b41aa..21cb96062 100644 --- a/boostregex/nppSpecifics_mingw.mak +++ b/boostregex/nppSpecifics_mingw.mak @@ -11,7 +11,7 @@ vpath %.h $(DIR_BOOST) vpath %.cxx $(DIR_BOOST) INCLUDES += -I $(DIR_BOOST) -CXXFLAGS += -DSCI_OWNREGEX +CXXFLAGS += -DSCI_OWNREGEX -DBOOST_REGEX_STANDALONE BOOST_OBJS = \ $(DIR_O)/BoostRegExSearch.o \ diff --git a/scintilla/win32/Scintilla.vcxproj b/scintilla/win32/Scintilla.vcxproj index ee595c207..1f826ba35 100644 --- a/scintilla/win32/Scintilla.vcxproj +++ b/scintilla/win32/Scintilla.vcxproj @@ -91,7 +91,7 @@ Level4 - _CRT_SECURE_NO_DEPRECATE;_USRDLL;SCI_OWNREGEX;SCI_NAMESPACE;%(PreprocessorDefinitions) + _CRT_SECURE_NO_DEPRECATE;_USRDLL;BOOST_REGEX_STANDALONE;SCI_OWNREGEX;SCI_NAMESPACE;%(PreprocessorDefinitions) ..\include;..\src;..\..\boostregex true true