module files are parsed for configuration by default

This commit is contained in:
Radovan Bast 2015-07-28 12:22:11 +02:00
parent 2e07af6017
commit faada401f4
26 changed files with 74 additions and 122 deletions

View File

@ -2,11 +2,6 @@
# #
# Generates source code that echoes configuration, version, and build # Generates source code that echoes configuration, version, and build
# information to the program output. # information to the program output.
#
# Example autocmake.cfg entry::
#
# [build_info]
# source: https://github.com/scisoft/autocmake/raw/master/modules/build_info.cmake
find_package(PythonInterp REQUIRED) find_package(PythonInterp REQUIRED)

View File

@ -17,10 +17,8 @@
# #
# CFLAGS # CFLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [cc]
# source: https://github.com/scisoft/autocmake/raw/master/modules/cc.cmake
# docopt: --cc=<CC> C compiler [default: gcc]. # docopt: --cc=<CC> C compiler [default: gcc].
# --extra-cc-flags=<EXTRA_CFLAGS> Extra C compiler flags [default: '']. # --extra-cc-flags=<EXTRA_CFLAGS> Extra C compiler flags [default: ''].
# export: 'CC=%s' % arguments['--cc'] # export: 'CC=%s' % arguments['--cc']

View File

@ -8,10 +8,8 @@
# CMAKE_C_FLAGS # CMAKE_C_FLAGS
# CMAKE_CXX_FLAGS # CMAKE_CXX_FLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [coverage]
# source: https://github.com/scisoft/autocmake/raw/master/modules/code_coverage.cmake
# docopt: --coverage Enable code coverage [default: False]. # docopt: --coverage Enable code coverage [default: False].
# define: '-DENABLE_CODE_COVERAGE=%s' % arguments['--coverage'] # define: '-DENABLE_CODE_COVERAGE=%s' % arguments['--coverage']

View File

@ -17,10 +17,8 @@
# #
# CXXFLAGS # CXXFLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [cxx]
# source: https://github.com/scisoft/autocmake/raw/master/modules/cxx.cmake
# docopt: --cxx=<CXX> C++ compiler [default: g++]. # docopt: --cxx=<CXX> C++ compiler [default: g++].
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']. # --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
# export: 'CXX=%s' % arguments['--cxx'] # export: 'CXX=%s' % arguments['--cxx']

View File

@ -7,11 +7,6 @@
# #
# CMAKE_RUNTIME_OUTPUT_DIRECTORY # CMAKE_RUNTIME_OUTPUT_DIRECTORY
# CMAKE_LIBRARY_OUTPUT_DIRECTORY # CMAKE_LIBRARY_OUTPUT_DIRECTORY
#
# Example autocmake.cfg entry::
#
# [default_build_paths]
# source: https://github.com/scisoft/autocmake/raw/master/modules/default_build_paths.cmake
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

View File

@ -21,10 +21,8 @@
# #
# FCFLAGS # FCFLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [fc]
# source: https://github.com/scisoft/autocmake/raw/master/modules/fc.cmake
# docopt: --fc=<FC> Fortran compiler [default: gfortran]. # docopt: --fc=<FC> Fortran compiler [default: gfortran].
# --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: '']. # --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
# export: 'FC=%s' % arguments['--fc'] # export: 'FC=%s' % arguments['--fc']

View File

@ -26,10 +26,8 @@
# #
# FCFLAGS # FCFLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [fc]
# source: https://github.com/scisoft/autocmake/raw/master/modules/fc.cmake
# docopt: --fc=<FC> Fortran compiler [default: gfortran]. # docopt: --fc=<FC> Fortran compiler [default: gfortran].
# --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: '']. # --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
# --fc-support=<FC_SUPPORT> Toggle Fortran language support (ON/OFF) [default: ON]. # --fc-support=<FC_SUPPORT> Toggle Fortran language support (ON/OFF) [default: ON].

View File

@ -6,10 +6,8 @@
# #
# GOOGLETEST_ROOT # GOOGLETEST_ROOT
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [googletest]
# source: https://github.com/scisoft/autocmake/raw/master/modules/googletest.cmake
# define: '-DGOOGLETEST_ROOT=external/googletest' # define: '-DGOOGLETEST_ROOT=external/googletest'
set(GOOGLETEST_ROOT external/googletest CACHE STRING "Google Test source root") set(GOOGLETEST_ROOT external/googletest CACHE STRING "Google Test source root")

