From e13e913a1ef0f79f080db513abd2a622bcef755d Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 14 Apr 2020 10:40:28 +0200 Subject: [PATCH] Remove main.cpp and add warning free build test The main.cpp speeds up builds but fails for static boost.Test builds as it is linked before Boost.Test which removes the required symbols Enabling warning allows consumers of Turtle to build with warnings enabled --- test/CMakeLists.txt | 20 +++++++++++++++++--- test/main.cpp | 10 ---------- 2 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 test/main.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4f16ac8..a50631a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,11 +4,25 @@ find_package(Boost 1.58 REQUIRED COMPONENTS unit_test_framework thread) -add_library(TurtleTestMain STATIC main.cpp) -target_link_libraries(TurtleTestMain PUBLIC Boost::unit_test_framework Boost::disable_autolinking) +add_library(TurtleTestMain INTERFACE) +target_link_libraries(TurtleTestMain INTERFACE Boost::unit_test_framework Boost::disable_autolinking) +target_compile_definitions(TurtleTestMain INTERFACE BOOST_AUTO_TEST_MAIN) # Heuristically guess if we are compiling against dynamic boost if(NOT Boost_USE_STATIC_LIBS AND Boost_UNIT_TEST_FRAMEWORK_LIBRARY AND NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}\$") - target_compile_definitions(TurtleTestMain PUBLIC BOOST_TEST_DYN_LINK) + target_compile_definitions(TurtleTestMain INTERFACE BOOST_TEST_DYN_LINK) +endif() +# Enable warnings +option(TURTLE_WERROR "Treat warnings as errors" ON) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(TurtleTestMain INTERFACE -Wall -Wextra -pedantic -Wno-long-long) + if(TURTLE_WERROR) + target_compile_options(TurtleTestMain INTERFACE -Werror) + endif() +elseif(MSVC) + target_compile_options(TurtleTestMain INTERFACE /W4) + if(TURTLE_WERROR) + target_compile_options(TurtleTestMain INTERFACE /WX) + endif() endif() file(GLOB_RECURSE testFiles test_*.cpp) diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 7045d4e..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// http://turtle.sourceforge.net -// -// Copyright Mathieu Champlon 2009 -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#define BOOST_AUTO_TEST_MAIN -#include