Simplify build config and enable C++11 by default

This commit is contained in:
vitaut
2016-02-09 08:43:39 -08:00
parent c7b7141b11
commit b8c6192a61
6 changed files with 64 additions and 80 deletions

View File

@ -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

View File

@ -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)