Merge topic 'fix-relocatable-include-dirs'

34d1ade Add the INSTALL_PREFIX genex.
3a17197 Generate the _IMPORT_PREFIX in the non-config export file.
This commit is contained in:
Brad King 2013-01-29 14:52:19 -05:00 committed by CMake Topic Stage
commit 5f78d2057f
9 changed files with 97 additions and 30 deletions

View File

@ -55,6 +55,8 @@
"the 'head' target was created, else '0'. If the policy was not " \ "the 'head' target was created, else '0'. If the policy was not " \
"set, the warning message for the policy will be emitted. This " \ "set, the warning message for the policy will be emitted. This " \
"generator expression only works for a subset of policies.\n" \ "generator expression only works for a subset of policies.\n" \
" $<INSTALL_PREFIX> = Content of the install prefix when " \
"the target is exported via INSTALL(EXPORT) and empty otherwise.\n" \
"Boolean expressions:\n" \ "Boolean expressions:\n" \
" $<AND:?[,?]...> = '1' if all '?' are '1', else '0'\n" \ " $<AND:?[,?]...> = '1' if all '?' are '1', else '0'\n" \
" $<OR:?[,?]...> = '0' if all '?' are '0', else '1'\n" \ " $<OR:?[,?]...> = '0' if all '?' are '0', else '1'\n" \

View File

@ -431,12 +431,22 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
input.replace(pos, endPos - pos + 1, targetName); input.replace(pos, endPos - pos + 1, targetName);
lastPos = endPos; lastPos = endPos;
} }
this->ReplaceInstallPrefix(input);
if (!errorString.empty()) if (!errorString.empty())
{ {
mf->IssueMessage(cmake::FATAL_ERROR, errorString); mf->IssueMessage(cmake::FATAL_ERROR, errorString);
} }
} }
//----------------------------------------------------------------------------
void
cmExportFileGenerator::ReplaceInstallPrefix(std::string &)
{
// Do nothing
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmExportFileGenerator cmExportFileGenerator

View File

@ -152,6 +152,8 @@ private:
void ResolveTargetsInGeneratorExpression(std::string &input, void ResolveTargetsInGeneratorExpression(std::string &input,
cmTarget* target, cmTarget* target,
std::vector<std::string> &missingTargets); std::vector<std::string> &missingTargets);
virtual void ReplaceInstallPrefix(std::string &input);
}; };
#endif #endif

View File

@ -69,6 +69,27 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
this->GenerateExpectedTargetsCode(os, expectedTargets); this->GenerateExpectedTargetsCode(os, expectedTargets);
} }
// Add code to compute the installation prefix relative to the
// import file location.
const char* installDest = this->IEGen->GetDestination();
if(!cmSystemTools::FileIsFullPath(installDest))
{
std::string dest = installDest;
os << "# Compute the installation prefix relative to this file.\n"
<< "get_filename_component(_IMPORT_PREFIX "
<< "\"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
while(!dest.empty())
{
os <<
"get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n";
dest = cmSystemTools::GetFilenamePath(dest);
}
os << "\n";
// Import location properties may reference this variable.
this->ImportPrefix = "${_IMPORT_PREFIX}/";
}
std::vector<std::string> missingTargets; std::vector<std::string> missingTargets;
// Create all the imported targets. // Create all the imported targets.
@ -107,6 +128,13 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
<< "endforeach()\n" << "endforeach()\n"
<< "\n"; << "\n";
// Cleanup the import prefix variable.
if(!this->ImportPrefix.empty())
{
os << "# Cleanup temporary variables.\n"
<< "set(_IMPORT_PREFIX)\n"
<< "\n";
}
this->GenerateImportedFileCheckLoop(os); this->GenerateImportedFileCheckLoop(os);
// Generate an import file for each configuration. // Generate an import file for each configuration.
@ -126,6 +154,21 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
return result; return result;
} }
//----------------------------------------------------------------------------
void
cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string &input)
{
std::string::size_type pos = 0;
std::string::size_type lastPos = pos;
while((pos = input.find("$<INSTALL_PREFIX>", lastPos)) != input.npos)
{
std::string::size_type endPos = pos + sizeof("$<INSTALL_PREFIX>") - 1;
input.replace(pos, endPos - pos, "${_IMPORT_PREFIX}");
lastPos = endPos;
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool bool
cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config, cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config,
@ -187,27 +230,6 @@ cmExportInstallFileGenerator
const char* config, std::string const& suffix, const char* config, std::string const& suffix,
std::vector<std::string> &missingTargets) std::vector<std::string> &missingTargets)
{ {
// Add code to compute the installation prefix relative to the
// import file location.
const char* installDest = this->IEGen->GetDestination();
if(!cmSystemTools::FileIsFullPath(installDest))
{
std::string dest = installDest;
os << "# Compute the installation prefix relative to this file.\n"
<< "get_filename_component(_IMPORT_PREFIX "
<< "\"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
while(!dest.empty())
{
os <<
"get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n";
dest = cmSystemTools::GetFilenamePath(dest);
}
os << "\n";
// Import location properties may reference this variable.
this->ImportPrefix = "${_IMPORT_PREFIX}/";
}
// Add each target in the set to the export. // Add each target in the set to the export.
for(std::vector<cmTargetExport*>::const_iterator for(std::vector<cmTargetExport*>::const_iterator
tei = this->IEGen->GetExportSet()->GetTargetExports()->begin(); tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
@ -253,14 +275,6 @@ cmExportInstallFileGenerator
importedLocations); importedLocations);
} }
} }
// Cleanup the import prefix variable.
if(!this->ImportPrefix.empty())
{
os << "# Cleanup temporary variables.\n"
<< "set(_IMPORT_PREFIX)\n"
<< "\n";
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -64,6 +64,8 @@ protected:
cmTarget* depender, cmTarget* depender,
cmTarget* dependee); cmTarget* dependee);
virtual void ReplaceInstallPrefix(std::string &input);
void ComplainAboutMissingTarget(cmTarget* depender, void ComplainAboutMissingTarget(cmTarget* depender,
cmTarget* dependee, cmTarget* dependee,
int occurrences); int occurrences);

