From b288d43d7eb229ac68fbbe10bba1e58d359ee4e7 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 12 Oct 2017 22:51:32 +0100 Subject: Add basic travis file --- .idea/.name | 2 +- .travis.yml | 31 +++++++++++++++++++++ CMakeLists.txt | 75 ++++++++++++++++++++++++++++++++++++-------------- CMakeLists.txt.in | 15 ++++++++++ build-instructions.md | 4 +-- clean-build.sh | 13 +++------ conanfile.txt | 9 ------ src/test/all_tests.cpp | 10 ------- 8 files changed, 107 insertions(+), 52 deletions(-) create mode 100644 .travis.yml create mode 100644 CMakeLists.txt.in delete mode 100644 conanfile.txt delete mode 100644 src/test/all_tests.cpp diff --git a/.idea/.name b/.idea/.name index a8eb715..9d853fa 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -solitaire_pip \ No newline at end of file +solvitaire \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0a05d99 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +language: c++ + +install: +# Upgrade GCC +- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y +- sudo apt-get update -qq +- sudo apt-get install -qq g++-6 +- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 + +# Boost +- echo "Installing Boost Libraries" +- sudo wget -O boost_1_63_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.gz/download > /dev/null 2>&1 +- sudo tar xzvf boost_1_63_0.tar.gz > /dev/null 2>&1 +- cd boost_1_63_0/ +- sudo ./bootstrap.sh --with-libraries=log > /dev/null 2>&1 +- sudo ./b2 link=shared threading=multi toolset=gcc optimization=space > /dev/null 2>&1 +- sudo ./b2 install > /dev/null 2>&1 +- cd .. + +script: +# Generate build +- cmake -G "CodeBlocks - Unix Makefiles" -D CMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=DEBUG --target solvitaire -Bcmake-build-debug -H. +- cmake -G "CodeBlocks - Unix Makefiles" -D CMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=RELEASE --target solvitaire -Bcmake-build-release -H. + +# Build +- cmake --build cmake-build-debug +- cmake --build cmake-build-release + +# Run unit tests +- ./cmake-build-debug/bin/unit_tests +- ./cmake-build-release/bin/unit_tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 196acdd..ee413e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,39 +1,73 @@ -# File based on solitaire_pip at https://stackoverflow.com/questions/21163188/most-simple-but-complete-cmake-example +# File based on https://stackoverflow.com/questions/21163188/most-simple-but-complete-cmake-example cmake_minimum_required(VERSION 3.0) -project(solitaire_pip) +project(solvitaire) set(CMAKE_CXX_STANDARD 14) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ############################################################################### ## source files ############################################################### ############################################################################### set(sources src/main/main.cpp src/main/Card.h src/main/Card.cpp) -set(sources_test src/test/all_tests.cpp src/test/main_test.cpp) +set(sources_test src/test/main_test.cpp) ############################################################################### -## conan.io setup ############################################################# +## Boost setup ################################################################ ############################################################################### -if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - # Disable warnings/errors for conan libraries - set(CONAN_SYSTEM_INCLUDES On) - conan_basic_setup() +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost 1.63.0 REQUIRED COMPONENTS log) + +if(Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) else() - message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first") + message(WARNING "Must install Boost libraries") +endif() + +############################################################################### +## GTest setup ################################################################ +############################################################################### + +# Download and unpack googletest at configure time +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src + ${CMAKE_BINARY_DIR}/googletest-build) + +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. Otherwise we have to add them here ourselves. +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") endif() ############################################################################### ## compile options ############################################################ ############################################################################### -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pedantic -Wall -Wextra \ --Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wformat=2 -Winit-self \ +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DBOOST_LOG_DYN_LINK -pthread -pedantic -Wall -Wextra \ +-Wcast-align -Wcast-qual -Wformat=2 -Winit-self \ -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept \ -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow \ --Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror") +-Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -s -DNDEBUG -Wl,-O1") @@ -47,13 +81,12 @@ if(NOT CMAKE_BUILD_TYPE) endif() # add the data to the target, so it becomes visible in some IDE -add_executable(solitaire_pip ${sources}) +add_executable(solvitaire ${sources}) # this lets me include files relative to the root src dir with a <> pair -target_include_directories(solitaire_pip PUBLIC src/main) +target_include_directories(solvitaire PUBLIC src/main) -# link conan libraries -target_link_libraries(solitaire_pip ${CONAN_LIBS}) +target_link_libraries(solvitaire LINK_PUBLIC ${Boost_LIBRARIES}) # this copies all resource files in the build directory # we need this, because we want to work with paths relative to the executable @@ -67,9 +100,9 @@ add_executable(unit_tests ${sources_test}) # this allows us to use our executable as a link library # therefore we can inherit all compiler options and library dependencies -set_target_properties(solitaire_pip PROPERTIES ENABLE_EXPORTS on) +set_target_properties(solvitaire PROPERTIES ENABLE_EXPORTS on) -target_link_libraries(unit_tests ${CONAN_LIBS} solitaire_pip) +target_link_libraries(unit_tests gtest_main) ENABLE_TESTING() ADD_TEST(NAME unit_tests @@ -82,11 +115,11 @@ ADD_TEST(NAME unit_tests # all install commands get the same destination. this allows us to use paths # relative to the executable. -install(TARGETS solitaire_pip DESTINATION solitaire_pip) +install(TARGETS solvitaire DESTINATION solvitaire) # this is basically a repeat of the file copy instruction that copies the # resources in the build directory, but here we tell cmake that we want it # in the package -install(DIRECTORY resources DESTINATION solitaire_pip) +install(DIRECTORY resources DESTINATION solvitaire) set(CPACK_OUTPUT_FILE_PREFIX installer) set(CPACK_PACKAGE_VERSION "1.0.0") diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in new file mode 100644 index 0000000..4c67ef5 --- /dev/null +++ b/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/build-instructions.md b/build-instructions.md index 85a7043..f0fe12d 100644 --- a/build-instructions.md +++ b/build-instructions.md @@ -10,7 +10,7 @@ compiler=gcc -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd ..` ### Generate Build System -`cmake [-G "CodeBlocks - Unix Makefiles"] -DCMAKE_BUILD_TYPE=[DEBUG|RELEASE] -Bcmake-build-[debug|release] -H.` +`cmake [-G "CodeBlocks - Unix Makefiles"] -D CMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=[DEBUG|RELEASE] -Bcmake-build-[debug|release] -H.` ### Build project @@ -18,7 +18,7 @@ compiler=gcc -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd ..` ### Run executable -`./cmake-build-[debug|release]/bin/solitaire_pip` +`./cmake-build-[debug|release]/bin/solvitaire` ### Create project installer diff --git a/clean-build.sh b/clean-build.sh index d037403..5b2fd26 100755 --- a/clean-build.sh +++ b/clean-build.sh @@ -1,17 +1,12 @@ #!/bin/sh echo "Cleaning..." -rm -r cmake-build-release/*; rm -r cmake-build-debug/* - -echo "Installing..." -cd cmake-build-debug; conan install .. --build missing -s compiler=gcc \ - -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd .. -cd cmake-build-release; conan install .. --build missing -s compiler=gcc \ - -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd .. +rm -rf cmake-build-debug; mkdir cmake-build-debug; +rm -rf cmake-build-release; mkdir cmake-build-release; echo "Generating build..." -cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=DEBUG --target solitaire_pip -Bcmake-build-debug -H. -cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=RELEASE --target solitaire_pip -Bcmake-build-release -H. +cmake -G "CodeBlocks - Unix Makefiles" -D CMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=DEBUG --target solvitaire -Bcmake-build-debug -H. +cmake -G "CodeBlocks - Unix Makefiles" -D CMAKE_CXX_COMPILER=g++-6 -DCMAKE_BUILD_TYPE=RELEASE --target solvitaire -Bcmake-build-release -H. echo "Building..." cmake --build cmake-build-debug diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index f181ce5..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,9 +0,0 @@ -[requires] -Boost/1.60.0@lasote/stable -gtest/1.8.0@lasote/stable - -[options] -gtest:shared=False - -[generators] -cmake diff --git a/src/test/all_tests.cpp b/src/test/all_tests.cpp deleted file mode 100644 index 7dce333..0000000 --- a/src/test/all_tests.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by thecharlesblake on 10/4/17. -// - -#include - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} -- cgit v1.2.1