From 9c48804b6917007fb7f9d0b8c137810b3b864256 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 22 May 2020 10:01:08 -0400 Subject: PCH: Fix source group of per-architecture PCH headers In commit f593b354da (PCH: Add support for multi architecture iOS projects, 2020-04-02) we forgot to update our regex that assigns PCH headers to the `Precompile Header File` source group to account for the `_` suffix that can now appear on their name. --- Source/cmSourceFile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index e527069..e2dfdc1 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -159,7 +159,7 @@ private: "\\.(C|F|M|c|c\\+\\+|cc|cpp|cxx|cu|f|f90|for|fpp|ftn|m|mm|" \ "rc|def|r|odl|idl|hpj|bat)$" -#define CM_PCH_REGEX "cmake_pch\\.(h|hxx)$" +#define CM_PCH_REGEX "cmake_pch(_[^.]+)?\\.(h|hxx)$" #define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$" -- cgit v0.12 From b3812c0e54c18d8fe9959624d8f09afc427a891e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 8 May 2020 09:25:42 -0400 Subject: Tests: Fix indentation in RunCMake.FileAPI cxx_exe.json --- Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json index 7631837..2d3eec6 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json @@ -46,14 +46,14 @@ "compileCommandFragments": [ { "fragment" : "TargetCompileOptions", - "backtrace": [ + "backtrace": [ { "file": "^cxx/CMakeLists\\.txt$", "line": 17, "command": "target_compile_options", "hasParent": true }, - { + { "file" : "^cxx/CMakeLists\\.txt$", "line": null, "command": null, -- cgit v0.12 From b698764a316d346e3c1bc33c7a88b5a09f144ad6 Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 28 Apr 2020 16:45:43 -0700 Subject: Tests: Add a PCH example to RunCMake.FileAPI codemodel-v2 --- Tests/RunCMake/CMakeLists.txt | 3 +- Tests/RunCMake/FileAPI/RunCMakeTest.cmake | 2 +- Tests/RunCMake/FileAPI/codemodel-v2-check.py | 15 ++ .../targets/cxx_exe_precompileheader.json | 123 ++++++++++++++ .../targets/cxx_exe_precompileheader_2arch.json | 180 +++++++++++++++++++++ .../targets/cxx_exe_precompileheader_multigen.json | 168 +++++++++++++++++++ Tests/RunCMake/FileAPI/cxx/CMakeLists.txt | 2 + Tests/RunCMake/FileAPI/empty.h | 0 8 files changed, 491 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json create mode 100644 Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json create mode 100644 Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json create mode 100644 Tests/RunCMake/FileAPI/empty.h diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index cc88868..e757dd4 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -200,7 +200,8 @@ add_RunCMake_test(DisallowedCommands) add_RunCMake_test(ExternalData) add_RunCMake_test(FeatureSummary) add_RunCMake_test(FPHSA) -add_RunCMake_test(FileAPI -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}) +add_RunCMake_test(FileAPI -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} + -DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}) add_RunCMake_test(FindBoost) add_RunCMake_test(FindLua) add_RunCMake_test(FindOpenGL) diff --git a/Tests/RunCMake/FileAPI/RunCMakeTest.cmake b/Tests/RunCMake/FileAPI/RunCMakeTest.cmake index 8cdc00c..4449ff1 100644 --- a/Tests/RunCMake/FileAPI/RunCMakeTest.cmake +++ b/Tests/RunCMake/FileAPI/RunCMakeTest.cmake @@ -23,7 +23,7 @@ function(check_python case) endif() file(GLOB index ${RunCMake_TEST_BINARY_DIR}/.cmake/api/v1/reply/index-*.json) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py" "${index}" + COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/${case}-check.py" "${index}" "${CMAKE_CXX_COMPILER_ID}" RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE output diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 9ee0c20..143e784 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -561,6 +561,20 @@ def gen_check_targets(c, g, inSource): read_codemodel_json_data("targets/generated_exe.json"), ] + if cxx_compiler_id in ['Clang', 'AppleClang', 'GNU', 'Intel', 'MSVC', 'Embarcadero'] and g["name"] != "Xcode": + for e in expected: + if e["name"] == "cxx_exe": + if matches(g["name"], "^(Visual Studio |Ninja Multi-Config)"): + precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_multigen.json") + else: + if ';' in os.environ.get("CMAKE_OSX_ARCHITECTURES", ""): + precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader_2arch.json") + else: + precompile_header_data = read_codemodel_json_data("targets/cxx_exe_precompileheader.json") + e["compileGroups"] = precompile_header_data["compileGroups"] + e["sources"] = precompile_header_data["sources"] + e["sourceGroups"] = precompile_header_data["sourceGroups"] + if not os.path.exists(os.path.join(reply_dir, "..", "..", "..", "..", "ipo_enabled.txt")): for e in expected: try: @@ -715,6 +729,7 @@ def check_object_codemodel(g): check_object_codemodel_configuration(c, g, inSource) return _check +cxx_compiler_id = sys.argv[2] assert is_dict(index) assert sorted(index.keys()) == ["cmake", "objects", "reply"] check_objects(index["objects"], index["cmake"]["generator"]) diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json new file mode 100644 index 0000000..0695a00 --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json @@ -0,0 +1,123 @@ +{ + "compileGroups": [ + { + "language": "CXX", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + { + "language": "CXX", + "sourcePaths": [ + "^empty\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + } + ], + "sources": [ + { + "path": ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^empty\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 5, + "command": "add_executable", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "sourceGroups": [ + { + "name": "Source Files", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "^empty\\.cxx$" + ] + }, + { + "name": "Precompile Header File", + "sourcePaths": [ + ".*/cmake_pch(_[^.]+)?\\.hxx$" + ] + } + ] +} diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json new file mode 100644 index 0000000..d42b835 --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json @@ -0,0 +1,180 @@ +{ + "compileGroups": [ + { + "language": "CXX", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + { + "language": "CXX", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + { + "language": "CXX", + "sourcePaths": [ + "^empty\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + } + ], + "sources": [ + { + "path": ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^empty\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 5, + "command": "add_executable", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "sourceGroups": [ + { + "name": "Source Files", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "^empty\\.cxx$" + ] + }, + { + "name": "Precompile Header File", + "sourcePaths": [ + ".*/cmake_pch(_[^.]+)?\\.hxx$", + ".*/cmake_pch(_[^.]+)?\\.hxx$" + ] + } + ] +} diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json new file mode 100644 index 0000000..9250017 --- /dev/null +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json @@ -0,0 +1,168 @@ +{ + "compileGroups": [ + { + "language": "CXX", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + }, + { + "language": "CXX", + "sourcePaths": [ + "^empty\\.cxx$" + ], + "includes": null, + "defines": null, + "compileCommandFragments": [ + { + "fragment": "TargetCompileOptions", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 17, + "command": "target_compile_options", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ] + } + ], + "sources": [ + { + "path": ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": "^empty\\.cxx$", + "isGenerated": null, + "sourceGroupName": "Source Files", + "compileGroupLanguage": "CXX", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 5, + "command": "add_executable", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/Debug/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/Release/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/MinSizeRel/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + }, + { + "path": ".*/RelWithDebInfo/cmake_pch(_[^.]+)?\\.hxx$", + "isGenerated": null, + "sourceGroupName": "Precompile Header File", + "compileGroupLanguage": null, + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], + "sourceGroups": [ + { + "name": "Source Files", + "sourcePaths": [ + ".*cmake_pch(_[^.]+)?(\\.hxx)?\\.cxx$", + "^empty\\.cxx$" + ] + }, + { + "name": "Precompile Header File", + "sourcePaths": [ + ".*/Debug/cmake_pch(_[^.]+)?\\.hxx$", + ".*/Release/cmake_pch(_[^.]+)?\\.hxx$", + ".*/MinSizeRel/cmake_pch(_[^.]+)?\\.hxx$", + ".*/RelWithDebInfo/cmake_pch(_[^.]+)?\\.hxx$" + ] + } + ] +} diff --git a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt index b0564f5..fa51195 100644 --- a/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt +++ b/Tests/RunCMake/FileAPI/cxx/CMakeLists.txt @@ -17,3 +17,5 @@ target_link_libraries(cxx_static_exe PRIVATE cxx_static_lib) target_compile_options(cxx_exe PUBLIC TargetCompileOptions) target_link_options(cxx_exe PUBLIC TargetLinkOptions) target_link_directories(cxx_exe PUBLIC "${CMAKE_BINARY_DIR}/TargetLinkDir") + +target_precompile_headers(cxx_exe PUBLIC ../empty.h) diff --git a/Tests/RunCMake/FileAPI/empty.h b/Tests/RunCMake/FileAPI/empty.h new file mode 100644 index 0000000..e69de29 -- cgit v0.12 From 9f6d40ee23113f1317e54d662316752adb9f368e Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Tue, 28 Apr 2020 16:45:43 -0700 Subject: fileapi: Extend codemodel targets with PRECOMPILE_HEADERS --- Help/manual/cmake-file-api.7.rst | 16 ++++++ Source/cmFileAPI.cxx | 2 +- Source/cmFileAPICodemodel.cxx | 30 ++++++++++++ .../RunCMake/CommandLine/E_capabilities-stdout.txt | 2 +- Tests/RunCMake/FileAPI/codemodel-v2-check.py | 19 +++++++- .../FileAPI/codemodel-v2-data/targets/cxx_exe.json | 19 ++++++++ .../targets/cxx_exe_precompileheader.json | 38 +++++++++++++++ .../targets/cxx_exe_precompileheader_2arch.json | 57 ++++++++++++++++++++++ .../targets/cxx_exe_precompileheader_multigen.json | 38 +++++++++++++++ 9 files changed, 218 insertions(+), 3 deletions(-) diff --git a/Help/manual/cmake-file-api.7.rst b/Help/manual/cmake-file-api.7.rst index 12eecd9..91be31d 100644 --- a/Help/manual/cmake-file-api.7.rst +++ b/Help/manual/cmake-file-api.7.rst @@ -899,6 +899,22 @@ with members: an unsigned integer 0-based index into the ``backtraceGraph`` member's ``nodes`` array. + ``precompileHeaders`` + Optional member that is present when :command:`target_precompile_headers` + or other command invocations set :prop_tgt:`PRECOMPILE_HEADERS` on the + target. The value is a JSON array with an entry for each header. Each + entry is a JSON object with members: + + ``header`` + Full path to the precompile header file. + + ``backtrace`` + Optional member that is present when a CMake language backtrace to + the :command:`target_precompile_headers` or other command invocation + that added this precompiled header is available. The value is an + unsigned integer 0-based index into the ``backtraceGraph`` member's + ``nodes`` array. + ``defines`` Optional member that is present when there are preprocessor definitions. The value is a JSON array with an entry for each definition. Each diff --git a/Source/cmFileAPI.cxx b/Source/cmFileAPI.cxx index a56ad22..594969b 100644 --- a/Source/cmFileAPI.cxx +++ b/Source/cmFileAPI.cxx @@ -665,7 +665,7 @@ std::string cmFileAPI::NoSupportedVersion( // The "codemodel" object kind. -static unsigned int const CodeModelV2Minor = 0; +static unsigned int const CodeModelV2Minor = 1; void cmFileAPI::BuildClientRequestCodeModel( ClientRequest& r, std::vector const& versions) diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index f34d7d5..26beebf 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -278,12 +278,14 @@ struct CompileData std::string Sysroot; std::vector> Flags; std::vector> Defines; + std::vector> PrecompileHeaders; std::vector Includes; friend bool operator==(CompileData const& l, CompileData const& r) { return (l.Language == r.Language && l.Sysroot == r.Sysroot && l.Flags == r.Flags && l.Defines == r.Defines && + l.PrecompileHeaders == r.PrecompileHeaders && l.Includes == r.Includes); } }; @@ -313,6 +315,10 @@ struct hash result = result ^ hash()(i.Value) ^ hash()(i.Backtrace.Index); } + for (auto const& i : in.PrecompileHeaders) { + result = result ^ hash()(i.Value) ^ + hash()(i.Backtrace.Index); + } return result; } }; @@ -369,6 +375,7 @@ class Target Json::Value DumpPaths(); Json::Value DumpCompileData(CompileData const& cd); Json::Value DumpInclude(CompileData::IncludeEntry const& inc); + Json::Value DumpPrecompileHeader(JBT const& header); Json::Value DumpDefine(JBT const& def); Json::Value DumpSources(); Json::Value DumpSource(cmGeneratorTarget::SourceAndKind const& sk, @@ -825,6 +832,11 @@ void Target::ProcessLanguage(std::string const& lang) this->ToJBT(i), this->GT->IsSystemIncludeDirectory(i.Value, this->Config, lang)); } + std::vector> precompileHeaders = + this->GT->GetPrecompileHeaders(this->Config, lang); + for (BT const& pch : precompileHeaders) { + cd.PrecompileHeaders.emplace_back(this->ToJBT(pch)); + } } Json::ArrayIndex Target::AddSourceGroup(cmSourceGroup* sg, Json::ArrayIndex si) @@ -980,6 +992,9 @@ CompileData Target::MergeCompileData(CompileData const& fd) // All compile groups share the sysroot of the target. cd.Sysroot = td.Sysroot; + // All compile groups share the precompile headers of the target. + cd.PrecompileHeaders = td.PrecompileHeaders; + // Use target-wide flags followed by source-specific flags. cd.Flags.reserve(td.Flags.size() + fd.Flags.size()); cd.Flags.insert(cd.Flags.end(), td.Flags.begin(), td.Flags.end()); @@ -1130,6 +1145,13 @@ Json::Value Target::DumpCompileData(CompileData const& cd) } result["defines"] = std::move(defines); } + if (!cd.PrecompileHeaders.empty()) { + Json::Value precompileHeaders = Json::arrayValue; + for (JBT const& pch : cd.PrecompileHeaders) { + precompileHeaders.append(this->DumpPrecompileHeader(pch)); + } + result["precompileHeaders"] = std::move(precompileHeaders); + } return result; } @@ -1145,6 +1167,14 @@ Json::Value Target::DumpInclude(CompileData::IncludeEntry const& inc) return include; } +Json::Value Target::DumpPrecompileHeader(JBT const& header) +{ + Json::Value precompileHeader = Json::objectValue; + precompileHeader["header"] = header.Value; + this->AddBacktrace(precompileHeader, header.Backtrace); + return precompileHeader; +} + Json::Value Target::DumpDefine(JBT const& def) { Json::Value define = Json::objectValue; diff --git a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt index b4b170e..03286f1 100644 --- a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt +++ b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt @@ -1 +1 @@ -^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":0}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$ +^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":1}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$ diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-check.py b/Tests/RunCMake/FileAPI/codemodel-v2-check.py index 143e784..a3dd9ff 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-check.py +++ b/Tests/RunCMake/FileAPI/codemodel-v2-check.py @@ -12,7 +12,7 @@ def read_codemodel_json_data(filename): def check_objects(o, g): assert is_list(o) assert len(o) == 1 - check_index_object(o[0], "codemodel", 2, 0, check_object_codemodel(g)) + check_index_object(o[0], "codemodel", 2, 1, check_object_codemodel(g)) def check_backtrace(t, b, backtrace): btg = t["backtraceGraph"] @@ -404,6 +404,23 @@ def check_target(c): missing_exception=lambda e: "Include path: %s" % e["path"], extra_exception=lambda a: "Include path: %s" % a["path"]) + if "precompileHeaders" in expected: + expected_keys.append("precompileHeaders") + + def check_precompile_header(actual, expected): + assert is_dict(actual) + expected_keys = ["backtrace", "header"] + check_backtrace(obj, actual["backtrace"], expected["backtrace"]) + + assert sorted(actual.keys()) == sorted(expected_keys) + + check_list_match(lambda a, e: matches(a["header"], e["header"]), + actual["precompileHeaders"], expected["precompileHeaders"], + check=check_precompile_header, + check_exception=lambda a, e: "Precompile header: %s" % a["header"], + missing_exception=lambda e: "Precompile header: %s" % e["header"], + extra_exception=lambda a: "Precompile header: %s" % a["header"]) + if expected["defines"] is not None: expected_keys.append("defines") diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json index 2d3eec6..e7ab55b 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe.json @@ -43,6 +43,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment" : "TargetCompileOptions", diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json index 0695a00..5a0f770 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader.json @@ -7,6 +7,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", @@ -34,6 +53,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json index d42b835..9455748 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_2arch.json @@ -7,6 +7,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", @@ -34,6 +53,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", @@ -61,6 +99,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", diff --git a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json index 9250017..9f6ffcc 100644 --- a/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json +++ b/Tests/RunCMake/FileAPI/codemodel-v2-data/targets/cxx_exe_precompileheader_multigen.json @@ -7,6 +7,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", @@ -34,6 +53,25 @@ ], "includes": null, "defines": null, + "precompileHeaders": [ + { + "header": ".*empty\\.h$", + "backtrace": [ + { + "file": "^cxx/CMakeLists\\.txt$", + "line": 21, + "command": "target_precompile_headers", + "hasParent": true + }, + { + "file": "^cxx/CMakeLists\\.txt$", + "line": null, + "command": null, + "hasParent": false + } + ] + } + ], "compileCommandFragments": [ { "fragment": "TargetCompileOptions", -- cgit v0.12