Merge topic 'cleanup-early-include-CTest-failure'

d90f49b CTest: Fail early without PROJECT_BINARY_DIR (#14005)
2e1c2bd build_command: Fail early without CMAKE_MAKE_PROGRAM (#14005)
4e5cb37 Refactor RunCMake.build_command test to allow more cases
This commit is contained in:
Brad King 2013-03-13 13:34:36 -04:00 committed by CMake Topic Stage
commit 8128940ac1
17 changed files with 116 additions and 60 deletions

View File

@ -16,6 +16,10 @@ if(NOT RUN_FROM_CTEST_OR_DART)
message(FATAL_ERROR "Do not incldue CTestTargets.cmake directly")
endif()
if(NOT PROJECT_BINARY_DIR)
message(FATAL_ERROR "Do not include(CTest) before calling project().")
endif()
# make directories in the binary tree
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Testing/Temporary)
get_filename_component(CMAKE_HOST_PATH ${CMAKE_COMMAND} PATH)

View File

@ -87,6 +87,14 @@ bool cmBuildCommand
const char* makeprogram
= this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
if(!makeprogram)
{
this->Makefile->IssueMessage(
cmake::FATAL_ERROR,
"build_command() requires CMAKE_MAKE_PROGRAM to be defined. "
"Call project() or enable_language() first.");
return true;
}
// If null/empty CONFIGURATION argument, GenerateBuildCommand uses 'Debug'
// in the currently implemented multi-configuration global generators...

View File

@ -52,6 +52,7 @@ if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 3)
endif()
add_RunCMake_test(CMP0019)
add_RunCMake_test(CTest)
if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
add_RunCMake_test(CompilerChange)
endif()

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at .*/Modules/CTest.cmake:[0-9]+ \(build_command\):
build_command\(\) requires CMAKE_MAKE_PROGRAM to be defined. Call project\(\)
or enable_language\(\) first.
Call Stack \(most recent call first\):
BeforeProject.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)

View File

@ -0,0 +1,2 @@
include(CTest)
project(${RunCMake_TEST} NONE)

View File

@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 2.8)
if(NOT NoProject)
project(${RunCMake_TEST} NONE)
endif()
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,5 @@
include(RunCMake)
set(RunCMake_TEST_OPTIONS -DNoProject=1)
run_cmake(BeforeProject)
unset(RunCMake_TEST_OPTIONS)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,5 @@
CMake Error at BeforeProject.cmake:[0-9]+ \(build_command\):
build_command\(\) requires CMAKE_MAKE_PROGRAM to be defined. Call project\(\)
or enable_language\(\) first.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)

View File

@ -0,0 +1,2 @@
build_command(MAKECOMMAND_DEFAULT_VALUE)
project(${RunCMake_TEST} NONE)

View File

