ENH: Support preprocessor def values in VS6

The add_definitions() command and COMPILE_DEFINITIONS dir/tgt/src
properties support preprocessor definitions with values.  Previously
values were not supported in the VS6 generator even though the native
tool supports them.  It is only values with spaces that VS6 does not
support.  This enables support and instead complains only for values
with spaces.  See issue #8779.
This commit is contained in:
Brad King 2009-03-23 14:48:09 -04:00
parent 10a91d8467
commit 4085454658
7 changed files with 42 additions and 41 deletions

View File

@ -1712,11 +1712,11 @@ cmLocalVisualStudio6Generator
} }
// Now do the VS6-specific check. // Now do the VS6-specific check.
if(define.find_first_of("=") != define.npos) if(define.find_first_of(" ") != define.npos)
{ {
cmOStringStream e; cmOStringStream e;
e << "WARNING: The VS6 IDE does not support preprocessor definitions " e << "WARNING: The VS6 IDE does not support preprocessor definition "
<< "with values.\n" << "values with spaces.\n"
<< "CMake is dropping a preprocessor definition: " << define << "\n" << "CMake is dropping a preprocessor definition: " << define << "\n"
<< "Consider defining the macro in a (configured) header file.\n"; << "Consider defining the macro in a (configured) header file.\n";
cmSystemTools::Message(e.str().c_str()); cmSystemTools::Message(e.str().c_str());

View File

@ -1216,10 +1216,10 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
return false; return false;
} }
// VS6 IDE does not support definitions with values. // VS6 IDE does not support definition values with spaces.
if((strcmp(this->LocalGenerator->GetGlobalGenerator()->GetName(), if((strcmp(this->LocalGenerator->GetGlobalGenerator()->GetName(),
"Visual Studio 6") == 0) && "Visual Studio 6") == 0) &&
(def.find("=") != def.npos)) (def.find(" ") != def.npos))
{ {
return false; return false;
} }
@ -3475,7 +3475,7 @@ void cmMakefile::DefineProperties(cmake *cm)
"in the directory's parent.\n" "in the directory's parent.\n"
"CMake will automatically drop some definitions that " "CMake will automatically drop some definitions that "
"are not supported by the native build tool. " "are not supported by the native build tool. "
"The VS6 IDE does not support definitions with values " "The VS6 IDE does not support definition values with spaces "
"(but NMake does).\n" "(but NMake does).\n"
"Dislaimer: Most native build tools have poor support for escaping " "Dislaimer: Most native build tools have poor support for escaping "
"certain values. CMake has work-arounds for many cases but some " "certain values. CMake has work-arounds for many cases but some "

View File

@ -405,7 +405,7 @@ void cmSourceFile::DefineProperties(cmake *cm)
"(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n" "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
"CMake will automatically drop some definitions that " "CMake will automatically drop some definitions that "
"are not supported by the native build tool. " "are not supported by the native build tool. "
"The VS6 IDE does not support definitions with values " "The VS6 IDE does not support definition values with spaces "
"(but NMake does). Xcode does not support per-configuration " "(but NMake does). Xcode does not support per-configuration "
"definitions on source files.\n" "definitions on source files.\n"
"Dislaimer: Most native build tools have poor support for escaping " "Dislaimer: Most native build tools have poor support for escaping "

View File

@ -108,7 +108,7 @@ void cmTarget::DefineProperties(cmake *cm)
"(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n" "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
"CMake will automatically drop some definitions that " "CMake will automatically drop some definitions that "
"are not supported by the native build tool. " "are not supported by the native build tool. "
"The VS6 IDE does not support definitions with values " "The VS6 IDE does not support definition values with spaces "
"(but NMake does).\n" "(but NMake does).\n"
"Dislaimer: Most native build tools have poor support for escaping " "Dislaimer: Most native build tools have poor support for escaping "
"certain values. CMake has work-arounds for many cases but some " "certain values. CMake has work-arounds for many cases but some "

View File