View File

@ -6,10 +6,8 @@
# #
# CMAKE_Fortran_FLAGS # CMAKE_Fortran_FLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [int64]
# source: https://github.com/scisoft/autocmake/raw/master/modules/int64.cmake
# docopt: --int64 Enable 64bit integers [default: False]. # docopt: --int64 Enable 64bit integers [default: False].
# define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64'] # define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64']

View File

@ -36,10 +36,8 @@
# MKL_ROOT # MKL_ROOT
# MKLROOT # MKLROOT
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [math_libs]
# source: https://github.com/scisoft/autocmake/raw/master/modules/math_libs.cmake
# docopt: --blas=<BLAS> Detect and link BLAS library (auto or off) [default: auto]. # docopt: --blas=<BLAS> Detect and link BLAS library (auto or off) [default: auto].
# --lapack=<LAPACK> Detect and link LAPACK library (auto or off) [default: auto]. # --lapack=<LAPACK> Detect and link LAPACK library (auto or off) [default: auto].
# --mkl=<MKL> Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off]. # --mkl=<MKL> Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off].

View File

@ -11,10 +11,8 @@
# #
# CMAKE_Fortran_FLAGS # CMAKE_Fortran_FLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [mpi]
# source: https://github.com/scisoft/autocmake/raw/master/modules/mpi.cmake
# docopt: --mpi Enable MPI parallelization [default: False]. # docopt: --mpi Enable MPI parallelization [default: False].
# define: '-DENABLE_MPI=%s' % arguments['--mpi'] # define: '-DENABLE_MPI=%s' % arguments['--mpi']

View File

@ -13,10 +13,8 @@
# CMAKE_C_FLAGS # CMAKE_C_FLAGS
# CMAKE_CXX_FLAGS # CMAKE_CXX_FLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [omp]
# source: https://github.com/scisoft/autocmake/raw/master/modules/omp.cmake
# docopt: --omp Enable OpenMP parallelization [default: False]. # docopt: --omp Enable OpenMP parallelization [default: False].
# define: '-DENABLE_OPENMP=%s' % arguments['--omp'] # define: '-DENABLE_OPENMP=%s' % arguments['--omp']

View File

@ -5,10 +5,5 @@
# Variables defined:: # Variables defined::
# #
# PYTHON_EXECUTABLE # PYTHON_EXECUTABLE
#
# Example autocmake.cfg entry::
#
# [python]
# source: https://github.com/scisoft/autocmake/raw/master/modules/python.cmake
find_package(PythonInterp REQUIRED) find_package(PythonInterp REQUIRED)

View File

@ -7,11 +7,6 @@
# PROJECT_SOURCE_DIR # PROJECT_SOURCE_DIR
# PROJECT_BINARY_DIR # PROJECT_BINARY_DIR
# CMAKE_BUILD_TYPE # CMAKE_BUILD_TYPE
#
# Example autocmake.cfg entry::
#
# [safeguards]
# source: https://github.com/scisoft/autocmake/raw/master/modules/safeguards.cmake
if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")

View File

@ -1,10 +1,5 @@
#.rst: #.rst:
# #
# Adds ${PROJECT_SOURCE_DIR}/src as subdirectory containing CMakeLists.txt. # Adds ${PROJECT_SOURCE_DIR}/src as subdirectory containing CMakeLists.txt.
#
# Example autocmake.cfg entry::
#
# [src]
# source: https://github.com/scisoft/autocmake/raw/master/modules/src.cmake
add_subdirectory(${PROJECT_SOURCE_DIR}/src) add_subdirectory(${PROJECT_SOURCE_DIR}/src)

View File

@ -8,10 +8,8 @@
# CMAKE_C_FLAGS # CMAKE_C_FLAGS
# CMAKE_CXX_FLAGS # CMAKE_CXX_FLAGS
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [static_linking]
# source: https://github.com/scisoft/autocmake/raw/master/modules/static_linking.cmake
# docopt: --static Enable static linking [default: False]. # docopt: --static Enable static linking [default: False].
# define: '-DENABLE_STATIC_LINKING=%s' % arguments['--static'] # define: '-DENABLE_STATIC_LINKING=%s' % arguments['--static']

