summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-09-22 14:46:59 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-09-22 14:46:59 (GMT)
commitda7c8a8dae10a4fd2f33798bc8aec8a3c238b2af (patch)
treef78089634b5873d3d8b4d7d7d2e0f21598fbaf1f /Source
parent4be709a6b715acb4100fceb4394ad5215d8b555b (diff)
parentb15f4e9b86bc3dc31b6a01c0ffc30747f467ec1f (diff)
downloadCMake-da7c8a8dae10a4fd2f33798bc8aec8a3c238b2af.zip
CMake-da7c8a8dae10a4fd2f33798bc8aec8a3c238b2af.tar.gz
CMake-da7c8a8dae10a4fd2f33798bc8aec8a3c238b2af.tar.bz2
Merge topic 'restrict-shlib-link-flags-to-enable-exports'
b15f4e9b try_compile: Propogate CMP0065 to the generated project. 9784af1b CMP0065: Restrict the use of CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCoreTryCompile.cxx10
-rw-r--r--Source/cmLocalGenerator.cxx44
-rw-r--r--Source/cmPolicies.h4
-rw-r--r--Source/cmTarget.cxx1
-rw-r--r--Source/cmTarget.h3
5 files changed, 56 insertions, 6 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 9411555..e489ad2 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -481,6 +481,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
fprintf(fout, "set(CMAKE_LINK_SEARCH_END_STATIC \"%s\")\n", lssDef);
}
+ /* Set the appropriate policy information for ENABLE_EXPORTS */
+ fprintf(fout, "cmake_policy(SET CMP0065 %s)\n",
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0065) ==
+ cmPolicies::NEW ? "NEW" : "OLD");
+ if(const char *ee = this->Makefile->GetDefinition(
+ "CMAKE_ENABLE_EXPORTS"))
+ {
+ fprintf(fout, "set(CMAKE_ENABLE_EXPORTS %s)\n", ee);
+ }
+
/* Put the executable at a known location (for COPY_FILE). */
fprintf(fout, "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"%s\")\n",
this->BinaryDirectory.c_str());
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 4418ead..6c7b194 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1540,13 +1540,47 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
this->Makefile->GetSafeDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
// Flags to link an executable to shared libraries.
- std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
- linkFlagsVar += linkLanguage;
- linkFlagsVar += "_FLAGS";
if( tgt.GetType() == cmTarget::EXECUTABLE )
{
- linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
- linkLibs += " ";
+ bool add_shlib_flags = false;
+ switch(tgt.Target->GetPolicyStatusCMP0065())
+ {
+ case cmPolicies::WARN:
+ if(!tgt.GetPropertyAsBool("ENABLE_EXPORTS") &&
+ this->Makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0065"))
+ {
+ std::ostringstream w;
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0065) << "\n"
+ "For compatibility with older versions of CMake, "
+ "additional flags may be added to export symbols on all "
+ "executables regardless of thier ENABLE_EXPORTS property.";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }
+ case cmPolicies::OLD:
+ // OLD behavior is to always add the flags
+ add_shlib_flags = true;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065)
+ );
+ case cmPolicies::NEW:
+ // NEW behavior is to only add the flags if ENABLE_EXPORTS is on
+ add_shlib_flags = tgt.GetPropertyAsBool("ENABLE_EXPORTS");
+ break;
+ }
+
+ if(add_shlib_flags)
+ {
+ std::string linkFlagsVar = "CMAKE_SHARED_LIBRARY_LINK_";
+ linkFlagsVar += linkLanguage;
+ linkFlagsVar += "_FLAGS";
+ linkLibs = this->Makefile->GetSafeDefinition(linkFlagsVar);
+ linkLibs += " ";
+ }
}
// Append the framework search path flags.
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index b20c7a9..283f277 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -220,6 +220,10 @@ class cmPolicy;
3, 3, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0064, \
"Support new TEST if() operator.", \
+ 3, 4, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0065, \
+ "Do not add flags to export symbols from executables without " \
+ "the ENABLE_EXPORTS target property.", \
3, 4, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 13e0d7e..bb44956 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -347,6 +347,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
{
this->SetPropertyDefault("ANDROID_GUI", 0);
this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", 0);
+ this->SetPropertyDefault("ENABLE_EXPORTS", 0);
}
if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
|| this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index c86ec24..3e71dbd 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -41,7 +41,8 @@
F(CMP0046) \
F(CMP0052) \
F(CMP0060) \
- F(CMP0063)
+ F(CMP0063) \
+ F(CMP0065)
class cmake;
class cmMakefile;