From f8a575b24f431b40b3ce4b2f2a4d58b97a63f9c8 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Oct 2018 09:45:01 +0200 Subject: Cleanup gn-generator Moves what can be to a config which avoids some boilerplate logic, and fix some other ugly parts in the generated results. Change-Id: Ifc4386009f95acb202f9482fa3a5857500fd5622 Reviewed-by: Michal Klocek --- mkspecs/features/gn_generator.prf | 81 ++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 40 deletions(-) (limited to 'mkspecs') diff --git a/mkspecs/features/gn_generator.prf b/mkspecs/features/gn_generator.prf index b1f04e570..88f64fa91 100644 --- a/mkspecs/features/gn_generator.prf +++ b/mkspecs/features/gn_generator.prf @@ -102,16 +102,9 @@ CLEAN_QMAKE_RCC = $$clean_path($$QMAKE_RCC) GN_CONTENTS += "}" } -# TARGET SETUP - -TARGET_TYPE = $$getTargetType() - -GN_CONTENTS += "$${TARGET_TYPE}(\"$$TARGET\") {" -!isEmpty(GN_CREATE_PRI): GN_CONTENTS += " create_pri_file = $$GN_CREATE_PRI" -!isEmpty(GN_IMPORTS) { -for (imp, GN_IMPORTS): GN_CONTENTS += " import(\"$$imp\")" -} +# CONFIG SETUP +GN_CONTENTS += "config(\"$${TARGET}_config\") {" !isEmpty(QMAKE_CFLAGS) { GN_CONTENTS += " cflags = [" for(flag, QMAKE_CFLAGS): GN_CONTENTS += " \"$$filter_flag_values($$flag)\"," @@ -138,10 +131,7 @@ gcc|clang { GN_CONTENTS += " ]" } -GN_CONTENTS += " if (!defined(defines)) {"\ - " defines = []"\ - " }" -GN_CONTENTS += " defines += [" +GN_CONTENTS += " defines = [" # Remove single quotes around function macro defines, so that GN doesn't escape them, thus breaking # the macro. # Also add a layer of escaping for double quotes. @@ -152,28 +142,13 @@ for (define, DEFINES): { } GN_CONTENTS += " ]" -# Source files to compile -GN_CONTENTS += " sources = [" -for (sourcefile, SOURCES): GN_CONTENTS += " \"$$GN_SRC_DIR/$$sourcefile\"," -for (headerfile, HEADERS): GN_CONTENTS += " \"$$GN_SRC_DIR/$$headerfile\"," -GN_CONTENTS += " ]" - -# Add Sources generated by rcc from qrc files. -!isEmpty(RESOURCES): GN_CONTENTS += " sources += get_target_outputs(\":generate_resources\")" - -GN_CONTENTS += " if (!defined(include_dirs)) {"\ - " include_dirs = []"\ - " }" -GN_CONTENTS += " include_dirs += [" +GN_CONTENTS += " include_dirs = [" for (path, INCLUDEPATH): GN_CONTENTS += " \"$$path\"," GN_CONTENTS += " rebase_path(\"$target_gen_dir/.moc/\")," GN_CONTENTS += " \"$$QMAKESPEC\"" GN_CONTENTS += " ]" -GN_CONTENTS += " if (!defined(ldflags)) {"\ - " ldflags = []"\ - " }" -GN_CONTENTS += " ldflags += [" +GN_CONTENTS += " ldflags = [" for (flag, QMAKE_LFLAGS): GN_CONTENTS += " \"$$filter_flag_values($$flag)\"," for (flag, GN_FLAGS): GN_CONTENTS += " \"$$flag\"," !isEmpty(QMAKE_RPATHDIR) { @@ -184,15 +159,35 @@ for (flag, GN_FLAGS): GN_CONTENTS += " \"$$flag\"," !isEmpty(QMAKE_RPATHLINKDIR): GN_CONTENTS += " \"-Wl,-rpath-link=$${QMAKE_RPATHLINKDIR}\"," GN_CONTENTS += " ]" -GN_CONTENTS += " if (!defined(lib_dirs)) {"\ - " lib_dirs = []"\ - " }" -GN_CONTENTS += " 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 += " ]" +GN_CONTENTS += "}" + +# TARGET SETUP + +TARGET_TYPE = $$getTargetType() + +GN_CONTENTS += "$${TARGET_TYPE}(\"$$TARGET\") {" +!isEmpty(GN_CREATE_PRI): GN_CONTENTS += " create_pri_file = $$GN_CREATE_PRI" +!isEmpty(GN_IMPORTS) { + for (imp, GN_IMPORTS): GN_CONTENTS += " import(\"$$imp\")" +} + +GN_CONTENTS += " configs += [ \":$${TARGET}_config\" ] " + +# Source files to compile +GN_CONTENTS += " sources = [" +for (sourcefile, SOURCES): GN_CONTENTS += " \"$$GN_SRC_DIR/$$sourcefile\"," +for (headerfile, HEADERS): GN_CONTENTS += " \"$$GN_SRC_DIR/$$headerfile\"," +GN_CONTENTS += " ]" + +# Add Sources generated by rcc from qrc files. +!isEmpty(RESOURCES): GN_CONTENTS += " sources += get_target_outputs(\":generate_resources\")" + GN_CONTENTS += " if (!defined(libs)) {"\ " libs = []"\ " }" @@ -206,9 +201,13 @@ GN_CONTENTS += " ]" GN_CONTENTS += " if (!defined(deps)) {"\ " deps = []"\ " }" -GN_CONTENTS += " deps += [" -!isEmpty(RESOURCES): GN_CONTENTS += " \":generate_resources\"," -GN_CONTENTS += " ]" + +!isEmpty(RESOURCES) { + GN_CONTENTS += " deps += [" + GN_CONTENTS += " \":generate_resources\"," + GN_CONTENTS += " ]" +} + GN_CONTENTS += " if (moc_source_h_files != []) {" GN_CONTENTS += " deps += [" GN_CONTENTS += " \":generate_h_mocs\"," @@ -222,14 +221,16 @@ GN_CONTENTS += " \":generate_cpp_mocs\"," GN_CONTENTS += " ]" GN_CONTENTS += " }" GN_CONTENTS += "}" -GN_CONTENTS += " if (!defined(core_include_dirs)) {"\ - " core_include_dirs = []"\ - " }" +GN_CONTENTS += "" +GN_CONTENTS += "if (!defined(core_include_dirs)) {"\ + " core_include_dirs = []"\ + "}" !isEmpty(GN_CORE_INCLUDE_DIRS) { GN_CONTENTS += "core_include_dirs += [" for (inc, GN_CORE_INCLUDE_DIRS): GN_CONTENTS += " \"$$inc\"," GN_CONTENTS += "]" } + !isEmpty(GN_INCLUDES) { for (inc, GN_INCLUDES): GN_CONTENTS += $$cat($$inc,lines) } -- cgit v1.2.3