From 5badf5f734119199fa42377b25d415532191a710 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Thu, 15 Dec 2011 21:56:34 -0500 Subject: Fix the case where cmake --build failed with two project cmds in one file. This adds a test that uses two project commands in the same CMakeLists.txt file. It also adds a fix so that cmake --build will work in that case. The fix sets the name of the last project command in the top level CMakeLists.txt in the cache variable CMAKE_PROJECT_NAME. This variable is used by cmake --build to find the project name. --- Source/cmProjectCommand.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Source/cmProjectCommand.cxx') diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 1a831d92a2..6e3b6afecc 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -47,9 +47,13 @@ bool cmProjectCommand this->Makefile->AddDefinition("PROJECT_NAME", args[0].c_str()); // Set the CMAKE_PROJECT_NAME variable to be the highest-level - // project name in the tree. This is always the first PROJECT - // command encountered. - if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME")) + // project name in the tree. If there are two project commands + // in the same CMakeLists.txt file, and it is the top level + // CMakeLists.txt file, then go with the last one, so that + // CMAKE_PROJECT_NAME will match PROJECT_NAME, and cmake --build + // will work. + if(!this->Makefile->GetDefinition("CMAKE_PROJECT_NAME") + || (this->Makefile->GetLocalGenerator()->GetParent() == 0) ) { this->Makefile->AddDefinition("CMAKE_PROJECT_NAME", args[0].c_str()); this->Makefile->AddCacheDefinition -- cgit v1.2.1