| 2775 | } |
| 2776 | |
| 2777 | void cmFindPackageCommand::FillPrefixesCMakeSystemVariable() |
| 2778 | { |
| 2779 | cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem]; |
| 2780 | |
| 2781 | bool const install_prefix_in_list = |
| 2782 | !this->Makefile->IsOn("CMAKE_FIND_NO_INSTALL_PREFIX"); |
| 2783 | bool const remove_install_prefix = this->NoCMakeInstallPath; |
| 2784 | bool const add_install_prefix = !this->NoCMakeInstallPath && |
| 2785 | this->Makefile->IsDefinitionSet("CMAKE_FIND_USE_INSTALL_PREFIX"); |
| 2786 | |
| 2787 | // We have 3 possible states for `CMAKE_SYSTEM_PREFIX_PATH` and |
| 2788 | // `CMAKE_INSTALL_PREFIX`. |
| 2789 | // Either we need to remove `CMAKE_INSTALL_PREFIX`, add |
| 2790 | // `CMAKE_INSTALL_PREFIX`, or do nothing. |
| 2791 | // |
| 2792 | // When we need to remove `CMAKE_INSTALL_PREFIX` we remove the Nth occurrence |
| 2793 | // of `CMAKE_INSTALL_PREFIX` from `CMAKE_SYSTEM_PREFIX_PATH`, where `N` is |
| 2794 | // computed by `CMakeSystemSpecificInformation.cmake` while constructing |
| 2795 | // `CMAKE_SYSTEM_PREFIX_PATH`. This ensures that if projects / toolchains |
| 2796 | // have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove |
| 2797 | // some other entry by mistake |
| 2798 | long install_prefix_count = -1; |
| 2799 | std::string install_path_to_remove; |
| 2800 | if (cmValue to_skip = this->Makefile->GetDefinition( |
| 2801 | "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT")) { |
| 2802 | cmStrToLong(*to_skip, &install_prefix_count); |
| 2803 | } |
| 2804 | if (cmValue install_value = this->Makefile->GetDefinition( |
| 2805 | "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE")) { |
| 2806 | install_path_to_remove = *install_value; |
| 2807 | } |
| 2808 | |
| 2809 | if (remove_install_prefix && install_prefix_in_list && |
| 2810 | install_prefix_count > 0 && !install_path_to_remove.empty()) { |
| 2811 | |
| 2812 | cmValue prefix_paths = |
| 2813 | this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH"); |
| 2814 | // remove entry from CMAKE_SYSTEM_PREFIX_PATH |
| 2815 | cmList expanded{ *prefix_paths }; |
| 2816 | long count = 0; |
| 2817 | for (auto const& path : expanded) { |
| 2818 | bool const to_add = |
| 2819 | !(path == install_path_to_remove && ++count == install_prefix_count); |
| 2820 | if (to_add) { |
| 2821 | paths.AddPath(path); |
| 2822 | } |
| 2823 | } |
| 2824 | } else if (add_install_prefix && !install_prefix_in_list) { |
| 2825 | paths.AddCMakePath("CMAKE_INSTALL_PREFIX"); |
| 2826 | paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH"); |
| 2827 | } else { |
| 2828 | // Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct |
| 2829 | paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH"); |
| 2830 | } |
| 2831 | |
| 2832 | paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH"); |
| 2833 | paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH"); |
| 2834 |
no test coverage detected