Commit 93d81bd0 authored by Ivan Čukić's avatar Ivan Čukić 👁

Require C++17

This patch removes CMake checks for C++11 features and increases
the compiler requirements to C++17 since this repository is not a
part of KDE Frameworks.
parent a28972ff
......@@ -36,6 +36,10 @@ include (ECMQtDeclareLoggingCategory)
include (ECMSetupQtPluginMacroNames)
include(KDEClangFormat)
# C++17
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
# Qt
find_package (Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core DBus Widgets)
......
# Macro that tests and returns whether a C++ feature is present in the
# current compiler
set(CXX_CHECK_FEATURE_MODULE_DIR "${CMAKE_SOURCE_DIR}/cmake/modules")
set(CXX_FEATURES_SUPPORTED "")
set(CXX_FEATURES_UNSUPPORTED "")
macro(CXX_PERFORM_TEST TEST_SOURCE_FILE TEST_TEST_BINARY_DIR EXPECTED_RESULT RESULT COMPILE_DEFINITIONS)
try_run(
RUN_RESULT_VAR COMPILE_RESULT_VAR
"${TEST_BINARY_DIR}" "${TEST_SOURCE_FILE}"
COMPILE_DEFINITIONS "${COMPILE_DEFINITIONS}"
COMPILE_OUTPUT_VARIABLE COMPILE_OUT
RUN_OUTPUT_VARIABLE RUN_OUT
)
set(RESULT_VAR FALSE)
if (COMPILE_RESULT_VAR AND NOT RUN_RESULT_VAR)
set(RESULT_VAR TRUE)
endif (COMPILE_RESULT_VAR AND NOT RUN_RESULT_VAR)
if (NOT ("${RESULT_VAR}" STREQUAL "${EXPECTED_RESULT}"))
# message ("Got ${RESULT_VAR} as a result, but ${EXPECTED_RESULT} expected")
if (NOT ${COMPILE_RESULT_VAR})
# message("------ compilation output ------")
# message("${COMPILE_OUT}")
endif (NOT ${COMPILE_RESULT_VAR})
if (${RUN_RESULT_VAR})
# message("---------- run output ----------")
# message("${RUN_OUT}")
# message("Process returned: ${RUN_RESULT_VAR}")
endif (${RUN_RESULT_VAR})
# message("--------------------------------")
set (${RESULT} FALSE)
else ()
set (${RESULT} TRUE)
endif ()
endmacro(CXX_PERFORM_TEST TEST_SOURCE EXPECTED_RESULT RESULT)
macro(CXX_CHECK_FEATURE CXX_VERSION FEATURE_NAME FEATURE_NUMBER RESULT_VAR COMPILE_DEFINITIONS)
# Testing whether we have previously set the variable
if(NOT DEFINED ${RESULT_VAR})
set(TEST_BINARY_DIR
"${CMAKE_CURRENT_BINARY_DIR}/cxx-check-feature/cxx_${FEATURE_NUMBER}"
)
set(TEST_SOURCE_BASE
"${CXX_CHECK_FEATURE_MODULE_DIR}/${CXX_VERSION}-test-${FEATURE_NAME}-${FEATURE_NUMBER}"
)
set(TEST_SOURCE_FILE "${TEST_SOURCE_BASE}.cpp")
set(FAILTEST_SOURCE_FILE "${TEST_SOURCE_BASE}-fail.cpp")
set(FEATURE_NAME
"'${FEATURE_NAME}' (${CXX_VERSION} N${FEATURE_NUMBER})"
)
message(STATUS "Checking C++ support for ${FEATURE_NAME}")
string (COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Clang" CMAKE_COMPILER_IS_CLANG)
string (COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "GNU" CMAKE_COMPILER_IS_GCC)
set (ADD_COMPILE_DEFINITIONS "")
if (EXISTS ${TEST_SOURCE_FILE})
CXX_PERFORM_TEST(${TEST_SOURCE_FILE} ${TEST_BINARY_DIR} TRUE ${RESULT_VAR} "${COMPILE_DEFINITIONS} ${ADD_COMPILE_DEFINITIONS}")
endif ()
if (${RESULT_VAR} AND EXISTS ${FAILTEST_SOURCE_FILE})
CXX_PERFORM_TEST(${FAILTEST_SOURCE_FILE} ${TEST_BINARY_DIR} FALSE ${RESULT_VAR} "${COMPILE_DEFINITIONS} ${ADD_COMPILE_DEFINITIONS}")
endif ()
if (${RESULT_VAR})
message(STATUS "Checking C++ support for ${FEATURE_NAME} -- works")
set (CXX_FEATURES_SUPPORTED
"${CXX_FEATURES_SUPPORTED} ${FEATURE_NAME} (${FEATURE_NUMBER}),"
)
else ()
message(STATUS "Checking C++ support for ${FEATURE_NAME} -- not supported")
set (CXX_FEATURES_UNSUPPORTED
"${CXX_FEATURES_UNSUPPORTED} ${FEATURE_NAME} (${FEATURE_NUMBER}),"
)
endif ()
# This would break the feature reporting on second call of cmake
# TODO: Fix?
# set(${RESULT_VAR} ${${RESULT_VAR}} CACHE INTERNAL "C++ support for ${FEATURE_NAME}")
endif(NOT DEFINED ${RESULT_VAR})
endmacro(CXX_CHECK_FEATURE)
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
class A {
public:
virtual int fn(int arg) {
return 10 * arg;
};
};
class B: public A {
public:
virtual int fn(long arg) __attribute__((override)) {
return 20 * arg;
};
};
int main()
{
A * a = new A();
A * b = new B();
int result = a->fn(2) - b->fn(1);
return 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
class A {
public:
virtual int fn(int arg) {
return 10 * arg;
};
};
class B: public A {
public:
virtual int fn(long arg) __attribute__((override)) {
return 20 * arg;
};
};
int main()
{
A * a = new A();
A * b = new B();
int result = a->fn(2) - b->fn(1);
return 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
int main()
{
auto i = 5;
auto f = 3.14159f;
auto d = 3.14159;
auto l = 3l;
bool checkFloats = (sizeof(f) < sizeof(d));
bool checkInts = (sizeof(i) == sizeof(int));
bool checkLongs = (sizeof(l) == sizeof(long));
std::cout
<< "Float sizes correct: " << checkFloats << std::endl
<< "Integer size correct: " << checkFloats << std::endl
<< "Long sizes correct: " << checkFloats << std::endl;
return (checkFloats && checkInts && checkLongs) ? 0 : 1;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// #include <iostream>
// #include <vector>
#include <string>
struct test {
int i;
int j;
double k;
std::string s;
};
int main()
{
test t { 1, 2, 4, "asdf" };
// std::vector<int> v { 1, 2, 3, 4 };
// return (
// t.i == v[0]
// && t.j == v[1]
// && t.k > v[2]
// && t.s.size() == v[3]
// )
// ? 0 : 1;
return 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
int main()
{
int ref = 10;
int pass = 2;
([&](int mul) {
ref *= mul;
})(pass);
bool checkRefNoref = (ref == 10 * pass);
int result = ([=](int mul) {
return ref * mul;
})(pass);
bool checkReturn = (result == 10 * pass * pass);
std::cout
<< "Capture by reference: " << checkRefNoref << std::endl
<< "Return a value: " << checkReturn << std::endl;
return (checkRefNoref && checkReturn) ? 0 : 1;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int main()
{
int i = nullptr;
return 1;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
int main()
{
int * test = nullptr;
return test ? 1 : 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
class A {
public:
virtual int fn(int arg) {
return 10 * arg;
};
};
class B: public A {
public:
virtual int fn(long arg) override {
return 20 * arg;
};
};
int main()
{
A * a = new A();
A * b = new B();
int result = a->fn(2) - b->fn(1);
return 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
class A {
public:
virtual int fn(int arg) {
return 10 * arg;
};
};
class B: public A {
public:
virtual int fn(int arg) override {
return 20 * arg;
};
};
int main()
{
A * a = new A();
A * b = new B();
int result = a->fn(2) - b->fn(1);
return 0;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include <string>
#include <iostream>
#include <utility>
struct Question {
long answer;
std::string description;
};
int main()
{
std::unique_ptr < Question > node_original(new Question());
node_original->answer = 42;
node_original->description = "The Answer to the Ultimate Question of Life, the Universe, and Everything";
std::unique_ptr < Question > node_second(std::move(node_original));
return (!node_original && (node_second->answer == 42))?0:1;
}
/*
* Copyright (C) 2014 - 2016 by Ivan Cukic <ivan.cukic@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
template <typename T>
int addall(T value)
{
return value;
}
template <typename T, typename... Args>
int addall(T value, Args ... args)
{
return value + addall(args...);
}
int main()
{
int v1 = addall(1, 2, 3, 4, 5); // 15
int v2 = addall(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4); // 40
return ((v1 == 15) && (v2 == 40)) ? 0 : 1;
}
......@@ -21,16 +21,6 @@ if (KACTIVITIES_ENABLE_EXCEPTIONS)
add_definitions (-fexceptions)
endif ()
# Testing for C++0x/C++11 features
include (CheckCxxFeatures)
cxx_check_feature ("c++11" "auto" "N2546" HAVE_CXX11_AUTO "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "nullptr" "N2431" HAVE_CXX11_NULLPTR "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "lambda" "N2927" HAVE_CXX11_LAMBDA "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "override" "N3206" HAVE_CXX11_OVERRIDE "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "unique_ptr" "none" HAVE_CXX11_UNIQUE_PTR "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "variadic-templates" "N2242" HAVE_CXX11_VARIADIC_TEMPLATES "${ADDITIONAL_DEFINITIONS}")
cxx_check_feature ("c++11" "initializer-lists" "N2672" HAVE_CXX11_INITIALIZER_LISTS "${ADDITIONAL_DEFINITIONS}")
# =======================================================
# Starting the actual project definition
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment