From 5aba10efb7c5d6043bbe11ecbdaeca4ce0a50c9b Mon Sep 17 00:00:00 2001 From: Sam Perry Date: Mon, 4 Jul 2016 16:45:04 +0100 Subject: [PATCH] In the process of creating unit tests/cmake files. --- CMakeLists.txt | 72 +++++++++++++++++++++++++----- external/CMakeLists.txt | 0 tests/CMakeLists.txt | 0 tests/Concatenator_Basic_Tests.cpp | 2 + 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 external/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/Concatenator_Basic_Tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d00662..95de6d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,28 +3,78 @@ set(CMAKE_CXX_STANDARD 11) # Set the project name project (concatenator) -set(Boost_USE_STATIC_LIBS OFF) -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.60.0 COMPONENTS program_options log log_setup thread date_time filesystem system) +############################################################################### +### Boost Settings +find_package(Boost 1.60.0 COMPONENTS program_options log log_setup thread date_time filesystem system REQUIRED) if (NOT FO_BOOST_STATIC_LINK) add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_ALL_DYN_LINK -DBOOST_LOG_DYN_LINK) endif() +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +############################################################################### + # Set build flags set(CMAKE_CXX_FLAGS "-g -Wall ") # Set cmake to output executable to the bin directory set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +# Find all included header files. include_directories(include) - -# Find all the source fies in the src directory -file(GLOB SOURCES "src/*.cpp") +include_directories(${Boost_INCLUDE_DIRS}) +add_subdirectory(external) # Build the executable from the source files found -if(Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) - add_executable(concatenator ${SOURCES}) - target_link_libraries(concatenator ${Boost_LIBRARIES}) + + +set(CONCATENATOR_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src) +set(CONCATENATOR_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) +set(CONCATENATOR_TEST_DIR ${PROJECT_SOURCE_DIR}/tests) + +set(CONCATENATOR_SOURCE_FILES + ${CONCATENATOR_SOURCE_DIR}/Concatenator.cpp +) +set(CONCATENATOR_HEADER_FILES + ${CONCATENATOR_INCLUDE_DIR}/config.hpp +) +set(CONCATENATOR_TEST_SOURCES + ${CONCATENATOR_TEST_DIR}/Concatenator_Basic_Tests.cpp +) + +add_executable(concatenator ${CONCATENATOR_SOURCE_DIR}/concatenator.cpp) + +target_link_libraries(concatenator ${Boost_LIBRARIES}) +# Test build options (this code adapted from: https://github.com/ComicSansMS/GhulbusBase/blob/master/CMakeLists.txt) +option(BUILD_TESTS "Determines whether to build tests." ON) +if(BUILD_TESTS) + enable_testing() + + if(NOT TARGET Catch) + include(ExternalProject) + if(WIN32) + set(FETCH_EXTERNAL_CATCH + URL https://github.com/philsquared/Catch/archive/v1.2.1-develop.12.zip + URL_HASH MD5=cda228922a1c9248364c99a3ff9cd9fa) + else() + set(FETCH_EXTERNAL_CATCH + URL https://github.com/philsquared/Catch/archive/v1.2.1-develop.12.tar.gz + URL_HASH MD5=a8dfb7be899a6e7fb30bd55d53426122) + endif() + ExternalProject_Add(Catch-External + PREFIX ${CMAKE_BINARY_DIR}/external/Catch + ${FETCH_EXTERNAL_CATCH} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/external/Catch/src/Catch-External/single_include/catch.hpp + ${CMAKE_BINARY_DIR}/external/Catch/include/catch.hpp + ) + add_library(Catch INTERFACE) + add_dependencies(Catch Catch-External) + target_include_directories(Catch INTERFACE ${CMAKE_BINARY_DIR}/external/Catch/include) + endif() + + add_executable(Concatenator_Base_Test ${CONCATENATOR_TEST_SOURCES}) + add_test(NAME TestBase COMMAND Concatenator_Base_Test) endif() diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/Concatenator_Basic_Tests.cpp b/tests/Concatenator_Basic_Tests.cpp new file mode 100644 index 0000000..e6d1d56 --- /dev/null +++ b/tests/Concatenator_Basic_Tests.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include "catch.hpp"