Skip to content

Commit

Permalink
Merge branch 'master' into feature/standardize_dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
idleroamer committed Oct 13, 2020
2 parents 73c9a06 + 63e4de6 commit 8e122fb
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 89 deletions.
62 changes: 52 additions & 10 deletions cmake/faceliftMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ function(facelift_generate_code )
list(APPEND BASE_CODEGEN_COMMAND "--all")
endif()

list(APPEND BASE_CODEGEN_COMMAND "--no_moc_file_path" "${ARGUMENT_OUTPUT_PATH}")

string(REPLACE ";" " " BASE_CODEGEN_COMMAND_WITH_SPACES "${BASE_CODEGEN_COMMAND}")
message("Calling facelift code generator. Command:\n PYTHONPATH=$ENV{PYTHONPATH} ${FACELIFT_PYTHON_EXECUTABLE} ${BASE_CODEGEN_COMMAND_WITH_SPACES}")

Expand Down Expand Up @@ -356,9 +358,10 @@ endfunction()
macro(_facelift_parse_target_arguments additionalOptions additionalOneValueArgs additionalMultiValueArgs)

set(options NO_INSTALL UNITY_BUILD NO_EXPORT INTERFACE ${additionalOptions})
set(oneValueArgs ${additionalOneValueArgs})
set(oneValueArgs ${additionalOneValueArgs} HEADERS_NO_MOC_FILE)
set(multiValueArgs PRIVATE_DEFINITIONS PUBLIC_DEFINITIONS PROPERTIES COMPILE_OPTIONS
HEADERS HEADERS_GLOB HEADERS_GLOB_RECURSE
HEADERS_NO_MOC
SOURCES SOURCES_GLOB SOURCES_GLOB_RECURSE
LINK_LIBRARIES
UI_FILES
Expand All @@ -379,13 +382,19 @@ macro(_facelift_parse_target_arguments additionalOptions additionalOneValueArgs
endforeach()

set(HEADERS ${ARGUMENT_HEADERS})
foreach(HEADER_GLOB ${ARGUMENT_HEADERS_GLOB_RECURSE})
file(GLOB_RECURSE GLOB_FILES ${HEADER_GLOB})
list(APPEND HEADERS ${GLOB_FILES})

set(HEADERS_NO_MOC ${ARGUMENT_HEADERS_NO_MOC})

set(HEADERS_NO_MOC_FILE ${ARGUMENT_HEADERS_NO_MOC_FILE})

unset(HEADERS_GLOB)
foreach(HEADER ${ARGUMENT_HEADERS_GLOB_RECURSE})
file(GLOB_RECURSE GLOB_FILES ${HEADER})
list(APPEND HEADERS_GLOB ${GLOB_FILES})
endforeach()
foreach(HEADER_GLOB ${ARGUMENT_HEADERS_GLOB})
file(GLOB GLOB_FILES ${HEADER_GLOB})
list(APPEND HEADERS ${GLOB_FILES})
foreach(HEADER ${ARGUMENT_HEADERS_GLOB})
file(GLOB GLOB_FILES ${HEADER})
list(APPEND HEADERS_GLOB ${GLOB_FILES})
endforeach()

set(HEADERS_NO_INSTALL ${ARGUMENT_HEADERS_NO_INSTALL})
Expand All @@ -402,13 +411,45 @@ endmacro()

macro(_facelift_add_target_start IMPLEMENTATION_TARGET_NAME)

set(HEADERS_TO_BE_MOCCED ${HEADERS} ${HEADERS_NO_INSTALL})
if(ORIGINAL_TARGET_NAME)
set(OUTPUT_PATH ${CMAKE_BINARY_DIR}/facelift_generated/${ORIGINAL_TARGET_NAME})
else()
set(OUTPUT_PATH ${CMAKE_BINARY_DIR}/facelift_generated/${TARGET_NAME})
endif()

# set HEADERS_NO_MOC_GENERATED in this include
include("${OUTPUT_PATH}/no_moc.cmake" OPTIONAL)
# set HEADERS_NO_MOC_FROM_FILE in this include (the file is the input parameter)
if(HEADERS_NO_MOC_FILE)
include("${HEADERS_NO_MOC_FILE}" OPTIONAL)
endif()

set(HEADERS_FOR_MOC ${HEADERS_GLOB} ${HEADERS_NO_INSTALL})

foreach(HEADER ${HEADERS_NO_MOC_GENERATED} ${HEADERS_NO_MOC})
list(REMOVE_ITEM HEADERS_FOR_MOC ${HEADER})
endforeach()

foreach(HEADER ${HEADERS_FOR_MOC})
list(FIND HEADERS_NO_MOC_FROM_FILE ${HEADER} IS_FOUND)

if(${IS_FOUND} GREATER_EQUAL 0)
list(REMOVE_ITEM HEADERS_FOR_MOC ${HEADER})
endif()

endforeach()

list(APPEND HEADERS_FOR_MOC ${HEADERS})

unset(HEADERS_MOCS)

if(HEADERS_TO_BE_MOCCED)
qt5_wrap_cpp(HEADERS_MOCS ${HEADERS} ${HEADERS_NO_INSTALL} TARGET ${IMPLEMENTATION_TARGET_NAME})
if(HEADERS_FOR_MOC)
qt5_wrap_cpp(HEADERS_MOCS ${HEADERS_FOR_MOC} TARGET ${IMPLEMENTATION_TARGET_NAME})
endif()

# add processed for moc headers to the list of headers for installation
list(APPEND HEADERS ${HEADERS_GLOB} ${HEADERS_NO_MOC})

unset(UI_FILES)
if(ARGUMENT_UI_FILES)
qt5_wrap_ui(UI_FILES ${ARGUMENT_UI_FILES})
Expand Down Expand Up @@ -553,6 +594,7 @@ function(facelift_add_library TARGET_NAME)

else()

set(ORIGINAL_TARGET_NAME ${TARGET_NAME})
set(TARGET_NAME ${TARGET_NAME}_OBJECTS)
add_library(${ALIAS_NAME} INTERFACE)
target_link_libraries(${ALIAS_NAME} INTERFACE ${TARGET_NAME})
Expand Down
26 changes: 21 additions & 5 deletions codegen/facelift/facelift-codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import logging.config
import yaml
import qface
import os

here = Path(__file__).dirname()

Expand Down Expand Up @@ -326,8 +327,10 @@ def hasReturnValue(self):
setattr(qface.idl.domain.Property, 'cppMethodArgumentType', property(cppMethodArgumentType))

##############################
def addFileNameToNoMocList(noMocListFile, filePath, fileName):
noMocListFile.write(' ' + os.path.join(filePath, fileName) + '\n')

def generateFile(generator, outputPath, templatePath, context, libraryName, libraryType):
def generateFile(generator, tmpPath, templatePath, context, libraryName, libraryType):
if libraryName:
name = libraryName
if libraryType:
Expand All @@ -337,9 +340,9 @@ def generateFile(generator, outputPath, templatePath, context, libraryName, libr
else:
context.update({'classExportDefines': ""})
context.update({'classExport': ""})
generator.write(outputPath, templatePath, context)
generator.write(tmpPath, templatePath, context)

def run_generation(input, output, dependency, libraryName, all):
def run_generation(input, output, dependency, libraryName, all, noMocFilePath, noMocListFile):
global generateAsyncProxy
global generateAll
generateAll = all
Expand Down Expand Up @@ -369,10 +372,16 @@ def run_generation(input, output, dependency, libraryName, all):
log.debug('process module %s' % module.module_name)
ctx.update({'path': module_path})
generateFile(generator, 'module/{{path}}/ModulePrivate.h', 'ModulePrivate.template.h', ctx, libraryName, "")
if not module.structs:
addFileNameToNoMocList(noMocListFile, noMocFilePath, 'module/{}/ModulePrivate.h'.format(module_path))

generateFile(generator, 'module/{{path}}/Module.h', 'Module.template.h', ctx, libraryName, "")
generateFile(generator, 'module/{{path}}/Module.cpp', 'Module.template.cpp', ctx, libraryName, "")
addFileNameToNoMocList(noMocListFile, noMocFilePath, 'module/{}/Module.h'.format(module_path))

generateFile(generator, 'ipc/{{path}}/ModuleIPC.h', 'ModuleIPC.template.h', ctx, libraryName, "")
generateFile(generator, 'ipc/{{path}}/ModuleIPC.cpp', 'ModuleIPC.template.cpp', ctx, libraryName, "")
addFileNameToNoMocList(noMocListFile, noMocFilePath, 'ipc/{}/ModuleIPC.h'.format(module_path))

for interface in module.interfaces:
log.debug('process interface %s' % interface)
Expand All @@ -393,7 +402,10 @@ def run_generation(input, output, dependency, libraryName, all):
if isIPCEnabled(interface):
generateFile(generator, 'ipc/{{path}}/{{interface}}IPCAdapter.h', 'IPCAdapter.template.h', ctx, libraryName, "")
generateFile(generator, 'ipc/{{path}}/{{interface}}IPCAdapter.cpp', 'IPCAdapter.template.cpp', ctx, libraryName, "")

generateFile(generator, 'types/{{path}}/{{interface}}IPCCommon.h', 'IPCCommon.template.h', ctx, libraryName, "")
addFileNameToNoMocList(noMocListFile, noMocFilePath, 'types/{}/{}IPCCommon.h'.format(module_path, interface))

generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.h', 'IPCDBusServiceAdapter.template.h', ctx, libraryName, "")
generateFile(generator, 'ipc_dbus/{{path}}/{{interface}}IPCDBusAdapter.cpp', 'IPCDBusServiceAdapter.template.cpp', ctx, libraryName, "")
generateFile(generator, 'ipc/{{path}}/{{interface}}IPCLocalServiceAdapter.h', 'IPCLocalServiceAdapter.template.h', ctx, libraryName, "")
Expand Down Expand Up @@ -446,10 +458,14 @@ def run_generation(input, output, dependency, libraryName, all):
@click.option('--input', '-i', multiple=True)
@click.option('--dependency', '-d', multiple=True)
@click.option('--all', is_flag=True)
def generate(input, output, dependency, library, all):
@click.option('--no_moc_file_path', default=".")
def generate(input, output, dependency, library, all, no_moc_file_path):
"""Takes several files or directories as input and generates the code
in the given output directory."""
run_generation(input, output, dependency, library, all)
with open('{}/no_moc.cmake'.format(output), 'a+') as noMocListFile:
noMocListFile.write('set(HEADERS_NO_MOC_GENERATED\n')
run_generation(input, output, dependency, library, all, no_moc_file_path, noMocListFile)
noMocListFile.write(')\n')


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions codegen/facelift/templates/QMLAdapter.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
#include "{{interfaceName}}.h"

{% for type in interface.referencedTypes %}
{% if type.requiredInclude != "" %}
{{type.requiredInclude}}
{% endif %}
{% endfor %}

//// Sub interfaces
Expand Down
2 changes: 2 additions & 0 deletions codegen/facelift/templates/Service.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@

// Dependencies
{% for type in interface.referencedTypes %}
{% if type.requiredInclude != "" %}
{{type.requiredInclude}}
{% endif %}
{% endfor %}

{{module.namespaceCppOpen}}
Expand Down
2 changes: 2 additions & 0 deletions codegen/facelift/templates/Struct.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

// Dependencies
{% for field in struct.fields %}
{% if field.type.requiredInclude != "" %}
{{field.type.requiredInclude}}
{% endif %}
{% endfor %}

{{module.namespaceCppOpen}}
Expand Down
2 changes: 2 additions & 0 deletions codegen/facelift/templates/StructQObjectWrapper.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

// Dependencies
{% for field in struct.fields %}
{% if field.type.requiredInclude != "" %}
{{field.type.requiredInclude}}
{% endif %}
{% endfor %}

{{module.namespaceCppOpen}}
Expand Down
26 changes: 25 additions & 1 deletion doc/page-cmakefunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ facelift_add_qml_plugin(<TargetName>
[HEADERS_GLOB [Globbing expressions]...]
[SOURCES_GLOB_RECURSE [Globbing expressions]...]
[HEADERS_GLOB_RECURSE [Globbing expressions]...]
[HEADERS_NO_MOC hdr1 [hdr2...]]
[HEADERS_NO_MOC_FILE file]
[HEADERS_NO_INSTALL hdrn1 [hdrn2...]]
[HEADERS_GLOB_NO_INSTALL [Globbing expressions]...]
[HEADERS_GLOB_RECURSE_NO_INSTALL [Globbing expressions]...]
Expand All @@ -65,6 +67,8 @@ facelift_add_library(<TargetName>
[HEADERS_GLOB [Globbing expressions]...]
[SOURCES_GLOB_RECURSE [Globbing expressions]...]
[HEADERS_GLOB_RECURSE [Globbing expressions]...]
[HEADERS_NO_MOC hdr1 [hdr2...]]
[HEADERS_NO_MOC_FILE file]
[HEADERS_NO_INSTALL hdrn1 [hdrn2...]]
[HEADERS_GLOB_NO_INSTALL [Globbing expressions]...]
[HEADERS_GLOB_RECURSE_NO_INSTALL [Globbing expressions]...]
Expand All @@ -76,7 +80,25 @@ facelift_add_library(<TargetName>
\endcode
This function adds a library with the name \e TargetName from the specified source and header files. The parameter descriptions can be found below.
In the parameter HEADERS_NO_MOC_FILE you can set the file with a list of the files which sould be excluded from processing by moc.
This set should have the name HEADERS_NO_MOC_FROM_FILE. E.g in we create the file ~/nomoc.cmake and fill it like this:
set(HEADERS_NO_MOC_FILE
file1.h
file2.h
...
filen.h
)
after that we should call
facelift_add_library(
...
HEADERS_NO_MOC
file3.h
hile4.h
HEADERS_NO_MOC_FILE ~/nomoc.cmake
...
)
This parameter is much preferred when the number of files which should not be processed by moc is quite large.
When there are not a lot of files rather use HEADERS_NO_MOC parameter.
\code
facelift_add_executable(<TargetName>
[SOURCES src1 [src2...]]
Expand Down Expand Up @@ -114,6 +136,8 @@ This function adds a test with the name \e TargetName.The parameter descriptions
\param SOURCES_GLOB_RECURSE List of source files searched recursively inside folder and subfolders, used to build this target provided as a wildcard expression
\param HEADERS_GLOB_RECURSE List of header files to be MOCed and added to this target, searched recursively inside folder and subfolders provided as a wildcard expression
\param LINK_LIBRARIES List of libraries that will be linked with this target
\param HEADERS_NO_MOC The headers that should be excluded from moc processing
\param HEADERS_NO_MOC_FILE The list of the files that should be excluded from moc processing
\param HEADERS_NO_INSTALL Same as HEADERS, but those headers wouldn't be installed
\param HEADERS_GLOB_NO_INSTALL Same as HEADERS_GLOB, but those headers wouldn't be installed
\param HEADERS_GLOB_RECURSE_NO_INSTALL Same as HEADERS_GLOB_RECURSE, but those headers wouldn't be installed
Expand Down
7 changes: 4 additions & 3 deletions examples/ModuleImport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
facelift_add_interface(MainInterface
INTERFACE_DEFINITION_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface
IMPORT_FOLDERS ${CMAKE_CURRENT_SOURCE_DIR}/interface)
INTERFACE_DEFINITION_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/interface
IMPORT_FOLDERS ${CMAKE_CURRENT_SOURCE_DIR}/interface)

facelift_add_qml_plugin(ModuleImportPlugin
URI mainmodule
SOURCES ModuleImportPlugin.cpp
HEADERS ModuleImportPlugin.h model/cpp/MainInterfaceCppImplementation.h
HEADERS ModuleImportPlugin.h
HEADERS_NO_MOC model/cpp/MainInterfaceCppImplementation.h
LINK_LIBRARIES MainInterface)

add_example_script(module-import ui/MyApp.qml)
1 change: 1 addition & 0 deletions examples/MyPackage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ facelift_add_qml_plugin(MyPackagePlugin
URI facelift.example.mypackage
SOURCES_GLOB_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
HEADERS_GLOB_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/*.h
HEADERS_NO_MOC ${CMAKE_CURRENT_SOURCE_DIR}/models/cpp/MyInterfaceCppImplementation.h
LINK_LIBRARIES MyPackageInterface
)

Expand Down
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
facelift_add_library(FaceliftCommonLib
SOURCES
FaceliftUtils.cpp
HEADERS
HEADERS_NO_MOC
span.h
FaceliftUtils.h
MONOLITHIC_SUPPORTED
Expand Down
11 changes: 6 additions & 5 deletions src/ipc/dbus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ if(Qt5DBus_FOUND)
DBusManager.cpp
HEADERS
DBusIPCCommon.h
DBusObjectRegistry.h
DBusIPCProxyBinder.h
IPCDBusServiceAdapterBase.h
HEADERS_NO_MOC
DBusIPCMessage.h
DBusRequestHandler.h
DBusManager.h
DBusManagerInterface.h
DBusIPCProxy.h
FaceliftDBusMarshaller.h
IPCDBusServiceAdapter.h
DBusObjectRegistry.h
DBusIPCMessage.h
DBusRequestHandler.h
DBusIPCProxyBinder.h
IPCDBusServiceAdapterBase.h
SOURCES_GLOB_RECURSE
${GENERATED_FILE_PATH}/ipc/*.cpp
${GENERATED_FILE_PATH}/ipc_dbus/*.cpp
Expand Down
34 changes: 17 additions & 17 deletions src/ipc/ipc-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ facelift_add_library(FaceliftIPCCommonLib
NewIPCServiceAdapterBase.cpp
LocalProviderBinderBase.cpp
HEADERS
ipc-common.h
DBusSignatureHelper.h
NotAvailableImpl.h
NotAvailableImplBase.h
IPCProxyNewBase.h
LocalProviderBinder.h
LocalProviderBinderBase.h
StaticArrayReference.h
IPCProxyBase.h
IPCProxy.h
InterfaceManager.h
InterfaceManagerInterface.h
IPCProxyModelProperty.h
IPCProxyBinderBase.h
IPCAdapterModelPropertyHandler.h
IPCServiceAdapterBase.h
NewIPCServiceAdapterBase.h
ModuleIPCBase.h
IPCAdapterFactoryManager.h
IPCAttachedPropertyFactory.h
HEADERS_NO_MOC
DBusSignatureHelper.h
IPCProxyBase.h
IPCAdapterModelPropertyHandler.h
IPCProxyModelProperty.h
IPCProxyBaseBase.h
IPCAdapterFactoryManager.h
IPCProxyNewBase.h
IPCProxy.h
ModuleIPCBase.h
IPCServiceAdapter.h
LocalProviderBinderBase.h
NotAvailableImpl.h
NotAvailableImplBase.h
Registry.h
LINK_LIBRARIES
FaceliftModelLib
FaceliftCommonLib
LocalProviderBinder.h
StaticArrayReference.h
ipc-common.h
LINK_LIBRARIES FaceliftModelLib FaceliftCommonLib
MONOLITHIC_SUPPORTED
)
Loading

0 comments on commit 8e122fb

Please sign in to comment.