diff options
-rw-r--r-- | Modules/Platform/Darwin.cmake | 5 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 36 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 42 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.h | 3 |
4 files changed, 82 insertions, 4 deletions
diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index ecc465c..f0bdd8b 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -27,6 +27,11 @@ SET(CMAKE_SHARED_MODULE_SUFFIX ".so") SET(CMAKE_MODULE_EXISTS 1) SET(CMAKE_DL_LIBS "") +SET(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG -Wl,-dylib_compatibility_version,) +SET(CMAKE_C_OSX_CURRENT_VERSION_FLAG -Wl,-dylib_current_version,) +SET(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") +SET(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") + SET(CMAKE_C_LINK_FLAGS "-headerpad_max_install_names") SET(CMAKE_CXX_LINK_FLAGS "-headerpad_max_install_names") diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 6ae073b..9f1c50a 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1459,10 +1459,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, buildSettings->AddAttribute("LIBRARY_STYLE", this->CreateString("DYNAMIC")); - buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION", - this->CreateString("1")); - buildSettings->AddAttribute("DYLIB_CURRENT_VERSION", - this->CreateString("1")); break; } case cmTarget::EXECUTABLE: @@ -1680,6 +1676,38 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->CreateString( "-Wmost -Wno-four-char-constants" " -Wno-unknown-pragmas")); + + // Runtime version information. + if(target.GetType() == cmTarget::SHARED_LIBRARY) + { + int major; + int minor; + int patch; + + // VERSION -> current_version + target.GetTargetVersion(false, major, minor, patch); + if(major == 0 && minor == 0 && patch == 0) + { + // Xcode always wants at least 1.0.0 + major = 1; + } + cmOStringStream v; + v << major << "." << minor << "." << patch; + buildSettings->AddAttribute("DYLIB_CURRENT_VERSION", + this->CreateString(v.str().c_str())); + + // SOVERSION -> compatibility_version + target.GetTargetVersion(true, major, minor, patch); + if(major == 0 && minor == 0 && patch == 0) + { + // Xcode always wants at least 1.0.0 + major = 1; + } + cmOStringStream vso; + vso << major << "." << minor << "." << patch; + buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION", + this->CreateString(vso.str().c_str())); + } } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index a881391..03b9622 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -364,6 +364,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules std::string linkFlags; this->LocalGenerator->AppendFlags(linkFlags, extraFlags); + // Add OSX version flags, if any. + if(this->Target->GetType() == cmTarget::SHARED_LIBRARY || + this->Target->GetType() == cmTarget::MODULE_LIBRARY) + { + this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true); + this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false); + } + // Construct the name of the library. std::string targetName; std::string targetNameSO; @@ -905,3 +913,37 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules this->CleanFiles.insert(this->CleanFiles.end(), libCleanFiles.begin(),libCleanFiles.end()); } + +//---------------------------------------------------------------------------- +void +cmMakefileLibraryTargetGenerator +::AppendOSXVerFlag(std::string& flags, const char* lang, + const char* name, bool so) +{ + // Lookup the flag to specify the version. + std::string fvar = "CMAKE_"; + fvar += lang; + fvar += "_OSX_"; + fvar += name; + fvar += "_VERSION_FLAG"; + const char* flag = this->Makefile->GetDefinition(fvar.c_str()); + + // Skip if no such flag. + if(!flag) + { + return; + } + + // Lookup the target version information. + int major; + int minor; + int patch; + this->Target->GetTargetVersion(so, major, minor, patch); + if(major > 0 || minor > 0 || patch > 0) + { + // Append the flag since a non-zero version is specified. + cmOStringStream vflag; + vflag << flag << major << "." << minor << "." << patch; + this->LocalGenerator->AppendFlags(flags, vflag.str().c_str()); + } +} diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index 7517785..e5f9482 100644 --- a/Source/cmMakefileLibraryTargetGenerator.h +++ b/Source/cmMakefileLibraryTargetGenerator.h @@ -41,6 +41,9 @@ protected: // Store the computd framework version for OS X Frameworks. std::string FrameworkVersion; + + void AppendOSXVerFlag(std::string& flags, const char* lang, + const char* name, bool so); }; #endif |