View File

@ -9,11 +9,6 @@
# Variables defined:: # Variables defined::
# #
# PROGRAM_VERSION # PROGRAM_VERSION
#
# Example autocmake.cfg entry::
#
# [version]
# source: https://github.com/scisoft/autocmake/raw/master/modules/version.cmake
if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION") if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION")
file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION) file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION)

View File

@ -3,10 +3,6 @@ name: example
[cxx] [cxx]
source: ../../../modules/cxx.cmake source: ../../../modules/cxx.cmake
docopt: --cxx=<CXX> C++ compiler [default: g++].
--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
export: 'CXX=%s' % arguments['--cxx']
define: '-DEXTRA_CXXFLAGS="%s"' % arguments['--extra-cxx-flags']
[default_build_paths] [default_build_paths]
source: ../../../modules/default_build_paths.cmake source: ../../../modules/default_build_paths.cmake

View File

@ -1,14 +0,0 @@
[project]
name: example
[cxx]
source: ../../../modules/cxx.cmake
auto: true
[default_build_paths]
source: ../../../modules/default_build_paths.cmake
auto: true
[src]
source: ../../../modules/src.cmake
auto: true

View File

@ -0,0 +1,16 @@
[project]
name: example
[cxx]
source: ../../../modules/cxx.cmake
config: custom
docopt: --cxx=<CXX> C++ compiler [default: g++].
--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
export: 'CXX=%s' % arguments['--cxx']
define: '-DEXTRA_CXXFLAGS="%s"' % arguments['--extra-cxx-flags']
[default_build_paths]
source: ../../../modules/default_build_paths.cmake
[src]
source: ../../../modules/src.cmake

View File

@ -3,10 +3,6 @@ name: example
[fc] [fc]
source: ../../../modules/fc.cmake source: ../../../modules/fc.cmake
docopt: --fc=<FC> Fortran compiler [default: gfortran].
--extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
export: 'FC=%s' % arguments['--fc']
define: '-DEXTRA_FCFLAGS="%s"' % arguments['--extra-fc-flags']
[default_build_paths] [default_build_paths]
source: ../../../modules/default_build_paths.cmake source: ../../../modules/default_build_paths.cmake

View File

@ -3,27 +3,12 @@ name: example
[fc] [fc]
source: ../../../modules/fc.cmake source: ../../../modules/fc.cmake
docopt: --fc=<FC> Fortran compiler [default: gfortran].
--extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
export: 'FC=%s' % arguments['--fc']
define: '-DEXTRA_FCFLAGS="%s"' % arguments['--extra-fc-flags']
[int64] [int64]
source: ../../../modules/int64.cmake source: ../../../modules/int64.cmake
docopt: --int64 Enable 64bit integers [default: False].
define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64']
[math_libs] [math_libs]
source: ../../../modules/math_libs.cmake source: ../../../modules/math_libs.cmake
docopt: --blas=<BLAS> Detect and link BLAS library (auto or off) [default: auto].
--lapack=<LAPACK> Detect and link LAPACK library (auto or off) [default: auto].
--mkl=<MKL> Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off].
define: '-DENABLE_BLAS=%s' % arguments['--blas']
'-DENABLE_LAPACK=%s' % arguments['--lapack']
'-DMKL_FLAG=%s' % arguments['--mkl']
'-DMATH_LIB_SEARCH_ORDER="MKL;ESSL;ATLAS;ACML;SYSTEM_NATIVE"'
'-DBLAS_LANG=Fortran'
'-DLAPACK_LANG=Fortran'
[default_build_paths] [default_build_paths]
source: ../../../modules/default_build_paths.cmake source: ../../../modules/default_build_paths.cmake

View File

