summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuck Atkins <chuck.atkins@kitware.com>2015-08-07 19:11:57 (GMT)
committerBrad King <brad.king@kitware.com>2015-08-13 14:34:44 (GMT)
commit675ef165f213a6db1f9d0dfbebf6a0afc5469494 (patch)
tree79fa37f2fd5a783478610ea72f8b524883c4d4fd
parent7a7922e0201fee6a6f45c702f96ca57a295c68fe (diff)
downloadCMake-675ef165f213a6db1f9d0dfbebf6a0afc5469494.zip
CMake-675ef165f213a6db1f9d0dfbebf6a0afc5469494.tar.gz
CMake-675ef165f213a6db1f9d0dfbebf6a0afc5469494.tar.bz2
Allow LINK_SEARCH_{START,END}_STATIC props to have default values.
Use the CMAKE_LINK_SEARCH_START_STATIC and CMAKE_LINK_SEARCH_END_STATIC variables to initialize the LINK_SEARCH_START_STATIC and LINK_SEARCH_END_STATIC target properties respectively.
-rw-r--r--Help/manual/cmake-variables.7.rst2
-rw-r--r--Help/prop_tgt/LINK_SEARCH_END_STATIC.rst8
-rw-r--r--Help/prop_tgt/LINK_SEARCH_START_STATIC.rst7
-rw-r--r--Help/variable/CMAKE_LINK_SEARCH_END_STATIC.rst18
-rw-r--r--Help/variable/CMAKE_LINK_SEARCH_START_STATIC.rst19
-rw-r--r--Source/cmComputeLinkInformation.cxx8
-rw-r--r--Source/cmTarget.cxx2
-rw-r--r--Tests/RunCMake/set_property/LINK_SEARCH_STATIC.cmake73
-rw-r--r--Tests/RunCMake/set_property/LinkStatic.c5
-rw-r--r--Tests/RunCMake/set_property/RunCMakeTest.cmake1
10 files changed, 137 insertions, 6 deletions
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 9066d97..e0dbdeb 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -47,6 +47,8 @@ Variables that Provide Information
/variable/CMAKE_JOB_POOL_COMPILE
/variable/CMAKE_JOB_POOL_LINK
/variable/CMAKE_LINK_LIBRARY_SUFFIX
+ /variable/CMAKE_LINK_SEARCH_END_STATIC
+ /variable/CMAKE_LINK_SEARCH_START_STATIC
/variable/CMAKE_MAJOR_VERSION
/variable/CMAKE_MAKE_PROGRAM
/variable/CMAKE_MATCH_COUNT
diff --git a/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
index fe105bd..cf9c871 100644
--- a/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
+++ b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
@@ -10,5 +10,9 @@ paths are not known or (in some cases) are in implicit link
directories for the platform. By default CMake adds an option at the
end of the library list (if necessary) to set the linker search type
back to its starting type. This property switches the final linker
-search type to -Bstatic regardless of how it started. See also
-LINK_SEARCH_START_STATIC.
+search type to -Bstatic regardless of how it started.
+
+This property is initialized by the value of the variable
+CMAKE_LINK_SEARCH_END_STATIC if it is set when a target is created.
+
+See also LINK_SEARCH_START_STATIC.
diff --git a/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
index ca899fe..2e0f9bd 100644
--- a/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
+++ b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
@@ -11,4 +11,9 @@ directories for the platform. By default the linker search type is
assumed to be -Bdynamic at the beginning of the library list. This
property switches the assumption to -Bstatic. It is intended for use
when linking an executable statically (e.g. with the GNU -static
-option). See also LINK_SEARCH_END_STATIC.
+option).
+
+This property is initialized by the value of the variable
+CMAKE_LINK_SEARCH_START_STATIC if it is set when a target is created.
+
+See also LINK_SEARCH_END_STATIC.
diff --git a/Help/variable/CMAKE_LINK_SEARCH_END_STATIC.rst b/Help/variable/CMAKE_LINK_SEARCH_END_STATIC.rst
new file mode 100644
index 0000000..8a9951d
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_SEARCH_END_STATIC.rst
@@ -0,0 +1,18 @@
+CMAKE_LINK_SEARCH_END_STATIC
+----------------------------
+
+End a link line such that static system libraries are used.
+
+Some linkers support switches such as -Bstatic and -Bdynamic to
+determine whether to use static or shared libraries for -lXXX options.
+CMake uses these options to set the link type for libraries whose full
+paths are not known or (in some cases) are in implicit link
+directories for the platform. By default CMake adds an option at the
+end of the library list (if necessary) to set the linker search type
+back to its starting type. This property switches the final linker
+search type to -Bstatic regardless of how it started.
+
+This variable is used to initialize the target property
+LINK_SEARCH_END_STATIC for all targets.
+
+See also CMAKE_LINK_SEARCH_START_STATIC.
diff --git a/Help/variable/CMAKE_LINK_SEARCH_START_STATIC.rst b/Help/variable/CMAKE_LINK_SEARCH_START_STATIC.rst
new file mode 100644
index 0000000..715db4b
--- /dev/null
+++ b/Help/variable/CMAKE_LINK_SEARCH_START_STATIC.rst
@@ -0,0 +1,19 @@
+CMAKE_LINK_SEARCH_START_STATIC
+------------------------------
+
+Assume the linker looks for static libraries by default.
+
+Some linkers support switches such as -Bstatic and -Bdynamic to
+determine whether to use static or shared libraries for -lXXX options.
+CMake uses these options to set the link type for libraries whose full
+paths are not known or (in some cases) are in implicit link
+directories for the platform. By default the linker search type is
+assumed to be -Bdynamic at the beginning of the library list. This
+property switches the assumption to -Bstatic. It is intended for use
+when linking an executable statically (e.g. with the GNU -static
+option).
+
+This variable is used to initialize the target property
+LINK_SEARCH_START_STATIC for all targets.
+
+See also CMAKE_LINK_SEARCH_END_STATIC.
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index c16472e..12dddd2 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -522,9 +522,10 @@ bool cmComputeLinkInformation::Compute()
// libraries are found.
const char* lss =
this->Target->Target->GetProperty("LINK_SEARCH_END_STATIC");
- if(cmSystemTools::IsOn(lss))
+ if(lss)
{
- this->SetCurrentLinkType(LinkStatic);
+ this->SetCurrentLinkType(
+ cmSystemTools::IsOn(lss) ? LinkStatic : LinkShared);
}
else
{
@@ -862,7 +863,8 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo()
const char* lss =
this->Target->Target->GetProperty("LINK_SEARCH_START_STATIC");
this->StartLinkType = cmSystemTools::IsOn(lss)? LinkStatic : LinkShared;
- this->CurrentLinkType = this->StartLinkType;
+ this->CurrentLinkType = LinkUnknown;
+ this->SetCurrentLinkType(this->StartLinkType);
}
//----------------------------------------------------------------------------
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 316d85c..59d4da0 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -306,6 +306,8 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("CXX_STANDARD", 0);
this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
this->SetPropertyDefault("CXX_EXTENSIONS", 0);
+ this->SetPropertyDefault("LINK_SEARCH_START_STATIC", 0);
+ this->SetPropertyDefault("LINK_SEARCH_END_STATIC", 0);
}
// Collect the set of configuration types.
diff --git a/Tests/RunCMake/set_property/LINK_SEARCH_STATIC.cmake b/Tests/RunCMake/set_property/LINK_SEARCH_STATIC.cmake
new file mode 100644
index 0000000..70d2fee
--- /dev/null
+++ b/Tests/RunCMake/set_property/LINK_SEARCH_STATIC.cmake
@@ -0,0 +1,73 @@
+project(LinkSearchStatic)
+
+set(CMAKE_LINK_SEARCH_START_STATIC ON)
+add_executable(LinkSearchStartStaticInit1 LinkStatic.c)
+get_target_property(LSSS LinkSearchStartStaticInit1
+ LINK_SEARCH_START_STATIC)
+if(NOT LSSS)
+ message(FATAL_ERROR "Failed to correctly initialize LINK_SEARCH_START_STATIC")
+endif()
+unset(CMAKE_LINK_SEARCH_START_STATIC)
+
+add_executable(LinkSearchStartStaticSet1 LinkStatic.c)
+set_target_properties(LinkSearchStartStaticSet1 PROPERTIES
+ LINK_SEARCH_START_STATIC ON)
+get_target_property(LSSS LinkSearchStartStaticSet1
+ LINK_SEARCH_START_STATIC)
+if(NOT LSSS)
+ message(FATAL_ERROR "Failed to correctly set LINK_SEARCH_START_STATIC")
+endif()
+
+set(CMAKE_LINK_SEARCH_START_STATIC OFF)
+add_executable(LinkSearchStartStaticInit2 LinkStatic.c)
+get_target_property(LSSS LinkSearchStartStaticInit2
+ LINK_SEARCH_START_STATIC)
+if(LSSS)
+ message(FATAL_ERROR "Failed to correctly initialize LINK_SEARCH_START_STATIC")
+endif()
+unset(CMAKE_LINK_SEARCH_START_STATIC)
+
+add_executable(LinkSearchStartStaticSet2 LinkStatic.c)
+set_target_properties(LinkSearchStartStaticSet2 PROPERTIES
+ LINK_SEARCH_START_STATIC OFF)
+get_target_property(LSSS LinkSearchStartStaticSet2
+ LINK_SEARCH_START_STATIC)
+if(LSSS)
+ message(FATAL_ERROR "Failed to correctly set LINK_SEARCH_START_STATIC")
+endif()
+
+set(CMAKE_LINK_SEARCH_END_STATIC ON)
+add_executable(LinkSearchEndStaticInit1 LinkStatic.c)
+get_target_property(LSES LinkSearchEndStaticInit1
+ LINK_SEARCH_END_STATIC)
+if(NOT LSES)
+ message(FATAL_ERROR "Failed to correctly initialize LINK_SEARCH_END_STATIC")
+endif()
+unset(CMAKE_LINK_SEARCH_END_STATIC)
+
+add_executable(LinkSearchEndStaticSet1 LinkStatic.c)
+set_target_properties(LinkSearchEndStaticSet1 PROPERTIES
+ LINK_SEARCH_END_STATIC ON)
+get_target_property(LSSS LinkSearchEndStaticSet1
+ LINK_SEARCH_END_STATIC)
+if(NOT LSSS)
+ message(FATAL_ERROR "Failed to correctly set LINK_SEARCH_END_STATIC")
+endif()
+
+set(CMAKE_LINK_SEARCH_END_STATIC OFF)
+add_executable(LinkSearchEndStaticInit2 LinkStatic.c)
+get_target_property(LSES LinkSearchEndStaticInit2
+ LINK_SEARCH_END_STATIC)
+if(LSES)
+ message(FATAL_ERROR "Failed to correctly initialize LINK_SEARCH_END_STATIC")
+endif()
+unset(CMAKE_LINK_SEARCH_END_STATIC)
+
+add_executable(LinkSearchEndStaticSet2 LinkStatic.c)
+set_target_properties(LinkSearchEndStaticSet2 PROPERTIES
+ LINK_SEARCH_END_STATIC ON)
+get_target_property(LSSS LinkSearchEndStaticSet2
+ LINK_SEARCH_END_STATIC)
+if(NOT LSSS)
+ message(FATAL_ERROR "Failed to correctly set LINK_SEARCH_END_STATIC")
+endif()
diff --git a/Tests/RunCMake/set_property/LinkStatic.c b/Tests/RunCMake/set_property/LinkStatic.c
new file mode 100644
index 0000000..3600977
--- /dev/null
+++ b/Tests/RunCMake/set_property/LinkStatic.c
@@ -0,0 +1,5 @@
+#include <math.h>
+int main(void)
+{
+ return (int)sin(0);
+}
diff --git a/Tests/RunCMake/set_property/RunCMakeTest.cmake b/Tests/RunCMake/set_property/RunCMakeTest.cmake
index 54e63f7..ada8804 100644
--- a/Tests/RunCMake/set_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/set_property/RunCMakeTest.cmake
@@ -1,3 +1,4 @@
include(RunCMake)
run_cmake(LINK_LIBRARIES)
+run_cmake(LINK_SEARCH_STATIC)