BUG: Fix REMOVE_DEFINITIONS command to not remove substrings.

This commit is contained in:
Brad King 2006-05-23 12:51:26 -04:00
parent 13a68cd978
commit 9a74185695
7 changed files with 85 additions and 1 deletions

View File

@ -36,6 +36,8 @@
#include <cmsys/RegularExpression.hxx>
#include <ctype.h> // for isspace
// default is not to be building executables
cmMakefile::cmMakefile()
{
@ -803,7 +805,29 @@ void cmMakefile::AddDefineFlag(const char* flag)
void cmMakefile::RemoveDefineFlag(const char* flag)
{
cmSystemTools::ReplaceString(this->DefineFlags, flag, " ");
// Check the length of the flag to remove.
std::string::size_type len = strlen(flag);
if(len < 1)
{
return;
}
// Remove all instances of the flag that are surrounded by
// whitespace or the beginning/end of the string.
for(std::string::size_type lpos = this->DefineFlags.find(flag, 0);
lpos != std::string::npos; lpos = this->DefineFlags.find(flag, lpos))
{
std::string::size_type rpos = lpos + len;
if((lpos <= 0 || isspace(this->DefineFlags[lpos-1])) &&
(rpos >= this->DefineFlags.size() || isspace(this->DefineFlags[rpos])))
{
this->DefineFlags.erase(lpos, len);
}
else
{
++lpos;
}
}
}
void cmMakefile::AddLinkLibrary(const char* lib,

View File

@ -55,6 +55,14 @@ IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_C
ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK)
ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
# Test add/remove definitions.
ADD_DEFINITIONS(
-DCOMPLEX_DEFINED_PRE
-DCOMPLEX_DEFINED
-DCOMPLEX_DEFINED_POST
-DCOMPLEX_DEFINED
)
REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
# Test pre-build/pre-link/post-build rules for an executable.
ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD

View File

@ -42,6 +42,18 @@ void cmPassed(const char* Message, const char* m2="")
cm_passed++;
}
#ifndef COMPLEX_DEFINED_PRE
# error "COMPLEX_DEFINED_PRE not defined!"
#endif
#ifdef COMPLEX_DEFINED
# error "COMPLEX_DEFINED is defined but it should not!"
#endif
#ifndef COMPLEX_DEFINED_POST
# error "COMPLEX_DEFINED_POST not defined!"
#endif
#ifndef CMAKE_IS_REALLY_FUN
This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
#endif

View File

@ -55,6 +55,14 @@ IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_C
ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK)
ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
# Test add/remove definitions.
ADD_DEFINITIONS(
-DCOMPLEX_DEFINED_PRE
-DCOMPLEX_DEFINED
-DCOMPLEX_DEFINED_POST
-DCOMPLEX_DEFINED
)
REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
# Test pre-build/pre-link/post-build rules for an executable.
ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD

View File

@ -42,6 +42,18 @@ void cmPassed(const char* Message, const char* m2="")
cm_passed++;
}
#ifndef COMPLEX_DEFINED_PRE
# error "COMPLEX_DEFINED_PRE not defined!"
#endif
#ifdef COMPLEX_DEFINED
# error "COMPLEX_DEFINED is defined but it should not!"
#endif
#ifndef COMPLEX_DEFINED_POST
# error "COMPLEX_DEFINED_POST not defined!"
#endif
#ifndef CMAKE_IS_REALLY_FUN
This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
#endif

View File

@ -55,6 +55,14 @@ IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_C
ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK)
ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
# Test add/remove definitions.
ADD_DEFINITIONS(
-DCOMPLEX_DEFINED_PRE
-DCOMPLEX_DEFINED
-DCOMPLEX_DEFINED_POST
-DCOMPLEX_DEFINED
)
REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
# Test pre-build/pre-link/post-build rules for an executable.
ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD

View File

@ -42,6 +42,18 @@ void cmPassed(const char* Message, const char* m2="")
cm_passed++;
}
#ifndef COMPLEX_DEFINED_PRE
# error "COMPLEX_DEFINED_PRE not defined!"
#endif
#ifdef COMPLEX_DEFINED
# error "COMPLEX_DEFINED is defined but it should not!"
#endif
#ifndef COMPLEX_DEFINED_POST
# error "COMPLEX_DEFINED_POST not defined!"
#endif
#ifndef CMAKE_IS_REALLY_FUN
This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
#endif