Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CMake option to toggle tests (on by default) #198

Merged
merged 1 commit into from
Aug 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 77 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -108,88 +109,92 @@ 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
PROPERTIES COMPILE_FLAGS "${FMT_EXTRA_COMPILE_FLAGS}")

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 <class T, class ...Types>
struct S { typedef typename S<Types...>::type type; };
int main() {}" FMT_VARIADIC_TEMPLATES)

# Check if initializer lists are supported.
check_cxx_source_compiles("
#include <initializer_list>
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)
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 <tuple> with clang.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1)
# 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 <class T, class ...Types>
struct S { typedef typename S<Types...>::type type; };
int main() {}" FMT_VARIADIC_TEMPLATES)

# Check if initializer lists are supported.
check_cxx_source_compiles("
#include <initializer_list>
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 <tuple> 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 ()

enable_testing()
add_subdirectory(test)

set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 2)
set(CPACK_PACKAGE_VERSION_PATCH 0)
Expand Down