Merge topic 'try-run-link-libraries'
d0adcccb
try_run: Add tests for LINK_LIBRARIES with mock libraries.223c5cb7
try_run: Add test for bad link libraries.e2b1f058
try_run: Add support for LINK_LIBRARIES option.
This commit is contained in:
commit
8def82585c
|
@ -6,8 +6,9 @@ Try compiling and then running some code.
|
|||
::
|
||||
|
||||
try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
|
||||
bindir srcfile [CMAKE_FLAGS <Flags>]
|
||||
bindir srcfile [CMAKE_FLAGS <flags>]
|
||||
[COMPILE_DEFINITIONS <flags>]
|
||||
[LINK_LIBRARIES <libs>]
|
||||
[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.
|
||||
|
||||
|
|
|
@ -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.
|
|
@ -109,7 +109,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> 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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -311,6 +311,21 @@ if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREA
|
|||
message(SEND_ERROR "EXP_ERROR_VARIABLE try_compile failed, but it was expected to succeed ${OUTPUT}.")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
unset(EXP_RUN_VAR CACHE)
|
||||
unset(EXP_COMPILE_VAR CACHE)
|
||||
try_run(EXP_RUN_VAR EXP_COMPILE_VAR
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_system"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
|
||||
COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
|
||||
LINK_LIBRARIES exp_systemlib
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
)
|
||||
if(NOT EXP_COMPILE_VAR)
|
||||
message(SEND_ERROR "try_run compile failed, but it was expected to succeed ${OUTPUT}.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_executable(test_system_bld test_system.cpp)
|
||||
target_link_libraries(test_system_bld bld_systemlib)
|
||||
target_compile_options(test_system_bld PRIVATE -Wunused-variable -Werror=unused-variable)
|
||||
|
@ -326,5 +341,20 @@ if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREA
|
|||
if(NOT BLD_ERROR_VARIABLE)
|
||||
message(SEND_ERROR "BLD_ERROR_VARIABLE try_compile failed, but it was expected to succeed.")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
unset(BLD_RUN_VAR CACHE)
|
||||
unset(BLD_COMPILE_VAR CACHE)
|
||||
try_run(BLD_RUN_VAR BLD_COMPILE_VAR
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_system"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
|
||||
COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
|
||||
LINK_LIBRARIES bld_systemlib
|
||||
OUTPUT_VARIABLE OUTPUT
|
||||
)
|
||||
if(NOT BLD_COMPILE_VAR)
|
||||
message(SEND_ERROR "try_run compile failed, but it was expected to succeed ${OUTPUT}.")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -132,6 +132,7 @@ add_RunCMake_test(project)
|
|||
add_RunCMake_test(return)
|
||||
add_RunCMake_test(string)
|
||||
add_RunCMake_test(try_compile)
|
||||
add_RunCMake_test(try_run)
|
||||
add_RunCMake_test(set)
|
||||
add_RunCMake_test(variable_watch)
|
||||
add_RunCMake_test(CMP0004)
|
||||
|
|
|
@ -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\)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,5 @@
|
|||
CMake Error at BadLinkLibraries.cmake:2 \(try_run\):
|
||||
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\)
|
|
@ -0,0 +1,4 @@
|
|||
add_custom_target(not_a_library)
|
||||
try_run(RUN_RESULT COMPILE_RESULT
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp ${CMAKE_CURRENT_SOURCE_DIR}/src.c
|
||||
LINK_LIBRARIES not_a_library)
|
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.0)
|
||||
project(${RunCMake_TEST} C)
|
||||
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1,3 @@
|
|||
include(RunCMake)
|
||||
|
||||
run_cmake(BadLinkLibraries)
|
|
@ -0,0 +1 @@
|
|||
int main(void) { return 0; }
|
Loading…
Reference in New Issue