VsCharacterSet-check.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. macro(check_project_file projectFile outvar)
  2. set(insideConfiguration FALSE)
  3. set(characterSetFound FALSE)
  4. if(NOT EXISTS "${projectFile}")
  5. set(RunCMake_TEST_FAILED "Project file ${projectFile} does not exist.")
  6. return()
  7. endif()
  8. string(REPLACE "${RunCMake_TEST_BINARY_DIR}/" "" projectName ${projectFile})
  9. file(STRINGS "${projectFile}" lines)
  10. foreach(line IN LISTS lines)
  11. if(line MATCHES "^ *<PropertyGroup Condition=\"'[$][(]Configuration[)]|[$][(]Platform[)]'=='([^\"])+\" Label=\"Configuration\">.*$")
  12. set(insideConfiguration TRUE)
  13. elseif(insideConfiguration)
  14. if(line MATCHES "^ *</PropertyGroup>.*$")
  15. set(insideConfiguration FALSE)
  16. elseif(line MATCHES "^ *<CharacterSet>(.+)</CharacterSet>*$")
  17. message(STATUS "Found CharacterSet = ${CMAKE_MATCH_1} in PropertyGroup 'Configuration' in ${projectName}")
  18. set(characterSetFound TRUE)
  19. set(${outvar} ${CMAKE_MATCH_1})
  20. endif()
  21. endif()
  22. endforeach()
  23. if(NOT characterSetFound)
  24. set(RunCMake_TEST_FAILED "CharacterSet not found in \"Configuration\" propertygroup in ${projectName}")
  25. return() # This should intentionally return from the caller, not the macro
  26. endif()
  27. endmacro()
  28. check_project_file("${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${CMAKE_VERSION}/CompilerIdCXX/CompilerIdCXX.vcxproj" MULTI_BYTE_CHARSET)
  29. check_project_file("${RunCMake_TEST_BINARY_DIR}/foo.vcxproj" OVERRIDDEN_CHARSET)
  30. if (NOT "${MULTI_BYTE_CHARSET}" STREQUAL "MultiByte")
  31. set(RunCMake_TEST_FAILED "Default character-set (\"MultiByte\") was overridden (it shouldn't)")
  32. return()
  33. endif()
  34. if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/set_charset.txt")
  35. set(RunCMake_TEST_FAILED "File 'set_charset.txt' with set charset does not exist.")
  36. return()
  37. endif()
  38. file(STRINGS "${RunCMake_TEST_BINARY_DIR}/set_charset.txt" SET_CHARSET)
  39. if (NOT "${OVERRIDDEN_CHARSET}" STREQUAL "${SET_CHARSET}")
  40. set(RunCMake_TEST_FAILED "Failed to override the character-set with \"${SET_CHARSET}\"")
  41. return()
  42. endif()