summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmVisualStudioGeneratorOptions.cxx12
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/VS10Project/VsCharacterSet-check.cmake49
-rw-r--r--Tests/RunCMake/VS10Project/VsCharacterSet.cmake17
4 files changed, 77 insertions, 4 deletions
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 6188134..9dd2e6c 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -137,14 +137,18 @@ bool cmVisualStudioGeneratorOptions::IsManaged() const
bool cmVisualStudioGeneratorOptions::UsingUnicode() const
{
// Look for a _UNICODE definition.
- return std::any_of(this->Defines.begin(), this->Defines.end(),
- [](std::string const& di) { return di == "_UNICODE"_s; });
+ return std::any_of(
+ this->Defines.begin(), this->Defines.end(), [](std::string const& di) {
+ return di == "_UNICODE"_s || cmHasLiteralPrefix(di, "_UNICODE=");
+ });
}
bool cmVisualStudioGeneratorOptions::UsingSBCS() const
{
// Look for a _SBCS definition.
- return std::any_of(this->Defines.begin(), this->Defines.end(),
- [](std::string const& di) { return di == "_SBCS"_s; });
+ return std::any_of(
+ this->Defines.begin(), this->Defines.end(), [](std::string const& di) {
+ return di == "_SBCS"_s || cmHasLiteralPrefix(di, "_SBCS=");
+ });
}
void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index 669049a..e0d74cf 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -11,6 +11,9 @@ run_cmake(CustomCommandGenex)
if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio 1[1-5] ")
run_cmake(CustomCommandParallel)
endif()
+run_cmake_with_options(VsCharacterSet -DSET_CHARSET=MultiByte)
+run_cmake_with_options(VsCharacterSet -DSET_CHARSET=Unicode)
+run_cmake_with_options(VsCharacterSet -DSET_CHARSET=NotSet)
run_cmake(VsCsharpSourceGroup)
run_cmake(VsCSharpCompilerOpts)
run_cmake(ExplicitCMakeLists)
diff --git a/Tests/RunCMake/VS10Project/VsCharacterSet-check.cmake b/Tests/RunCMake/VS10Project/VsCharacterSet-check.cmake
new file mode 100644
index 0000000..93770a1
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsCharacterSet-check.cmake
@@ -0,0 +1,49 @@
+macro(check_project_file projectFile outvar)
+ set(insideConfiguration FALSE)
+ set(characterSetFound FALSE)
+
+ if(NOT EXISTS "${projectFile}")
+ set(RunCMake_TEST_FAILED "Project file ${projectFile} does not exist.")
+ return()
+ endif()
+
+ string(REPLACE "${RunCMake_TEST_BINARY_DIR}/" "" projectName ${projectFile})
+
+ file(STRINGS "${projectFile}" lines)
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^ *<PropertyGroup Condition=\"'[$][(]Configuration[)]|[$][(]Platform[)]'=='([^\"])+\" Label=\"Configuration\">.*$")
+ set(insideConfiguration TRUE)
+ elseif(insideConfiguration)
+ if(line MATCHES "^ *</PropertyGroup>.*$")
+ set(insideConfiguration FALSE)
+ elseif(line MATCHES "^ *<CharacterSet>(.+)</CharacterSet>*$")
+ message(STATUS "Found CharacterSet = ${CMAKE_MATCH_1} in PropertyGroup 'Configuration' in ${projectName}")
+ set(characterSetFound TRUE)
+ set(${outvar} ${CMAKE_MATCH_1})
+ endif()
+ endif()
+ endforeach()
+ if(NOT characterSetFound)
+ set(RunCMake_TEST_FAILED "CharacterSet not found in \"Configuration\" propertygroup in ${projectName}")
+ return() # This should intentionally return from the caller, not the macro
+ endif()
+endmacro()
+
+check_project_file("${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${CMAKE_VERSION}/CompilerIdCXX/CompilerIdCXX.vcxproj" MULTI_BYTE_CHARSET)
+check_project_file("${RunCMake_TEST_BINARY_DIR}/foo.vcxproj" OVERRIDDEN_CHARSET)
+
+if (NOT "${MULTI_BYTE_CHARSET}" STREQUAL "MultiByte")
+ set(RunCMake_TEST_FAILED "Default character-set (\"MultiByte\") was overridden (it shouldn't)")
+ return()
+endif()
+
+if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/set_charset.txt")
+ set(RunCMake_TEST_FAILED "File 'set_charset.txt' with set charset does not exist.")
+ return()
+endif()
+file(STRINGS "${RunCMake_TEST_BINARY_DIR}/set_charset.txt" SET_CHARSET)
+
+if (NOT "${OVERRIDDEN_CHARSET}" STREQUAL "${SET_CHARSET}")
+ set(RunCMake_TEST_FAILED "Failed to override the character-set with \"${SET_CHARSET}\"")
+ return()
+endif()
diff --git a/Tests/RunCMake/VS10Project/VsCharacterSet.cmake b/Tests/RunCMake/VS10Project/VsCharacterSet.cmake
new file mode 100644
index 0000000..c8c3e0e
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsCharacterSet.cmake
@@ -0,0 +1,17 @@
+enable_language(CXX)
+
+# Write value of `SET_CHARSET` for comparison later.
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/set_charset.txt" "${SET_CHARSET}")
+
+# Set macro which determines the character-set.
+if("${SET_CHARSET}" STREQUAL "MultiByte")
+ add_compile_definitions(_MBCS=1)
+endif()
+if("${SET_CHARSET}" STREQUAL "NotSet")
+ add_compile_definitions(_SBCS=1)
+endif()
+if("${SET_CHARSET}" STREQUAL "Unicode")
+ add_compile_definitions(_UNICODE=1)
+endif()
+
+add_library(foo foo.cpp)