From b1ccd9ab328cc7f7e34ab653ec93f389b9945e19 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Sun, 9 May 2021 20:27:28 +0200 Subject: cmake: Add bundled QtScript build Also, make QtScript dependency optional like we do in the Qbs build. Tested on macOS, Linux and Windows. CMake 3.15 is now required for the CMP0092 policy which removes default warning flags from CMAKE_CXX_FLAGS. Change-Id: I199fb802d5ad72d1ac8d5a89c05372c43581c95d Reviewed-by: Christian Kandeler --- .github/workflows/main.yml | 3 + CMakeLists.txt | 6 +- cmake/QbsBuildConfig.cmake | 1 + src/lib/CMakeLists.txt | 6 + src/lib/corelib/CMakeLists.txt | 2 +- src/lib/scriptengine/CMakeLists.txt | 361 +++++++++++++++++++++++++++++++++++ tests/auto/buildgraph/CMakeLists.txt | 2 + tests/auto/language/CMakeLists.txt | 2 +- 8 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 src/lib/scriptengine/CMakeLists.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1245daeca..b15885b8a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,6 +68,7 @@ jobs: - { name: 'Build on Linux (CMake)', script: './scripts/build-qbs-with-cmake.sh', + options: '-DQBS_USE_BUNDLED_QT_SCRIPT=1', cacheid: 'cmake', } - { @@ -81,6 +82,8 @@ jobs: QTEST_FUNCTION_TIMEOUT: 9000000 steps: - uses: actions/checkout@v1 + with: + submodules: true - name: Create .ccache dir run: mkdir -p ~/.ccache - name: prepare timestamp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b95f959d..2e3d15219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.15) ## Add paths to check for cmake modules: list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -29,10 +29,12 @@ if(WITH_TESTS) endif() find_package(Qt5 - COMPONENTS Concurrent Core Gui Network Script Widgets Xml ${QT_TEST_COMPONENT} + COMPONENTS Concurrent Core Gui Network Widgets Xml ${QT_TEST_COMPONENT} REQUIRED ) +find_package(Qt5 COMPONENTS Script) + add_subdirectory(src) add_subdirectory(doc) add_subdirectory(share) diff --git a/cmake/QbsBuildConfig.cmake b/cmake/QbsBuildConfig.cmake index b6614ce3f..a1eecded8 100644 --- a/cmake/QbsBuildConfig.cmake +++ b/cmake/QbsBuildConfig.cmake @@ -3,6 +3,7 @@ option(WITH_UNIT_TESTS "Build Unit Tests" OFF) option(WITH_PROJECT_FILE_UPDATES "Enable project file updates support" ON) option(INSTALL_PUBLIC_HEADERS "Whether to install public headers" ON) option(QBS_ENABLE_RPATH "Whether to enable RPATH" ON) +option(QBS_USE_BUNDLED_QT_SCRIPT "Whether to use bundled QtScript module" OFF) option(QBS_INSTALL_HTML_DOCS "Whether to install HTML Documentation" OFF) option(QBS_INSTALL_QCH_DOCS "Whether to install QCH Documentation" OFF) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index f029edd1f..8356cd6a1 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,2 +1,8 @@ +if (QBS_USE_BUNDLED_QT_SCRIPT OR NOT Qt5Script_FOUND) + add_subdirectory(scriptengine) +else() + add_library(qbsscriptengine ALIAS Qt5::Script) +endif() + add_subdirectory(corelib) add_subdirectory(msbuild) diff --git a/src/lib/corelib/CMakeLists.txt b/src/lib/corelib/CMakeLists.txt index 224754a30..3a070b55c 100644 --- a/src/lib/corelib/CMakeLists.txt +++ b/src/lib/corelib/CMakeLists.txt @@ -422,7 +422,7 @@ add_qbs_library(qbscore PUBLIC_DEFINES ${QBS_PROJECT_FILE_UPDATES_DEFINES} DEPENDS - Qt5::CorePrivate Qt5::Network Qt5::Script Qt5::Xml ${EXTERNAL_DEPENDS} + Qt5::CorePrivate Qt5::Network qbsscriptengine Qt5::Xml ${EXTERNAL_DEPENDS} PUBLIC_DEPENDS Qt5::Core INCLUDES diff --git a/src/lib/scriptengine/CMakeLists.txt b/src/lib/scriptengine/CMakeLists.txt new file mode 100644 index 000000000..452605888 --- /dev/null +++ b/src/lib/scriptengine/CMakeLists.txt @@ -0,0 +1,361 @@ +set(QT_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../shared/qtscript/src/") + +if (UNIX) + set(_USE_SYSTEM_MALLOC NO) +else() + set(_USE_SYSTEM_MALLOC YES) +endif (UNIX) + +set(JAVASCRIPT_CORE_INCLUDES + assembler + bytecode + bytecompiler + debugger + interpreter + jit + parser + pcre + profiler + runtime + wrec + wtf + wtf/unicode + yarr + API + ForwardingHeaders + generated +) +list_transform_prepend(JAVASCRIPT_CORE_INCLUDES "${QT_SCRIPT_PATH}/3rdparty/javascriptcore/JavaScriptCore/") + +set(QT_SCRIPT_PUBLIC_INCLUDES + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_BINARY_DIR}/include" +) + +set(QT_SCRIPT_INCLUDES + "${QT_SCRIPT_PATH}/3rdparty/javascriptcore" + "${QT_SCRIPT_PATH}/3rdparty/javascriptcore/JavaScriptCore" + "${QT_SCRIPT_PATH}/script" + "${QT_SCRIPT_PATH}/script/api" + "${QT_SCRIPT_PATH}/script/parser" + "${CMAKE_CURRENT_BINARY_DIR}/include/QtScript/${Qt5_VERSION}/QtScript" +) + +set(QT_SCRIPT_DEFINES + "QT_BUILD_SCRIPT_LIB" + "QT_NO_USING_NAMESPACE" + "JSC=QTJSC" + "jscyyparse=qtjscyyparse" + "jscyylex=qtjscyylex" + "jscyyerror=qtjscyyerror" + "WTF=QTWTF" + "LOG_DISABLED=1" + "WTF_USE_JAVASCRIPTCORE_BINDINGS=1" + "WTF_CHANGES=1" + "JS_NO_EXPORT" + + # JavaScriptCore + "BUILDING_QT__" + "BUILDING_JavaScriptCore" + "BUILDING_WTF" + "ENABLE_JIT=0" + "ENABLE_YARR_JIT=0" + "ENABLE_YARR=0" + + # WebKit + "WTF_USE_ACCELERATED_COMPOSITING" +) + +if (APPLE) + list(APPEND QT_SCRIPT_DEFINES "ENABLE_JSC_MULTIPLE_THREADS=0") +elseif(WIN32) + list(APPEND QT_SCRIPT_DEFINES "NOMINMAX" "_CRT_RAND_S") +endif() + +if (MSVC) + set(QT_SCRIPT_CXX_FLAGS "/wd4291" "/wd4344" "/wd4396" "/wd4503" "/wd4800" "/wd4819" "/wd4996") +else() + set(QT_SCRIPT_CXX_FLAGS "-fno-strict-aliasing" "-w" + "-Wall" "-Wreturn-type" "-Wcast-align" "-Wchar-subscripts" + "-Wformat-security" "-Wreturn-type" "-Wno-unused-parameter" + "-Wno-sign-compare" "-Wno-switch" "-Wno-switch-enum" "-Wundef" + "-Wmissing-noreturn" "-Winit-self" "-Wno-deprecated" "-Wno-suggest-attribute=noreturn" + "-Wno-nonnull-compare" "-pthread") +endif() + +set(QT_SCRIPT_PUBLIC_DEPENDS Qt5::Core) +if (UNIX) + list(APPEND QT_SCRIPT_PUBLIC_DEPENDS "pthread") +elseif(WIN32) + list(APPEND QT_SCRIPT_PUBLIC_DEPENDS "winmm") +endif() + +set(PCRE_SOURCES + pcre_compile.cpp + pcre_exec.cpp + pcre_tables.cpp + pcre_ucp_searchfuncs.cpp + pcre_xclass.cpp +) +list_transform_prepend(PCRE_SOURCES "${QT_SCRIPT_PATH}/3rdparty/javascriptcore/JavaScriptCore/pcre/") + +if (NOT _USE_SYSTEM_MALLOC) + set(SYSTEM_MALLOC_SOURCES + wtf/TCSystemAlloc.cpp + ) + list_transform_prepend(SYSTEM_MALLOC_SOURCES "${QT_SCRIPT_PATH}/3rdparty/javascriptcore/JavaScriptCore/") + + list(APPEND QT_SCRIPT_DEFINES "USE_SYSTEM_MALLOC") +else() + set(SYSTEM_MALLOC_SOURCES "") +endif() + +set(JAVASCRIPT_CORE_SOURCES + API/JSBase.cpp + API/JSCallbackConstructor.cpp + API/JSCallbackFunction.cpp + API/JSCallbackObject.cpp + API/JSClassRef.cpp + API/JSContextRef.cpp + API/JSObjectRef.cpp + API/JSStringRef.cpp + API/JSValueRef.cpp + API/OpaqueJSString.cpp + assembler/ARMAssembler.cpp + assembler/MacroAssemblerARM.cpp + bytecode/CodeBlock.cpp + bytecode/JumpTable.cpp + bytecode/Opcode.cpp + bytecode/SamplingTool.cpp + bytecode/StructureStubInfo.cpp + bytecompiler/BytecodeGenerator.cpp + bytecompiler/NodesCodegen.cpp + debugger/DebuggerActivation.cpp + debugger/DebuggerCallFrame.cpp + debugger/Debugger.cpp + generated/Grammar.cpp + interpreter/CallFrame.cpp + interpreter/Interpreter.cpp + interpreter/RegisterFile.cpp + parser/Lexer.cpp + parser/Nodes.cpp + parser/ParserArena.cpp + parser/Parser.cpp + profiler/Profile.cpp + profiler/ProfileGenerator.cpp + profiler/ProfileNode.cpp + profiler/Profiler.cpp + runtime/ArgList.cpp + runtime/Arguments.cpp + runtime/ArrayConstructor.cpp + runtime/ArrayPrototype.cpp + runtime/BooleanConstructor.cpp + runtime/BooleanObject.cpp + runtime/BooleanPrototype.cpp + runtime/CallData.cpp + runtime/Collector.cpp + runtime/CommonIdentifiers.cpp + runtime/Completion.cpp + runtime/ConstructData.cpp + runtime/DateConstructor.cpp + runtime/DateConversion.cpp + runtime/DateInstance.cpp + runtime/DatePrototype.cpp + runtime/ErrorConstructor.cpp + runtime/Error.cpp + runtime/ErrorInstance.cpp + runtime/ErrorPrototype.cpp + runtime/ExceptionHelpers.cpp + runtime/Executable.cpp + runtime/FunctionConstructor.cpp + runtime/FunctionPrototype.cpp + runtime/GetterSetter.cpp + runtime/GlobalEvalFunction.cpp + runtime/Identifier.cpp + runtime/InitializeThreading.cpp + runtime/InternalFunction.cpp + runtime/JSActivation.cpp + runtime/JSAPIValueWrapper.cpp + runtime/JSArray.cpp + runtime/JSByteArray.cpp + runtime/JSCell.cpp + runtime/JSFunction.cpp + runtime/JSGlobalData.cpp + runtime/JSGlobalObject.cpp + runtime/JSGlobalObjectFunctions.cpp + runtime/JSImmediate.cpp + runtime/JSLock.cpp + runtime/JSNotAnObject.cpp + runtime/JSNumberCell.cpp + runtime/JSObject.cpp + runtime/JSONObject.cpp + runtime/JSPropertyNameIterator.cpp + runtime/JSStaticScopeObject.cpp + runtime/JSString.cpp + runtime/JSValue.cpp + runtime/JSVariableObject.cpp + runtime/JSWrapperObject.cpp + runtime/LiteralParser.cpp + runtime/Lookup.cpp + runtime/MarkStackPosix.cpp + runtime/MarkStackSymbian.cpp + runtime/MarkStackWin.cpp + runtime/MarkStack.cpp + runtime/MathObject.cpp + runtime/NativeErrorConstructor.cpp + runtime/NativeErrorPrototype.cpp + runtime/NumberConstructor.cpp + runtime/NumberObject.cpp + runtime/NumberPrototype.cpp + runtime/ObjectConstructor.cpp + runtime/ObjectPrototype.cpp + runtime/Operations.cpp + runtime/PropertyDescriptor.cpp + runtime/PropertyNameArray.cpp + runtime/PropertySlot.cpp + runtime/PrototypeFunction.cpp + runtime/RegExpConstructor.cpp + runtime/RegExp.cpp + runtime/RegExpObject.cpp + runtime/RegExpPrototype.cpp + runtime/ScopeChain.cpp + runtime/SmallStrings.cpp + runtime/StringConstructor.cpp + runtime/StringObject.cpp + runtime/StringPrototype.cpp + runtime/StructureChain.cpp + runtime/Structure.cpp + runtime/TimeoutChecker.cpp + runtime/UString.cpp + runtime/UStringImpl.cpp + wtf/Assertions.cpp + wtf/ByteArray.cpp + wtf/CurrentTime.cpp + wtf/DateMath.cpp + wtf/dtoa.cpp + wtf/FastMalloc.cpp + wtf/HashTable.cpp + wtf/MainThread.cpp + wtf/qt/MainThreadQt.cpp + wtf/qt/ThreadingQt.cpp + wtf/RandomNumber.cpp + wtf/RefCountedLeakCounter.cpp + wtf/ThreadingNone.cpp + wtf/Threading.cpp + wtf/TypeTraits.cpp + wtf/unicode/CollatorDefault.cpp + wtf/unicode/icu/CollatorICU.cpp + wtf/unicode/UTF8.cpp +) +list_transform_prepend(JAVASCRIPT_CORE_SOURCES "${QT_SCRIPT_PATH}/3rdparty/javascriptcore/JavaScriptCore/") + +set(API_SOURCES + qscriptable.cpp + qscriptable.h + qscriptable_p.h + qscriptclass.cpp + qscriptclass.h + qscriptclasspropertyiterator.cpp + qscriptclasspropertyiterator.h + qscriptcontext.cpp + qscriptcontext.h + qscriptcontextinfo.cpp + qscriptcontextinfo.h + qscriptcontext_p.h + qscriptengineagent.cpp + qscriptengineagent.h + qscriptengineagent_p.h + qscriptengine.cpp + qscriptengine.h + qscriptengine_p.h + qscriptextensioninterface.h + qscriptextensionplugin.cpp + qscriptextensionplugin.h + qscriptprogram.cpp + qscriptprogram.h + qscriptprogram_p.h + qscriptstring.cpp + qscriptstring.h + qscriptstring_p.h + qscriptvalue.cpp + qscriptvalue.h + qscriptvalueiterator.cpp + qscriptvalueiterator.h + qscriptvalue_p.h + qtscriptglobal.h +) +list_transform_prepend(API_SOURCES "${QT_SCRIPT_PATH}/script/api/") + +set(BRIDGE_SOURCES + qscriptactivationobject.cpp + qscriptactivationobject_p.h + qscriptclassobject.cpp + qscriptclassobject_p.h + qscriptfunction.cpp + qscriptfunction_p.h + qscriptglobalobject.cpp + qscriptglobalobject_p.h + qscriptobject.cpp + qscriptobject_p.h + qscriptqobject.cpp + qscriptqobject_p.h + qscriptstaticscopeobject.cpp + qscriptstaticscopeobject_p.h + qscriptvariant.cpp + qscriptvariant_p.h +) +list_transform_prepend(BRIDGE_SOURCES "${QT_SCRIPT_PATH}/script/bridge/") + +set(PARSER_SOURCES + qscriptast.cpp + qscriptastfwd_p.h + qscriptast_p.h + qscriptastvisitor.cpp + qscriptastvisitor_p.h + qscriptgrammar.cpp + qscriptgrammar_p.h + qscriptlexer.cpp + qscriptlexer_p.h + qscriptsyntaxchecker.cpp + qscriptsyntaxchecker_p.h +) +list_transform_prepend(PARSER_SOURCES "${QT_SCRIPT_PATH}/script/parser/") + +find_package(Perl) + +get_target_property(_QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) +get_filename_component(_QT_BIN_DIRECTORY ${_QT_QMAKE_EXECUTABLE} DIRECTORY) + +file(GLOB API_HEADERS "${QT_SCRIPT_PATH}/script/api/*.h") + +message("${QT_SCRIPT_PATH}") + +add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/QtScript/qscriptengine.h" + COMMAND ${PERL_EXECUTABLE} "${_QT_BIN_DIRECTORY}/syncqt.pl" + -minimal + -version "${Qt5_VERSION}" + -outdir ${CMAKE_CURRENT_BINARY_DIR} + "${QT_SCRIPT_PATH}/.." + BYPRODUCTS + DEPENDS ${API_HEADERS} + ) + +add_qbs_library(qbsscriptengine + STATIC + DEFINES ${QT_SCRIPT_DEFINES} + DEPENDS Qt5::CorePrivate + PUBLIC_DEPENDS ${QT_SCRIPT_PUBLIC_DEPENDS} + INCLUDES ${QT_SCRIPT_PUBLIC_INCLUDES} ${QT_SCRIPT_INCLUDES} ${JAVASCRIPT_CORE_INCLUDES} + PUBLIC_INCLUDES ${QT_SCRIPT_PUBLIC_INCLUDES} + SOURCES + "${CMAKE_CURRENT_BINARY_DIR}/include/QtScript/qscriptengine.h" + ${PCRE_SOURCES} + ${SYSTEM_MALLOC_SOURCES} + ${JAVASCRIPT_CORE_SOURCES} + ${API_SOURCES} + ${BRIDGE_SOURCES} + ${PARSER_SOURCES} + ) +set_property(TARGET qbsscriptengine PROPERTY CXX_STANDARD 14) +target_compile_options(qbsscriptengine PRIVATE ${QT_SCRIPT_CXX_FLAGS}) diff --git a/tests/auto/buildgraph/CMakeLists.txt b/tests/auto/buildgraph/CMakeLists.txt index a3019295e..3d9d0348d 100644 --- a/tests/auto/buildgraph/CMakeLists.txt +++ b/tests/auto/buildgraph/CMakeLists.txt @@ -2,4 +2,6 @@ add_qbs_test(buildgraph SOURCES tst_buildgraph.cpp tst_buildgraph.h + DEPENDS + qbsscriptengine ) diff --git a/tests/auto/language/CMakeLists.txt b/tests/auto/language/CMakeLists.txt index 008a66fe0..b008f52d7 100644 --- a/tests/auto/language/CMakeLists.txt +++ b/tests/auto/language/CMakeLists.txt @@ -2,7 +2,7 @@ add_qbs_test(language DEFINES "QBS_VERSION=\"${QBS_VERSION}\"" DEPENDS - Qt5::Script + qbsscriptengine SOURCES tst_language.cpp tst_language.h -- cgit v1.2.3