Merge topic 'compiler-change-cleanup'
e83e6a1
Test Unix Makefiles generator support for changing compilersc307e1c
Tests/RunCMake: Allow tests to control build tree behavior2963c98
Merge branch 'empty-compiler-crash' into compiler-change-cleanup1df09e5
Delete entire CMakeFiles directory when deleting CMakeCache.txt (#13756)
This commit is contained in:
commit
fc7b4d5cf3
|
@ -584,23 +584,15 @@ bool cmCacheManager::DeleteCache(const char* path)
|
|||
cmSystemTools::ConvertToUnixSlashes(cacheFile);
|
||||
std::string cmakeFiles = cacheFile;
|
||||
cacheFile += "/CMakeCache.txt";
|
||||
cmSystemTools::RemoveFile(cacheFile.c_str());
|
||||
// now remove the files in the CMakeFiles directory
|
||||
// this cleans up language cache files
|
||||
cmsys::Directory dir;
|
||||
cmakeFiles += cmake::GetCMakeFilesDirectory();
|
||||
dir.Load(cmakeFiles.c_str());
|
||||
for (unsigned long fileNum = 0;
|
||||
fileNum < dir.GetNumberOfFiles();
|
||||
++fileNum)
|
||||
if(cmSystemTools::FileExists(cacheFile.c_str()))
|
||||
{
|
||||
if(!cmSystemTools::
|
||||
FileIsDirectory(dir.GetFile(fileNum)))
|
||||
cmSystemTools::RemoveFile(cacheFile.c_str());
|
||||
// now remove the files in the CMakeFiles directory
|
||||
// this cleans up language cache files
|
||||
cmakeFiles += cmake::GetCMakeFilesDirectory();
|
||||
if(cmSystemTools::FileIsDirectory(cmakeFiles.c_str()))
|
||||
{
|
||||
std::string fullPath = cmakeFiles;
|
||||
fullPath += "/";
|
||||
fullPath += dir.GetFile(fileNum);
|
||||
cmSystemTools::RemoveFile(fullPath.c_str());
|
||||
cmSystemTools::RemoveADirectory(cmakeFiles.c_str());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -52,6 +52,9 @@ if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 3)
|
|||
endif()
|
||||
|
||||
add_RunCMake_test(CMP0019)
|
||||
if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
|
||||
add_RunCMake_test(CompilerChange)
|
||||
endif()
|
||||
add_RunCMake_test(ExternalData)
|
||||
add_RunCMake_test(GeneratorExpression)
|
||||
add_RunCMake_test(GeneratorToolset)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
if(NOT RunCMake_TEST)
|
||||
set(RunCMake_TEST "$ENV{RunCMake_TEST}") # needed when cache is deleted
|
||||
endif()
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,5 @@
|
|||
You have changed variables that require your cache to be deleted.
|
||||
Configure will be re-run and you may have to reset some variables.
|
||||
The following variables have changed:
|
||||
CMAKE_C_COMPILER= *(
|
||||
|$)
|
|
@ -0,0 +1,3 @@
|
|||
enable_language(C)
|
||||
message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
|
|
@ -0,0 +1,2 @@
|
|||
enable_language(C)
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
|
|
@ -0,0 +1 @@
|
|||
-- CMAKE_C_COMPILER is ".*/Tests/RunCMake/CompilerChange/cc1.sh"
|
|
@ -0,0 +1,3 @@
|
|||
enable_language(C)
|
||||
message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
|
|
@ -0,0 +1,58 @@
|
|||
include(RunCMake)
|
||||
|
||||
# Detect the compiler in use in the current environment.
|
||||
run_cmake(FindCompiler)
|
||||
include(${RunCMake_BINARY_DIR}/FindCompiler-build/cc.cmake)
|
||||
if(NOT CMAKE_C_COMPILER)
|
||||
message(FATAL_ERROR "FindCompiler provided no compiler!")
|
||||
endif()
|
||||
if(NOT IS_ABSOLUTE "${CMAKE_C_COMPILER}")
|
||||
message(FATAL_ERROR "FindCompiler provided non-absolute path \"${CMAKE_C_COMPILER}\"!")
|
||||
endif()
|
||||
if(NOT EXISTS "${CMAKE_C_COMPILER}")
|
||||
message(FATAL_ERROR "FindCompiler provided non-existing path \"${CMAKE_C_COMPILER}\"!")
|
||||
endif()
|
||||
|
||||
# Now that we have the full compiler path, hide CC.
|
||||
unset(ENV{CC})
|
||||
|
||||
# Wrap around the real compiler so we can change the compiler
|
||||
# path without changing the underlying compiler.
|
||||
set(ccIn ${RunCMake_SOURCE_DIR}/cc.sh.in)
|
||||
set(cc1 ${RunCMake_BINARY_DIR}/cc1.sh)
|
||||
set(cc2 ${RunCMake_BINARY_DIR}/cc2.sh)
|
||||
set(cc3 CMAKE_C_COMPILER-NOTFOUND)
|
||||
configure_file(${ccIn} ${cc1} @ONLY IMMEDIATE)
|
||||
configure_file(${ccIn} ${cc2} @ONLY IMMEDIATE)
|
||||
|
||||
# Use a single build tree for remaining tests without cleaning.
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ChangeCompiler-build)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
|
||||
|
||||
# Check build with compiler wrapper 1.
|
||||
set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=${cc1})
|
||||
set(ENV{RunCMake_TEST} "FirstCompiler")
|
||||
run_cmake(FirstCompiler)
|
||||
include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
|
||||
if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc1}")
|
||||
message(FATAL_ERROR "FirstCompiler built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc1}")
|
||||
endif()
|
||||
|
||||
# Check rebuild with compiler wrapper 2.
|
||||
set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=${cc2})
|
||||
set(ENV{RunCMake_TEST} "SecondCompiler")
|
||||
run_cmake(SecondCompiler)
|
||||
include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
|
||||
if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc2}")
|
||||
message(FATAL_ERROR "SecondCompiler built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc2}")
|
||||
endif()
|
||||
|
||||
# Check failure with an empty compiler string.
|
||||
set(RunCMake_TEST_OPTIONS -DCMAKE_C_COMPILER=)
|
||||
set(ENV{RunCMake_TEST} "EmptyCompiler")
|
||||
run_cmake(EmptyCompiler)
|
||||
include(${RunCMake_TEST_BINARY_DIR}/cc.cmake)
|
||||
if(NOT "${CMAKE_C_COMPILER}" STREQUAL "${cc3}")
|
||||
message(FATAL_ERROR "Empty built with compiler:\n ${CMAKE_C_COMPILER}\nand not with:\n ${cc3}")
|
||||
endif()
|
|
@ -0,0 +1,4 @@
|
|||
You have changed variables that require your cache to be deleted.
|
||||
Configure will be re-run and you may have to reset some variables.
|
||||
The following variables have changed:
|
||||
CMAKE_C_COMPILER=.*/Tests/RunCMake/CompilerChange/cc2.sh
|
|
@ -0,0 +1 @@
|
|||
-- CMAKE_C_COMPILER is ".*/Tests/RunCMake/CompilerChange/cc2.sh"
|
|
@ -0,0 +1,3 @@
|
|||
enable_language(C)
|
||||
message(STATUS "CMAKE_C_COMPILER is \"${CMAKE_C_COMPILER}\"")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cc.cmake" "set(CMAKE_C_COMPILER \"${CMAKE_C_COMPILER}\")\n")
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
exec "@CMAKE_C_COMPILER@" "$@"
|
|
@ -26,8 +26,12 @@ function(run_cmake test)
|
|||
endif()
|
||||
endforeach()
|
||||
set(RunCMake_TEST_SOURCE_DIR "${top_src}")
|
||||
set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build")
|
||||
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
|
||||
if(NOT RunCMake_TEST_BINARY_DIR)
|
||||
set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build")
|
||||
endif()
|
||||
if(NOT RunCMake_TEST_NO_CLEAN)
|
||||
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
|
||||
if(NOT DEFINED RunCMake_TEST_OPTIONS)
|
||||
set(RunCMake_TEST_OPTIONS "")
|
||||
|
|
Loading…
Reference in New Issue