| 1865 | } |
| 1866 | |
| 1867 | bool cmake::SetDirectoriesFromFile(std::string const& arg) |
| 1868 | { |
| 1869 | // Check if the argument refers to a CMakeCache.txt or CMakeLists.txt file. |
| 1870 | // Do not check for the custom project filename CMAKE_LIST_FILE_NAME, as it |
| 1871 | // cannot be determined until after reading the CMakeCache.txt |
| 1872 | std::string listPath; |
| 1873 | std::string cachePath; |
| 1874 | bool is_source_dir = false; |
| 1875 | bool is_empty_directory = false; |
| 1876 | if (cmSystemTools::FileIsDirectory(arg)) { |
| 1877 | std::string path = cmSystemTools::ToNormalizedPathOnDisk(arg); |
| 1878 | std::string cacheFile = cmStrCat(path, "/CMakeCache.txt"); |
| 1879 | std::string listFile = this->GetCMakeListFile(path); |
| 1880 | |
| 1881 | is_empty_directory = true; |
| 1882 | if (cmSystemTools::FileExists(cacheFile)) { |
| 1883 | cachePath = path; |
| 1884 | is_empty_directory = false; |
| 1885 | } |
| 1886 | if (cmSystemTools::FileExists(listFile)) { |
| 1887 | listPath = path; |
| 1888 | is_empty_directory = false; |
| 1889 | is_source_dir = true; |
| 1890 | } |
| 1891 | } else if (cmSystemTools::FileExists(arg)) { |
| 1892 | std::string fullPath = cmSystemTools::ToNormalizedPathOnDisk(arg); |
| 1893 | std::string name = cmSystemTools::GetFilenameName(fullPath); |
| 1894 | name = cmSystemTools::LowerCase(name); |
| 1895 | if (name == "cmakecache.txt"_s) { |
| 1896 | cachePath = cmSystemTools::GetFilenamePath(fullPath); |
| 1897 | } else if (name == "cmakelists.txt"_s) { |
| 1898 | listPath = cmSystemTools::GetFilenamePath(fullPath); |
| 1899 | } |
| 1900 | } else { |
| 1901 | // Specified file or directory does not exist. Try to set things |
| 1902 | // up to produce a meaningful error message. |
| 1903 | std::string fullPath = cmSystemTools::CollapseFullPath(arg); |
| 1904 | std::string name = cmSystemTools::GetFilenameName(fullPath); |
| 1905 | name = cmSystemTools::LowerCase(name); |
| 1906 | if (name == "cmakecache.txt"_s || name == "cmakelists.txt"_s) { |
| 1907 | listPath = cmSystemTools::GetFilenamePath(fullPath); |
| 1908 | } else { |
| 1909 | listPath = fullPath; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | // If there is a CMakeCache.txt file, use its settings. |
| 1914 | if (!cachePath.empty()) { |
| 1915 | if (this->LoadCache(cachePath)) { |
| 1916 | cmValue existingValue = |
| 1917 | this->State->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"); |
| 1918 | if (existingValue && !existingValue.IsEmpty()) { |
| 1919 | this->SetHomeOutputDirectory(cachePath); |
| 1920 | this->SetHomeDirectory(*existingValue); |
| 1921 | return true; |
| 1922 | } |
| 1923 | } |
| 1924 | } |
no test coverage detected