Permalink
Browse files

Added Win32 UNICODE wmain support (#903)

* Added wmain support
* Added appveyor.yml wmain configuration
* Added wmain configuration flag to CMake
  • Loading branch information...
becrux authored and horenmar committed May 11, 2017
1 parent 5604ec7 commit b8443e67da47f02ec865ab38edc5756b1895b7e4
Showing with 43 additions and 1 deletion.
  1. +4 −0 CMakeLists.txt
  2. +7 −1 appveyor.yml
  3. +26 −0 include/catch_session.hpp
  4. +6 −0 include/internal/catch_default_main.hpp
View
@@ -19,6 +19,10 @@ elseif(USE_CPP14)
set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
endif()
+if(USE_WMAIN)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
+endif()
+
#checks that the given hard-coded list contains all headers + sources in the given folder
function(CheckFileList LIST_VAR FOLDER)
set(MESSAGE " should be added to the variable ${LIST_VAR}")
View
@@ -9,7 +9,13 @@ os:
environment:
matrix:
- additional_flags: "/permissive- /std:c++latest"
+ wmain: 0
+
- additional_flags: ""
+ wmain: 0
+
+ - additional_flags: "/D_UNICODE /DUNICODE"
+ wmain: 1
matrix:
exclude:
@@ -42,7 +48,7 @@ configuration:
#Cmake will autodetect the compiler, but we set the arch
before_build:
- set CXXFLAGS=%additional_flags%
- - cmake -H. -BBuild -A%PLATFORM%
+ - cmake -H. -BBuild -A%PLATFORM% -DUSE_WMAIN=%wmain%
# build with MSBuild
build:
View
@@ -166,6 +166,32 @@ namespace Catch {
return returnCode;
}
+ #if defined(WIN32) && defined(UNICODE)
+ int run( int argc, wchar_t const* const* const argv ) {
+
+ char **utf8Argv = new char *[ argc ];
+
+ for ( int i = 0; i < argc; ++i ) {
+ int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL );
+
+ utf8Argv[ i ] = new char[ bufSize ];
+
+ WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
+ }
+
+ int returnCode = applyCommandLine( argc, utf8Argv );
+ if( returnCode == 0 )
+ returnCode = run();
+
+ for ( int i = 0; i < argc; ++i )
+ delete [] utf8Argv[ i ];
+
+ delete [] utf8Argv;
+
+ return returnCode;
+ }
+ #endif
+
int run() {
if( m_configData.showHelp )
return 0;
@@ -10,8 +10,14 @@
#ifndef __OBJC__
+#if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
+// Standard C/C++ Win32 Unicode wmain entry point
+extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
+#else
// Standard C/C++ main entry point
int main (int argc, char * argv[]) {
+#endif
+
int result = Catch::Session().run( argc, argv );
return ( result < 0xff ? result : 0xff );
}

0 comments on commit b8443e6

Please sign in to comment.