diff --git a/.travis.yml b/.travis.yml index 89b359094666..d6b81a2a6ffa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,10 +25,9 @@ matrix: addons: apt: sources: - - kubuntu-backports # cmake 2.8.12 -# - george-edison55-precise-backports # cmake 3.2.3 + - kubuntu-backports # cmake 2.8.12 packages: - - cmake + - cmake script: - support/travis-build.py diff --git a/CMakeLists.txt b/CMakeLists.txt index ab58c67a7943..940b5d039f14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF) option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT}) option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT}) option(FMT_TEST "Generate the test target." ${MASTER_PROJECT}) -option(FMT_USE_CPP11 "Enable the addition of c++11 compiler flags." ${MASTER_PROJECT}) +option(FMT_USE_CPP11 "Enable the addition of C++11 compiler flags." ON) project(FORMAT) diff --git a/cppformat/CMakeLists.txt b/cppformat/CMakeLists.txt index 576757045531..6422a7f91a64 100644 --- a/cppformat/CMakeLists.txt +++ b/cppformat/CMakeLists.txt @@ -1,5 +1,5 @@ -#------------------------------------------------------------------------------ -# define the cppformat library, its includes and the needed defines +# Define the cppformat library, its includes and the needed defines. +# format.cc is added to FMT_HEADERS for the header-only configuration. set(FMT_HEADERS format.h format.cc) if (HAVE_OPEN) set(FMT_HEADERS ${FMT_HEADERS} posix.h) @@ -8,9 +8,8 @@ endif () add_library(cppformat ${FMT_SOURCES} ${FMT_HEADERS}) -if (FMT_USE_CPP11) - target_compile_options(cppformat PUBLIC ${CPP11_FLAG}) # starting with cmake 3.1 the CXX_STANDARD property can be used -endif () +# Starting with cmake 3.1 the CXX_STANDARD property can be used instead. +target_compile_options(cppformat PUBLIC ${CPP11_FLAG}) if (FMT_PEDANTIC) target_compile_options(cppformat PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () diff --git a/support/cmake/testCxx11.cmake b/support/cmake/testCxx11.cmake index d49ae6d014ca..5f06321e794a 100644 --- a/support/cmake/testCxx11.cmake +++ b/support/cmake/testCxx11.cmake @@ -1,37 +1,37 @@ include(CheckCXXCompilerFlag) -check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG) -if (HAVE_STD_CPP11_FLAG) - # Check if including cmath works with -std=c++11 and -O3. - # It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/. - set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3") - check_cxx_source_compiles(" - #include - int main() {}" FMT_CPP11_CMATH) - # Check if including works with -std=c++11. - # It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/. - check_cxx_source_compiles(" - #include - int main() {}" FMT_CPP11_UNISTD_H) - if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H) - set(CPP11_FLAG -std=c++11) +if (FMT_USE_CPP11) + check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG) + if (HAVE_STD_CPP11_FLAG) + # Check if including cmath works with -std=c++11 and -O3. + # It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/. + set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3") + check_cxx_source_compiles(" + #include + int main() {}" FMT_CPP11_CMATH) + # Check if including works with -std=c++11. + # It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/. + check_cxx_source_compiles(" + #include + int main() {}" FMT_CPP11_UNISTD_H) + if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H) + set(CPP11_FLAG -std=c++11) + else () + check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG) + if (HAVE_STD_CPP11_FLAG) + set(CPP11_FLAG -std=gnu++11) + endif () + endif () + set(CMAKE_REQUIRED_FLAGS ) else () - check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG) - if (HAVE_STD_CPP11_FLAG) - set(CPP11_FLAG -std=gnu++11) + check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG) + if (HAVE_STD_CPP0X_FLAG) + set(CPP11_FLAG -std=c++0x) endif () endif () - set(CMAKE_REQUIRED_FLAGS ) -else () - check_cxx_compiler_flag(-std=c++0x HAVE_STD_CPP0X_FLAG) - if (HAVE_STD_CPP0X_FLAG) - set(CPP11_FLAG -std=c++0x) - endif () endif () -if (FMT_USE_CPP11) - set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) -endif () +set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG}) # Check if variadic templates are working and not affected by GCC bug 39653: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39653 diff --git a/support/travis-build.py b/support/travis-build.py index 65632a6e31ab..a86032f2ed89 100755 --- a/support/travis-build.py +++ b/support/travis-build.py @@ -19,6 +19,8 @@ def makedirs_if_not_exist(dir): if e.errno != errno.EEXIST: raise +cppformat_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + build = os.environ['BUILD'] if build == 'Doc': travis = 'TRAVIS' in os.environ @@ -39,7 +41,6 @@ def makedirs_if_not_exist(dir): urllib.urlretrieve('http://mirrors.kernel.org/ubuntu/pool/main/d/doxygen/' + deb_file, deb_file) check_call(['sudo', 'dpkg', '-i', deb_file]) - cppformat_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.join(cppformat_dir, 'doc')) import build html_dir = build.build_docs() @@ -74,52 +75,39 @@ def makedirs_if_not_exist(dir): raise CalledProcessError(p.returncode, cmd) exit(0) -cppStandard = os.environ['STANDARD'] -srcDir = os.getcwd() -srcDir_test = os.path.join(srcDir,"test","find-package-test") - -installDir = os.path.join(srcDir,"_install") -buildDir = os.path.join(srcDir,"_build") -buildDir_test = os.path.join(srcDir,"_build_test") +standard = os.environ['STANDARD'] +install_dir = os.path.join(cppformat_dir, "_install") +build_dir = os.path.join(cppformat_dir, "_build") +test_build_dir = os.path.join(cppformat_dir, "_build_test") -# configure library -makedirs_if_not_exist(buildDir) -os.chdir(buildDir) -if cppStandard == '0x': - # default configuration - check_call(['cmake', '-DCMAKE_INSTALL_PREFIX='+installDir, - '-DCMAKE_BUILD_TYPE=' + build, - '-DFMT_DOC=OFF', - '-DFMT_PEDANTIC=ON', - srcDir]) -else: - check_call(['cmake', '-DCMAKE_INSTALL_PREFIX='+installDir, - '-DCMAKE_BUILD_TYPE=' + build, - '-DCMAKE_CXX_FLAGS=-std=c++' + cppStandard, - '-DFMT_USE_CPP11=OFF', - '-DFMT_DOC=OFF', - '-DFMT_PEDANTIC=ON', - srcDir]) +# Configure library. +makedirs_if_not_exist(build_dir) +common_cmake_flags = [ + '-DCMAKE_INSTALL_PREFIX=' + install_dir, '-DCMAKE_BUILD_TYPE=' + build +] +extra_cmake_flags = [] +if standard != '0x': + extra_cmake_flags = ['-DCMAKE_CXX_FLAGS=-std=c++' + standard, '-DFMT_USE_CPP11=OFF'] +check_call(['cmake', '-DFMT_DOC=OFF', '-DFMT_PEDANTIC=ON', cppformat_dir] + + common_cmake_flags + extra_cmake_flags, cwd=build_dir) -# build library -check_call(['make', '-j4']) +# Build library. +check_call(['make', '-j4'], cwd=build_dir) -# test library +# Test library. env = os.environ.copy() env['CTEST_OUTPUT_ON_FAILURE'] = '1' -if call(['make', 'test'], env=env): +if call(['make', 'test'], env=env, cwd=build_dir): with open('Testing/Temporary/LastTest.log', 'r') as f: print(f.read()) sys.exit(-1) -# install library -check_call(['make', 'install']) +# Install library. +check_call(['make', 'install'], cwd=build_dir) -# test installation -makedirs_if_not_exist(buildDir_test) -os.chdir(buildDir_test) -check_call(['cmake', '-DCMAKE_INSTALL_PREFIX='+installDir, - '-DCMAKE_BUILD_TYPE=' + build, - '-DCMAKE_CXX_FLAGS=-std=c++' + cppStandard, - srcDir_test]) -check_call(['make', '-j4']) \ No newline at end of file +# Test installation. +makedirs_if_not_exist(test_build_dir) +check_call(['cmake', '-DCMAKE_CXX_FLAGS=-std=c++' + standard, + os.path.join(cppformat_dir, "test", "find-package-test")] + + common_cmake_flags, cwd=test_build_dir) +check_call(['make', '-j4'], cwd=test_build_dir) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bbe5057ec1b..b0ab19d82aee 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,9 +10,7 @@ add_library(gmock STATIC ${FMT_GMOCK_DIR}/gmock-gtest-all.cc ${FMT_GMOCK_DIR}/gmock/gmock.h ${FMT_GMOCK_DIR}/gtest/gtest.h ${FMT_GMOCK_DIR}/gtest/gtest-spi.h) target_include_directories(gmock PUBLIC ${FMT_GMOCK_DIR}) -if (FMT_USE_CPP11) - target_compile_options(gmock PUBLIC ${CPP11_FLAG}) -endif () +target_compile_options(gmock PUBLIC ${CPP11_FLAG}) find_package(Threads) if (Threads_FOUND)