diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx index 3722ab635..91d55a5a2 100644 --- a/Source/cmBuildCommand.cxx +++ b/Source/cmBuildCommand.cxx @@ -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... diff --git a/Tests/RunCMake/build_command/BeforeProject-result.txt b/Tests/RunCMake/build_command/BeforeProject-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/build_command/BeforeProject-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/build_command/BeforeProject-stderr.txt b/Tests/RunCMake/build_command/BeforeProject-stderr.txt new file mode 100644 index 000000000..d3d766163 --- /dev/null +++ b/Tests/RunCMake/build_command/BeforeProject-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/build_command/BeforeProject.cmake b/Tests/RunCMake/build_command/BeforeProject.cmake new file mode 100644 index 000000000..15788d15b --- /dev/null +++ b/Tests/RunCMake/build_command/BeforeProject.cmake @@ -0,0 +1,2 @@ +build_command(MAKECOMMAND_DEFAULT_VALUE) +project(${RunCMake_TEST} NONE) diff --git a/Tests/RunCMake/build_command/CMakeLists.txt b/Tests/RunCMake/build_command/CMakeLists.txt index e8db6b05b..f6e84c04d 100644 --- a/Tests/RunCMake/build_command/CMakeLists.txt +++ b/Tests/RunCMake/build_command/CMakeLists.txt @@ -1,3 +1,5 @@ cmake_minimum_required(VERSION 2.8) -project(${RunCMake_TEST} NONE) +if(NOT NoProject) + project(${RunCMake_TEST} NONE) +endif() include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/build_command/RunCMakeTest.cmake b/Tests/RunCMake/build_command/RunCMakeTest.cmake index 4525c5725..eaa1d77d8 100644 --- a/Tests/RunCMake/build_command/RunCMakeTest.cmake +++ b/Tests/RunCMake/build_command/RunCMakeTest.cmake @@ -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)