├── .default.nix ├── .envrc ├── .gitignore ├── .travis.yml ├── AUTHORS.md ├── LICENSE ├── Pipfile ├── Pipfile.lock ├── README.md ├── autocmake ├── __init__.py ├── configure.py ├── external │ ├── LICENSE-MIT │ ├── __init__.py │ └── docopt.py ├── extract.py ├── generate.py ├── interpolate.py ├── parse_rst.py └── parse_yaml.py ├── compilers ├── Clang.C.cmake ├── Clang.CXX.cmake ├── GNU.C.cmake ├── GNU.CXX.cmake ├── GNU.Fortran.cmake ├── Intel.C.cmake ├── Intel.CXX.cmake ├── Intel.Fortran.cmake ├── PGI.C.cmake ├── PGI.CXX.cmake ├── PGI.Fortran.cmake ├── XL.C.cmake ├── XL.CXX.cmake └── XL.Fortran.cmake ├── doc ├── _static │ └── .gitignore ├── conf.py ├── contributors │ ├── doc.rst │ ├── guidelines.rst │ └── testing.rst ├── developers │ ├── bootstrap.rst │ ├── configuration.rst │ ├── customizing-modules.rst │ ├── example.rst │ ├── faq.rst │ ├── interpolation.rst │ └── updating-modules.rst ├── extract_rst.py ├── general │ ├── about.rst │ ├── help.rst │ └── requirements.rst ├── index.rst └── users │ └── faq.rst ├── example └── autocmake.yml ├── img ├── autocmake.png └── autocmake.svg ├── modules ├── attach-license-header.py ├── cc.cmake ├── ccache.cmake ├── code_coverage.cmake ├── custom_color_messages.cmake ├── cxx.cmake ├── default_build_paths.cmake ├── definitions.cmake ├── export_header.cmake ├── fc.cmake ├── fc_optional.cmake ├── find │ ├── find_include_files.cmake │ └── find_libraries.cmake ├── git_info │ ├── git_info.cmake │ └── git_info.h.in ├── googletest.cmake ├── int64.cmake ├── math │ ├── accelerate.cmake │ ├── acml.cmake │ ├── atlas.cmake │ ├── blas.cmake │ ├── cblas.cmake │ ├── goto.cmake │ ├── lapack.cmake │ └── lapacke.cmake ├── math_libs.cmake ├── mpi.cmake ├── omp.cmake ├── profile.cmake ├── python_interpreter.cmake ├── python_libs.cmake ├── safeguards.cmake ├── save_flags.cmake ├── src.cmake └── version.cmake ├── requirements.txt ├── test ├── cxx │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── cxx_accelerate │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── cxx_cblas │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── extra_cmake_options │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── fc │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ ├── example.f90 │ │ └── module.f90 ├── fc_blas │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.f90 ├── fc_git_info │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.F90 ├── fc_int64 │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.f90 ├── fc_lapack │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.f90 ├── fc_omp │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.f90 ├── python_interpreter │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── python_interpreter_custom │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── python_libs │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp ├── python_libs_custom │ ├── cmake │ │ └── autocmake.yml │ └── src │ │ ├── CMakeLists.txt │ │ └── example.cpp └── test.py └── update.py /.default.nix: -------------------------------------------------------------------------------- 1 | let 2 | hostPkgs = import {}; 3 | nixpkgs = (hostPkgs.fetchFromGitHub { 4 | owner = "NixOS"; 5 | repo = "nixpkgs-channels"; 6 | rev = "nixos-unstable"; 7 | sha256 = "1rc1pjnvfi194gka45zc1nivzsncc819kvxlfv277l2c8ryhgbpc"; 8 | }); 9 | in 10 | with import nixpkgs {}; 11 | stdenv.mkDerivation { 12 | name = "Autocmake"; 13 | buildInputs = [ 14 | ccache 15 | cmake 16 | doxygen 17 | gcc 18 | gfortran 19 | liblapack 20 | openmpi 21 | pipenv 22 | python3Packages.pep8 23 | python3Packages.pytest 24 | python3Packages.pyyaml 25 | zlib 26 | ]; 27 | src = null; 28 | shellHook = '' 29 | export NINJA_STATUS="[Built edge %f of %t in %e sec]" 30 | SOURCE_DATE_EPOCH=$(date +%s) 31 | ''; 32 | } 33 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use nix .default.nix 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cache/ 2 | venv/ 3 | *.pyc 4 | __pycache__/ 5 | 6 | # generated by unit tests 7 | test/*/CMakeLists.txt 8 | test/*/build*/ 9 | test/*/cmake/update.py 10 | test/*/cmake/autocmake/ 11 | test/*/cmake/downloaded/ 12 | test/*/setup 13 | test/*/cmake_output 14 | 15 | # generated by doc/extract_rst.py 16 | doc/module-reference.rst 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | sudo: false 3 | 4 | matrix: 5 | include: 6 | 7 | - os: linux 8 | python: 2.7 9 | compiler: gcc 10 | env: SOURCES=ubuntu-toolchain-r-test 11 | addons: 12 | apt: 13 | sources: 14 | - ubuntu-toolchain-r-test 15 | packages: 16 | # compilers 17 | - g++ 18 | - gfortran 19 | # math libraries 20 | - libblas-dev 21 | - liblapack-dev 22 | - libatlas-base-dev 23 | # mpi 24 | - openmpi-bin 25 | - libopenmpi-dev 26 | # python library, development version 27 | - libpython2.7 28 | 29 | - os: linux 30 | python: 3.5 31 | compiler: gcc 32 | env: SOURCES=ubuntu-toolchain-r-test 33 | addons: 34 | apt: 35 | sources: 36 | - ubuntu-toolchain-r-test 37 | packages: 38 | # compilers 39 | - g++ 40 | - gfortran 41 | # math libraries 42 | - libblas-dev 43 | - liblapack-dev 44 | - libatlas-base-dev 45 | # mpi 46 | - openmpi-bin 47 | - libopenmpi-dev 48 | # python library, development version 49 | - libpython2.7 50 | 51 | - os: osx 52 | osx_image: xcode11 53 | compiler: gcc 54 | env: 55 | - SOURCES=homebrew 56 | 57 | install: 58 | - | 59 | if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then 60 | brew update &> /dev/null 61 | pip install virtualenv 62 | elif [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then 63 | pip install --user virtualenv 64 | mkdir -p $HOME/dependencies/cmake 65 | curl -Ls https://cmake.org/files/v3.8/cmake-3.8.0-Linux-x86_64.tar.gz | tar -xz -C $HOME/dependencies/cmake --strip-components=1 66 | export PATH=$HOME/dependencies/cmake/bin${PATH:+:$PATH} 67 | fi 68 | - cmake --version 69 | - virtualenv venv 70 | - source venv/bin/activate 71 | - pip install -r requirements.txt 72 | 73 | script: 74 | # pycodestyle tests 75 | - pycodestyle --ignore E501 update.py 76 | - pycodestyle --ignore E501,E265,E741 autocmake --exclude autocmake/external/docopt.py 77 | # unit tests 78 | - py.test -vv autocmake/* 79 | - py.test -vv test/test.py 80 | 81 | notifications: 82 | email: false 83 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Authors 2 | 3 | - Radovan Bast 4 | - Roberto Di Remigio 5 | - Jonas Juselius 6 | 7 | # Contributors 8 | 9 | - Miroslav Ilias (Windows, portability, earliest adopter testing and feedback, math library testing) 10 | - Ivan Hrasko (Windows, Appveyor testing) 11 | - Dan Jonsson (idea for configuration file approach which preceded YAML solution) 12 | 13 | For a list of all the contributions, 14 | see https://github.com/dev-cafe/autocmake/contributors. 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2017 by Radovan Bast, Roberto Di Remigio, Jonas Juselius, and contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Autocmake nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | 3 | url = "https://pypi.python.org/simple" 4 | verify_ssl = true 5 | name = "pypi" 6 | 7 | 8 | [packages] 9 | 10 | pycodestyle = "*" 11 | pytest = "*" 12 | PyYAML = "==4.2b4" 13 | 14 | 15 | [dev-packages] 16 | 17 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "f86826fa4239dea24ceb6dbac0dd68caeb99b9c982dc6ace46ea32fbd09ab747" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": {}, 8 | "sources": [ 9 | { 10 | "name": "pypi", 11 | "url": "https://pypi.python.org/simple", 12 | "verify_ssl": true 13 | } 14 | ] 15 | }, 16 | "default": { 17 | "atomicwrites": { 18 | "hashes": [ 19 | "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", 20 | "sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee" 21 | ], 22 | "version": "==1.2.1" 23 | }, 24 | "attrs": { 25 | "hashes": [ 26 | "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", 27 | "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" 28 | ], 29 | "version": "==18.2.0" 30 | }, 31 | "more-itertools": { 32 | "hashes": [ 33 | "sha256:38a936c0a6d98a38bcc2d03fdaaedaba9f412879461dd2ceff8d37564d6522e4", 34 | "sha256:c0a5785b1109a6bd7fac76d6837fd1feca158e54e521ccd2ae8bfe393cc9d4fc", 35 | "sha256:fe7a7cae1ccb57d33952113ff4fa1bc5f879963600ed74918f1236e212ee50b9" 36 | ], 37 | "version": "==5.0.0" 38 | }, 39 | "pluggy": { 40 | "hashes": [ 41 | "sha256:8ddc32f03971bfdf900a81961a48ccf2fb677cf7715108f85295c67405798616", 42 | "sha256:980710797ff6a041e9a73a5787804f848996ecaa6f8a1b1e08224a5894f2074a" 43 | ], 44 | "version": "==0.8.1" 45 | }, 46 | "py": { 47 | "hashes": [ 48 | "sha256:bf92637198836372b520efcba9e020c330123be8ce527e535d185ed4b6f45694", 49 | "sha256:e76826342cefe3c3d5f7e8ee4316b80d1dd8a300781612ddbc765c17ba25a6c6" 50 | ], 51 | "version": "==1.7.0" 52 | }, 53 | "pycodestyle": { 54 | "hashes": [ 55 | "sha256:cbc619d09254895b0d12c2c691e237b2e91e9b2ecf5e84c26b35400f93dcfb83", 56 | "sha256:cbfca99bd594a10f674d0cd97a3d802a1fdef635d4361e1a2658de47ed261e3a" 57 | ], 58 | "index": "pypi", 59 | "version": "==2.4.0" 60 | }, 61 | "pytest": { 62 | "hashes": [ 63 | "sha256:41568ea7ecb4a68d7f63837cf65b92ce8d0105e43196ff2b26622995bb3dc4b2", 64 | "sha256:c3c573a29d7c9547fb90217ece8a8843aa0c1328a797e200290dc3d0b4b823be" 65 | ], 66 | "index": "pypi", 67 | "version": "==4.1.1" 68 | }, 69 | "pyyaml": { 70 | "hashes": [ 71 | "sha256:254bf6fda2b7c651837acb2c718e213df29d531eebf00edb54743d10bcb694eb", 72 | "sha256:3108529b78577327d15eec243f0ff348a0640b0c3478d67ad7f5648f93bac3e2", 73 | "sha256:3c17fb92c8ba2f525e4b5f7941d850e7a48c3a59b32d331e2502a3cdc6648e76", 74 | "sha256:8d6d96001aa7f0a6a4a95e8143225b5d06e41b1131044913fecb8f85a125714b", 75 | "sha256:c8a88edd93ee29ede719080b2be6cb2333dfee1dccba213b422a9c8e97f2967b" 76 | ], 77 | "index": "pypi", 78 | "version": "==4.2b4" 79 | }, 80 | "six": { 81 | "hashes": [ 82 | "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", 83 | "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" 84 | ], 85 | "version": "==1.12.0" 86 | } 87 | }, 88 | "develop": {} 89 | } 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/dev-cafe/autocmake.svg?branch=master)](https://travis-ci.org/dev-cafe/autocmake/builds) 2 | [![Documentation Status](https://readthedocs.org/projects/autocmake/badge/?version=latest)](http://autocmake.readthedocs.org) 3 | [![License](https://img.shields.io/badge/license-%20BSD--3-blue.svg)](LICENSE) 4 | [![DOI](https://zenodo.org/badge/36069881.svg)](https://zenodo.org/badge/latestdoi/36069881) 5 | 6 | ![alt text](https://github.com/dev-cafe/autocmake/raw/master/img/autocmake.png "Autocmake") 7 | 8 | A CMake plugin composer. 9 | Licensed under [BSD-3](LICENSE). 10 | See http://autocmake.org. 11 | 12 | 13 | ## Documentation 14 | 15 | - [Latest stable code](http://autocmake.readthedocs.io/en/stable-0.x/) (stable-0.x branch) 16 | - [Bleeding edge code](http://autocmake.readthedocs.io/en/latest/) (master branch) 17 | 18 | 19 | ## Projects using Autocmake 20 | 21 | - [Numgrid](https://github.com/dftlibs/numgrid) 22 | - [XCint](https://github.com/dftlibs/xcint) 23 | - [DIRAC](http://diracprogram.org) 24 | - [mathlib-tester](https://github.com/miroi/mathlibs-tester) 25 | - [Fortran Input Reader](https://github.com/miroi/fortran_input_reader) 26 | - [PCMSolver](https://github.com/PCMSolver/pcmsolver) 27 | - GRASP: General-purpose Relativistic Atomic Structure Program 28 | - [MRChem](https://github.com/MRChemSoft/mrchem) 29 | - [ReSpect](http://rel-qchem.sav.sk) 30 | - [Flanders](https://github.com/bast/flanders) 31 | - [Polygons](https://github.com/bast/polygons) 32 | - [GIMIC](https://github.com/qmcurrents/gimic) 33 | 34 | If you use Autocmake, please link to your project via a pull request. 35 | -------------------------------------------------------------------------------- /autocmake/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "1.0.0" 2 | -------------------------------------------------------------------------------- /autocmake/configure.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | def module_exists(module_name): 6 | try: 7 | __import__(module_name) 8 | except ImportError: 9 | return False 10 | else: 11 | return True 12 | 13 | 14 | def check_cmake_exists(cmake_command): 15 | """ 16 | Check whether CMake is installed. If not, print 17 | informative error message and quits. 18 | """ 19 | from subprocess import Popen, PIPE 20 | 21 | p = Popen( 22 | "{0} --version".format(cmake_command), shell=True, stdin=PIPE, stdout=PIPE 23 | ) 24 | if not ("cmake version" in p.communicate()[0].decode("UTF-8")): 25 | sys.stderr.write(" This code is built using CMake\n\n") 26 | sys.stderr.write(" CMake is not found\n") 27 | sys.stderr.write(" get CMake at http://www.cmake.org/\n") 28 | sys.stderr.write(" on many clusters CMake is installed\n") 29 | sys.stderr.write(" but you have to load it first:\n") 30 | sys.stderr.write(" $ module load cmake\n") 31 | sys.exit(1) 32 | 33 | 34 | def setup_build_path(build_path): 35 | """ 36 | Create build directory. If this already exists, print informative 37 | error message and quit. 38 | """ 39 | if os.path.isdir(build_path): 40 | fname = os.path.join(build_path, "CMakeCache.txt") 41 | if os.path.exists(fname): 42 | sys.stderr.write("aborting setup\n") 43 | sys.stderr.write( 44 | "build directory {0} which contains CMakeCache.txt already exists\n".format( 45 | build_path 46 | ) 47 | ) 48 | sys.stderr.write("remove the build directory and then rerun setup\n") 49 | sys.exit(1) 50 | else: 51 | os.makedirs(build_path, 0o755) 52 | 53 | 54 | def add_quotes_to_argv(argv, arguments): 55 | """ 56 | This function tries to solve this problem: 57 | https://stackoverflow.com/questions/19120247/python-sys-argv-to-preserve-or 58 | 59 | The problem is that sys.argv has been stripped of quotes by the shell but 60 | docopt's arguments contains quotes. 61 | 62 | So what we do is cycle through all docopt arguments: if they are also 63 | present in sys.argv and contain spaces, we add quotes. 64 | """ 65 | setup_command = " ".join(argv[:]) 66 | 67 | for k, v in arguments.items(): 68 | if isinstance(v, str): 69 | if " " in v: 70 | if v in setup_command: 71 | setup_command = setup_command.replace(v, '"{}"'.format(v)) 72 | 73 | return setup_command 74 | 75 | 76 | def run_cmake(command, build_path, default_build_path, arguments): 77 | """ 78 | Execute CMake command. 79 | """ 80 | from subprocess import Popen, PIPE 81 | 82 | topdir = os.getcwd() 83 | p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) 84 | stdout_coded, stderr_coded = p.communicate() 85 | stdout = stdout_coded.decode("UTF-8") 86 | stderr = stderr_coded.decode("UTF-8") 87 | 88 | # print cmake output to screen 89 | print(stdout) 90 | 91 | if stderr: 92 | # we write out stderr but we do not stop yet 93 | # this is because CMake warnings are sent to stderr 94 | # and they might be benign 95 | sys.stderr.write(stderr) 96 | 97 | # write cmake output to file 98 | with open(os.path.join(build_path, "cmake_output"), "w") as f: 99 | f.write(stdout) 100 | 101 | # change directory and return 102 | os.chdir(topdir) 103 | 104 | # to figure out whether configuration was a success 105 | # we check for 3 sentences that should be part of stdout 106 | configuring_done = "-- Configuring done" in stdout 107 | generating_done = "-- Generating done" in stdout 108 | build_files_written = "-- Build files have been written to" in stdout 109 | configuration_successful = ( 110 | configuring_done and generating_done and build_files_written 111 | ) 112 | 113 | if configuration_successful: 114 | setup_command = add_quotes_to_argv(sys.argv, arguments) 115 | save_setup_command(setup_command, build_path) 116 | print_build_help(build_path, default_build_path) 117 | 118 | 119 | def print_build_help(build_path, default_build_path): 120 | """ 121 | Print help text after configuration step is done. 122 | """ 123 | print(" configure step is done") 124 | print(" now you need to compile the sources:") 125 | if build_path == default_build_path: 126 | print(" $ cd build") 127 | else: 128 | print(" $ cd " + build_path) 129 | print(" $ make") 130 | 131 | 132 | def save_setup_command(setup_command, build_path): 133 | """ 134 | Save setup command to a file. 135 | """ 136 | file_name = os.path.join(build_path, "setup_command") 137 | with open(file_name, "w") as f: 138 | f.write(setup_command + "\n") 139 | 140 | 141 | def configure(root_directory, build_path, cmake_command, arguments): 142 | """ 143 | Main configure function. 144 | """ 145 | default_build_path = os.path.join(root_directory, "build") 146 | 147 | # check that CMake is available, if not stop 148 | check_cmake_exists("cmake") 149 | 150 | # deal with build path 151 | if build_path is None: 152 | build_path = default_build_path 153 | if not arguments["--show"]: 154 | setup_build_path(build_path) 155 | 156 | cmake_command += " -B" + build_path 157 | print("{0}\n".format(cmake_command)) 158 | if arguments["--show"]: 159 | sys.exit(0) 160 | 161 | run_cmake(cmake_command, build_path, default_build_path, arguments) 162 | -------------------------------------------------------------------------------- /autocmake/external/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Vladimir Keleshev, 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the Software 6 | without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to 9 | whom the Software is furnished to do so, subject to the 10 | following conditions: 11 | 12 | The above copyright notice and this permission notice shall 13 | be included in all copies or substantial portions of the 14 | Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 17 | KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 18 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 19 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /autocmake/external/__init__.py: -------------------------------------------------------------------------------- 1 | # empty - this line is here to avoid problem when fetching empty files from web 2 | -------------------------------------------------------------------------------- /autocmake/extract.py: -------------------------------------------------------------------------------- 1 | def extract_list(config, section): 2 | from collections.abc import Iterable 3 | 4 | l = [] 5 | if "modules" in config: 6 | for module in config["modules"]: 7 | for k, v in module.items(): 8 | for x in v: 9 | if section in x: 10 | if isinstance(x[section], Iterable) and not isinstance( 11 | x[section], str 12 | ): 13 | for y in x[section]: 14 | l.append(y) 15 | else: 16 | l.append(x[section]) 17 | return l 18 | 19 | 20 | def to_d(l): 21 | """ 22 | Converts list of dicts to dict. 23 | """ 24 | _d = {} 25 | for x in l: 26 | for k, v in x.items(): 27 | _d[k] = v 28 | return _d 29 | 30 | 31 | def test_to_d(): 32 | l = [{"a": "b"}, {"c": "d"}] 33 | d = {"a": "b", "c": "d"} 34 | assert to_d(l) == d 35 | 36 | 37 | def to_l(x): 38 | """ 39 | Converts list of dicts to dict. 40 | """ 41 | if isinstance(x, str): 42 | return [x] 43 | else: 44 | return x 45 | 46 | 47 | def test_to_l(): 48 | assert to_l("foo") == ["foo"] 49 | assert to_l(["foo", "bar"]) == ["foo", "bar"] 50 | -------------------------------------------------------------------------------- /autocmake/generate.py: -------------------------------------------------------------------------------- 1 | from autocmake.extract import extract_list 2 | from datetime import date 3 | from . import __version__ 4 | import os 5 | 6 | 7 | def gen_cmake_command(config): 8 | """ 9 | Generate CMake command. 10 | """ 11 | s = [] 12 | s.append("\n\ndef gen_cmake_command(options, arguments):") 13 | s.append(' """') 14 | s.append(" Generate CMake command based on options and arguments.") 15 | s.append(' """') 16 | s.append(" command = []") 17 | 18 | for env in config["export"]: 19 | s.append(" command.append({0})".format(env)) 20 | 21 | s.append(" command.append(arguments['--cmake-executable'])") 22 | 23 | for definition in config["define"]: 24 | s.append(" command.append({0})".format(definition)) 25 | 26 | s.append(" command.append('-DCMAKE_BUILD_TYPE={0}'.format(arguments['--type']))") 27 | s.append(" command.append('-G\"{0}\"'.format(arguments['--generator']))") 28 | s.append(" if arguments['--cmake-options'] != \"''\":") 29 | s.append(" command.append(arguments['--cmake-options'])") 30 | s.append(" if arguments['--prefix']:") 31 | s.append( 32 | " command.append('-DCMAKE_INSTALL_PREFIX=\"{0}\"'.format(arguments['--prefix']))" 33 | ) 34 | 35 | s.append("\n return ' '.join(command)") 36 | 37 | return "\n".join(s) 38 | 39 | 40 | def autogenerated_notice(): 41 | current_year = date.today().year 42 | year_range = "2015-{0}".format(current_year) 43 | 44 | return f""" 45 | # This file is autogenerated by Autocmake v{__version__} (http://autocmake.org). 46 | # Copyright (c) 2015-{current_year} by Radovan Bast, Roberto Di Remigio, Jonas Juselius, and contributors.""" 47 | 48 | 49 | def gen_cmake_options_wrappers(): 50 | s = """\n# Options handling utilities 51 | include(CMakeDependentOption) 52 | # Macro for printing an option in a consistent manner 53 | # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard) 54 | # Syntax: print_option(