ENH: Add support for adding content to bundles

This commit is contained in:
Andy Cedilnik 2006-03-28 08:54:01 -05:00
parent 5d722df21f
commit 40272a16bd
9 changed files with 178 additions and 43 deletions

View File

@ -47,6 +47,8 @@ IF(NOT XCODE)
SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-install_name")
ENDIF(NOT XCODE)
SET(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>")
SET(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
SET(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
SET(CMAKE_C_CREATE_SHARED_LIBRARY

View File

@ -1542,15 +1542,54 @@ cmLocalUnixMakefileGenerator3
{
objectName = objectName.substr(0, dot_pos);
}
if ( source.GetPropertyAsBool("KEEP_EXTENSION") )
{
if ( !source.GetSourceExtension().empty() )
{
objectName += "." + source.GetSourceExtension();
}
}
else
{
objectName +=
this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
source.GetSourceExtension().c_str());
}
// Convert to a safe name.
objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
// Prepend the target directory.
std::string obj = this->GetTargetDirectory(target);
std::string obj;
const char* fileTargetDirectory = source.GetProperty("MACOSX_PACKAGE_LOCATION");
if ( fileTargetDirectory )
{
std::string targetName;
std::string targetNameReal;
target.GetExecutableNames(targetName, targetNameReal,
this->ConfigurationName.c_str());
if ( target.GetPropertyAsBool("MACOSX_BUNDLE") )
{
// Construct the full path version of the names.
obj = this->ExecutableOutputPath;
if(obj.empty())
{
obj = this->Makefile->GetStartOutputDirectory();
obj += "/";
}
obj += targetName + ".app/Contents/";
obj += fileTargetDirectory;
}
else
{
// Framework not handled yet
abort();
}
}
else
{
obj = this->GetTargetDirectory(target);
}
obj += "/";
obj += objectName;
if(nameWithoutTargetDir)
@ -1763,6 +1802,11 @@ const char*
cmLocalUnixMakefileGenerator3
::GetSourceFileLanguage(const cmSourceFile& source)
{
const char* lang = source.GetProperty("LANGUAGE");
if ( lang )
{
return lang;
}
// Identify the language of the source file.
return (this->GlobalGenerator
->GetLanguageFromExtension(source.GetSourceExtension().c_str()));

View File

@ -130,6 +130,25 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
macdir += targetName;
macdir += ".app/Contents/";
std::vector<cmSourceFile*>::iterator sourceIt;
for ( sourceIt = this->Target->GetSourceFiles().begin();
sourceIt != this->Target->GetSourceFiles().end();
++ sourceIt )
{
const char* subDir = (*sourceIt)->GetProperty("MACOSX_PACKAGE_LOCATION");
if ( subDir )
{
std::string newDir = macdir;
newDir += subDir;
if ( !cmSystemTools::MakeDirectory(newDir.c_str()) )
{
cmSystemTools::Error("Cannot create a subdirectory for \"",
newDir.c_str(), "\".");
return;
}
}
}
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
std::string f2 = macdir + "Info.plist";

View File

@ -237,8 +237,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
}
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
{
@ -282,6 +280,10 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
(this->LocalGenerator->ConvertToFullPath(dir).c_str());
// Save this in the target's list of object files.
if ( source.GetPropertyAsBool("EXTRA_CONTENT") )
{
this->ExtraContent.insert(obj);
}
this->Objects.push_back(obj);
std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
relativeObj += obj;
@ -587,6 +589,7 @@ void cmMakefileTargetGenerator
}
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::WriteCustomCommands()
{
// add custom commands to the clean rules?
@ -667,6 +670,10 @@ cmMakefileTargetGenerator
for(std::vector<std::string>::const_iterator i = this->Objects.begin();
i != this->Objects.end(); ++i)
{
if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
{
continue;
}
*this->BuildFileStream << " " << lineContinue << "\n";
if(objName)
{

View File

@ -132,6 +132,7 @@ protected:
// objects used by this target
std::vector<std::string> Objects;
std::vector<std::string> ExternalObjects;
std::set<std::string> ExtraContent;
// Set of object file names that will be built in this directory.
std::set<cmStdString> ObjectFiles;

View File

@ -63,7 +63,8 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
++j;
if(j == args.end())
{
this->SetError("called with incorrect number of arguments COMPILE_FLAGS with no flags");
this->SetError("called with incorrect number of arguments "
"COMPILE_FLAGS with no flags");
return false;
}
propertyPairs.push_back(*j);
@ -85,6 +86,7 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
{
// now loop through the rest of the arguments, new style
++j;
bool dontPush = false;
while (j != args.end())
{
propertyPairs.push_back(*j);
@ -96,6 +98,25 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
generated = true;
}
}
else if(*j == "MACOSX_PACKAGE_LOCATION")
{
doingFiles = false;
++j;
if(j == args.end())
{
this->SetError("called with incorrect number of arguments "
"MACOSX_PACKAGE_LOCATION with no flags");
return false;
}
propertyPairs.push_back(*j);
propertyPairs.push_back("EXTRA_CONTENT");
propertyPairs.push_back("1");
propertyPairs.push_back("KEEP_EXTENSION");
propertyPairs.push_back("1");
propertyPairs.push_back("LANGUAGE");
propertyPairs.push_back("MacOSX_Content");
dontPush = true;
}
else
{
++j;
@ -105,8 +126,12 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
this->SetError("called with incorrect number of arguments.");
return false;
}
if ( !dontPush )
{
propertyPairs.push_back(*j);
}
++j;
dontPush = false;
}
// break out of the loop because j is already == end
break;
@ -117,7 +142,8 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
}
else
{
this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
this->SetError("called with illegal arguments, maybe missing a "
"PROPERTIES specifier?");
return false;
}
}

View File

@ -1,9 +1,36 @@
PROJECT(BundleTest)
SET(MACOSX_BUNDLE_INFO_STRING "bundle_info_string")
SET(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>")
ADD_CUSTOM_COMMAND(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
COMMAND /bin/cp
ARGS "${CMAKE_CURRENT_SOURCE_DIR}/randomResourceFile.plist.in"
"${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist")
SET_SOURCE_FILES_PROPERTIES(
"${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
SET_SOURCE_FILES_PROPERTIES(
SomeRandomFile.txt
PROPERTIES
MACOSX_PACKAGE_LOCATION MacOS
)
SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar")
# Test building a bundle linking to a shared library.
ADD_LIBRARY(BundleTestLib SHARED BundleLib.cxx)
ADD_EXECUTABLE(BundleTest MACOSX_BUNDLE BundleTest.cxx)
ADD_EXECUTABLE(BundleTest
MACOSX_BUNDLE
BundleTest.cxx
SomeRandomFile.txt
"${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
)
TARGET_LINK_LIBRARIES(BundleTest BundleTestLib)
# Test bundle installation.

View File

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Package</key>
<string>CMake</string>
</dict>
</plist>