CMake/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
Stephen Kelly b80557c7bd file(GENERATE): Evaluate early to allow generating source files
The evaluation files must be known before cmTargetTraceDependencies
attempts to find them, but we must actually generate the files after
cmTargetTraceDependencies, as that can add to target SOURCES.  The
limitation is that the generated output name must not depend on the
SOURCES of a target if the generated file is used by that target.

Mark the output files as GENERATED so that trace dependencies does
not expect them to already exist in the filesystem.

Move the invokation of ForceLinkerLanguage in the Generate logic
to after the generated file names are known.  ForceLinkerLanguage
tries to determine the sources of a target (in order to determine
an already-known language) and otherwise fails to get information
about the generated file.

Test that the output of file(GENERATE) can be used as a target source
file and that accessing the target SOURCES in the name of the output
file is an error.  Accessing the TARGET_OBJECTS would be a similar
error if it was legal to use that generator expression in this
context.  That is not currently possible and is a different error
condition, so test the current error output as a reminder to change
the expected output if that becomes possible in the future.  Test
that generated rule files resulting from cmTargetTraceDependencies
appear in the SOURCES generated in the output file.
2014-11-12 22:36:45 +01:00

64 lines
2.4 KiB
CMake

include(RunCMake)
run_cmake(CommandConflict)
if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode" AND NOT XCODE_BELOW_2)
run_cmake(OutputConflict)
endif()
run_cmake(EmptyCondition1)
run_cmake(EmptyCondition2)
run_cmake(BadCondition)
run_cmake(DebugEvaluate)
run_cmake(GenerateSource)
run_cmake(OutputNameMatchesSources)
run_cmake(OutputNameMatchesObjects)
run_cmake(OutputNameMatchesOtherSources)
file(READ "${RunCMake_BINARY_DIR}/OutputNameMatchesOtherSources-build/1somefile.cpp" file_contents)
if (NOT file_contents MATCHES "generated.cpp.rule")
message(SEND_ERROR "Rule file not in target sources! ${file_contents}")
endif()
set(timeformat "%Y%j%H%M%S")
file(REMOVE "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt")
set(RunCMake_TEST_OPTIONS "-DTEST_FILE=WriteIfDifferent.cmake")
set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/WriteIfDifferent-build")
run_cmake(WriteIfDifferent-prepare)
unset(RunCMake_TEST_OPTIONS)
unset(RunCMake_TEST_BINARY_DIR)
file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp ${timeformat})
if(NOT timestamp)
message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1)
set(RunCMake_TEST_NO_CLEAN ON)
run_cmake(WriteIfDifferent)
file(TIMESTAMP "${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt" timestamp_after ${timeformat})
if(NOT timestamp_after)
message(SEND_ERROR "Could not get timestamp for \"${RunCMake_BINARY_DIR}/WriteIfDifferent-build/output_file.txt\"")
endif()
unset(RunCMake_TEST_NO_CLEAN)
if (NOT timestamp_after STREQUAL timestamp)
message(SEND_ERROR "WriteIfDifferent changed output file.")
endif()
if (UNIX AND EXISTS /bin/sh)
set(RunCMake_TEST_NO_CLEAN ON)
run_cmake(CarryPermissions)
execute_process(
COMMAND "${RunCMake_BINARY_DIR}/CarryPermissions-build/output_script.sh"
OUTPUT_VARIABLE script_output
RESULT_VARIABLE script_result
ERROR_VARIABLE script_error
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (script_result)
message(SEND_ERROR "Generated script did not execute correctly: [${script_result}]\n${script_output}\n====\n${script_error}")
endif()
if (NOT script_output STREQUAL SUCCESS)
message(SEND_ERROR "Generated script did not execute correctly:\n${script_output}\n====\n${script_error}")
endif()
endif()