add CMake option to toggle tests (on by default)

This commit is contained in:
Alex Martin 2015-08-19 10:41:37 +02:00
parent 4150fa0f95
commit 914b97859c

View File

@ -12,6 +12,7 @@ endif ()
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
option(FMT_INSTALL "Generate install target." ON) option(FMT_INSTALL "Generate install target." ON)
option(FMT_TESTS "Generate tests." ON)
project(FORMAT) project(FORMAT)
@ -108,8 +109,10 @@ endif ()
if (CPP11_FLAG AND FMT_PEDANTIC) if (CPP11_FLAG AND FMT_PEDANTIC)
set(FMT_EXTRA_COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS} ${CPP11_FLAG}") set(FMT_EXTRA_COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS} ${CPP11_FLAG}")
# Test compilation with default flags. # Test compilation with default flags.
if (FMT_TESTS)
file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cc test/*.h) file(GLOB src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*.cc test/*.h)
add_library(testformat STATIC ${FMT_SOURCE_FILES} ${src}) add_library(testformat STATIC ${FMT_SOURCE_FILES} ${src})
endif ()
endif () endif ()
set_target_properties(cppformat set_target_properties(cppformat
@ -117,78 +120,80 @@ set_target_properties(cppformat
add_subdirectory(doc) add_subdirectory(doc)
include_directories(. gmock) if (FMT_TESTS)
include_directories(. gmock)
# We compile Google Test ourselves instead of using pre-compiled libraries. # We compile Google Test ourselves instead of using pre-compiled libraries.
# See the Google Test FAQ "Why is it not recommended to install a # See the Google Test FAQ "Why is it not recommended to install a
# pre-compiled copy of Google Test (for example, into /usr/local)?" # pre-compiled copy of Google Test (for example, into /usr/local)?"
# at http://code.google.com/p/googletest/wiki/FAQ for more details. # at http://code.google.com/p/googletest/wiki/FAQ for more details.
add_library(gmock STATIC add_library(gmock STATIC
gmock/gmock-gtest-all.cc gmock/gmock/gmock.h gmock/gmock-gtest-all.cc gmock/gmock/gmock.h
gmock/gtest/gtest.h gmock/gtest/gtest-spi.h) gmock/gtest/gtest.h gmock/gtest/gtest-spi.h)
find_package(Threads) find_package(Threads)
if (Threads_FOUND) if (Threads_FOUND)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
else () else ()
target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0) target_compile_definitions(gmock PUBLIC GTEST_HAS_PTHREAD=0)
endif () endif ()
# Check if variadic templates are working and not affected by GCC bug 39653: # Check if variadic templates are working and not affected by GCC bug 39653:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653
check_cxx_source_compiles(" check_cxx_source_compiles("
template <class T, class ...Types> template <class T, class ...Types>
struct S { typedef typename S<Types...>::type type; }; struct S { typedef typename S<Types...>::type type; };
int main() {}" FMT_VARIADIC_TEMPLATES) int main() {}" FMT_VARIADIC_TEMPLATES)
# Check if initializer lists are supported. # Check if initializer lists are supported.
check_cxx_source_compiles(" check_cxx_source_compiles("
#include <initializer_list> #include <initializer_list>
int main() {}" FMT_INITIALIZER_LIST) int main() {}" FMT_INITIALIZER_LIST)
if (NOT FMT_VARIADIC_TEMPLATES OR NOT FMT_INITIALIZER_LIST) if (NOT FMT_VARIADIC_TEMPLATES OR NOT FMT_INITIALIZER_LIST)
add_definitions(-DGTEST_LANG_CXX11=0) add_definitions(-DGTEST_LANG_CXX11=0)
endif () endif ()
# This is disabled at the moment because format is compiled without -std=c++11 # This is disabled at the moment because format is compiled without -std=c++11
# by default. # by default.
#check_cxx_source_compiles(" #check_cxx_source_compiles("
# void f() noexcept {} # void f() noexcept {}
# int main(){ f(); }" FMT_BASIC_NOEXCEPT_SUPPORT) # int main(){ f(); }" FMT_BASIC_NOEXCEPT_SUPPORT)
#if (FMT_BASIC_NOEXCEPT_SUPPORT) #if (FMT_BASIC_NOEXCEPT_SUPPORT)
# add_definitions(-DFMT_USE_NOEXCEPT=1) # add_definitions(-DFMT_USE_NOEXCEPT=1)
#endif () #endif ()
#check_cxx_source_compiles(" #check_cxx_source_compiles("
# struct C{ # struct C{
# C()=delete; # C()=delete;
# C(const C&)=delete; # C(const C&)=delete;
# C& operator=(const C&)=delete; # C& operator=(const C&)=delete;
# }; # };
# int main(){}" FMT_DELETED_FUNCTIONS) # int main(){}" FMT_DELETED_FUNCTIONS)
#if (FMT_DELETED_FUNCTIONS) #if (FMT_DELETED_FUNCTIONS)
# add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) # add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1)
#endif () #endif ()
#check_cxx_source_compiles(" #check_cxx_source_compiles("
# static_assert(true, \"\"); # static_assert(true, \"\");
# int main(){}" FMT_STATIC_ASSERT) # int main(){}" FMT_STATIC_ASSERT)
#if (FMT_STATIC_ASSERT) #if (FMT_STATIC_ASSERT)
# add_definitions(-DFMT_USE_STATIC_ASSERT=1) # add_definitions(-DFMT_USE_STATIC_ASSERT=1)
#endif () #endif ()
# Workaround a bug in implementation of variadic templates in MSVC11. # Workaround a bug in implementation of variadic templates in MSVC11.
if (MSVC) if (MSVC)
target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10)
endif () endif ()
# GTest doesn't detect <tuple> with clang. # GTest doesn't detect <tuple> with clang.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1)
endif () endif ()
enable_testing() enable_testing()
add_subdirectory(test) add_subdirectory(test)
endif ()
set(CPACK_PACKAGE_VERSION_MAJOR 1) set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 2) set(CPACK_PACKAGE_VERSION_MINOR 2)