Merge branch 'master' into yaml

This commit is contained in:
Radovan Bast 2016-04-18 11:53:44 +02:00
commit 806564e2e8
5 changed files with 81 additions and 43 deletions

View File

@ -7,9 +7,5 @@ Autocmake update and test scripts require Python 2.7 or higher. We try to also
support Python 3 (tested with Python 3.4). If the script fails with Python 3,
consider this a bug and please file an issue.
The generated setup script runs with Python >= 2.7 (also tested with Python
The generated setup script runs with Python >= 2.6 (also tested with Python
3.4; probably also lower).
.. todo::
Figure out lower Python version bound for setup.

View File

@ -23,7 +23,7 @@ def check_cmake_exists(cmake_command):
"""
from subprocess import Popen, PIPE
p = Popen('{} --version'.format(cmake_command),
p = Popen('{0} --version'.format(cmake_command),
shell=True,
stdin=PIPE,
stdout=PIPE)
@ -46,7 +46,7 @@ def setup_build_path(build_path):
fname = os.path.join(build_path, 'CMakeCache.txt')
if os.path.exists(fname):
sys.stderr.write('aborting setup\n')
sys.stderr.write('build directory {} which contains CMakeCache.txt already exists\n'.format(build_path))
sys.stderr.write('build directory {0} which contains CMakeCache.txt already exists\n'.format(build_path))
sys.stderr.write('remove the build directory and then rerun setup\n')
sys.exit(1)
else:
@ -74,7 +74,7 @@ def adapt_cmake_command_to_platform(cmake_command, platform):
"""
if platform == 'win32':
pos = cmake_command.find('cmake')
s = ['set {} &&'.format(e) for e in cmake_command[:pos].split()]
s = ['set {0} &&'.format(e) for e in cmake_command[:pos].split()]
s.append(cmake_command[pos:])
return ' '.join(s)
else:
@ -159,7 +159,7 @@ def configure(root_directory, build_path, cmake_command, only_show):
cmake_command = adapt_cmake_command_to_platform(cmake_command, sys.platform)
print('{}\n'.format(cmake_command))
print('{0}\n'.format(cmake_command))
if only_show:
sys.exit(0)

43
modules/save_flags.cmake Normal file
View File

@ -0,0 +1,43 @@
#.rst:
#
# Take care of updating the cache for fresh configurations.
#
# Variables modified (provided the corresponding language is enabled)::
#
# DEFAULT_Fortran_FLAGS_SET
# DEFAULT_C_FLAGS_SET
# DEFAULT_CXX_FLAGS_SET
macro(save_compiler_flags lang)
if (NOT DEFINED DEFAULT_${lang}_FLAGS_SET)
mark_as_advanced(DEFAULT_${lang}_FLAGS_SET)
set (DEFAULT_${lang}_FLAGS_SET ON
CACHE INTERNAL
"Flag that the default ${lang} compiler flags have been set.")
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}"
CACHE STRING
"Flags used by the compiler during all builds." FORCE)
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}"
CACHE STRING
"Flags used by the compiler during debug builds." FORCE)
set(CMAKE_${lang}_FLAGS_RELEASE "${CMAKE_${lang}_FLAGS_RELEASE}"
CACHE STRING
"Flags used by the compiler during release builds." FORCE)
endif()
endmacro()
if(DEFINED CMAKE_Fortran_COMPILER_ID)
save_compiler_flags(Fortran)
endif()
if(DEFINED CMAKE_C_COMPILER_ID)
save_compiler_flags(C)
endif()
if(DEFINED CMAKE_CXX_COMPILER_ID)
save_compiler_flags(CXX)
endif()

View File

@ -151,7 +151,7 @@ def test_python_libs():
def test_python_libs_custom():
python_executable = sys.executable
configure_build_and_exe('python_libs_custom', 'python setup --cxx=g++ --python={}'.format(python_executable))
configure_build_and_exe('python_libs_custom', 'python setup --cxx=g++ --python={0}'.format(python_executable))
def test_boost_header_only():

View File

