module files are parsed for configuration by default
This commit is contained in:
parent
2e07af6017
commit
faada401f4
@ -2,11 +2,6 @@
|
||||
#
|
||||
# Generates source code that echoes configuration, version, and build
|
||||
# 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)
|
||||
|
||||
|
@ -17,10 +17,8 @@
|
||||
#
|
||||
# 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].
|
||||
# --extra-cc-flags=<EXTRA_CFLAGS> Extra C compiler flags [default: ''].
|
||||
# export: 'CC=%s' % arguments['--cc']
|
||||
|
@ -8,10 +8,8 @@
|
||||
# CMAKE_C_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].
|
||||
# define: '-DENABLE_CODE_COVERAGE=%s' % arguments['--coverage']
|
||||
|
||||
|
@ -17,10 +17,8 @@
|
||||
#
|
||||
# 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++].
|
||||
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
|
||||
# export: 'CXX=%s' % arguments['--cxx']
|
||||
|
@ -7,11 +7,6 @@
|
||||
#
|
||||
# CMAKE_RUNTIME_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_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||
|
@ -21,10 +21,8 @@
|
||||
#
|
||||
# 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].
|
||||
# --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
|
||||
# export: 'FC=%s' % arguments['--fc']
|
||||
|
@ -26,10 +26,8 @@
|
||||
#
|
||||
# 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].
|
||||
# --extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: ''].
|
||||
# --fc-support=<FC_SUPPORT> Toggle Fortran language support (ON/OFF) [default: ON].
|
||||
|
@ -6,10 +6,8 @@
|
||||
#
|
||||
# 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'
|
||||
|
||||
set(GOOGLETEST_ROOT external/googletest CACHE STRING "Google Test source root")
|
||||
|
@ -6,10 +6,8 @@
|
||||
#
|
||||
# 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].
|
||||
# define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64']
|
||||
|
||||
|
@ -36,10 +36,8 @@
|
||||
# MKL_ROOT
|
||||
# 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].
|
||||
# --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].
|
||||
|
@ -11,10 +11,8 @@
|
||||
#
|
||||
# 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].
|
||||
# define: '-DENABLE_MPI=%s' % arguments['--mpi']
|
||||
|
||||
|
@ -13,10 +13,8 @@
|
||||
# CMAKE_C_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].
|
||||
# define: '-DENABLE_OPENMP=%s' % arguments['--omp']
|
||||
|
||||
|
@ -5,10 +5,5 @@
|
||||
# Variables defined::
|
||||
#
|
||||
# PYTHON_EXECUTABLE
|
||||
#
|
||||
# Example autocmake.cfg entry::
|
||||
#
|
||||
# [python]
|
||||
# source: https://github.com/scisoft/autocmake/raw/master/modules/python.cmake
|
||||
|
||||
find_package(PythonInterp REQUIRED)
|
||||
|
@ -7,11 +7,6 @@
|
||||
# PROJECT_SOURCE_DIR
|
||||
# PROJECT_BINARY_DIR
|
||||
# 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})
|
||||
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
|
||||
|
@ -1,10 +1,5 @@
|
||||
#.rst:
|
||||
#
|
||||
# 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)
|
||||
|
@ -8,10 +8,8 @@
|
||||
# CMAKE_C_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].
|
||||
# define: '-DENABLE_STATIC_LINKING=%s' % arguments['--static']
|
||||
|
||||
|
@ -9,11 +9,6 @@
|
||||
# Variables defined::
|
||||
#
|
||||
# PROGRAM_VERSION
|
||||
#
|
||||
# Example autocmake.cfg entry::
|
||||
#
|
||||
# [version]
|
||||
# source: https://github.com/scisoft/autocmake/raw/master/modules/version.cmake
|
||||
|
||||
if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION")
|
||||
file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION)
|
||||
|
@ -3,10 +3,6 @@ name: example
|
||||
|
||||
[cxx]
|
||||
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]
|
||||
source: ../../../modules/default_build_paths.cmake
|
||||
|
@ -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
|
16
test/cxx_custom/cmake/autocmake.cfg
Normal file
16
test/cxx_custom/cmake/autocmake.cfg
Normal 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
|
@ -3,10 +3,6 @@ name: example
|
||||
|
||||
[fc]
|
||||
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]
|
||||
source: ../../../modules/default_build_paths.cmake
|
||||
|
@ -3,27 +3,12 @@ name: example
|
||||
|
||||
[fc]
|
||||
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]
|
||||
source: ../../../modules/int64.cmake
|
||||
docopt: --int64 Enable 64bit integers [default: False].
|
||||
define: '-DENABLE_64BIT_INTEGERS=%s' % arguments['--int64']
|
||||
|
||||
[math_libs]
|
||||
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]
|
||||
source: ../../../modules/default_build_paths.cmake
|
||||
|
@ -107,15 +107,15 @@ def configure_build_and_exe(name, setup_command):
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_cxx():
|
||||
stdout, stderr = configure_build_and_exe('cxx', 'python setup.py --cxx=g++')
|
||||
def test_cxx_custom():
|
||||
stdout, stderr = configure_build_and_exe('cxx_custom', 'python setup.py --cxx=g++')
|
||||
assert 'Hello World!' in stdout
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_cxx_auto():
|
||||
stdout, stderr = configure_build_and_exe('cxx_auto', 'python setup.py --cxx=g++')
|
||||
def test_cxx():
|
||||
stdout, stderr = configure_build_and_exe('cxx', 'python setup.py --cxx=g++')
|
||||
assert 'Hello World!' in stdout
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
45
update.py
45
update.py
@ -258,10 +258,14 @@ def fetch_modules(config, relative_path):
|
||||
else:
|
||||
sys.stderr.write("ERROR: %s does not exist\n" % src)
|
||||
sys.exit(-1)
|
||||
# if auto is true we infer configuration
|
||||
|
||||
# unless config is 'custom' we infer configuration
|
||||
# from the module documentation
|
||||
if config.has_option(section, 'auto'):
|
||||
if config.get(section, 'auto') == 'true':
|
||||
parse_doc = True
|
||||
if config.has_option(section, 'config'):
|
||||
if config.get(section, 'config') == 'custom':
|
||||
parse_doc = False
|
||||
if parse_doc:
|
||||
with open(file_name, 'r') as f:
|
||||
config_docopt, config_define, config_export = parse_cmake_module(f.read())
|
||||
if config_docopt:
|
||||
@ -358,6 +362,13 @@ def main(argv):
|
||||
|
||||
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 = []
|
||||
is_rst_line = False
|
||||
for line in s_in.split('\n'):
|
||||
@ -372,16 +383,16 @@ def parse_cmake_module(s_in):
|
||||
if '#.rst:' in line:
|
||||
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')
|
||||
|
||||
# we prepend a fake section heading so that we can parse it with configparser
|
||||
autocmake_entry = '[foo]\n' + autocmake_entry
|
||||
|
||||
buf = StringIO(autocmake_entry)
|
||||
config = RawConfigParser(dict_type=OrderedDict)
|
||||
config.readfp(buf)
|
||||
|
||||
config_docopt = None
|
||||
config_define = None
|
||||
config_export = None
|
||||
for section in config.sections():
|
||||
if config.has_option(section, 'docopt'):
|
||||
config_docopt = config.get(section, 'docopt')
|
||||
@ -401,10 +412,8 @@ def test_parse_cmake_module():
|
||||
#
|
||||
# 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++].
|
||||
# --extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: ''].
|
||||
# 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: '']."
|
||||
|
||||
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
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user