View File

@ -614,6 +614,24 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode
} targetPolicyNode; } targetPolicyNode;
//----------------------------------------------------------------------------
static const struct InstallPrefixNode : public cmGeneratorExpressionNode
{
InstallPrefixNode() {}
virtual bool GeneratesContent() const { return false; }
virtual int NumExpectedParameters() const { return 0; }
std::string Evaluate(const std::vector<std::string> &,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *,
cmGeneratorExpressionDAGChecker *) const
{
return std::string();
}
} installPrefixNode;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
template<bool linker, bool soname> template<bool linker, bool soname>
struct TargetFilesystemArtifactResultCreator struct TargetFilesystemArtifactResultCreator
@ -849,6 +867,8 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &installInterfaceNode; return &installInterfaceNode;
else if (identifier == "TARGET_DEFINED") else if (identifier == "TARGET_DEFINED")
return &targetDefinedNode; return &targetDefinedNode;
else if (identifier == "INSTALL_PREFIX")
return &installPrefixNode;
return 0; return 0;
} }

View File

@ -113,9 +113,16 @@ macro(add_include_lib _libName)
add_library(${_libName} "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c") add_library(${_libName} "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_libName}") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_libName}")
set_property(TARGET ${_libName} APPEND PROPERTY set_property(TARGET ${_libName} APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/${_libName}") INTERFACE_INCLUDE_DIRECTORIES
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${_libName}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include/${_libName}>"
)
if (NOT "${ARGV1}" STREQUAL "NO_HEADER") if (NOT "${ARGV1}" STREQUAL "NO_HEADER")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}/${_libName}.h" "// no content\n") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}/${_libName}.h" "// no content\n")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${_libName}/${_libName}.h"
DESTINATION include/${_libName}
)
endif() endif()
endmacro() endmacro()
@ -129,6 +136,10 @@ add_include_lib(testLibIncludeRequired3 NO_HEADER)
# but we are testing that the INSTALL_INTERFACE causes it not to be used # but we are testing that the INSTALL_INTERFACE causes it not to be used
# at build time. # at build time.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired3/testLibIncludeRequired4.h" "#error Should not be included\n") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired3/testLibIncludeRequired4.h" "#error Should not be included\n")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired3/testLibIncludeRequired4.h"
DESTINATION include/testLibIncludeRequired3
)
add_include_lib(testLibIncludeRequired4) add_include_lib(testLibIncludeRequired4)
add_include_lib(testLibIncludeRequired5 NO_HEADER) add_include_lib(testLibIncludeRequired5 NO_HEADER)
# Generate testLibIncludeRequired6 in the testLibIncludeRequired5 directory # Generate testLibIncludeRequired6 in the testLibIncludeRequired5 directory
@ -139,6 +150,10 @@ add_include_lib(testLibIncludeRequired5 NO_HEADER)
# the Import side of this unit test, the '6' include from the '5' directory # the Import side of this unit test, the '6' include from the '5' directory
# will not be used because it is in the BUILD_INTERFACE only. # will not be used because it is in the BUILD_INTERFACE only.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired5/testLibIncludeRequired6.h" "#error Should not be included\n") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired5/testLibIncludeRequired6.h" "#error Should not be included\n")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/testLibIncludeRequired5/testLibIncludeRequired6.h"
DESTINATION include/testLibIncludeRequired5
)
add_include_lib(testLibIncludeRequired6) add_include_lib(testLibIncludeRequired6)
set_property(TARGET testLibRequired APPEND PROPERTY set_property(TARGET testLibRequired APPEND PROPERTY

View File

@ -89,6 +89,7 @@ add_custom_target(check-part2 ALL
-Dtest_install_interface=$<INSTALL_INTERFACE:install> -Dtest_install_interface=$<INSTALL_INTERFACE:install>
-Dtest_target_name_1=$<TARGET_NAME:tgt,ok> -Dtest_target_name_1=$<TARGET_NAME:tgt,ok>
-Dtest_target_name_2=$<TARGET_NAME:tgt:ok> -Dtest_target_name_2=$<TARGET_NAME:tgt:ok>
-Dtest_install_prefix=$<INSTALL_PREFIX>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake
COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 2)" COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 2)"
VERBATIM VERBATIM

View File

@ -26,3 +26,4 @@ check(test_build_interface "build")
check(test_install_interface "") check(test_install_interface "")
check(test_target_name_1 "tgt,ok") check(test_target_name_1 "tgt,ok")
check(test_target_name_2 "tgt:ok") check(test_target_name_2 "tgt:ok")
check(test_install_prefix "")