diff options
author | Brad King <brad.king@kitware.com> | 2013-07-03 19:57:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-07-15 13:14:56 (GMT) |
commit | 290857bb03a4ce2f42df751c319769ff5863dd73 (patch) | |
tree | 95fc3cca9b850e5d0df4535e7b14c84e870a93a4 /Source/cmCoreTryCompile.cxx | |
parent | 99a814e5b9a4f0bd497b8785b60257b232d54e79 (diff) | |
download | CMake-290857bb03a4ce2f42df751c319769ff5863dd73.zip CMake-290857bb03a4ce2f42df751c319769ff5863dd73.tar.gz CMake-290857bb03a4ce2f42df751c319769ff5863dd73.tar.bz2 |
try_compile: Escape CMAKE_<lang>_FLAGS in test projects (#14268)
If CMAKE_<lang>_FLAGS contains quotes or other CMake language characters
they must be escaped when written into the generated CMakeLists.txt file
so that the test project parses them properly.
Teach the TryCompile test to cover this case by adding a flag with
quotes into CMAKE_C_FLAGS during a C language try_compile.
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 860417f..e312806 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -12,6 +12,7 @@ #include "cmCoreTryCompile.h" #include "cmake.h" #include "cmCacheManager.h" +#include "cmLocalGenerator.h" #include "cmGlobalGenerator.h" #include "cmExportTryCompileFileGenerator.h" #include <cmsys/Directory.hxx> @@ -214,8 +215,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) } // Detect languages to enable. - cmGlobalGenerator* gg = - this->Makefile->GetCMakeInstance()->GetGlobalGenerator(); + cmLocalGenerator* lg = this->Makefile->GetLocalGenerator(); + cmGlobalGenerator* gg = lg->GetGlobalGenerator(); std::set<std::string> testLangs; for(std::vector<std::string>::iterator si = sources.begin(); si != sources.end(); ++si) @@ -295,13 +296,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv) for(std::set<std::string>::iterator li = testLangs.begin(); li != testLangs.end(); ++li) { - fprintf(fout, "SET(CMAKE_%s_FLAGS \"", li->c_str()); std::string langFlags = "CMAKE_" + *li + "_FLAGS"; - if(const char* flags = this->Makefile->GetDefinition(langFlags.c_str())) - { - fprintf(fout, " %s ", flags); - } - fprintf(fout, " ${COMPILE_DEFINITIONS}\")\n"); + const char* flags = this->Makefile->GetDefinition(langFlags.c_str()); + fprintf(fout, "SET(CMAKE_%s_FLAGS %s)\n", li->c_str(), + lg->EscapeForCMake(flags?flags:"").c_str()); + fprintf(fout, "SET(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}" + " ${COMPILE_DEFINITIONS}\")\n", li->c_str(), li->c_str()); } fprintf(fout, "INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})\n"); fprintf(fout, "SET(CMAKE_SUPPRESS_REGENERATION 1)\n"); |