summaryrefslogtreecommitdiffstats
path: root/Source/cmExportFileGenerator.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-11-30 08:26:09 (GMT)
committerStephen Kelly <steveire@gmail.com>2012-11-30 08:51:17 (GMT)
commitbf2ddceb4e55b2b9e3fb749fbee6126340f73f07 (patch)
tree8bf995edfd69e1a11dfbc65aad9415559559a1fe /Source/cmExportFileGenerator.cxx
parentd5ac791366595be307896e9894c66815c1e1eb2f (diff)
downloadCMake-bf2ddceb4e55b2b9e3fb749fbee6126340f73f07.zip
CMake-bf2ddceb4e55b2b9e3fb749fbee6126340f73f07.tar.gz
CMake-bf2ddceb4e55b2b9e3fb749fbee6126340f73f07.tar.bz2
Generate an early-return guard in target Export files.
Previously it was necessary for writers of Config files which incude exported target files to write the guard themselves, but this was not immediately obvious or documented. Options for them would be to use a variable, or an INHERITED directory property in an effort to avoid accidental name clashes in all contexts in which find_package can be used. Getting this right requires boiler plate code, so generate a simpler check automatically instead.
Diffstat (limited to 'Source/cmExportFileGenerator.cxx')
-rw-r--r--Source/cmExportFileGenerator.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 8dffae4..3f738cc 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -287,6 +287,37 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
}
//----------------------------------------------------------------------------
+void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
+ const std::string &expectedTargets)
+{
+ os << "SET(_targetsDefined)\n"
+ "SET(_targetsNotDefined)\n"
+ "SET(_expectedTargets)\n"
+ "FOREACH(_expectedTarget " << expectedTargets << ")\n"
+ " LIST(APPEND _expectedTargets ${_expectedTarget})\n"
+ " IF(NOT TARGET ${_expectedTarget})\n"
+ " LIST(APPEND _targetsNotDefined ${_expectedTarget})\n"
+ " ENDIF(NOT TARGET ${_expectedTarget})\n"
+ " IF(TARGET ${_expectedTarget})\n"
+ " LIST(APPEND _targetsDefined ${_expectedTarget})\n"
+ " ENDIF(TARGET ${_expectedTarget})\n"
+ "ENDFOREACH(_expectedTarget)\n"
+ "IF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
+ " SET(CMAKE_IMPORT_FILE_VERSION)\n"
+ " CMAKE_POLICY(POP)\n"
+ " RETURN()\n"
+ "ENDIF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
+ "IF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ " MESSAGE(FATAL_ERROR \"Some (but not all) targets in this export "
+ "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
+ "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
+ "ENDIF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
+ "UNSET(_targetsDefined)\n"
+ "UNSET(_targetsNotDefined)\n"
+ "UNSET(_expectedTargets)\n"
+ "\n\n";
+}
+//----------------------------------------------------------------------------
void
cmExportFileGenerator
::GenerateImportTargetCode(std::ostream& os, cmTarget* target)