diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc9e4b9..e735488e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,3 +232,10 @@ if(WITH_ORACLE) add_subdirectory(oracle) SET(CPACK_INSTALL_CMAKE_PROJECTS "release/oracle.app;oracle;ALL;/" ${CPACK_INSTALL_CMAKE_PROJECTS}) endif() + +# Compile tests (default off) +option(TEST "build tests" OFF) +if(TEST) + include(CTest) + add_subdirectory(tests) +endif() 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 .`
diff --git a/cmake/gtest-CMakeLists.txt.in b/cmake/gtest-CMakeLists.txt.in new file mode 100644 index 00000000..f5e07d30 --- /dev/null +++ b/cmake/gtest-CMakeLists.txt.in @@ -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/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 2a600e1b..ca9342a4 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -340,4 +340,4 @@ endif() option(PORTABLE "portable build" OFF) IF(PORTABLE) add_definitions(-DPORTABLE_BUILD) -endif() +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/tests/dummy_test.cpp b/tests/dummy_test.cpp new file mode 100644 index 00000000..a5416d09 --- /dev/null +++ b/tests/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/travis-compile.sh b/travis-compile.sh index 23345d84..37467226 100755 --- a/travis-compile.sh +++ b/travis-compile.sh @@ -9,13 +9,14 @@ 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 -cmake .. -DWITH_SERVER=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -DWITH_QT4=$QT4 $prefix if [[ $BUILDTYPE == "Debug" ]]; then + cmake .. -DWITH_SERVER=1 -DTEST=1 -DCMAKE_BUILD_TYPE=$BUILDTYPE -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..dcb65e29 100755 --- a/travis-dependencies.sh +++ b/travis-dependencies.sh @@ -7,15 +7,25 @@ if [[ $TRAVIS_OS_NAME == "osx" ]] ; then else brew install qt5 protobuf libgcrypt > /dev/null fi + 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 libprotobuf-dev protobuf-compiler libqt4-dev + sudo apt-get install -y qtmobility-dev libqt4-dev else - sudo add-apt-repository -y ppa:beineri/opt-qt521 - sudo add-apt-repository -y ppa:kalakris/cmake + sudo add-apt-repository -y ppa:beineri/opt-qt541 sudo apt-get update -qq - sudo apt-get install -y libprotobuf-dev protobuf-compiler cmake libsqlite3-dev\ - qt52base qt52webkit qt52tools qt52svg qt52multimedia + sudo apt-get install -y libsqlite3-dev\ + qt54base qt54webkit qt54tools qt54svg qt54multimedia fi + 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