Commit 247c1640 authored by Yves Starreveld's avatar Yves Starreveld
Browse files

Changes to allow MODULE type target for a shared library
parent 0b58132c
......@@ -52,7 +52,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string>& args)
// Library type defaults to value of BUILD_SHARED_LIBS, if it exists,
// otherwise it defaults to static library.
bool shared = !cmSystemTools::IsOff(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"));
int shared = !cmSystemTools::IsOff(m_Makefile->GetDefinition("BUILD_SHARED_LIBS"));
std::vector<std::string>::iterator s = args.begin();
++s;
......@@ -67,12 +67,17 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string>& args)
if(libType == "STATIC")
{
++s;
shared = false;
shared = 0;
}
else if(libType == "SHARED")
{
++s;
shared = true;
shared = 1;
}
else if(libType == "MODULE")
{
++s;
shared = 2;
}
}
std::vector<std::string> srclists(s, args.end());
......
......@@ -86,9 +86,11 @@ public:
virtual const char* GetFullDocumentation()
{
return
"ADD_LIBRARY(libname [SHARED | STATIC] srclist srclist srclist ...)\n"
"Adds a library target. If the keyword SHARED or STATIC appears, it\n"
"sets the library type. If neither keyword appears as the second\n"
"ADD_LIBRARY(libname [SHARED | STATIC | MODULE] srclist srclist ...)\n"
"Adds a library target. SHARED, STATIC or MODULE keywords are used\n"
"to set the library type. If the keywork MODULE appears, the library\n"
"type is set to MH_BUNDLE on systems which use dyld. Systems without\n"
"dyld MODULE is treated like SHARED. If no keywords appear as the second\n"
"argument, the type defaults to the current value of BUILD_SHARED_LIBS.\n"
"If this variable is not set, the type defaults to STATIC.";
}
......
......@@ -608,11 +608,25 @@ void cmMakefile::SetProjectName(const char* p)
m_ProjectName = p;
}
void cmMakefile::AddLibrary(const char* lname, bool shared,
void cmMakefile::AddLibrary(const char* lname, int shared,
const std::vector<std::string> &srcs)
{
cmTarget target;
target.SetType(shared? cmTarget::SHARED_LIBRARY : cmTarget::STATIC_LIBRARY);
switch (shared)
{
case 0:
target.SetType(cmTarget::STATIC_LIBRARY);
break;
case 1:
target.SetType(cmTarget::SHARED_LIBRARY);
break;
case 2:
target.SetType(cmTarget::MODULE_LIBRARY);
break;
default:
target.SetType(cmTarget::STATIC_LIBRARY);
}
target.SetInAll(true);
target.GetSourceLists() = srcs;
m_Targets.insert(cmTargets::value_type(lname,target));
......@@ -626,11 +640,36 @@ void cmMakefile::AddLibrary(const char* lname, bool shared,
// Add an entry into the cache
std::string ltname = lname;
ltname += "_LIBRARY_TYPE";
cmCacheManager::GetInstance()->
AddCacheEntry(ltname.c_str(),
shared? "SHARED":"STATIC",
"Whether a library is static or shared.",
cmCacheManager::INTERNAL);
switch (shared)
{
case 0:
cmCacheManager::GetInstance()->
AddCacheEntry(ltname.c_str(),
"STATIC",
"Whether a library is static, shared or module.",
cmCacheManager::INTERNAL);
break;
case 1:
cmCacheManager::GetInstance()->
AddCacheEntry(ltname.c_str(),
"SHARED",
"Whether a library is static, shared or module.",
cmCacheManager::INTERNAL);
break;
case 2:
cmCacheManager::GetInstance()->
AddCacheEntry(ltname.c_str(),
"MODULE",
"Whether a library is static, shared or module.",
cmCacheManager::INTERNAL);
break;
default:
cmCacheManager::GetInstance()->
AddCacheEntry(ltname.c_str(),
"STATIC",
"Whether a library is static, shared or module.",
cmCacheManager::INTERNAL);
}
}
void cmMakefile::AddExecutable(const char *exeName,
......
......@@ -243,7 +243,7 @@ public:
/**
* Set the name of the library.
*/
void AddLibrary(const char *libname, bool shared,
void AddLibrary(const char *libname, int shared,
const std::vector<std::string> &srcs);
/**
......
......@@ -55,7 +55,7 @@ class cmTarget
{
public:
enum TargetType { EXECUTABLE, WIN32_EXECUTABLE, STATIC_LIBRARY,
SHARED_LIBRARY, UTILITY, INSTALL_FILES, INSTALL_PROGRAMS };
SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, INSTALL_FILES, INSTALL_PROGRAMS };
/**
* Return the type of target.
......
......@@ -281,6 +281,11 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str()
<< m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
}
else if(l->second.GetType() == cmTarget::MODULE_LIBRARY)
{
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str()
<< m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX");
}
}
}
// executables
......@@ -539,6 +544,22 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
fout << "\n\n";
}
else if (l->second.GetType() == cmTarget::MODULE_LIBRARY)
{
fout << "#---------------------------------------------------------\n";
fout << "# rules for a shared module library\n";
fout << "#\n";
fout << m_LibraryOutputPath << "lib" << l->first << "$(MODULE_SUFFIX): ${" <<
l->first << "_SRC_OBJS} \n";
fout << "\trm -f lib" << l->first << "$(MODULE_SUFFIX)\n";
fout << "\t$(CMAKE_CXX_COMPILER) ${CMAKE_MODULE_LINK_FLAGS} "
"${CMAKE_MODULE_BUILD_FLAGS} ${CMAKE_CXXFLAGS} -o \\\n";
fout << "\t " << m_LibraryOutputPath << "lib" << l->first << "$(MODULE_SUFFIX) \\\n";
fout << "\t ${" << l->first <<
"_SRC_OBJS} ";
this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
fout << "\n\n";
}
else if ((l->second.GetType() == cmTarget::EXECUTABLE)
|| (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
{
......@@ -608,6 +629,10 @@ void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
{
libpath += m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
}
else if (libType && std::string(libType) == "MODULE")
{
libpath += m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX");
}
else
{
libpath += ".a";
......@@ -642,6 +667,10 @@ void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
{
library += m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
}
else if(libType && std::string(libType) == "MODULE")
{
library += m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX");
}
else
{
library += ".a";
......@@ -994,12 +1023,15 @@ void cmUnixMakefileGenerator::OutputMakeVariables(std::ostream& fout)
"CMAKE_CXX_COMPILER = @CMAKE_CXX_COMPILER@\n"
"CMAKE_CXXFLAGS = @CMAKE_CXX_FLAGS@ @CMAKE_TEMPLATE_FLAGS@\n"
"\n"
"CMAKE_SHLIB_BUILD_FLAGS = @CMAKE_SHLIB_BUILD_FLAGS@\n"
"CMAKE_SHLIB_LINK_FLAGS = @CMAKE_SHLIB_LINK_FLAGS@\n"
"DL_LIBS = @CMAKE_DL_LIBS@\n"
"SHLIB_LD_LIBS = @CMAKE_SHLIB_LD_LIBS@\n"
"SHLIB_SUFFIX = @CMAKE_SHLIB_SUFFIX@\n"
"THREAD_LIBS = @CMAKE_THREAD_LIBS@\n"
"CMAKE_SHLIB_BUILD_FLAGS = @CMAKE_SHLIB_BUILD_FLAGS@\n"
"CMAKE_SHLIB_LINK_FLAGS = @CMAKE_SHLIB_LINK_FLAGS@\n"
"CMAKE_MODULE_BUILD_FLAGS = @CMAKE_MODULE_BUILD_FLAGS@\n"
"CMAKE_MODULE_LINK_FLAGS = @CMAKE_MODULE_LINK_FLAGS@\n"
"DL_LIBS = @CMAKE_DL_LIBS@\n"
"SHLIB_LD_LIBS = @CMAKE_SHLIB_LD_LIBS@\n"
"SHLIB_SUFFIX = @CMAKE_SHLIB_SUFFIX@\n"
"MODULE_SUFFIX = @CMAKE_MODULE_SUFFIX@\n"
"THREAD_LIBS = @CMAKE_THREAD_LIBS@\n"
"\n"
"# set up the path to the rulesgen program\n"
"CMAKE_COMMAND = ${CMAKE_COMMAND}\n"
......@@ -1065,6 +1097,12 @@ void cmUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
fout << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
fout << " " << prefix << l->second.GetInstallPath() << "\n";
break;
case cmTarget::MODULE_LIBRARY:
fout << "\t$(INSTALL_DATA) " << m_LibraryOutputPath << "lib"
<< l->first;
fout << m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX");
fout << " " << prefix << l->second.GetInstallPath() << "\n";
break;
case cmTarget::WIN32_EXECUTABLE:
case cmTarget::EXECUTABLE:
fout << "\t$(INSTALL_PROGRAM) " << m_ExecutableOutputPath
......@@ -1263,7 +1301,8 @@ void cmUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream& fout)
for(std::map<cmStdString, cmTarget>::const_iterator target = targets.begin();
target != targets.end(); ++target)
{
bool shared = (target->second.GetType() == cmTarget::SHARED_LIBRARY);
bool shared = ((target->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(target->second.GetType() == cmTarget::MODULE_LIBRARY));
std::string exportsDef = "";
if(shared)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment