From c188dda0e9c9755ff57eba307d12bd0bb027c608 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 5 Jan 2017 20:35:38 +0100 Subject: Enhance gn generator Do not generate actions if no moc_source_h_files or moc_source_cpp_files, handle correctly ldflags, add handling for lib_dirs, rpath and rpath-link. Add checks if 'libs' 'deps' 'include_dirs' comes from imports. Change-Id: Icee51e491f9f041cfce055f9e79acfade85c0b95 Reviewed-by: Allan Sandfeld Jensen --- tools/qmake/mkspecs/features/gn_generator.prf | 130 +++++++++++++++----------- 1 file changed, 75 insertions(+), 55 deletions(-) (limited to 'tools/qmake') diff --git a/tools/qmake/mkspecs/features/gn_generator.prf b/tools/qmake/mkspecs/features/gn_generator.prf index 924297aae..c5f283a99 100644 --- a/tools/qmake/mkspecs/features/gn_generator.prf +++ b/tools/qmake/mkspecs/features/gn_generator.prf @@ -37,33 +37,35 @@ MOC_COMMAND = $$replace(MOC_COMMAND, $$re_escape("$(DEFINES)"), $$DEFINES_LIST) MOC_COMMAND = $$replace(MOC_COMMAND, $$re_escape("$(INCPATH)"), $$INCLUDE_LIST) MOC_COMMAND = $$eval($$list($$MOC_COMMAND)) -GN_CONTENTS += "action_foreach(\"generate_h_mocs\") {"\ - " script = \"$$GN_RUN_BINARY_SCRIPT\"" -GN_CONTENTS += " sources = moc_source_h_files" \ - " outputs = [ \"$target_gen_dir/.moc/moc_{{source_name_part}}.cpp\" ]" -GN_CONTENTS += " inputs = [ \"$$system_path($$_PRO_FILE_)\" ]" \ - " args = [" -for(token, MOC_COMMAND): GN_CONTENTS += " \"$$replace(token,\',)\"," -GN_CONTENTS += " \"{{source}}\"," \ - " \"-o\"," \ - " rebase_path(\"$target_gen_dir/.moc/moc_{{source_name_part}}.cpp\")"\ - " ]" +GN_CONTENTS += "if (moc_source_h_files != []) {" +GN_CONTENTS += " action_foreach(\"generate_h_mocs\") {"\ + " script = \"$$GN_RUN_BINARY_SCRIPT\"" +GN_CONTENTS += " sources = moc_source_h_files" \ + " outputs = [ \"$target_gen_dir/.moc/moc_{{source_name_part}}.cpp\" ]" +GN_CONTENTS += " inputs = [ \"$$system_path($$_PRO_FILE_)\" ]" \ + " args = [" +for(token, MOC_COMMAND): GN_CONTENTS += " \"$$replace(token,\',)\"," +GN_CONTENTS += " \"{{source}}\"," \ + " \"-o\"," \ + " rebase_path(\"$target_gen_dir/.moc/moc_{{source_name_part}}.cpp\")"\ + " ]" +GN_CONTENTS += " }" GN_CONTENTS += "}" -GN_CONTENTS += "action_foreach(\"generate_cpp_mocs\") {"\ - " script = \"$$GN_RUN_BINARY_SCRIPT\"" -GN_CONTENTS += " sources = moc_source_cpp_files" \ - " outputs = [ \"$target_gen_dir/.moc/{{source_name_part}}.moc\" ]" -GN_CONTENTS += " inputs = [ \"$$system_path($$_PRO_FILE_)\" ]" \ - " args = [" -for(token, MOC_COMMAND): GN_CONTENTS += " \"$$replace(token,\',)\"," -GN_CONTENTS += " \"{{source}}\"," \ - " \"-o\"," \ - " rebase_path(\"$target_gen_dir/.moc/{{source_name_part}}.moc\")"\ - " ]" +GN_CONTENTS += "if (moc_source_cpp_files != []) {" +GN_CONTENTS += " action_foreach(\"generate_cpp_mocs\") {"\ + " script = \"$$GN_RUN_BINARY_SCRIPT\"" +GN_CONTENTS += " sources = moc_source_cpp_files" \ + " outputs = [ \"$target_gen_dir/.moc/{{source_name_part}}.moc\" ]" +GN_CONTENTS += " inputs = [ \"$$system_path($$_PRO_FILE_)\" ]" \ + " args = [" +for(token, MOC_COMMAND): GN_CONTENTS += " \"$$replace(token,\',)\"," +GN_CONTENTS += " \"{{source}}\"," \ + " \"-o\"," \ + " rebase_path(\"$target_gen_dir/.moc/{{source_name_part}}.moc\")"\ + " ]" +GN_CONTENTS += " }" GN_CONTENTS += "}" - - # RESOURCES SETUP CLEAN_QMAKE_RCC = $$clean_path($$QMAKE_RCC) @@ -113,6 +115,9 @@ for (imp, GN_IMPORTS): GN_CONTENTS += " import(\"$$imp\")" GN_CONTENTS += " ]" } +GN_CONTENTS += " if (!defined(defines)) {"\ + " defines = []"\ + " }" GN_CONTENTS += " defines += [" for (define, DEFINES): GN_CONTENTS += " \"$$define\"," !isEmpty(QMAKE_LIBDIR_EGL): @@ -128,49 +133,64 @@ for (headerfile, HEADERS): GN_CONTENTS += " \"$$GN_SRC_DIR/$$headerfile\"," GN_CONTENTS += " ]" # Add Sources generated by rcc from qrc files. -GN_CONTENTS += " sources += get_target_outputs(\":generate_resources\")" -# Add moc output files to compile -GN_CONTENTS += " sources += get_target_outputs(\":generate_h_mocs\")" +!isEmpty(RESOURCES): GN_CONTENTS += " sources += get_target_outputs(\":generate_resources\")" +GN_CONTENTS += " if (!defined(include_dirs)) {"\ + " include_dirs = []"\ + " }" GN_CONTENTS += " include_dirs += [" for (path, INCLUDEPATH): GN_CONTENTS += " \"$$path\"," GN_CONTENTS += " rebase_path(\"$target_gen_dir/.moc/\")" GN_CONTENTS += " ]" -GN_CONTENTS += " ldflags = [" -for (lib, LIBS): GN_CONTENTS += " \"$$lib\"," -GN_CONTENTS += " \"-Wl,-rpath=$$[QT_INSTALL_LIBS]\"," \ - " \"-Wl,-rpath-link=\"," +GN_CONTENTS += " if (!defined(ldflags)) {"\ + " ldflags = []"\ + " }" +GN_CONTENTS += " ldflags += [" +for (flag, QMAKE_LFLAGS): GN_CONTENTS += " \"$$flag\"," +for (flag, GN_FLAGS): GN_CONTENTS += " \"$$flag\"," +!isEmpty(QMAKE_RPATHDIR): GN_CONTENTS += " \"-Wl,-rpath=$${QMAKE_RPATHDIR}\"," +!isEmpty(QMAKE_RPATHLINKDIR): GN_CONTENTS += " \"-Wl,-rpath-link=$${QMAKE_RPATHLINKDIR}\"," GN_CONTENTS += " ]" -GN_CONTENTS += " deps += [" -!isEmpty(RESOURCES): GN_CONTENTS += " \":generate_resources\"," -GN_CONTENTS += " \":generate_h_mocs\"," -GN_CONTENTS += " \":generate_cpp_mocs\"," +GN_CONTENTS += " if (!defined(lib_dirs)) {"\ + " lib_dirs = []"\ + " }" +GN_CONTENTS += " lib_dirs += [" +lib_dirs = $$find(LIBS, ^-L.*) +lib_dirs = $$unique(lib_dirs) +for (lib_dir, lib_dirs): GN_CONTENTS += " \"$$replace(lib_dir, -L, )\"," GN_CONTENTS += " ]" -!isEmpty(GN_LIBS) { - GN_CONTENTS += " libs += [" - for (lib, GN_LIBS): GN_CONTENTS += " \"$$lib\"," - GN_CONTENTS += " ]" -} - -!isEmpty(GN_STATIC_LIBS) { - GN_CONTENTS += " ldflags += [" - for (lib, GN_STATIC_LIBS) { - linux { - GN_CONTENTS += " \"-Wl,--whole-archive\"," - GN_CONTENTS += " \"$$lib\"," - GN_CONTENTS += " \"-Wl,--no-whole-archive\"," - } else: macos { - GN_CONTENTS += " \"-Wl,-force_load,$$lib\"," - } - } - GN_CONTENTS += " ]" -} +GN_CONTENTS += " if (!defined(libs)) {"\ + " libs = []"\ + " }" +GN_CONTENTS += " libs += [" +for (lib, GN_LIBS): GN_CONTENTS += " \"$$lib\"," +libs = $$find(LIBS, ^-l.*) +libs = $$unique(libs) +for (lib, libs): GN_CONTENTS += " \"$$replace(lib, -l, )\"," +GN_CONTENTS += " ]" +GN_CONTENTS += " if (!defined(deps)) {"\ + " deps = []"\ + " }" +GN_CONTENTS += " deps += [" +!isEmpty(RESOURCES): GN_CONTENTS += " \":generate_resources\"," +GN_CONTENTS += " ]" +GN_CONTENTS += " if (moc_source_h_files != []) {" +GN_CONTENTS += " deps += [" +GN_CONTENTS += " \":generate_h_mocs\"," +GN_CONTENTS += " ]" +# Add moc output files to compile +GN_CONTENTS += " sources += get_target_outputs(\":generate_h_mocs\")" +GN_CONTENTS += " }" +GN_CONTENTS += " if (moc_source_cpp_files != []) {" +GN_CONTENTS += " deps += [" +GN_CONTENTS += " \":generate_cpp_mocs\"," +GN_CONTENTS += " ]" +GN_CONTENTS += " }" GN_CONTENTS += "}" - !isEmpty(GN_INCLUDES) { for (inc, GN_INCLUDES): GN_CONTENTS += $$cat($$inc,lines) } -- cgit v1.2.3