@ -65,14 +65,20 @@ if(NOT BORLAND AND NOT PP_VS70)
set(SEMICOLON "\;") set(SEMICOLON "\;")
endif(NOT BORLAND AND NOT PP_VS70) endif(NOT BORLAND AND NOT PP_VS70)
if(NOT PP_BORLAND AND NOT PP_WATCOM) if(NOT PP_VS6)
# Borland, WMake: multiple spaces # VS 6 IDE: spaces
# The make tool seems to remove extra whitespace from inside # The project parser unconditionally separates arguments at spaces.
# quoted strings when passing to the compiler. It does not have set(STRING_EXTRA "${STRING_EXTRA} ")
# trouble passing to other tools, and the compiler may be directly
# invoked from the command line. if(NOT PP_BORLAND AND NOT PP_WATCOM)
set(STRING_EXTRA "${STRING_EXTRA} ") # Borland, WMake: multiple spaces
endif(NOT PP_BORLAND AND NOT PP_WATCOM) # The make tool seems to remove extra whitespace from inside
# quoted strings when passing to the compiler. It does not have
# trouble passing to other tools, and the compiler may be directly
# invoked from the command line.
set(STRING_EXTRA "${STRING_EXTRA} ")
endif(NOT PP_BORLAND AND NOT PP_WATCOM)
endif(NOT PP_VS6)
if(NOT PP_VS) if(NOT PP_VS)
# VS: , # VS: ,
@ -152,7 +158,7 @@ endif(PP_NMAKE OR PP_UMAKE)
# support it and it is not an operator it is not worthwhile. # support it and it is not an operator it is not worthwhile.
# Compose the final test string. # Compose the final test string.
set(STRING_VALUE "hello `~!@$*)(_+-=}{][:'.?/ ${STRING_EXTRA}world") set(STRING_VALUE "hello`~!@$*)(_+-=}{][:'.?/${STRING_EXTRA}world")
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Function-style macro command-line support: # Function-style macro command-line support:
@ -194,11 +200,7 @@ endif(PP_VS6)
add_definitions(-DOLD_DEF -DOLD_EXPR=2) add_definitions(-DOLD_DEF -DOLD_EXPR=2)
# Make sure old-style definitions are converted to directory property. # Make sure old-style definitions are converted to directory property.
if(PREPROCESS_VS6) set(OLD_DEFS_EXPECTED "OLD_DEF;OLD_EXPR=2")
set(OLD_DEFS_EXPECTED "OLD_DEF")
else(PREPROCESS_VS6)
set(OLD_DEFS_EXPECTED "OLD_DEF;OLD_EXPR=2")
endif(PREPROCESS_VS6)
get_property(OLD_DEFS DIRECTORY PROPERTY COMPILE_DEFINITIONS) get_property(OLD_DEFS DIRECTORY PROPERTY COMPILE_DEFINITIONS)
if(NOT "${OLD_DEFS}" STREQUAL "${OLD_DEFS_EXPECTED}") if(NOT "${OLD_DEFS}" STREQUAL "${OLD_DEFS_EXPECTED}")
message(SEND_ERROR "add_definitions not converted to directory property!") message(SEND_ERROR "add_definitions not converted to directory property!")
@ -225,23 +227,26 @@ foreach(c "" "_DEBUG" "_RELEASE")
) )
endforeach(c) endforeach(c)
# Add definitions with values. VS6 does not support this. # Add definitions with values.
if(NOT PREPROCESS_VS6) if(NOT PREPROCESS_VS6)
set_property( # The path might have spaces, which VS6 does not support.
TARGET Preprocess set(DEF_TARGET_PATH "TARGET_PATH=\"${TARGET_PATH}\"")
APPEND PROPERTY COMPILE_DEFINITIONS set(DEF_FILE_PATH "FILE_PATH=\"${FILE_PATH}\"")
"TARGET_STRING=\"${STRING_VALUE}${SEMICOLON}\""
"TARGET_EXPR=${EXPR}"
"TARGET_PATH=\"${TARGET_PATH}\""
)
set_property(
SOURCE preprocess.c preprocess${VS6}.cxx
APPEND PROPERTY COMPILE_DEFINITIONS
"FILE_STRING=\"${STRING_VALUE}${SEMICOLON}\""
"FILE_EXPR=${EXPR}"
"FILE_PATH=\"${FILE_PATH}\""
)
endif(NOT PREPROCESS_VS6) endif(NOT PREPROCESS_VS6)
set_property(
TARGET Preprocess
APPEND PROPERTY COMPILE_DEFINITIONS
"TARGET_STRING=\"${STRING_VALUE}${SEMICOLON}\""
"TARGET_EXPR=${EXPR}"
${DEF_TARGET_PATH}
)
set_property(
SOURCE preprocess.c preprocess${VS6}.cxx
APPEND PROPERTY COMPILE_DEFINITIONS
"FILE_STRING=\"${STRING_VALUE}${SEMICOLON}\""
"FILE_EXPR=${EXPR}"
${DEF_FILE_PATH}
)
# Helper target for running test manually in build tree. # Helper target for running test manually in build tree.
add_custom_target(drive COMMAND Preprocess) add_custom_target(drive COMMAND Preprocess)

View File

@ -9,7 +9,6 @@
int check_defines_C(void) int check_defines_C(void)
{ {
int result = 1; int result = 1;
#ifndef PREPROCESS_VS6
if(strcmp(FILE_STRING, STRING_VALUE) != 0) if(strcmp(FILE_STRING, STRING_VALUE) != 0)
{ {
fprintf(stderr, fprintf(stderr,
@ -38,7 +37,6 @@ int check_defines_C(void)
result = 0; result = 0;
} }
} }
#endif
#ifdef NDEBUG #ifdef NDEBUG
# ifdef FILE_DEF_DEBUG # ifdef FILE_DEF_DEBUG
{ {

View File

@ -11,7 +11,6 @@ extern "C" int check_defines_C(void);
int check_defines_CXX() int check_defines_CXX()
{ {
int result = 1; int result = 1;
#ifndef PREPROCESS_VS6
if(strcmp(FILE_STRING, STRING_VALUE) != 0) if(strcmp(FILE_STRING, STRING_VALUE) != 0)
{ {
fprintf(stderr, fprintf(stderr,
@ -40,7 +39,6 @@ int check_defines_CXX()
result = 0; result = 0;
} }
} }
#endif
#ifdef NDEBUG #ifdef NDEBUG
# ifdef FILE_DEF_DEBUG # ifdef FILE_DEF_DEBUG
{ {