-
Notifications
You must be signed in to change notification settings - Fork 1
Add CMakeLists.txt #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,3 +163,7 @@ CMakeLists.txt.user* | |
| *build*/ | ||
|
|
||
| .vscode/ | ||
|
|
||
| src/QScriptEngine/build | ||
|
|
||
| src/QQScriptDemo/build | ||
| 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 | ||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 | ||||||||
| ) | ||||||||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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) | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
-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() | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.gitignorefile already contains*build*/, so the two new entries are actually redundant (as they are already covered by the wildcard).