Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ CMakeLists.txt.user*
*build*/

.vscode/

src/QScriptEngine/build

src/QQScriptDemo/build
Comment on lines +166 to +169
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
src/QScriptEngine/build
src/QQScriptDemo/build

The .gitignore file already contains *build*/, so the two new entries are actually redundant (as they are already covered by the wildcard).

84 changes: 84 additions & 0 deletions examples/QQScriptDemo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.16)

project(QQScriptDemo LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)

find_package(Qt6 REQUIRED COMPONENTS
Copy link
Copy Markdown
Owner

@G-Yong G-Yong May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
find_package(Qt6 REQUIRED COMPONENTS
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS

Adaptive Qt version

Core
Gui
Widgets
Concurrent
)

# Check whether Qt Script is available.
# Qt6 normally doesn't provide QtScript, but this preserves the qmake logic.
find_package(Qt6 QUIET COMPONENTS Script)

if(Qt6Script_FOUND)
set(SCRIPT_LIB Qt6::Script)
else()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../src/QScriptEngine
${CMAKE_BINARY_DIR}/QScriptEngine)

# Replace ScriptEngine with the actual target name exported
# by ../../src/QScriptEngine/CMakeLists.txt.
set(SCRIPT_LIB QuickQtScript)
endif()

qt_standard_project_setup()

qt_add_executable(${PROJECT_NAME}
main.cpp
mainwindow.cpp
myqobject.cpp
myscriptengineagent.cpp

codeEditor/jscodeeditor.cpp
codeEditor/jssyntaxhighlighter.cpp
codeEditor/linenumberarea.cpp
codeEditor/codefoldingarea.cpp

mainwindow.h
myqobject.h
barprototype.h
myscriptcode.h
myscriptengineagent.h

codeEditor/jscodeeditor.h
codeEditor/jssyntaxhighlighter.h
codeEditor/linenumberarea.h
codeEditor/codefoldingarea.h

mainwindow.ui
js.qrc
)

if(NOT Qt6Script_FOUND)
target_sources(${PROJECT_NAME}
PRIVATE
quickjsTest.h
)
endif()

target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
Qt6::Concurrent
${SCRIPT_LIB}
)

# Equivalent of:
# DESTDIR = $$OUT_PWD
set_target_properties(${PROJECT_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)

install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
)
109 changes: 109 additions & 0 deletions src/QScriptEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
cmake_minimum_required(VERSION 3.16)
project(QuickQtScript LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)

find_package(Qt6 REQUIRED COMPONENTS Core)

# -------------------------------------------------
# Includes
# -------------------------------------------------
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include
)
Comment on lines +12 to +18
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# -------------------------------------------------
# Includes
# -------------------------------------------------
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include
)

Since target_include_directories(...) already handles the same path, the global include_directories variable will pollute the parent project’s scope and should be removed.



# -------------------------------------------------
# Option: system or bundled QuickJS
# -------------------------------------------------
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/quickjs/CMakeLists.txt")
set(USE_SYSTEM_QUICKJS_DEFAULT OFF)
else()
set(USE_SYSTEM_QUICKJS_DEFAULT ON)
endif()

option(USE_SYSTEM_QUICKJS "Use system-installed QuickJS instead of bundled" ${USE_SYSTEM_QUICKJS_DEFAULT})

# -------------------------------------------------
# QuickJS selection
# -------------------------------------------------
if(USE_SYSTEM_QUICKJS)
message(STATUS "Using SYSTEM QuickJS")
find_package(qjs REQUIRED CONFIG)
else()
message(STATUS "Using BUNDLED QuickJS")

add_subdirectory(quickjs)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t seem necessary to include the entire QuickJS library, as we only need a few of its files. If we include the whole thing, it looks as though it will compile things like qjs by default, which we don’t need.

endif()

# -------------------------------------------------
# Library target
# -------------------------------------------------
add_library(${PROJECT_NAME} STATIC SHARED
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STATIC SHARED is an invalid parameter; CMake will return an error immediately. You should either specify a single type or omit the type entirely (allowing the user to control this via BUILD_SHARED_LIBS).

${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptContext.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptEngine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptValue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptValueIterator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptEngineAgent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptContextInfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptSyntaxCheckResult.cpp

${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptContext.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptEngine.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptValue.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptValueIterator.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptEngineAgent.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptContextInfo.h
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptSyntaxCheckResult.h
)

target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Core
)

target_compile_options(${PROJECT_NAME} PRIVATE -fpermissive -Wno-narrowing)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_compile_options(${PROJECT_NAME} PRIVATE -fpermissive -Wno-narrowing)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -fpermissive -Wno-narrowing)
endif()

-fpermissive and -Wno-narrowing are GCC/Clang-specific flags; they will cause errors in MSVC. A compiler check is required.


target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include
)

# -------------------------------------------------
# Compile definitions
# -------------------------------------------------

target_compile_definitions(${PROJECT_NAME} PRIVATE
JS_HAVE_THREADS
_GNU_SOURCE
)

if (WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE
__TINYC__
WIN32_LEAN_AND_MEAN
)

target_link_libraries(${PROJECT_NAME} PRIVATE
ws2_32
iphlpapi
)
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE qjs)

# -------------------------------------------------
# Optional feature (USE_LIBC)
# -------------------------------------------------
option(USE_LIBC "Enable libc support" OFF)

if (USE_LIBC)
target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/QScriptLibrary.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scriptEngine/include/QScriptLibrary.h
)
endif()
2 changes: 1 addition & 1 deletion src/QScriptEngine/scriptEngine/QScriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
#include <QDebug>
#include <QApplication>
#include <QCoreApplication>
#include <QScriptEngine.h>
#include <QScriptEngineAgent.h>
#include "quickjs.h"
Expand Down