From 1cc92ec1119bb91d36c586b4431e0a330d3737d0 Mon Sep 17 00:00:00 2001 From: Joakim Karlsson Date: Sat, 18 Jul 2015 11:32:44 +0200 Subject: [PATCH] Puts the C++11 and C++ tracks on the same branch Keeping a branch for C++11 and C++ each is too much of a hassle. This keeps both tracks in one code base and uses #if statements to separate constructs. --- CMakeLists.txt | 28 ++++++++---- cross_compile.sh | 44 +++++++++++-------- snowhouse/assertionexception.h | 10 +++++ .../constraints/equalscontainerconstraint.h | 7 ++- .../fluent/operators/constraintoperator.h | 9 ++-- snowhouse/snowhouse.h | 9 ++++ 6 files changed, 76 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa543b3..5f4ff72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,20 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.8) project(snowhouse) +option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" ON) +option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" ON) +option(SNOWHOUSE_IS_CPP11 "Whether to build this as a C++11 project" OFF) + include_directories("${PROJECT_SOURCE_DIR}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin) set(CMAKE_CXX_FLAGS "-Wfatal-errors -Wall -W -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors") -if(${cfg} STREQUAL "C++11") +if(SNOWHOUSE_IS_CPP11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdeprecated") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") @@ -28,10 +34,16 @@ endif() message(${CMAKE_CXX_FLAGS}) -FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp) -add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles}) +if (SNOWHOUSE_BUILD_TESTS) + FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp) + add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles}) +endif() -add_custom_command(TARGET snowhouse-tests - POST_BUILD - COMMAND snowhouse-tests - WORKING_DIRECTORY ./bin) +if (SNOWHOUSE_BUILD_TESTS AND SNOWHOUSE_RUN_TESTS) + add_custom_command(TARGET snowhouse-tests + POST_BUILD + COMMAND snowhouse-tests + WORKING_DIRECTORY ./bin) +elseif (SNOWHOUSE_RUN_TESTS) + message(WARNING "Unable to run snowhouse tests - set:\n option(SNOWHOUSE_BUILD_TESTS, \"Build the Snowhouse tests\" ON)\nand clear your CMakeCache.txt") +endif() diff --git a/cross_compile.sh b/cross_compile.sh index 1a70516..d3a7327 100755 --- a/cross_compile.sh +++ b/cross_compile.sh @@ -3,25 +3,27 @@ STATUS="" function build_for { - CC=$1 - CXX=$2 + local CC=$1 + local CXX=$2 + local CXX_VERSION=$3 - BUILD_DIR=build-$CC-CXX - mkdir $BUILD_DIR - pushd $BUILD_DIR - CC=$CC CXX=$CXX cmake -Dcfg=C++ ../.. - make - STATUS="$STATUS\n$BUILD_DIR - Status: $?" - popd + echo "Compiling for $CC, $CXX, $CXX_VERSION..." - BUILD_DIR=build-$CC-CXX11 + if [[ "$CXX_VERSION" == "CXX" ]]; then + local SNOWHOUSE_IS_CPP11=OFF + else + local SNOWHOUSE_IS_CPP11=ON + fi + + echo "SNOWHOUSE_IS_CPP11=$SNOWHOUSE_IS_CPP11" + + BUILD_DIR=build-$CC-$CXX_VERSION mkdir $BUILD_DIR pushd $BUILD_DIR - CC=$CC CXX=$CXX cmake -Dcfg=C++11 ../.. + CC=$CC CXX=$CXX cmake -DSNOWHOUSE_IS_CPP11=$SNOWHOUSE_IS_CPP11 ../.. make STATUS="$STATUS\n$BUILD_DIR - Status: $?" popd - } if [[ -d builds ]]; then @@ -31,13 +33,17 @@ fi mkdir builds pushd builds - -build_for gcc-4.5 g++-4.5 -build_for gcc-4.6 g++-4.6 -build_for gcc-4.7 g++-4.7 -build_for gcc-4.8 g++-4.8 -build_for gcc-4.9 g++-4.9 -build_for clang clang++ +build_for gcc-4.5 g++-4.5 CXX +build_for gcc-4.6 g++-4.6 CXX +build_for gcc-4.6 g++-4.6 CXX11 +build_for gcc-4.7 g++-4.7 CXX +build_for gcc-4.7 g++-4.7 CXX11 +build_for gcc-4.8 g++-4.8 CXX +build_for gcc-4.8 g++-4.8 CXX11 +build_for gcc-4.9 g++-4.9 CXX +build_for gcc-4.9 g++-4.9 CXX11 +build_for clang clang++ CXX +build_for clang clang++ CXX11 popd echo "============================================" diff --git a/snowhouse/assertionexception.h b/snowhouse/assertionexception.h index 77890a7..d074774 100644 --- a/snowhouse/assertionexception.h +++ b/snowhouse/assertionexception.h @@ -19,9 +19,19 @@ namespace snowhouse { : m_message(message), m_fileName(fileName), m_line(line) {} +#if __cplusplus > 199711L + AssertionException(const AssertionException&) = default; +#endif + +#if __cplusplus > 199711L + virtual ~AssertionException() noexcept + { + } +#else virtual ~AssertionException() throw() { } +#endif std::string GetMessage() const { diff --git a/snowhouse/constraints/equalscontainerconstraint.h b/snowhouse/constraints/equalscontainerconstraint.h index 6bb5d79..f865095 100644 --- a/snowhouse/constraints/equalscontainerconstraint.h +++ b/snowhouse/constraints/equalscontainerconstraint.h @@ -45,7 +45,12 @@ namespace snowhouse { const BinaryPredicate predicate_; private: - EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) { return *this; } + +#if __cplusplus > 199711L +#else + EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) { return *this; } +#endif + }; template< typename ExpectedType> diff --git a/snowhouse/fluent/operators/constraintoperator.h b/snowhouse/fluent/operators/constraintoperator.h index efe396f..eafe6c5 100644 --- a/snowhouse/fluent/operators/constraintoperator.h +++ b/snowhouse/fluent/operators/constraintoperator.h @@ -10,14 +10,17 @@ #include "invalidexpressionexception.h" namespace snowhouse { - + struct ConstraintOperator { +#if __cplusplus > 199711L +#else virtual ~ConstraintOperator() {} - +#endif + virtual void PerformOperation(ResultStack& result) = 0; virtual int Precedence() const = 0; - + template static bool EvaluateElementAgainstRestOfExpression(ConstraintListType& list, const ActualType& actual) { diff --git a/snowhouse/snowhouse.h b/snowhouse/snowhouse.h index 4c36968..914b26d 100644 --- a/snowhouse/snowhouse.h +++ b/snowhouse/snowhouse.h @@ -3,6 +3,15 @@ #define SNOWHOUSE_VERSION "1.0.2" +#if __cplusplus > 199711L +#ifdef _MSC_VER +// Visual Studio (including 2013) does not support the noexcept keyword +#define _ALLOW_KEYWORD_MACROS +#define noexcept +#endif +#endif + + #include #include #include