Skip to content

Commit

Permalink
PR sakura-editor#894 の不備・不整合を正します。修正されるのは以下の通り。
Browse files Browse the repository at this point in the history
* 一部の環境でしかテストプログラムを作成できなくなっていた。
* パッケージ版で gmock が利用できなかった。
  => 必要になるまで gmock 非対応とし、ソースビルド版から
     gmock を削除することで足並みを揃えた。
* AppVeyor で、パッケージを使わないときにもインストールしていた。
  • Loading branch information
ds14050 committed May 12, 2019
1 parent 3de3153 commit 8ad9f9f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ skip_commits:
install:
- cmd: |
pip install openpyxl --user
C:\msys64\usr\bin\bash --login -c "pacman -S --noconfirm mingw-w64-x86_64-gtest"
if "%platform%" == "MinGW" C:\msys64\usr\bin\bash --login -c "pacman -S --noconfirm mingw-w64-x86_64-gtest"
build_script:
- cmd: |
Expand Down
22 changes: 13 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(${CMAKE_SOURCE_DIR}/runtime.cmake)

project (sakura-unittest)

option(BUILD_GTEST "Build GoogleTest." ON)
option(GTEST_PACKAGE "Use pre-built Google Test package." ON)
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)

# switch DLL or static libary by specifying by command line
Expand All @@ -17,22 +17,26 @@ endif (BUILD_SHARED_LIBS)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(BUILD_GTEST)
if(GTEST_PACKAGE)
find_package(GTest)
set (GTEST GTest::GTest)
set (GTEST_MAIN GTest::Main)
endif()
if(NOT GTEST_FOUND)
set (BUILD_GMOCK OFF CACHE BOOL "overwrite default value of BUILD_GMOCK")
add_subdirectory(googletest)
set (GTEST gtest)
set (GTEST_MAIN gtest_main)
endif()
add_subdirectory(unittests)

# turn on solution folder
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# create solution folder
if(BUILD_GTEST)
set_target_properties(gmock PROPERTIES FOLDER GoogleTest)
set_target_properties(gmock_main PROPERTIES FOLDER GoogleTest)
set_target_properties(gtest PROPERTIES FOLDER GoogleTest)
set_target_properties(gtest_main PROPERTIES FOLDER GoogleTest)
endif()
set_target_properties(tests1 PROPERTIES FOLDER Tests)
set_target_properties(${GTEST} PROPERTIES FOLDER GoogleTest)
set_target_properties(${GTEST_MAIN} PROPERTIES FOLDER GoogleTest)
set_target_properties(tests1 PROPERTIES FOLDER Tests)

# specify startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT tests1)
Expand Down
4 changes: 2 additions & 2 deletions tests/create-project.bat
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ exit /b

:setenv_Win32
:setenv_x64
set CMAKE_GEN_OPT=-G "Visual Studio 15 2017" -A "%~1" -D BUILD_GTEST=ON
set CMAKE_GEN_OPT=-G "Visual Studio 15 2017" -A "%~1"
exit /b

:setenv_MinGW
set CMAKE_GEN_OPT=-G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="%~2" -D BUILD_GTEST=OFF
set CMAKE_GEN_OPT=-G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="%~2" -D GTEST_PACKAGE=ON
set PATH=C:\msys64\mingw64\bin;%PATH:C:\Program Files\Git\usr\bin;=%
exit /b
17 changes: 3 additions & 14 deletions tests/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if (BUILD_SHARED_LIBS)
endif(MSVC)
endif (BUILD_SHARED_LIBS)

# link with GoogleTest
target_link_libraries (${project_name} PRIVATE ${GTEST_MAIN} ${GTEST})

# Hacks to reuse compiled editor objects.
target_compile_definitions(${project_name} PRIVATE WIN32 _WIN32_WINNT=_WIN32_WINNT_WIN7)
if (MSVC)
Expand All @@ -47,18 +50,4 @@ elseif (MINGW)
list (TRANSFORM ALL_O REPLACE "\\.(cpp|rc)$" ".o")
target_link_libraries (${project_name} PRIVATE ${ALL_O})
endif ()

# link with GoogleTest
if(BUILD_GTEST)
# Build GoogleTest from source code.
target_link_libraries(${project_name} PRIVATE gtest)
target_link_libraries(${project_name} PRIVATE gtest_main)
else()
# Build without GoogleTest(use system library).
find_package(GTest REQUIRED)
target_link_libraries(${project_name} PRIVATE GTest::GTest)
target_link_libraries(${project_name} PRIVATE GTest::Main)
endif()

# link libraries
target_link_libraries (${project_name} PRIVATE winspool ole32 oleaut32 uuid comctl32 imm32 mpr imagehlp shlwapi winmm windowscodecs msimg32)

0 comments on commit 8ad9f9f

Please sign in to comment.