From faada401f44f23cf118cb0fbf1fb7ccdca0176c8 Mon Sep 17 00:00:00 2001 From: Radovan Bast Date: Tue, 28 Jul 2015 12:22:11 +0200 Subject: [PATCH] module files are parsed for configuration by default --- modules/build_info.cmake | 5 -- modules/cc.cmake | 4 +- modules/code_coverage.cmake | 4 +- modules/cxx.cmake | 4 +- modules/default_build_paths.cmake | 5 -- modules/fc.cmake | 4 +- modules/fc_optional.cmake | 4 +- modules/googletest.cmake | 4 +- modules/int64.cmake | 4 +- modules/math_libs.cmake | 4 +- modules/mpi.cmake | 4 +- modules/omp.cmake | 4 +- modules/python.cmake | 5 -- modules/safeguards.cmake | 5 -- modules/src.cmake | 5 -- modules/static_linking.cmake | 4 +- modules/version.cmake | 5 -- test/cxx/cmake/autocmake.cfg | 4 -- test/cxx_auto/cmake/autocmake.cfg | 14 ----- test/cxx_custom/cmake/autocmake.cfg | 16 +++++ .../src/CMakeLists.txt | 0 test/{cxx_auto => cxx_custom}/src/example.cpp | 0 test/fc/cmake/autocmake.cfg | 4 -- test/fc_blas/cmake/autocmake.cfg | 15 ----- test/test.py | 8 +-- update.py | 61 +++++++++++++------ 26 files changed, 74 insertions(+), 122 deletions(-) delete mode 100644 test/cxx_auto/cmake/autocmake.cfg create mode 100644 test/cxx_custom/cmake/autocmake.cfg rename test/{cxx_auto => cxx_custom}/src/CMakeLists.txt (100%) rename test/{cxx_auto => cxx_custom}/src/example.cpp (100%) diff --git a/modules/build_info.cmake b/modules/build_info.cmake index 4cd4e39..9128238 100644 --- a/modules/build_info.cmake +++ b/modules/build_info.cmake @@ -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) diff --git a/modules/cc.cmake b/modules/cc.cmake index e7ae618..589d75b 100644 --- a/modules/cc.cmake +++ b/modules/cc.cmake @@ -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= C compiler [default: gcc]. # --extra-cc-flags= Extra C compiler flags [default: '']. # export: 'CC=%s' % arguments['--cc'] diff --git a/modules/code_coverage.cmake b/modules/code_coverage.cmake index 48f0ac6..d617945 100644 --- a/modules/code_coverage.cmake +++ b/modules/code_coverage.cmake @@ -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'] diff --git a/modules/cxx.cmake b/modules/cxx.cmake index 21cc4ca..a050b2f 100644 --- a/modules/cxx.cmake +++ b/modules/cxx.cmake @@ -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= C++ compiler [default: g++]. # --extra-cxx-flags= Extra C++ compiler flags [default: '']. # export: 'CXX=%s' % arguments['--cxx'] diff --git a/modules/default_build_paths.cmake b/modules/default_build_paths.cmake index ec18966..f59cfed 100644 --- a/modules/default_build_paths.cmake +++ b/modules/default_build_paths.cmake @@ -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) diff --git a/modules/fc.cmake b/modules/fc.cmake index c4b005f..eadc10d 100644 --- a/modules/fc.cmake +++ b/modules/fc.cmake @@ -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= Fortran compiler [default: gfortran]. # --extra-fc-flags= Extra Fortran compiler flags [default: '']. # export: 'FC=%s' % arguments['--fc'] diff --git a/modules/fc_optional.cmake b/modules/fc_optional.cmake index cb47e0a..b29673c 100644 --- a/modules/fc_optional.cmake +++ b/modules/fc_optional.cmake @@ -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= Fortran compiler [default: gfortran]. # --extra-fc-flags= Extra Fortran compiler flags [default: '']. # --fc-support= Toggle Fortran language support (ON/OFF) [default: ON]. diff --git a/modules/googletest.cmake b/modules/googletest.cmake index 97c84d0..edbb0db 100644 --- a/modules/googletest.cmake +++ b/modules/googletest.cmake @@ -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") diff --git a/modules/int64.cmake b/modules/int64.cmake index b82605a..944ea3b 100644 --- a/modules/int64.cmake +++ b/modules/int64.cmake @@ -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'] diff --git a/modules/math_libs.cmake b/modules/math_libs.cmake index 695e377..93dc1b6 100644 --- a/modules/math_libs.cmake +++ b/modules/math_libs.cmake @@ -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= Detect and link BLAS library (auto or off) [default: auto]. # --lapack= Detect and link LAPACK library (auto or off) [default: auto]. # --mkl= Pass MKL flag to the Intel compiler and linker and skip BLAS/LAPACK detection (sequential, parallel, cluster, or off) [default: off]. diff --git a/modules/mpi.cmake b/modules/mpi.cmake index a214b33..8033564 100644 --- a/modules/mpi.cmake +++ b/modules/mpi.cmake @@ -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'] diff --git a/modules/omp.cmake b/modules/omp.cmake index 58f8e43..6c2f432 100644 --- a/modules/omp.cmake +++ b/modules/omp.cmake @@ -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'] diff --git a/modules/python.cmake b/modules/python.cmake index 1b01a18..dbc6507 100644 --- a/modules/python.cmake +++ b/modules/python.cmake @@ -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) diff --git a/modules/safeguards.cmake b/modules/safeguards.cmake index d7a83fe..39505a7 100644 --- a/modules/safeguards.cmake +++ b/modules/safeguards.cmake @@ -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.") diff --git a/modules/src.cmake b/modules/src.cmake index 8df35d2..1abaddf 100644 --- a/modules/src.cmake +++ b/modules/src.cmake @@ -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) diff --git a/modules/static_linking.cmake b/modules/static_linking.cmake index 0cace63..07a1af9 100644 --- a/modules/static_linking.cmake +++ b/modules/static_linking.cmake @@ -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'] diff --git a/modules/version.cmake b/modules/version.cmake index 28fb4a8..518cfab 100644 --- a/modules/version.cmake +++ b/modules/version.cmake @@ -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) diff --git a/test/cxx/cmake/autocmake.cfg b/test/cxx/cmake/autocmake.cfg index cbe5364..e35cf0c 100644 --- a/test/cxx/cmake/autocmake.cfg +++ b/test/cxx/cmake/autocmake.cfg @@ -3,10 +3,6 @@ name: example [cxx] source: ../../../modules/cxx.cmake -docopt: --cxx= C++ compiler [default: g++]. - --extra-cxx-flags= 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 diff --git a/test/cxx_auto/cmake/autocmake.cfg b/test/cxx_auto/cmake/autocmake.cfg deleted file mode 100644 index 6ab81fc..0000000 --- a/test/cxx_auto/cmake/autocmake.cfg +++ /dev/null @@ -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 diff --git a/test/cxx_custom/cmake/autocmake.cfg b/test/cxx_custom/cmake/autocmake.cfg new file mode 100644 index 0000000..70d48fc --- /dev/null +++ b/test/cxx_custom/cmake/autocmake.cfg @@ -0,0 +1,16 @@ +[project] +name: example + +[cxx] +source: ../../../modules/cxx.cmake +config: custom +docopt: --cxx= C++ compiler [default: g++]. + --extra-cxx-flags= 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 diff --git a/test/cxx_auto/src/CMakeLists.txt b/test/cxx_custom/src/CMakeLists.txt similarity index 100% rename from test/cxx_auto/src/CMakeLists.txt rename to test/cxx_custom/src/CMakeLists.txt diff --git a/test/cxx_auto/src/example.cpp b/test/cxx_custom/src/example.cpp similarity index 100% rename from test/cxx_auto/src/example.cpp rename to test/cxx_custom/src/example.cpp diff --git a/test/fc/cmake/autocmake.cfg b/test/fc/cmake/autocmake.cfg index a8df0c3..79e4a61 100644 --- a/test/fc/cmake/autocmake.cfg +++ b/test/fc/cmake/autocmake.cfg @@ -3,10 +3,6 @@ name: example [fc] source: ../../../modules/fc.cmake -docopt: --fc= Fortran compiler [default: gfortran]. - --extra-fc-flags= 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 diff --git a/test/fc_blas/cmake/autocmake.cfg b/test/fc_blas/cmake/autocmake.cfg index 917703e..8d08592 100644 --- a/test/fc_blas/cmake/autocmake.cfg +++ b/test/fc_blas/cmake/autocmake.cfg @@ -3,27 +3,12 @@ name: example [fc] source: ../../../modules/fc.cmake -docopt: --fc= Fortran compiler [default: gfortran]. - --extra-fc-flags= 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= Detect and link BLAS library (auto or off) [default: auto]. - --lapack= Detect and link LAPACK library (auto or off) [default: auto]. - --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 diff --git a/test/test.py b/test/test.py index 965b8f4..6bd21e3 100644 --- a/test/test.py +++ b/test/test.py @@ -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 # ------------------------------------------------------------------------------ diff --git a/update.py b/update.py index 339b60a..335630d 100755 --- a/update.py +++ b/update.py @@ -258,18 +258,22 @@ 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': - with open(file_name, 'r') as f: - config_docopt, config_define, config_export = parse_cmake_module(f.read()) - if config_docopt: - config.set(section, 'docopt', config_docopt) - if config_define: - config.set(section, 'define', config_define) - if config_export: - config.set(section, 'export', config_export) + 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: + config.set(section, 'docopt', config_docopt) + 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)) i += 1 print_progress_bar( @@ -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= C++ compiler [default: g++]. # --extra-cxx-flags= Extra C++ compiler flags [default: '']. # export: 'CXX=%s' % arguments['--cxx'] @@ -420,6 +429,22 @@ endif()''' assert config_docopt == "--cxx= C++ compiler [default: g++].\n--extra-cxx-flags= 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 + # ------------------------------------------------------------------------------