From 1738af51c67de825d539922da372c5a939b9e05f Mon Sep 17 00:00:00 2001 From: ds14050 Date: Fri, 2 Nov 2018 19:45:57 +0900 Subject: [PATCH] Build and run tests on MinGW environment. --- sakura_core/Makefile | 2 +- tests/build-and-test.bat | 11 +++------- tests/create-project.bat | 38 ++++++++++++++++++++++++++++------ tests/unittests/CMakeLists.txt | 27 +++++++++++++++++------- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/sakura_core/Makefile b/sakura_core/Makefile index d60cacf28f..7556173051 100644 --- a/sakura_core/Makefile +++ b/sakura_core/Makefile @@ -439,7 +439,7 @@ Funccode_enum.h: $(HEADERMAKE) Funccode_x.hsrc $(HEADERMAKE) -in=../sakura_core/Funccode_x.hsrc -out=../sakura_core/Funccode_enum.h -mode=enum -enum=EFunctionCode githash: - cmd /c $(CURDIR)/../sakura/githash.bat ..\\sakura_core + cmd /c ..\sakura\githash.bat ..\sakura_core stdafx: Funccode_enum.h StdAfx.h $(CXX) $(CXXFLAGS) -c StdAfx.h diff --git a/tests/build-and-test.bat b/tests/build-and-test.bat index ebf294e626..7db947c8f1 100644 --- a/tests/build-and-test.bat +++ b/tests/build-and-test.bat @@ -2,13 +2,8 @@ set platform=%1 set configuration=%2 set ERROR_RESULT=0 -if "%platform%" == "MinGW" ( - @echo test for MinGW will be skipped. ^(platform: %platform%, configuration: %configuration%^) - exit /b 0 -) - @echo ---- start create-project.bat ---- -call %~dp0create-project.bat %platform% %configuration% +call "%~dp0create-project.bat" %platform% %configuration% if %ERRORLEVEL% neq 0 ( @echo ERROR in create-project.bat exit /b 1 @@ -16,7 +11,7 @@ if %ERRORLEVEL% neq 0 ( @echo ---- end create-project.bat ---- @echo ---- start build-project.bat ---- -call %~dp0build-project.bat %platform% %configuration% +call "%~dp0build-project.bat" %platform% %configuration% if %ERRORLEVEL% neq 0 ( @echo ERROR in build-project.bat exit /b 1 @@ -24,7 +19,7 @@ if %ERRORLEVEL% neq 0 ( @echo ---- end build-project.bat ---- @echo ---- start run-tests.bat ---- -call %~dp0run-tests.bat %platform% %configuration% +call "%~dp0run-tests.bat" %platform% %configuration% if %ERRORLEVEL% neq 0 ( @echo ERROR in run-tests.bat exit /b 1 diff --git a/tests/create-project.bat b/tests/create-project.bat index 779997c896..3d8f28e172 100644 --- a/tests/create-project.bat +++ b/tests/create-project.bat @@ -2,11 +2,16 @@ set platform=%1 set configuration=%2 set ERROR_RESULT=0 +@rem produces header files necessary in creating the project. +if "%platform%" == "MinGW" ( + set BUILD_EDITOR_BAT=build-gnu.bat +) else ( + set BUILD_EDITOR_BAT=build-sln.bat +) pushd "%~dp0.." -rem produces header files necessary in creating the project. -@echo ---- start build-sln.bat ---- -call build-sln.bat %platform% %configuration% || set ERROR_RESULT=1 -@echo ---- end build-sln.bat ---- +@echo ---- start %BUILD_EDITOR_BAT% ---- +call "%BUILD_EDITOR_BAT%" %platform% %configuration% || set ERROR_RESULT=1 +@echo ---- end %BUILD_EDITOR_BAT% ---- popd if "%ERROR_RESULT%" == "1" ( @echo ERROR @@ -24,8 +29,12 @@ set BUILDDIR=build\%platform% if exist "%BUILDDIR%" ( rmdir /s /q "%BUILDDIR%" ) -mkdir %BUILDDIR% -cmake -DCMAKE_GENERATOR_PLATFORM=%platform% -B%BUILDDIR% -H. || set ERROR_RESULT=1 +mkdir "%BUILDDIR%" + +pushd "%BUILDDIR%" +call :SETENV_"%Platform%" "%Platform%" "%Config%" +cmake %CMAKE_GEN_OPT% "%~dp0" +popd popd @@ -33,3 +42,20 @@ if "%ERROR_RESULT%" == "1" ( @echo ERROR exit /b 1 ) + +exit /b + + +@rem ---------------------------------------------------- +@rem sub-routines +@rem ---------------------------------------------------- + +:SETENV_"Win32" %1=Platform %2=Config +:SETENV_"x64" %1=Platform %2=Config + set CMAKE_GEN_OPT=-G "Visual Studio 15 2017" -A "%~1" +exit /B + +:SETENV_"MinGW" %1=Platform %2=Config + set CMAKE_GEN_OPT=-G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="%~2" + set PATH=C:\msys64\mingw64\bin;%PATH:C:\Program Files\Git\usr\bin;=% +exit /B diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index ee5dacf3f7..61ad2acbc6 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -30,13 +30,24 @@ if (BUILD_SHARED_LIBS) endif (BUILD_SHARED_LIBS) # link libraries -target_link_libraries(${project_name} gtest) -target_link_libraries(${project_name} gtest_main) +target_link_libraries(${project_name} PRIVATE gtest) +target_link_libraries(${project_name} PRIVATE gtest_main) # Hacks to reuse compiled editor objects. -target_compile_definitions(${project_name} PUBLIC WIN32 _WIN32_WINNT=_WIN32_WINNT_WIN7) -target_compile_options (${project_name} PUBLIC $<$:/GL> /MT$<$:d> /GF /FD /EHsc /Zi /TP /source-charset:utf-8 /execution-charset:shift_jis) -target_link_libraries (${project_name} $<$:-LTCG> comctl32.lib Imm32.lib mpr.lib imagehlp.lib Shlwapi.lib "${CMAKE_CURRENT_LIST_DIR}/../../sakura/${CMAKE_GENERATOR_PLATFORM}/$/*.obj") -set_target_properties (${project_name} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_GENERATOR_PLATFORM}/$" -) +target_compile_definitions(${project_name} PRIVATE WIN32 _WIN32_WINNT=_WIN32_WINNT_WIN7) +if (MSVC) + target_compile_options (${project_name} PRIVATE $<$:/GL> /MT$<$:d> /GF /FD /EHsc /Zi /TP /source-charset:utf-8 /execution-charset:shift_jis) + target_link_libraries (${project_name} PRIVATE $<$:-LTCG> "${CMAKE_CURRENT_LIST_DIR}/../../sakura/${CMAKE_GENERATOR_PLATFORM}/$/*.obj") + set_target_properties (${project_name} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_GENERATOR_PLATFORM}/$" + ) +elseif (MINGW) + target_compile_options (${project_name} PRIVATE -finput-charset=utf-8 -fexec-charset=cp932) + file (GLOB_RECURSE ALL_O + "${CMAKE_CURRENT_LIST_DIR}/../../sakura_core/*.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../../sakura_core/*.rc" + ) + list (TRANSFORM ALL_O REPLACE "\\.(cpp|rc)$" ".o") + target_link_libraries (${project_name} PRIVATE ${ALL_O}) +endif () +target_link_libraries (${project_name} PRIVATE winspool ole32 oleaut32 uuid comctl32 imm32 mpr imagehlp shlwapi winmm)