@ -14,7 +14,7 @@ if sys.version_info[0] > 2:
class URLopener(urllib.request.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
sys.stderr.write("ERROR: could not fetch {}\n".format(url))
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
sys.exit(-1)
else:
from StringIO import StringIO
@ -22,7 +22,7 @@ else:
class URLopener(urllib.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
sys.stderr.write("ERROR: could not fetch {}\n".format(url))
sys.stderr.write("ERROR: could not fetch {0}\n".format(url))
sys.exit(-1)
@ -133,8 +133,7 @@ def print_progress_bar(text, done, total, width):
Print progress bar.
"""
n = int(float(width) * float(done) / float(total))
sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n,
' ' * (width - n), done, total))
sys.stdout.write("\r{0} [{1}{2}] ({3}/{4})".format(text, '#' * n, ' ' * (width - n), done, total))
sys.stdout.flush()
# ------------------------------------------------------------------------------
@ -172,7 +171,7 @@ def gen_cmake_command(config):
for section in config.sections():
if config.has_option(section, 'export'):
for env in config.get(section, 'export').split('\n'):
s.append(' command.append({})'.format(env))
s.append(' command.append({0})'.format(env))
s.append(" command.append(arguments['--cmake-executable'])")
@ -180,10 +179,10 @@ def gen_cmake_command(config):
for section in config.sections():
if config.has_option(section, 'define'):
for definition in config.get(section, 'define').split('\n'):
s.append(' command.append({})'.format(definition))
s.append(' command.append({0})'.format(definition))
s.append(" command.append('-DCMAKE_BUILD_TYPE={}'.format(arguments['--type']))")
s.append(" command.append('-G \"{}\"'.format(arguments['--generator']))")
s.append(" command.append('-DCMAKE_BUILD_TYPE={0}'.format(arguments['--type']))")
s.append(" command.append('-G \"{0}\"'.format(arguments['--generator']))")
s.append(" if arguments['--cmake-options'] != \"''\":")
s.append(" command.append(arguments['--cmake-options'])")
s.append(" if arguments['--prefix']:")
@ -198,10 +197,10 @@ def gen_cmake_command(config):
def autogenerated_notice():
current_year = datetime.date.today().year
year_range = '2015-{}'.format(current_year)
year_range = '2015-{0}'.format(current_year)
s = []
s.append('# This file is autogenerated by Autocmake http://autocmake.org')
s.append('# Copyright (c) {} by Radovan Bast and Jonas Juselius'.format(year_range))
s.append('# Copyright (c) {0} by Radovan Bast and Jonas Juselius'.format(year_range))
return '\n'.join(s)
# ------------------------------------------------------------------------------
@ -213,7 +212,7 @@ def gen_setup(config, relative_path, setup_script_name):
"""
s = []
s.append('#!/usr/bin/env python')
s.append('\n{}'.format(autogenerated_notice()))
s.append('\n{0}'.format(autogenerated_notice()))
s.append('\nimport os')
s.append('import sys')
@ -258,7 +257,7 @@ def gen_setup(config, relative_path, setup_script_name):
s.append("try:")
s.append(" arguments = docopt.docopt(options, argv=None)")
s.append("except docopt.DocoptExit:")
s.append(r" sys.stderr.write('ERROR: bad input to {}\n'.format(sys.argv[0]))")
s.append(r" sys.stderr.write('ERROR: bad input to {0}\n'.format(sys.argv[0]))")
s.append(" sys.stderr.write(options)")
s.append(" sys.exit(-1)")
s.append("\n")
@ -291,10 +290,10 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
s.append(autogenerated_notice())
s.append('\n# set minimum cmake version')
s.append('cmake_minimum_required(VERSION {} FATAL_ERROR)'.format(min_cmake_version))
s.append('cmake_minimum_required(VERSION {0} FATAL_ERROR)'.format(min_cmake_version))
s.append('\n# project name')
s.append('project({})'.format(project_name))
s.append('project({0})'.format(project_name))
s.append('\n# do not rebuild if rules (compiler flags) change')
s.append('set(CMAKE_SKIP_RULE_DEPENDENCY TRUE)')
@ -315,12 +314,12 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
rel_cmake_module_path = os.path.join(relative_path, directory)
# on windows cmake corrects this so we have to make it wrong again
rel_cmake_module_path = rel_cmake_module_path.replace('\\', '/')
s.append('set(CMAKE_MODULE_PATH ${{CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{})'.format(rel_cmake_module_path))
s.append('set(CMAKE_MODULE_PATH ${{CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{0})'.format(rel_cmake_module_path))
if len(modules) > 0:
s.append('\n# included cmake modules')
for module in modules:
s.append('include({})'.format(os.path.splitext(module.name)[0]))
s.append('include({0})'.format(os.path.splitext(module.name)[0]))
return s
@ -335,7 +334,7 @@ def prepend_or_set(config, section, option, value, defaults):
"""
if value:
if config.has_option(section, option):
value += '\n{}'.format(config.get(section, option, 0, defaults))
value += '\n{0}'.format(config.get(section, option, 0, defaults))
config.set(section, option, value)
return config
@ -370,8 +369,8 @@ def fetch_modules(config, relative_path):
module_name = os.path.basename(src)
if 'http' in src:
path = download_directory
name = 'autocmake_{}'.format(module_name)
dst = os.path.join(download_directory, 'autocmake_{}'.format(module_name))
name = 'autocmake_{0}'.format(module_name)
dst = os.path.join(download_directory, 'autocmake_{0}'.format(module_name))
fetch_url(src, dst)
file_name = dst
fetch_dst_directory = download_directory
@ -382,7 +381,7 @@ def fetch_modules(config, relative_path):
file_name = src
fetch_dst_directory = path
else:
sys.stderr.write("ERROR: {} does not exist\n".format(src))
sys.stderr.write("ERROR: {0} does not exist\n".format(src))
sys.exit(-1)
if config.has_option(section, 'override'):
@ -420,7 +419,7 @@ def fetch_modules(config, relative_path):
print('')
if warnings != []:
print('- {}'.format('\n- '.join(warnings)))
print('- {0}'.format('\n- '.join(warnings)))
return modules
@ -435,11 +434,11 @@ def main(argv):
sys.stderr.write("\nYou can update a project in two steps.\n\n")
sys.stderr.write("Step 1: Update or create infrastructure files\n")
sys.stderr.write(" which will be needed to configure and build the project:\n")
sys.stderr.write(" $ {} --self\n\n".format(argv[0]))
sys.stderr.write(" $ {0} --self\n\n".format(argv[0]))
sys.stderr.write("Step 2: Create CMakeLists.txt and setup script in PROJECT_ROOT:\n")
sys.stderr.write(" $ {} <PROJECT_ROOT>\n".format(argv[0]))
sys.stderr.write(" $ {0} <PROJECT_ROOT>\n".format(argv[0]))
sys.stderr.write(" example:\n")
sys.stderr.write(" $ {} ..\n".format(argv[0]))
sys.stderr.write(" $ {0} ..\n".format(argv[0]))
sys.exit(-1)
if argv[1] in ['-h', '--help']:
@ -454,7 +453,7 @@ def main(argv):
if not os.path.isfile('autocmake.yml'):
print('- fetching example autocmake.yml') # FIXME
fetch_url(
src='{}/raw/master/example/autocmake.yml'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/example/autocmake.cfg'.format(AUTOCMAKE_GITHUB_URL),
dst='autocmake.yml'
)
if not os.path.isfile('.gitignore'):
@ -463,24 +462,24 @@ def main(argv):
f.write('*.pyc\n')
print('- fetching lib/config.py')
fetch_url(
src='{}/raw/master/lib/config.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/lib/config.py'.format(AUTOCMAKE_GITHUB_URL),
dst='lib/config.py'
)
print('- fetching lib/docopt/docopt.py')
fetch_url(
src='{}/raw/master/lib/docopt/docopt.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/lib/docopt/docopt.py'.format(AUTOCMAKE_GITHUB_URL),
dst='lib/docopt/docopt.py'
)
print('- fetching update.py')
fetch_url(
src='{}/raw/master/update.py'.format(AUTOCMAKE_GITHUB_URL),
src='{0}/raw/master/update.py'.format(AUTOCMAKE_GITHUB_URL),
dst='update.py'
)
sys.exit(0)
project_root = argv[1]
if not os.path.isdir(project_root):
sys.stderr.write("ERROR: {} is not a directory\n".format(project_root))
sys.stderr.write("ERROR: {0} is not a directory\n".format(project_root))
sys.exit(-1)
# read config file
@ -517,14 +516,14 @@ def main(argv):
print('- generating CMakeLists.txt')
s = gen_cmakelists(project_name, min_cmake_version, relative_path, modules)
with open(os.path.join(project_root, 'CMakeLists.txt'), 'w') as f:
f.write('{}\n'.format('\n'.join(s)))
f.write('{0}\n'.format('\n'.join(s)))
# create setup script
print('- generating setup script')
s = gen_setup(config, relative_path, setup_script_name)
file_path = os.path.join(project_root, setup_script_name)
with open(file_path, 'w') as f:
f.write('{}\n'.format('\n'.join(s)))
f.write('{0}\n'.format('\n'.join(s)))
if sys.platform != 'win32':
make_executable(file_path)
@ -592,8 +591,8 @@ def test_parse_cmake_module():
#
# docopt: --cxx=<CXX> C++ compiler [default: g++].
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
# export: 'CXX={}'.format(arguments['--cxx'])
# define: '-DEXTRA_CXXFLAGS="{}"'.format(arguments['--extra-cxx-flags'])
# export: 'CXX={0}'.format(arguments['--cxx'])
# define: '-DEXTRA_CXXFLAGS="{0}"'.format(arguments['--extra-cxx-flags'])
enable_language(CXX)