mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-26 12:35:32 +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:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
sources:
|
||||||
- kubuntu-backports # cmake 2.8.12
|
- kubuntu-backports # cmake 2.8.12
|
||||||
# - george-edison55-precise-backports # cmake 3.2.3
|
|
||||||
packages:
|
packages:
|
||||||
- cmake
|
- cmake
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- support/travis-build.py
|
- 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_DOC "Generate the doc target." ${MASTER_PROJECT})
|
||||||
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
|
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
|
||||||
option(FMT_TEST "Generate the test 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)
|
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)
|
set(FMT_HEADERS format.h format.cc)
|
||||||
if (HAVE_OPEN)
|
if (HAVE_OPEN)
|
||||||
set(FMT_HEADERS ${FMT_HEADERS} posix.h)
|
set(FMT_HEADERS ${FMT_HEADERS} posix.h)
|
||||||
@ -8,9 +8,8 @@ endif ()
|
|||||||
|
|
||||||
add_library(cppformat ${FMT_SOURCES} ${FMT_HEADERS})
|
add_library(cppformat ${FMT_SOURCES} ${FMT_HEADERS})
|
||||||
|
|
||||||
if (FMT_USE_CPP11)
|
# Starting with cmake 3.1 the CXX_STANDARD property can be used instead.
|
||||||
target_compile_options(cppformat PUBLIC ${CPP11_FLAG}) # starting with cmake 3.1 the CXX_STANDARD property can be used
|
target_compile_options(cppformat PUBLIC ${CPP11_FLAG})
|
||||||
endif ()
|
|
||||||
if (FMT_PEDANTIC)
|
if (FMT_PEDANTIC)
|
||||||
target_compile_options(cppformat PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
target_compile_options(cppformat PRIVATE ${PEDANTIC_COMPILE_FLAGS})
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG)
|
if (FMT_USE_CPP11)
|
||||||
if (HAVE_STD_CPP11_FLAG)
|
check_cxx_compiler_flag(-std=c++11 HAVE_STD_CPP11_FLAG)
|
||||||
# Check if including cmath works with -std=c++11 and -O3.
|
if (HAVE_STD_CPP11_FLAG)
|
||||||
# It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/.
|
# Check if including cmath works with -std=c++11 and -O3.
|
||||||
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3")
|
# It may not in MinGW due to bug http://ehc.ac/p/mingw/bugs/2250/.
|
||||||
check_cxx_source_compiles("
|
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3")
|
||||||
#include <cmath>
|
check_cxx_source_compiles("
|
||||||
int main() {}" FMT_CPP11_CMATH)
|
#include <cmath>
|
||||||
# Check if including <unistd.h> works with -std=c++11.
|
int main() {}" FMT_CPP11_CMATH)
|
||||||
# It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/.
|
# Check if including <unistd.h> works with -std=c++11.
|
||||||
check_cxx_source_compiles("
|
# It may not in MinGW due to bug http://sourceforge.net/p/mingw/bugs/2024/.
|
||||||
#include <unistd.h>
|
check_cxx_source_compiles("
|
||||||
int main() {}" FMT_CPP11_UNISTD_H)
|
#include <unistd.h>
|
||||||
if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H)
|
int main() {}" FMT_CPP11_UNISTD_H)
|
||||||
set(CPP11_FLAG -std=c++11)
|
if (FMT_CPP11_CMATH AND FMT_CPP11_UNISTD_H)
|
||||||
else ()
|
set(CPP11_FLAG -std=c++11)
|
||||||
check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG)
|
else ()
|
||||||
if (HAVE_STD_CPP11_FLAG)
|
check_cxx_compiler_flag(-std=gnu++11 HAVE_STD_GNUPP11_FLAG)
|
||||||
set(CPP11_FLAG -std=gnu++11)
|
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 ()
|
||||||
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 ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (FMT_USE_CPP11)
|
set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG})
|
||||||
set(CMAKE_REQUIRED_FLAGS ${CPP11_FLAG})
|
|
||||||
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
|
||||||
|
@ -19,6 +19,8 @@ def makedirs_if_not_exist(dir):
|
|||||||
if e.errno != errno.EEXIST:
|
if e.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
cppformat_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
build = os.environ['BUILD']
|
build = os.environ['BUILD']
|
||||||
if build == 'Doc':
|
if build == 'Doc':
|
||||||
travis = 'TRAVIS' in os.environ
|
travis = 'TRAVIS' in os.environ
|
||||||
@ -39,7 +41,6 @@ if build == 'Doc':
|
|||||||
urllib.urlretrieve('http://mirrors.kernel.org/ubuntu/pool/main/d/doxygen/' +
|
urllib.urlretrieve('http://mirrors.kernel.org/ubuntu/pool/main/d/doxygen/' +
|
||||||
deb_file, deb_file)
|
deb_file, deb_file)
|
||||||
check_call(['sudo', 'dpkg', '-i', 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'))
|
sys.path.insert(0, os.path.join(cppformat_dir, 'doc'))
|
||||||
import build
|
import build
|
||||||
html_dir = build.build_docs()
|
html_dir = build.build_docs()
|
||||||
@ -74,52 +75,39 @@ if build == 'Doc':
|
|||||||
raise CalledProcessError(p.returncode, cmd)
|
raise CalledProcessError(p.returncode, cmd)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
cppStandard = os.environ['STANDARD']
|
standard = os.environ['STANDARD']
|
||||||
srcDir = os.getcwd()
|
install_dir = os.path.join(cppformat_dir, "_install")
|
||||||
srcDir_test = os.path.join(srcDir,"test","find-package-test")
|
build_dir = os.path.join(cppformat_dir, "_build")
|
||||||
|
test_build_dir = os.path.join(cppformat_dir, "_build_test")
|
||||||
|
|
||||||
installDir = os.path.join(srcDir,"_install")
|
# Configure library.
|
||||||
buildDir = os.path.join(srcDir,"_build")
|
makedirs_if_not_exist(build_dir)
|
||||||
buildDir_test = os.path.join(srcDir,"_build_test")
|
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
|
# Build library.
|
||||||
makedirs_if_not_exist(buildDir)
|
check_call(['make', '-j4'], cwd=build_dir)
|
||||||
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
|
# Test library.
|
||||||
check_call(['make', '-j4'])
|
|
||||||
|
|
||||||
# test library
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['CTEST_OUTPUT_ON_FAILURE'] = '1'
|
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:
|
with open('Testing/Temporary/LastTest.log', 'r') as f:
|
||||||
print(f.read())
|
print(f.read())
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# install library
|
# Install library.
|
||||||
check_call(['make', 'install'])
|
check_call(['make', 'install'], cwd=build_dir)
|
||||||
|
|
||||||
# test installation
|
# Test installation.
|
||||||
makedirs_if_not_exist(buildDir_test)
|
makedirs_if_not_exist(test_build_dir)
|
||||||
os.chdir(buildDir_test)
|
check_call(['cmake', '-DCMAKE_CXX_FLAGS=-std=c++' + standard,
|
||||||
check_call(['cmake', '-DCMAKE_INSTALL_PREFIX='+installDir,
|
os.path.join(cppformat_dir, "test", "find-package-test")] +
|
||||||
'-DCMAKE_BUILD_TYPE=' + build,
|
common_cmake_flags, cwd=test_build_dir)
|
||||||
'-DCMAKE_CXX_FLAGS=-std=c++' + cppStandard,
|
check_call(['make', '-j4'], cwd=test_build_dir)
|
||||||
srcDir_test])
|
|
||||||
check_call(['make', '-j4'])
|
|
||||||
|
@ -10,9 +10,7 @@ add_library(gmock STATIC
|
|||||||
${FMT_GMOCK_DIR}/gmock-gtest-all.cc ${FMT_GMOCK_DIR}/gmock/gmock.h
|
${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)
|
${FMT_GMOCK_DIR}/gtest/gtest.h ${FMT_GMOCK_DIR}/gtest/gtest-spi.h)
|
||||||
target_include_directories(gmock PUBLIC ${FMT_GMOCK_DIR})
|
target_include_directories(gmock PUBLIC ${FMT_GMOCK_DIR})
|
||||||
if (FMT_USE_CPP11)
|
target_compile_options(gmock PUBLIC ${CPP11_FLAG})
|
||||||
target_compile_options(gmock PUBLIC ${CPP11_FLAG})
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
if (Threads_FOUND)
|
if (Threads_FOUND)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user