mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 21:16:56 +00:00
Simplify build config and enable C++11 by default
This commit is contained in:
parent
c7b7141b11
commit
b8c6192a61
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 ()
|
||||
|
@ -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 <cmath>
|
||||
int main() {}" FMT_CPP11_CMATH)
|
||||
# Check if including <unistd.h> 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 <unistd.h>
|
||||
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)
|
||||
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 <cmath>
|
||||
int main() {}" FMT_CPP11_CMATH)
|
||||
# Check if including <unistd.h> 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 <unistd.h>
|
||||
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=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
|
||||
|
@ -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 @@ if build == 'Doc':
|
||||
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 @@ if build == 'Doc':
|
||||
raise CalledProcessError(p.returncode, cmd)
|
||||
exit(0)
|
||||
|
||||
cppStandard = os.environ['STANDARD']
|
||||
srcDir = os.getcwd()
|
||||
srcDir_test = os.path.join(srcDir,"test","find-package-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")
|
||||
|
||||
installDir = os.path.join(srcDir,"_install")
|
||||
buildDir = os.path.join(srcDir,"_build")
|
||||
buildDir_test = os.path.join(srcDir,"_build_test")
|
||||
# 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)
|
||||
|
||||
# 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])
|
||||
# Build library.
|
||||
check_call(['make', '-j4'], cwd=build_dir)
|
||||
|
||||
# build library
|
||||
check_call(['make', '-j4'])
|
||||
|
||||
# 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'])
|
||||
# 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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user