Ver Fonte

try_compile: Propogate the CMAKE_LINK_SEARCH_ variables

Chuck Atkins há 10 anos atrás
pai
commit
fb77c2c54b

+ 7 - 0
Help/command/try_compile.rst

@@ -96,5 +96,12 @@ the try_compile call of interest, and then re-run cmake again with
 Other Behavior Settings
 ^^^^^^^^^^^^^^^^^^^^^^^
 
+If set, the following variables are passed in to the generated
+try_compile CMakeLists.txt to initialize compile target properties with
+default values:
+
+* :variable:`CMAKE_LINK_SEARCH_START_STATIC`
+* :variable:`CMAKE_LINK_SEARCH_END_STATIC`
+
 Set the :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` variable to choose
 a build configuration.

+ 3 - 2
Help/variable/CMAKE_LINK_SEARCH_END_STATIC.rst

@@ -13,6 +13,7 @@ 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.
+:prop_tgt:`LINK_SEARCH_END_STATIC` for all targets. If set, it's
+value is also used by the :command:`try_compile` command.
 
-See also CMAKE_LINK_SEARCH_START_STATIC.
+See also :variable:`CMAKE_LINK_SEARCH_START_STATIC`.

+ 3 - 2
Help/variable/CMAKE_LINK_SEARCH_START_STATIC.rst

@@ -14,6 +14,7 @@ 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.
+:prop_tgt:`LINK_SEARCH_START_STATIC` for all targets.  If set, it's
+value is also used by the :command:`try_compile` command.
 
-See also CMAKE_LINK_SEARCH_END_STATIC.
+See also :variable:`CMAKE_LINK_SEARCH_END_STATIC`.

+ 10 - 0
Source/cmCoreTryCompile.cxx

@@ -470,6 +470,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
       {
       fprintf(fout, "set(CMAKE_POSITION_INDEPENDENT_CODE \"ON\")\n");
       }
+    if (const char *lssDef = this->Makefile->GetDefinition(
+        "CMAKE_LINK_SEARCH_START_STATIC"))
+      {
+      fprintf(fout, "set(CMAKE_LINK_SEARCH_START_STATIC \"%s\")\n", lssDef);
+      }
+    if (const char *lssDef = this->Makefile->GetDefinition(
+        "CMAKE_LINK_SEARCH_END_STATIC"))
+      {
+      fprintf(fout, "set(CMAKE_LINK_SEARCH_END_STATIC \"%s\")\n", lssDef);
+      }
 
     /* Put the executable at a known location (for COPY_FILE).  */
     fprintf(fout, "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"%s\")\n",