ENH: Add support for adding content to bundles
This commit is contained in:
parent
5d722df21f
commit
40272a16bd
|
@ -47,6 +47,8 @@ IF(NOT XCODE)
|
||||||
SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-install_name")
|
SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-install_name")
|
||||||
ENDIF(NOT XCODE)
|
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_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
|
||||||
SET(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
|
SET(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
|
||||||
SET(CMAKE_C_CREATE_SHARED_LIBRARY
|
SET(CMAKE_C_CREATE_SHARED_LIBRARY
|
||||||
|
|
|
@ -1542,15 +1542,54 @@ cmLocalUnixMakefileGenerator3
|
||||||
{
|
{
|
||||||
objectName = objectName.substr(0, dot_pos);
|
objectName = objectName.substr(0, dot_pos);
|
||||||
}
|
}
|
||||||
objectName +=
|
if ( source.GetPropertyAsBool("KEEP_EXTENSION") )
|
||||||
this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
|
{
|
||||||
source.GetSourceExtension().c_str());
|
if ( !source.GetSourceExtension().empty() )
|
||||||
|
{
|
||||||
|
objectName += "." + source.GetSourceExtension();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
objectName +=
|
||||||
|
this->GlobalGenerator->GetLanguageOutputExtensionFromExtension(
|
||||||
|
source.GetSourceExtension().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to a safe name.
|
// Convert to a safe name.
|
||||||
objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
|
objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
|
||||||
|
|
||||||
// Prepend the target directory.
|
// 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 += "/";
|
||||||
obj += objectName;
|
obj += objectName;
|
||||||
if(nameWithoutTargetDir)
|
if(nameWithoutTargetDir)
|
||||||
|
@ -1763,6 +1802,11 @@ const char*
|
||||||
cmLocalUnixMakefileGenerator3
|
cmLocalUnixMakefileGenerator3
|
||||||
::GetSourceFileLanguage(const cmSourceFile& source)
|
::GetSourceFileLanguage(const cmSourceFile& source)
|
||||||
{
|
{
|
||||||
|
const char* lang = source.GetProperty("LANGUAGE");
|
||||||
|
if ( lang )
|
||||||
|
{
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
// Identify the language of the source file.
|
// Identify the language of the source file.
|
||||||
return (this->GlobalGenerator
|
return (this->GlobalGenerator
|
||||||
->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
|
->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
|
||||||
|
|
|
@ -130,6 +130,25 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||||
macdir += targetName;
|
macdir += targetName;
|
||||||
macdir += ".app/Contents/";
|
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
|
// Configure the Info.plist file. Note that it needs the executable name
|
||||||
// to be set.
|
// to be set.
|
||||||
std::string f2 = macdir + "Info.plist";
|
std::string f2 = macdir + "Info.plist";
|
||||||
|
|
|
@ -237,8 +237,6 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
|
void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
|
||||||
{
|
{
|
||||||
|
@ -282,6 +280,10 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source)
|
||||||
(this->LocalGenerator->ConvertToFullPath(dir).c_str());
|
(this->LocalGenerator->ConvertToFullPath(dir).c_str());
|
||||||
|
|
||||||
// Save this in the target's list of object files.
|
// Save this in the target's list of object files.
|
||||||
|
if ( source.GetPropertyAsBool("EXTRA_CONTENT") )
|
||||||
|
{
|
||||||
|
this->ExtraContent.insert(obj);
|
||||||
|
}
|
||||||
this->Objects.push_back(obj);
|
this->Objects.push_back(obj);
|
||||||
std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
|
std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
|
||||||
relativeObj += obj;
|
relativeObj += obj;
|
||||||
|
@ -587,6 +589,7 @@ void cmMakefileTargetGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
void cmMakefileTargetGenerator::WriteCustomCommands()
|
void cmMakefileTargetGenerator::WriteCustomCommands()
|
||||||
{
|
{
|
||||||
// add custom commands to the clean rules?
|
// add custom commands to the clean rules?
|
||||||
|
@ -667,6 +670,10 @@ cmMakefileTargetGenerator
|
||||||
for(std::vector<std::string>::const_iterator i = this->Objects.begin();
|
for(std::vector<std::string>::const_iterator i = this->Objects.begin();
|
||||||
i != this->Objects.end(); ++i)
|
i != this->Objects.end(); ++i)
|
||||||
{
|
{
|
||||||
|
if ( this->ExtraContent.find(i->c_str()) != this->ExtraContent.end() )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
*this->BuildFileStream << " " << lineContinue << "\n";
|
*this->BuildFileStream << " " << lineContinue << "\n";
|
||||||
if(objName)
|
if(objName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,6 +132,7 @@ protected:
|
||||||
// objects used by this target
|
// objects used by this target
|
||||||
std::vector<std::string> Objects;
|
std::vector<std::string> Objects;
|
||||||
std::vector<std::string> ExternalObjects;
|
std::vector<std::string> ExternalObjects;
|
||||||
|
std::set<std::string> ExtraContent;
|
||||||
|
|
||||||
// Set of object file names that will be built in this directory.
|
// Set of object file names that will be built in this directory.
|
||||||
std::set<cmStdString> ObjectFiles;
|
std::set<cmStdString> ObjectFiles;
|
||||||
|
|
|
@ -63,7 +63,8 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
|
||||||
++j;
|
++j;
|
||||||
if(j == args.end())
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
propertyPairs.push_back(*j);
|
propertyPairs.push_back(*j);
|
||||||
|
@ -85,6 +86,7 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
|
||||||
{
|
{
|
||||||
// now loop through the rest of the arguments, new style
|
// now loop through the rest of the arguments, new style
|
||||||
++j;
|
++j;
|
||||||
|
bool dontPush = false;
|
||||||
while (j != args.end())
|
while (j != args.end())
|
||||||
{
|
{
|
||||||
propertyPairs.push_back(*j);
|
propertyPairs.push_back(*j);
|
||||||
|
@ -96,6 +98,25 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
|
||||||
generated = true;
|
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
|
else
|
||||||
{
|
{
|
||||||
++j;
|
++j;
|
||||||
|
@ -105,8 +126,12 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
|
||||||
this->SetError("called with incorrect number of arguments.");
|
this->SetError("called with incorrect number of arguments.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
propertyPairs.push_back(*j);
|
if ( !dontPush )
|
||||||
|
{
|
||||||
|
propertyPairs.push_back(*j);
|
||||||
|
}
|
||||||
++j;
|
++j;
|
||||||
|
dontPush = false;
|
||||||
}
|
}
|
||||||
// break out of the loop because j is already == end
|
// break out of the loop because j is already == end
|
||||||
break;
|
break;
|
||||||
|
@ -117,7 +142,8 @@ bool cmSetSourceFilesPropertiesCommand::InitialPass(
|
||||||
}
|
}
|
||||||
else
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,36 @@
|
||||||
PROJECT(BundleTest)
|
PROJECT(BundleTest)
|
||||||
SET(MACOSX_BUNDLE_INFO_STRING "bundle_info_string")
|
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.
|
# Test building a bundle linking to a shared library.
|
||||||
ADD_LIBRARY(BundleTestLib SHARED BundleLib.cxx)
|
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)
|
TARGET_LINK_LIBRARIES(BundleTest BundleTestLib)
|
||||||
|
|
||||||
# Test bundle installation.
|
# Test bundle installation.
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue