From 914b97859c309116dac1c93953153e6c96903513 Mon Sep 17 00:00:00 2001 From: Alex Martin Date: Wed, 19 Aug 2015 10:41:37 +0200 Subject: [PATCH] add CMake option to toggle tests (on by default) --- CMakeLists.txt | 149 +++++++++++++++++++++++++------------------------ 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2507a048..3b5a3361 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ endif () option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_INSTALL "Generate install target." ON) +option(FMT_TESTS "Generate tests." ON) project(FORMAT) @@ -108,8 +109,10 @@ endif () if (CPP11_FLAG AND FMT_PEDANTIC) set(FMT_EXTRA_COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS} ${CPP11_FLAG}") # Test compilation with default flags. - file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cc test/*.h) - add_library(testformat STATIC ${FMT_SOURCE_FILES} ${src}) + if (FMT_TESTS) + file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cc test/*.h) + add_library(testformat STATIC ${FMT_SOURCE_FILES} ${src}) + endif () endif () set_target_properties(cppformat @@ -117,79 +120,81 @@ set_target_properties(cppformat add_subdirectory(doc) -include_directories(. gmock) - -# We compile Google Test ourselves instead of using pre-compiled libraries. -# See the Google Test FAQ "Why is it not recommended to install a -# pre-compiled copy of Google Test (for example, into /usr/local)?" -# at http://code.google.com/p/googletest/wiki/FAQ for more details. - -add_library(gmock STATIC - gmock/gmock-gtest-all.cc gmock/gmock/gmock.h - gmock/gtest/gtest.h gmock/gtest/gtest-spi.h) -find_package(Threads) -if (Threads_FOUND) - target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) -else () - target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0) -endif () - -# Check if variadic templates are working and not affected by GCC bug 39653: -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 -check_cxx_source_compiles(" - template - struct S { typedef typename S::type type; }; - int main() {}" FMT_VARIADIC_TEMPLATES) - -# Check if initializer lists are supported. -check_cxx_source_compiles(" - #include - int main() {}" FMT_INITIALIZER_LIST) +if (FMT_TESTS) + include_directories(. gmock) -if (NOT FMT_VARIADIC_TEMPLATES OR NOT FMT_INITIALIZER_LIST) - add_definitions(-DGTEST_LANG_CXX11=0) + # We compile Google Test ourselves instead of using pre-compiled libraries. + # See the Google Test FAQ "Why is it not recommended to install a + # pre-compiled copy of Google Test (for example, into /usr/local)?" + # at http://code.google.com/p/googletest/wiki/FAQ for more details. + + add_library(gmock STATIC + gmock/gmock-gtest-all.cc gmock/gmock/gmock.h + gmock/gtest/gtest.h gmock/gtest/gtest-spi.h) + find_package(Threads) + if (Threads_FOUND) + target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) + else () + target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0) + endif () + + # Check if variadic templates are working and not affected by GCC bug 39653: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 + check_cxx_source_compiles(" + template + struct S { typedef typename S::type type; }; + int main() {}" FMT_VARIADIC_TEMPLATES) + + # Check if initializer lists are supported. + check_cxx_source_compiles(" + #include + int main() {}" FMT_INITIALIZER_LIST) + + if (NOT FMT_VARIADIC_TEMPLATES OR NOT FMT_INITIALIZER_LIST) + add_definitions(-DGTEST_LANG_CXX11=0) + endif () + + # This is disabled at the moment because format is compiled without -std=c++11 + # by default. + #check_cxx_source_compiles(" + # void f() noexcept {} + # int main(){ f(); }" FMT_BASIC_NOEXCEPT_SUPPORT) + #if (FMT_BASIC_NOEXCEPT_SUPPORT) + # add_definitions(-DFMT_USE_NOEXCEPT=1) + #endif () + + #check_cxx_source_compiles(" + # struct C{ + # C()=delete; + # C(const C&)=delete; + # C& operator=(const C&)=delete; + # }; + # int main(){}" FMT_DELETED_FUNCTIONS) + #if (FMT_DELETED_FUNCTIONS) + # add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) + #endif () + + #check_cxx_source_compiles(" + # static_assert(true, \"\"); + # int main(){}" FMT_STATIC_ASSERT) + #if (FMT_STATIC_ASSERT) + # add_definitions(-DFMT_USE_STATIC_ASSERT=1) + #endif () + + # Workaround a bug in implementation of variadic templates in MSVC11. + if (MSVC) + target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) + endif () + + # GTest doesn't detect with clang. + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) + endif () + + enable_testing() + add_subdirectory(test) endif () -# This is disabled at the moment because format is compiled without -std=c++11 -# by default. -#check_cxx_source_compiles(" -# void f() noexcept {} -# int main(){ f(); }" FMT_BASIC_NOEXCEPT_SUPPORT) -#if (FMT_BASIC_NOEXCEPT_SUPPORT) -# add_definitions(-DFMT_USE_NOEXCEPT=1) -#endif () - -#check_cxx_source_compiles(" -# struct C{ -# C()=delete; -# C(const C&)=delete; -# C& operator=(const C&)=delete; -# }; -# int main(){}" FMT_DELETED_FUNCTIONS) -#if (FMT_DELETED_FUNCTIONS) -# add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) -#endif () - -#check_cxx_source_compiles(" -# static_assert(true, \"\"); -# int main(){}" FMT_STATIC_ASSERT) -#if (FMT_STATIC_ASSERT) -# add_definitions(-DFMT_USE_STATIC_ASSERT=1) -#endif () - -# Workaround a bug in implementation of variadic templates in MSVC11. -if (MSVC) - target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) -endif () - -# GTest doesn't detect with clang. -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) -endif () - -enable_testing() -add_subdirectory(test) - set(CPACK_PACKAGE_VERSION_MAJOR 1) set(CPACK_PACKAGE_VERSION_MINOR 2) set(CPACK_PACKAGE_VERSION_PATCH 0)