From e2b1f0583f7293bce280dfab397e96acf8a5b26e Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 1 Jan 2015 22:30:08 -0500 Subject: try_run: Add support for LINK_LIBRARIES option. Most functionality is already implemented in Source/cmCoreTryCompile.{h,cxx}. Document and improve argument parsing. This functionality is already being used by a number of modules, like CheckCSourceCompiles.cmake, but it is not documented. --- Help/command/try_run.rst | 9 ++++++++- Help/release/dev/try-run-link-libraries.rst | 5 +++++ Source/cmCoreTryCompile.cxx | 2 +- Source/cmTryRunCommand.cxx | 3 ++- Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 Help/release/dev/try-run-link-libraries.rst diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst index 9a17ad9..b8ea0fe 100644 --- a/Help/command/try_run.rst +++ b/Help/command/try_run.rst @@ -6,8 +6,9 @@ Try compiling and then running some code. :: try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR - bindir srcfile [CMAKE_FLAGS ] + bindir srcfile [CMAKE_FLAGS ] [COMPILE_DEFINITIONS ] + [LINK_LIBRARIES ] [COMPILE_OUTPUT_VARIABLE comp] [RUN_OUTPUT_VARIABLE run] [OUTPUT_VARIABLE var] @@ -22,6 +23,12 @@ where the output from the compile step goes. RUN_OUTPUT_VARIABLE specifies the variable where the output from the running executable goes. +The srcfile signature also accepts a LINK_LIBRARIES argument which may +contain a list of libraries or IMPORTED targets which will be linked +to in the generated project. If LINK_LIBRARIES is specified as a +parameter to try_run, then any LINK_LIBRARIES passed as +CMAKE_FLAGS will be ignored. + For compatibility reasons OUTPUT_VARIABLE is still supported, which gives you the output from the compile and run step combined. diff --git a/Help/release/dev/try-run-link-libraries.rst b/Help/release/dev/try-run-link-libraries.rst new file mode 100644 index 0000000..4f20cbd --- /dev/null +++ b/Help/release/dev/try-run-link-libraries.rst @@ -0,0 +1,5 @@ +try-run-link-libraries +---------------------- + +* The :command:`try_run` command learned to honor the ``LINK_LIBRARIES`` + option just as :command:`try_compile` already does. diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 0030b84..2f58d96 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -109,7 +109,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) } default: this->Makefile->IssueMessage(cmake::FATAL_ERROR, - "Only libraries may be used as try_compile IMPORTED " + "Only libraries may be used as try_compile or try_run IMPORTED " "LINK_LIBRARIES. Got " + std::string(tgt->GetName()) + " of " "type " + tgt->GetTargetTypeName(tgt->GetType()) + "."); return -1; diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 8f2deeb..8bd33d0 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -48,7 +48,8 @@ bool cmTryRunCommand { ++i; while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" && - argv[i] != "CMAKE_FLAGS") + argv[i] != "CMAKE_FLAGS" && + argv[i] != "LINK_LIBRARIES") { runArgs += " "; runArgs += argv[i]; diff --git a/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt b/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt index eceffec..652bcfc 100644 --- a/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt +++ b/Tests/RunCMake/try_compile/BadLinkLibraries-stderr.txt @@ -1,5 +1,5 @@ CMake Error at BadLinkLibraries.cmake:2 \(try_compile\): - Only libraries may be used as try_compile IMPORTED LINK_LIBRARIES. Got - not_a_library of type UTILITY. + Only libraries may be used as try_compile or try_run IMPORTED + LINK_LIBRARIES. Got not_a_library of type UTILITY. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) -- cgit v0.12