@ -107,15 +107,15 @@ def configure_build_and_exe(name, setup_command):
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
def test_cxx(): def test_cxx_custom():
stdout, stderr = configure_build_and_exe('cxx', 'python setup.py --cxx=g++') stdout, stderr = configure_build_and_exe('cxx_custom', 'python setup.py --cxx=g++')
assert 'Hello World!' in stdout assert 'Hello World!' in stdout
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
def test_cxx_auto(): def test_cxx():
stdout, stderr = configure_build_and_exe('cxx_auto', 'python setup.py --cxx=g++') stdout, stderr = configure_build_and_exe('cxx', 'python setup.py --cxx=g++')
assert 'Hello World!' in stdout assert 'Hello World!' in stdout
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -258,18 +258,22 @@ def fetch_modules(config, relative_path):
else: else:
sys.stderr.write("ERROR: %s does not exist\n" % src) sys.stderr.write("ERROR: %s does not exist\n" % src)
sys.exit(-1) sys.exit(-1)
# if auto is true we infer configuration
# unless config is 'custom' we infer configuration
# from the module documentation # from the module documentation
if config.has_option(section, 'auto'): parse_doc = True
if config.get(section, 'auto') == 'true': if config.has_option(section, 'config'):
with open(file_name, 'r') as f: if config.get(section, 'config') == 'custom':
config_docopt, config_define, config_export = parse_cmake_module(f.read()) parse_doc = False
if config_docopt: if parse_doc:
config.set(section, 'docopt', config_docopt) with open(file_name, 'r') as f:
if config_define: config_docopt, config_define, config_export = parse_cmake_module(f.read())
config.set(section, 'define', config_define) if config_docopt:
if config_export: config.set(section, 'docopt', config_docopt)
config.set(section, 'export', config_export) if config_define:
config.set(section, 'define', config_define)
if config_export:
config.set(section, 'export', config_export)
modules.append(Module(path=path, name=name)) modules.append(Module(path=path, name=name))
i += 1 i += 1
print_progress_bar( print_progress_bar(
@ -358,6 +362,13 @@ def main(argv):
def parse_cmake_module(s_in): def parse_cmake_module(s_in):
config_docopt = None
config_define = None
config_export = None
if 'autocmake.cfg configuration::' not in s_in:
return config_docopt, config_define, config_export
s_out = [] s_out = []
is_rst_line = False is_rst_line = False
for line in s_in.split('\n'): for line in s_in.split('\n'):
@ -372,16 +383,16 @@ def parse_cmake_module(s_in):
if '#.rst:' in line: if '#.rst:' in line:
is_rst_line = True is_rst_line = True
autocmake_entry = '\n'.join(s_out).split('Example autocmake.cfg entry::')[1] autocmake_entry = '\n'.join(s_out).split('autocmake.cfg configuration::')[1]
autocmake_entry = autocmake_entry.replace('\n ', '\n') autocmake_entry = autocmake_entry.replace('\n ', '\n')
# we prepend a fake section heading so that we can parse it with configparser
autocmake_entry = '[foo]\n' + autocmake_entry
buf = StringIO(autocmake_entry) buf = StringIO(autocmake_entry)
config = RawConfigParser(dict_type=OrderedDict) config = RawConfigParser(dict_type=OrderedDict)
config.readfp(buf) config.readfp(buf)
config_docopt = None
config_define = None
config_export = None
for section in config.sections(): for section in config.sections():
if config.has_option(section, 'docopt'): if config.has_option(section, 'docopt'):
config_docopt = config.get(section, 'docopt') config_docopt = config.get(section, 'docopt')
@ -401,10 +412,8 @@ def test_parse_cmake_module():
# #
# Foo ... # Foo ...
# #
# Example autocmake.cfg entry:: # autocmake.cfg configuration::
# #
# [cxx]
# source: https://github.com/scisoft/autocmake/raw/master/modules/cxx.cmake
# docopt: --cxx=<CXX> C++ compiler [default: g++]. # docopt: --cxx=<CXX> C++ compiler [default: g++].
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']. # --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
# export: 'CXX=%s' % arguments['--cxx'] # export: 'CXX=%s' % arguments['--cxx']
@ -420,6 +429,22 @@ endif()'''
assert config_docopt == "--cxx=<CXX> C++ compiler [default: g++].\n--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']." assert config_docopt == "--cxx=<CXX> C++ compiler [default: g++].\n--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']."
s = '''#.rst:
#
# Foo ...
#
# Bar ...
enable_language(CXX)
if(NOT DEFINED CMAKE_C_COMPILER_ID)
message(FATAL_ERROR "CMAKE_C_COMPILER_ID variable is not defined!")
endif()'''
config_docopt, config_define, config_export = parse_cmake_module(s)
assert config_docopt is None
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------