summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-06-25 10:39:21 -0400
committerCMake Topic Stage <kwrobot@kitware.com>2015-06-25 10:39:21 -0400
commit1051c4c810a4d4f2aad7c1140af2e75c906bfbcd (patch)
tree35c9649b835cd59b7d7fe805c79521b7f5f40177
parentbd5bf762c821ca6175095cdabb46237afb6aa3fa (diff)
parent60eb396f104ff6c662029b16f8859288776afbe8 (diff)
downloadcmake-1051c4c810a4d4f2aad7c1140af2e75c906bfbcd.tar.gz
Merge topic 'export-escaping'
60eb396f Export: Escape exported property values when writing CMake language files
-rw-r--r--Source/cmExportFileGenerator.cxx24
-rw-r--r--Tests/ExportImport/Export/Interface/CMakeLists.txt4
-rw-r--r--Tests/ExportImport/Import/Interface/CMakeLists.txt11
3 files changed, 36 insertions, 3 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index a51fb2a008..094ad4f763 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -23,12 +23,28 @@
#include "cmVersion.h"
#include "cmComputeLinkInformation.h"
#include "cmAlgorithms.h"
+#include "cmOutputConverter.h"
#include <cmsys/auto_ptr.hxx>
#include <cmsys/FStream.hxx>
#include <assert.h>
//----------------------------------------------------------------------------
+static std::string cmExportFileGeneratorEscape(std::string const& str)
+{
+ // Escape a property value for writing into a .cmake file.
+ std::string result = cmOutputConverter::EscapeForCMake(str);
+ // Un-escape variable references generated by our own export code.
+ cmSystemTools::ReplaceString(result,
+ "\\${_IMPORT_PREFIX}",
+ "${_IMPORT_PREFIX}");
+ cmSystemTools::ReplaceString(result,
+ "\\${CMAKE_IMPORT_LIBRARY_SUFFIX}",
+ "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
+ return result;
+}
+
+//----------------------------------------------------------------------------
cmExportFileGenerator::cmExportFileGenerator()
{
this->AppendMode = false;
@@ -608,7 +624,8 @@ void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget const* target,
for(ImportPropertyMap::const_iterator pi = properties.begin();
pi != properties.end(); ++pi)
{
- os << " " << pi->first << " \"" << pi->second << "\"\n";
+ os << " " << pi->first << " "
+ << cmExportFileGeneratorEscape(pi->second) << "\n";
}
os << ")\n\n";
}
@@ -1112,7 +1129,8 @@ cmExportFileGenerator
for(ImportPropertyMap::const_iterator pi = properties.begin();
pi != properties.end(); ++pi)
{
- os << " " << pi->first << " \"" << pi->second << "\"\n";
+ os << " " << pi->first << " "
+ << cmExportFileGeneratorEscape(pi->second) << "\n";
}
os << " )\n"
<< "\n";
@@ -1223,7 +1241,7 @@ cmExportFileGenerator
ImportPropertyMap::const_iterator pi = properties.find(*li);
if (pi != properties.end())
{
- os << "\"" << pi->second << "\" ";
+ os << cmExportFileGeneratorEscape(pi->second) << " ";
}
}
diff --git a/Tests/ExportImport/Export/Interface/CMakeLists.txt b/Tests/ExportImport/Export/Interface/CMakeLists.txt
index 00a53756d2..fd55c423c4 100644
--- a/Tests/ExportImport/Export/Interface/CMakeLists.txt
+++ b/Tests/ExportImport/Export/Interface/CMakeLists.txt
@@ -39,7 +39,11 @@ install(FILES
DESTINATION src
)
+add_library(cmakeonly INTERFACE)
+set_property(TARGET cmakeonly PROPERTY INTERFACE_COMPILE_DEFINITIONS [[DEF="\"\$\B"]])
+
install(TARGETS headeronly sharediface use_auto_type use_c_restrict source_target
+ cmakeonly
EXPORT expInterface
)
install(TARGETS sharedlib
diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt
index 51d518e996..c850508e5d 100644
--- a/Tests/ExportImport/Import/Interface/CMakeLists.txt
+++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt
@@ -99,3 +99,14 @@ add_executable(interfacetest_exp interfacetest.cpp)
target_link_libraries(interfacetest_exp exp::sharediface)
do_try_compile(exp)
+
+foreach(ns exp bld)
+ get_property(defs TARGET ${ns}::cmakeonly PROPERTY INTERFACE_COMPILE_DEFINITIONS)
+ if(NOT defs STREQUAL [[DEF="\"\$\B"]])
+ message(SEND_ERROR
+ "${ns}::cmakeonly property INTERFACE_COMPILE_DEFINITIONS is:\n"
+ " ${defs}\n"
+ "not\n"
+ " " [[DEF="\"\$\B"]] "\n")
+ endif()
+endforeach()