From 3ebe42c4006e5a754fd609c5f7370b09affa4ecd Mon Sep 17 00:00:00 2001 From: Gavin Bisesi Date: Sun, 27 Sep 2015 23:39:02 -0400 Subject: [PATCH 1/4] Add dummy googletest Uses the built in cmake -Dtest=ON It should download googletest on the fly if needed. Adds a new make target, `make test` Ref #167 --- CMakeLists.txt | 25 +++++++++++++++++++++++++ cockatrice/CMakeLists.txt | 8 ++++++++ cockatrice/test/dummy_test.cpp | 16 ++++++++++++++++ gtest-CMakeLists.txt | 15 +++++++++++++++ travis-compile.sh | 7 ++++--- travis-dependencies.sh | 10 +++++++--- 6 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 cockatrice/test/dummy_test.cpp create mode 100644 gtest-CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc9e4b9..74b2f98e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,3 +232,28 @@ if(WITH_ORACLE) add_subdirectory(oracle) SET(CPACK_INSTALL_CMAKE_PROJECTS "release/oracle.app;oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() + +if(test) + find_package(Gtest REQUIRED) + if(GTEST_FOUND) + include_directories(${GTEST_INCLUDE_DIRS}) + else() + message(STATUS "Downloading googletest") + configure_file(gtest-CMakeLists.txt gtest-download/CMakeLists.txt) + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) + execute_process(COMMAND ${CMAKE_COMMAND} --build . + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) + + # Add gtest directly to our build + add_subdirectory(${CMAKE_BINARY_DIR}/gtest-src + ${CMAKE_BINARY_DIR}/gtest-build + EXCLUDE_FROM_ALL ) + + # Add the gtest include directory, since gtest + # doesn't add that dependency to its gtest target + target_include_directories(gtest INTERFACE + "${CMAKE_BINARY_DIR}/gtest-src/include" ) + endif() + enable_testing() +endif() diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 2a600e1b..a2870bae 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -341,3 +341,11 @@ option(PORTABLE "portable build" OFF) IF(PORTABLE) add_definitions(-DPORTABLE_BUILD) endif() + +if(test) + enable_testing() + message(STATUS "Adding tests") + add_executable(cockatrice_test test/dummy_test.cpp) + target_link_libraries(cockatrice_test gtest_main) + add_test(NAME cockatrice_test COMMAND cockatrice_test) +endif() \ No newline at end of file diff --git a/cockatrice/test/dummy_test.cpp b/cockatrice/test/dummy_test.cpp new file mode 100644 index 00000000..a5416d09 --- /dev/null +++ b/cockatrice/test/dummy_test.cpp @@ -0,0 +1,16 @@ +#include "gtest/gtest.h" + +namespace { + class FooTest : public ::testing::Test { + + }; + + TEST(DummyTest, Works) { + ASSERT_EQ(1, 1) << "One is not equal to one"; + } +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/gtest-CMakeLists.txt b/gtest-CMakeLists.txt new file mode 100644 index 00000000..f5e07d30 --- /dev/null +++ b/gtest-CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.2) + +project(gtest-download LANGUAGES NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + URL https://googletest.googlecode.com/files/gtest-1.7.0.zip + URL_HASH SHA1=f85f6d2481e2c6c4a18539e391aa4ea8ab0394af + SOURCE_DIR "${CMAKE_BINARY_DIR}/gtest-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/gtest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/travis-compile.sh b/travis-compile.sh index 23345d84..86836437 100755 --- a/travis-compile.sh +++ b/travis-compile.sh @@ -11,11 +11,12 @@ fi if [[ $TRAVIS_OS_NAME == "linux" && $QT4 == 0 ]]; then prefix="-DCMAKE_PREFIX_PATH=/opt/qt52/lib/cmake/" fi -cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix if [[ $BUILDTYPE == "Debug" ]]; then + cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -Dtest=ON -DWITH_QT4=$QT4 $prefix make -j2 + make test else + cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix make package -j2 -fi - +fi \ No newline at end of file diff --git a/travis-dependencies.sh b/travis-dependencies.sh index 37e529ec..15048ef8 100755 --- a/travis-dependencies.sh +++ b/travis-dependencies.sh @@ -7,15 +7,19 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then else brew install qt5 protobuf libgcrypt > /dev/null fi + brew unlink cmake + brew upgrade cmake else if (( QT4 )); then sudo apt-get update -qq - sudo apt-get install -y qtmobility-dev libprotobuf-dev protobuf-compiler libqt4-dev + sudo apt-get install -y qtmobility-dev libqt4-dev else + sudo add-apt-repository -y ppa:george-edison55/precise-backports sudo add-apt-repository -y ppa:beineri/opt-qt521 - sudo add-apt-repository -y ppa:kalakris/cmake sudo apt-get update -qq - sudo apt-get install -y libprotobuf-dev protobuf-compiler cmake libsqlite3-dev\ + sudo apt-get install -y libsqlite3-dev\ qt52base qt52webkit qt52tools qt52svg qt52multimedia fi + sudo apt-get install -y cmake libgtest-dev libprotobuf-dev protobuf-compiler + cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd - fi From 7fe60279de45cbb46f20f4ea33346736a455759f Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 8 Oct 2015 21:33:24 +0200 Subject: [PATCH 2/4] Fix PR #1600 --- CMakeLists.txt | 28 +++----------- .../gtest-CMakeLists.txt.in | 0 cockatrice/CMakeLists.txt | 8 ---- tests/CMakeLists.txt | 38 +++++++++++++++++++ {cockatrice/test => tests}/dummy_test.cpp | 0 travis-compile.sh | 4 +- travis-dependencies.sh | 16 +++++--- 7 files changed, 56 insertions(+), 38 deletions(-) rename gtest-CMakeLists.txt => cmake/gtest-CMakeLists.txt.in (100%) create mode 100644 tests/CMakeLists.txt rename {cockatrice/test => tests}/dummy_test.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74b2f98e..ef9474e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,27 +233,9 @@ if(WITH_ORACLE) SET(CPACK_INSTALL_CMAKE_PROJECTS "release/oracle.app;oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() -if(test) - find_package(Gtest REQUIRED) - if(GTEST_FOUND) - include_directories(${GTEST_INCLUDE_DIRS}) - else() - message(STATUS "Downloading googletest") - configure_file(gtest-CMakeLists.txt gtest-download/CMakeLists.txt) - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) - execute_process(COMMAND ${CMAKE_COMMAND} --build . - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) - - # Add gtest directly to our build - add_subdirectory(${CMAKE_BINARY_DIR}/gtest-src - ${CMAKE_BINARY_DIR}/gtest-build - EXCLUDE_FROM_ALL ) - - # Add the gtest include directory, since gtest - # doesn't add that dependency to its gtest target - target_include_directories(gtest INTERFACE - "${CMAKE_BINARY_DIR}/gtest-src/include" ) - endif() - enable_testing() +# Compile tests (default off) +option(WITH_TESTS "build tests" OFF) +if(WITH_TESTS) + include(CTest) + add_subdirectory(tests) endif() diff --git a/gtest-CMakeLists.txt b/cmake/gtest-CMakeLists.txt.in similarity index 100% rename from gtest-CMakeLists.txt rename to cmake/gtest-CMakeLists.txt.in diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index a2870bae..ca9342a4 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -340,12 +340,4 @@ endif() option(PORTABLE "portable build" OFF) IF(PORTABLE) add_definitions(-DPORTABLE_BUILD) -endif() - -if(test) - enable_testing() - message(STATUS "Adding tests") - add_executable(cockatrice_test test/dummy_test.cpp) - target_link_libraries(cockatrice_test gtest_main) - add_test(NAME cockatrice_test COMMAND cockatrice_test) endif() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..93deb7df --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,38 @@ +enable_testing() +add_test(NAME dummy_test COMMAND dummy_test) + +# Find GTest + +add_executable(dummy_test dummy_test.cpp) + +find_package(GTest) + +if(NOT GTEST_FOUND) + IF(NOT EXISTS "${CMAKE_BINARY_DIR}/gtest-build") + message(STATUS "Downloading googletest") + configure_file("${CMAKE_SOURCE_DIR}/cmake/gtest-CMakeLists.txt.in" "${CMAKE_BINARY_DIR}/gtest-download/CMakeLists.txt") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) + execute_process(COMMAND ${CMAKE_COMMAND} --build . + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-download ) + ELSE() + message(STATUS "GoogleTest directory exists") + ENDIF() + + # Add gtest directly to our build + add_subdirectory(${CMAKE_BINARY_DIR}/gtest-src + ${CMAKE_BINARY_DIR}/gtest-build + EXCLUDE_FROM_ALL ) + + # Add the gtest include directory, since gtest + # doesn't add that dependency to its gtest target + target_include_directories(gtest INTERFACE + "${CMAKE_BINARY_DIR}/gtest-src/include" ) + + SET(GTEST_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/gtest-src/include") + SET(GTEST_BOTH_LIBRARIES gtest) + add_dependencies(dummy_test gtest) +endif() + +include_directories(${GTEST_INCLUDE_DIRS}) +target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES}) \ No newline at end of file diff --git a/cockatrice/test/dummy_test.cpp b/tests/dummy_test.cpp similarity index 100% rename from cockatrice/test/dummy_test.cpp rename to tests/dummy_test.cpp diff --git a/travis-compile.sh b/travis-compile.sh index 86836437..f3624ebb 100755 --- a/travis-compile.sh +++ b/travis-compile.sh @@ -9,11 +9,11 @@ if [[ $TRAVIS_OS_NAME == "osx" && $QT4 == 0 ]]; then prefix="-DCMAKE_PREFIX_PATH=`echo /usr/local/Cellar/qt5/5.*/`" fi if [[ $TRAVIS_OS_NAME == "linux" && $QT4 == 0 ]]; then - prefix="-DCMAKE_PREFIX_PATH=/opt/qt52/lib/cmake/" + prefix="-DCMAKE_PREFIX_PATH=`echo /opt/qt5*/lib/cmake/`" fi if [[ $BUILDTYPE == "Debug" ]]; then - cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -Dtest=ON -DWITH_QT4=$QT4 $prefix + cmake .. -DWITH_SERVER=1 -DWITH_TESTS=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix make -j2 make test else diff --git a/travis-dependencies.sh b/travis-dependencies.sh index 15048ef8..dcb65e29 100755 --- a/travis-dependencies.sh +++ b/travis-dependencies.sh @@ -10,16 +10,22 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then brew unlink cmake brew upgrade cmake else + sudo add-apt-repository -y ppa:george-edison55/precise-backports if (( QT4 )); then sudo apt-get update -qq sudo apt-get install -y qtmobility-dev libqt4-dev else - sudo add-apt-repository -y ppa:george-edison55/precise-backports - sudo add-apt-repository -y ppa:beineri/opt-qt521 + sudo add-apt-repository -y ppa:beineri/opt-qt541 sudo apt-get update -qq sudo apt-get install -y libsqlite3-dev\ - qt52base qt52webkit qt52tools qt52svg qt52multimedia + qt54base qt54webkit qt54tools qt54svg qt54multimedia fi - sudo apt-get install -y cmake libgtest-dev libprotobuf-dev protobuf-compiler - cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd - + sudo apt-get install -y cmake cmake-data libgtest-dev libprotobuf-dev protobuf-compiler + sudo mkdir /usr/src/gtest/build + cd /usr/src/gtest/build + sudo cmake .. -DBUILD_SHARED_LIBS=1 + sudo make -j2 + sudo ln -s /usr/src/gtest/build/libgtest.so /usr/lib/libgtest.so + sudo ln -s /usr/src/gtest/build/libgtest_main.so /usr/lib/libgtest_main.so + cd - fi From b63475829b1f7b2855fdb82f38c92078a2327d4c Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Fri, 9 Oct 2015 15:47:34 +0200 Subject: [PATCH 3/4] Revert option from WITH_TESTS to TEST --- CMakeLists.txt | 4 ++-- travis-compile.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef9474e1..e735488e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -234,8 +234,8 @@ if(WITH_ORACLE) endif() # Compile tests (default off) -option(WITH_TESTS "build tests" OFF) -if(WITH_TESTS) +option(TEST "build tests" OFF) +if(TEST) include(CTest) add_subdirectory(tests) endif() diff --git a/travis-compile.sh b/travis-compile.sh index f3624ebb..37467226 100755 --- a/travis-compile.sh +++ b/travis-compile.sh @@ -13,7 +13,7 @@ if [[ $TRAVIS_OS_NAME == "linux" && $QT4 == 0 ]]; then fi if [[ $BUILDTYPE == "Debug" ]]; then - cmake .. -DWITH_SERVER=1 -DWITH_TESTS=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix + cmake .. -DWITH_SERVER=1 -DTEST=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix make -j2 make test else From 5fed8d04d66ab252a881ff7e99aefeb79e892410 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Fri, 9 Oct 2015 18:51:30 +0200 Subject: [PATCH 4/4] Updated docs --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2a50748a..6802aea2 100644 --- a/README.md +++ b/README.md @@ -59,17 +59,28 @@ To compile: cd build cmake .. make + +You can then run + make install +to get a cockatrice installation inside the `release` folder, or: + + make package + +to create a system-specific installation package. + The following flags can be passed to `cmake`: -- `-DWITH_SERVER=1` Build the server. -- `-DWITH_CLIENT=0` Do not build the client. -- `-DWITH_ORACLE=0` Do not build oracle. -- `-DPORTABLE=1` Build portable versions of client & oracle. -- `-DWITH_QT4=1` Force compilation to use Qt4 instead of Qt5. -- `-DCMAKE_BUILD_TYPE=Debug` Compile in debug mode. Enables extra logging output, debug symbols, and much more verbose compiler warnings. -- `-DUPDATE_TRANSLATIONS=1` Configure `make` to update the translation .ts files for new strings in the source code. Note: Running `make clean` will remove the .ts files. +- `-DWITH_SERVER=1` Whether to build the server (default 0 = no). +- `-DWITH_CLIENT=0` Whether to build the client (default 1 = yes). +- `-DWITH_ORACLE=0` Whether to build oracle (default 1 = yes). +- `-DPORTABLE=1` Build portable versions of client & oracle (default 0 = no). +- `-DWITH_QT4=1` Force compilation to use Qt4 instead of Qt5 (default 0 = no). +- `-DCMAKE_BUILD_TYPE=Debug` Compile in debug mode. Enables extra logging output, debug symbols, and much more verbose compiler warnings (default `Release`). +- `-DUPDATE_TRANSLATIONS=1` Configure `make` to update the translation .ts files for new strings in the source code. Note: Running `make clean` will remove the .ts files (default 0 = no). +- `-DTEST=1` Enable regression tests (default 0 = no). Note: needs googletest, will be downloaded on the fly if unavailable. To run tests: ```make test```. + #### Building servatrice Docker container `docker build -t servatrice .`