From b3714625c08b05a4995eb156cb30f0184580194f Mon Sep 17 00:00:00 2001 From: vitaut Date: Wed, 19 Aug 2015 08:03:17 -0700 Subject: [PATCH] Fix compilation with FMT_PEDANTIC=ON --- CMakeLists.txt | 6 +----- test/CMakeLists.txt | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c866bc43..c31d1b7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,11 +108,7 @@ endif () # over compile options, so the options used here only matter for testing. if (CPP11_FLAG AND FMT_PEDANTIC) set(FMT_EXTRA_COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS} ${CPP11_FLAG}") - # Test compilation with default flags. - if (FMT_TESTS) - file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cc test/*.h) - add_library(testformat STATIC ${FMT_SOURCES} ${src}) - endif () + set(FMT_TEST_DEFAULT_FLAGS TRUE) endif () set_target_properties(cppformat diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 843330c9..d30c222b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,14 +59,6 @@ function(add_fmt_test name) add_test(NAME ${name} COMMAND ${name}) endfunction() -check_cxx_source_compiles(" - enum C : char {A}; - int main() {}" - HAVE_ENUM_BASE) -if (HAVE_ENUM_BASE) - add_definitions(-DFMT_USE_ENUM_BASE=1) -endif () - add_fmt_test(assert-test) add_fmt_test(gtest-extra-test) add_fmt_test(format-test) @@ -90,6 +82,15 @@ if (CPP11_FLAG) set_target_properties(util-test PROPERTIES COMPILE_FLAGS ${CPP11_FLAG}) endif () +check_cxx_source_compiles(" + enum C : char {A}; + int main() {}" + HAVE_ENUM_BASE) +if (HAVE_ENUM_BASE) + set_target_properties(util-test + PROPERTIES COMPILE_DEFINITIONS "FMT_USE_ENUM_BASE=1") +endif () + foreach (src ${FMT_SOURCES}) set(FMT_TEST_SOURCES ${FMT_TEST_SOURCES} ../${src}) endforeach () @@ -100,7 +101,10 @@ check_cxx_source_compiles(" int main() { static_assert(!std::is_copy_assignable::value, \"\"); }" HAVE_TYPE_TRAITS) if (HAVE_TYPE_TRAITS) - add_definitions(-DFMT_USE_TYPE_TRAITS=1) + foreach (target format-test util-test) + set_target_properties(${target} + PROPERTIES COMPILE_DEFINITIONS "FMT_USE_TYPE_TRAITS=1") + endforeach () endif () add_executable(macro-test macro-test.cc ${FMT_TEST_SOURCES} ${TEST_MAIN_SRC}) @@ -127,6 +131,15 @@ if (HAVE_FNO_EXCEPTIONS_FLAG) PROPERTIES COMPILE_FLAGS -fno-exceptions) endif () +# Test compilation with default flags. +if (FMT_TEST_DEFAULT_FLAGS) + file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cc *.h) + foreach (s ${FMT_SOURCES}) + set(src ${src} ../${s}) + endforeach () + add_library(testformat STATIC ${src}) +endif () + if (FMT_PEDANTIC) add_test(compile-test ${CMAKE_CTEST_COMMAND} --build-and-test