@ -1,59 +1,5 @@
cmake_minimum_required(VERSION 2.8)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
# This CMakeLists file is *sometimes expected* to result in a configure error.
#
# expect this to succeed:
# ../bin/Release/cmake -G Xcode
# ../../CMake/Tests/CMakeCommands/build_command
#
# expect this to fail:
# ../bin/Release/cmake -DTEST_ERROR_CONDITIONS:BOOL=ON -G Xcode
# ../../CMake/Tests/CMakeCommands/build_command
#
# This project exists merely to test the CMake command 'build_command'...
# ...even purposefully calling it with known-bad argument lists to cover
# error handling code.
#
set(cmd "initial")
message("0. begin")
if(TEST_ERROR_CONDITIONS)
# Test with no arguments (an error):
build_command()
message("1. cmd='${cmd}'")
# Test with unknown arguments (also an error):
build_command(cmd BOGUS STUFF)
message("2. cmd='${cmd}'")
build_command(cmd STUFF BOGUS)
message("3. cmd='${cmd}'")
else()
message("(skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF)")
if(NOT NoProject)
project(${RunCMake_TEST} NONE)
endif()
# Test the one arg signature with none of the optional KEYWORD arguments:
build_command(cmd)
message("4. cmd='${cmd}'")
# Test the two-arg legacy signature:
build_command(legacy_cmd ${CMAKE_BUILD_TOOL})
message("5. legacy_cmd='${legacy_cmd}'")
message(" CMAKE_BUILD_TOOL='${CMAKE_BUILD_TOOL}'")
# Test the optional KEYWORDs:
build_command(cmd CONFIGURATION hoohaaConfig)
message("6. cmd='${cmd}'")
build_command(cmd PROJECT_NAME hoohaaProject)
message("7. cmd='${cmd}'")
build_command(cmd TARGET hoohaaTarget)
message("8. cmd='${cmd}'")
set(cmd "final")
message("9. cmd='${cmd}'")
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,55 @@
# This CMakeLists file is *sometimes expected* to result in a configure error.
#
# expect this to succeed:
# ../bin/Release/cmake -G Xcode
# ../../CMake/Tests/CMakeCommands/build_command
#
# expect this to fail:
# ../bin/Release/cmake -DTEST_ERROR_CONDITIONS:BOOL=ON -G Xcode
# ../../CMake/Tests/CMakeCommands/build_command
#
# This project exists merely to test the CMake command 'build_command'...
# ...even purposefully calling it with known-bad argument lists to cover
# error handling code.
#
set(cmd "initial")
message("0. begin")
if(TEST_ERROR_CONDITIONS)
# Test with no arguments (an error):
build_command()
message("1. cmd='${cmd}'")
# Test with unknown arguments (also an error):
build_command(cmd BOGUS STUFF)
message("2. cmd='${cmd}'")
build_command(cmd STUFF BOGUS)
message("3. cmd='${cmd}'")
else()
message("(skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF)")
endif()
# Test the one arg signature with none of the optional KEYWORD arguments:
build_command(cmd)
message("4. cmd='${cmd}'")
# Test the two-arg legacy signature:
build_command(legacy_cmd ${CMAKE_BUILD_TOOL})
message("5. legacy_cmd='${legacy_cmd}'")
message(" CMAKE_BUILD_TOOL='${CMAKE_BUILD_TOOL}'")
# Test the optional KEYWORDs:
build_command(cmd CONFIGURATION hoohaaConfig)
message("6. cmd='${cmd}'")
build_command(cmd PROJECT_NAME hoohaaProject)
message("7. cmd='${cmd}'")
build_command(cmd TARGET hoohaaTarget)
message("8. cmd='${cmd}'")
set(cmd "final")
message("9. cmd='${cmd}'")

View File

@ -1 +1,2 @@
set(TEST_ERROR_CONDITIONS OFF)
include(ErrorsCommon.cmake)

View File

@ -1,12 +1,21 @@
CMake Error at CMakeLists.txt:[0-9]+ \(build_command\):
CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
build_command requires at least one argument naming a CMake variable
Call Stack \(most recent call first\):
ErrorsON.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)
+
1. cmd='initial'
CMake Error at CMakeLists.txt:[0-9]+ \(build_command\):
CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
build_command unknown argument "BOGUS"
Call Stack \(most recent call first\):
ErrorsON.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)
+
2. cmd='initial'
CMake Error at CMakeLists.txt:[0-9]+ \(build_command\):
CMake Error at ErrorsCommon.cmake:[0-9]+ \(build_command\):
build_command unknown argument "STUFF"
Call Stack \(most recent call first\):
ErrorsON.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\)

View File

@ -1 +1,2 @@
set(TEST_ERROR_CONDITIONS ON)
include(ErrorsCommon.cmake)

View File

@ -2,3 +2,7 @@ include(RunCMake)
run_cmake(ErrorsOFF)
run_cmake(ErrorsON)
set(RunCMake_TEST_OPTIONS -DNoProject=1)
run_cmake(BeforeProject)
unset(RunCMake_TEST_OPTIONS)