diff options
author | Brad King <brad.king@kitware.com> | 2019-12-09 15:15:08 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-12-09 15:15:19 (GMT) |
commit | 835f1bcbdec21ec7acf84e7ed4c9d45a2dabb602 (patch) | |
tree | b62d7e1e21ecfa50f7f4b5209a2f0bcea762dcae | |
parent | 5d6b70ccfe3b2ce986b1f05a25f93f763498ee17 (diff) | |
parent | 93becd61d19baa718bb10f2df25fedf31dfc2ded (diff) | |
download | CMake-835f1bcbdec21ec7acf84e7ed4c9d45a2dabb602.zip CMake-835f1bcbdec21ec7acf84e7ed4c9d45a2dabb602.tar.gz CMake-835f1bcbdec21ec7acf84e7ed4c9d45a2dabb602.tar.bz2 |
Merge topic 'pch-reuse-importlib'
93becd61d1 PCH: Use the target's PREFIX for building the pdb file name
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4114
4 files changed, 49 insertions, 1 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 7451ff3..fa997f4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2467,9 +2467,25 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target) target->GetLocalGenerator()->GetCurrentBinaryDirectory(), "/", target->GetName(), ".dir/${PDB_PREFIX}"); - file << "if (EXISTS \"" << from_file << "\")\n"; + const std::string to_file = + cmStrCat(to_dir, pchReuseFrom, extension); + + std::string dest_file = to_file; + + const std::string prefix = target->GetSafeProperty("PREFIX"); + if (!prefix.empty()) { + dest_file = cmStrCat(to_dir, prefix, pchReuseFrom, extension); + } + + file << "if (EXISTS \"" << from_file << "\" AND \"" << from_file + << "\" IS_NEWER_THAN \"" << dest_file << "\")\n"; file << " file(COPY \"" << from_file << "\"" << " DESTINATION \"" << to_dir << "\")\n"; + if (!prefix.empty()) { + file << " file(REMOVE \"" << dest_file << "\")\n"; + file << " file(RENAME \"" << to_file << "\" \"" << dest_file + << "\")\n"; + } file << "endif()\n"; } diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed-build-stderr.txt b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed-build-stderr.txt new file mode 100644 index 0000000..8cdcfd9 --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed-build-stderr.txt @@ -0,0 +1,2 @@ +^(|Warning #670: precompiled header file [^ +]* was not generated in this directory)$ diff --git a/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake new file mode 100644 index 0000000..e306d8e --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchReuseFromPrefixed.cmake @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.15) +project(PchReuseFromPrefixed C) + +if(CMAKE_C_COMPILE_OPTIONS_USE_PCH) + add_definitions(-DHAVE_PCH_SUPPORT) +endif() + +add_library(empty empty.c) +target_precompile_headers(empty PRIVATE + <stdio.h> + <string.h> +) +target_include_directories(empty PUBLIC include) + +add_library(foo foo.c) +target_include_directories(foo PUBLIC include) +target_precompile_headers(foo REUSE_FROM empty) + +# Visual Studio 2017 and greater +if (NOT (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL 19.10)) + set_target_properties(foo PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib") +endif() + +add_executable(foobar foobar.c) +target_link_libraries(foobar foo ) +set_target_properties(foobar PROPERTIES PRECOMPILE_HEADERS_REUSE_FROM empty) + +enable_testing() +add_test(NAME foobar COMMAND foobar) diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake index ec13663..8d2f4f9 100644 --- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake +++ b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake @@ -17,5 +17,6 @@ run_test(PchInterface) run_cmake(PchPrologueEpilogue) run_test(SkipPrecompileHeaders) run_test(PchReuseFrom) +run_test(PchReuseFromPrefixed) run_test(PchReuseFromSubdir) run_cmake(PchMultilanguage) |