the default setup script name becomes "setup"

it can be changed in autocmake.cfg
This commit is contained in:
Radovan Bast 2015-10-12 15:30:51 +02:00
parent db3a250e30
commit fd8ec93851
12 changed files with 91 additions and 75 deletions

2
.gitignore vendored
View File

@ -7,7 +7,7 @@ test/*/build*/
test/*/cmake/update.py
test/*/cmake/lib/
test/*/cmake/downloaded/
test/*/setup.py
test/*/setup
# generated by doc/extract_rst.py
doc/module-reference.rst

View File

@ -39,7 +39,7 @@ Generating the CMake infrastructure
Now customize ``autocmake.cfg`` to your needs
(see :ref:`autocmake_cfg`)
and then run the ``update.py`` script which
creates ``CMakeLists.txt`` and ``setup.py`` in the target path::
creates ``CMakeLists.txt`` and a setup script in the target path::
$ python update.py ..
@ -59,10 +59,10 @@ called ``downloaded/``::
Building the project
--------------------
Now you have ``CMakeLists.txt`` and ``setup.py`` in the project root and the project
Now you have ``CMakeLists.txt`` and setup script in the project root and the project
can be built::
$ cd ..
$ python setup.py [-h]
$ python setup [-h]
$ cd build
$ make

View File

@ -105,13 +105,13 @@ to all libraries it needs::
- fetching lib/docopt/docopt.py
- fetching update.py
Good. Now we can generate ``CMakeLists.txt`` and ``setup.py``::
Good. Now we can generate ``CMakeLists.txt`` and the setup script::
$ python update ..
- parsing autocmake.cfg
- generating CMakeLists.txt
- generating setup.py
- generating setup script
Excellent. Here is the generated ``CMakeLists.txt``::
@ -134,12 +134,12 @@ Excellent. Here is the generated ``CMakeLists.txt``::
This is the very bare minimum. Every Autocmake project will have at least these
settings.
And we also got a ``setup.py`` script (front-end to ``CMakeLists.txt``) with
And we also got a setup script (front-end to ``CMakeLists.txt``) with
the following default options::
Usage:
./setup.py [options] [<builddir>]
./setup.py (-h | --help)
./setup [options] [<builddir>]
./setup (-h | --help)
Options:
--type=<TYPE> Set the CMake build type (debug, release, or relwithdeb) [default: release].
@ -195,10 +195,10 @@ documentation (see below), then the fetched file is placed into the same
directory as the CMake module file which fetches it.
Generating setup.py options
---------------------------
Generating setup options
------------------------
Options for the ``setup.py`` script can be generated with the ``docopt``
Options for the setup script can be generated with the ``docopt``
option. As an example, the following ``autocmake.cfg`` snippet will add a
``--something`` flag::

View File

@ -71,7 +71,7 @@ We need to create ``src/CMakeLists.txt`` which can look like this::
We wrote that we want to get an executable "hello.x" built from our sources.
Now we have everything to generate ``CMakeLists.txt`` and ``setup.py``::
Now we have everything to generate ``CMakeLists.txt`` and a setup script::
$ cd cmake
$ python update ..
@ -91,7 +91,7 @@ And this is what we got::
| | `-- docopt
| | `-- docopt.py
| `-- update.py
|-- setup.py
|-- setup
`-- src
|-- CMakeLists.txt
|-- feature1.F90
@ -100,7 +100,7 @@ And this is what we got::
Now we are ready to build::
$ python setup.py --fc=gfortran --cc=gcc
$ python setup --fc=gfortran --cc=gcc
FC=gfortran CC=gcc cmake -DEXTRA_FCFLAGS="''" -DENABLE_FC_SUPPORT="ON" -DEXTRA_CFLAGS="''" -DCMAKE_BUILD_TYPE=release -G "Unix Makefiles" None /home/user/example

View File

@ -4,8 +4,8 @@ FAQ for developers
==================
Autocmake does not do feature X - I really need feature X and a setup.py flag --X
---------------------------------------------------------------------------------
Autocmake does not do feature X - I really need feature X and a setup flag --X
------------------------------------------------------------------------------
The Autocmake developers have to be very conservative and only a very limited
set of portable features of absolutely general interest become part of the
@ -25,7 +25,7 @@ And include this feature to the main ``CMakeLists.txt`` in ``autocmake.cfg``::
source: custom/my_feature.cmake
Now your code is included in the main ``CMakeLists.txt``. Perhaps you also
want a ``setup.py`` flag to toggle the feature::
want a setup script flag to toggle the feature::
[my_feature]
source: custom/my_feature.cmake
@ -37,8 +37,8 @@ good code quality, and of general interest, you can suggest it to be part of
the standard set of modules or even a core feature.
How can I get a setup.py flag --X that toggles a CMake variable?
----------------------------------------------------------------
How can I get a setup flag --X that toggles a CMake variable?
-------------------------------------------------------------
The following will add a ``--something`` flag which toggles the CMake variable
``ENABLE_SOMETHING``::
@ -48,6 +48,17 @@ The following will add a ``--something`` flag which toggles the CMake variable
define: '-DENABLE_SOMETHING={0}'.format(arguments['--something'])
Can I change the name of the setup script?
------------------------------------------
Yes you can do that in ``autocmake.cfg``. Here we for instance change the name to "configure"::
[project]
name: myproject
min_cmake_version: 2.8
setup_script: configure
In CMake I can do feature X - can I do that also with Autocmake?
----------------------------------------------------------------
@ -63,26 +74,26 @@ Yes, you probably want to do that. Autocmake generates a number of files which
in principle could be generated at configure- or build-time. However, you
probably do not want the users of your code to run any Autocmake scripts like
``update.py`` to generate the files they need to build the project. The users
of your code will run ``setup.py`` directly and expect everything to just work
of your code will run ``setup`` directly and expect everything to just work
(TM).
The update.py script is overwriting my CMakeLists.txt and setup.py, isn't this bad?
-----------------------------------------------------------------------------------
The update.py script is overwriting my CMakeLists.txt and setup, isn't this bad?
--------------------------------------------------------------------------------
No, it is not as bad as it first looks. It is a feature. Normally
``CMakeLists.txt`` and ``setup.py`` should not contain any explicit
``CMakeLists.txt`` and ``setup`` should not contain any explicit
customization and therefore should not contain anything that could not be
regenerated. In any case you should use version control so that you can inspect
and compare changes introduced to ``CMakeLists.txt`` and ``setup.py`` and
and compare changes introduced to ``CMakeLists.txt`` and ``setup`` and
possibly revert them. See also the next remark.
But I need to manually edit and customize CMakeLists.txt and setup.py every time I run update.py!?
--------------------------------------------------------------------------------------------------
But I need to manually edit and customize CMakeLists.txt and setup every time I run update.py!?
-----------------------------------------------------------------------------------------------
You typically never need to manually edit and customize ``CMakeLists.txt`` and
``setup.py`` directly. You can introduce customizations in ``autocmake.cfg``
``setup`` directly. You can introduce customizations in ``autocmake.cfg``
which get assembled into the front-end scripts.

View File

@ -8,7 +8,7 @@ solutions exist to this problem: GNU Makefiles is the traditional approach.
Today, CMake is one of the trendier alternatives which can generate Makefiles
starting from a file called ``CMakeLists.txt``.
Autocmake composes CMake building blocks into a CMake project and generates
``CMakeLists.txt`` as well as ``setup.py``, which serves as a front-end to
``CMakeLists.txt`` as well as a setup script, which serves as a front-end to
``CMakeLists.txt``. All this is done based on a lightweight ``autocmake.cfg``
file::
@ -24,9 +24,9 @@ file::
| python update.py .. |
| |
v v
CMakeLists.txt (and setup.py front-end)
CMakeLists.txt (and setup front-end)
| |
| python setup.py |
| python setup |
| which invokes CMake |
v User of the code
Makefile (or something else) |
@ -44,7 +44,7 @@ scientific projects which typically have very similar requirements:
- Fortran and/or C and/or C++ support
- Tuning of compiler flags
- Front-end script with good defaults (setup.py)
- Front-end script with good defaults
- Support for parallelization: MPI, OMP, CUDA
- Math libraries: BLAS, LAPACK

View File

@ -7,9 +7,9 @@ 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.py`` runs with Python >= 2.7 (also tested with Python
The generated setup script runs with Python >= 2.7 (also tested with Python
3.4; probably also lower).
.. todo::
Figure out lower Python version bound for setup.py.
Figure out lower Python version bound for setup.

View File

@ -9,7 +9,7 @@ TL;DR How do I compile the code?
::
$ python setup.py [-h]
$ python setup [-h]
$ cd build
$ make
@ -17,10 +17,10 @@ TL;DR How do I compile the code?
How can I specify the compiler?
-------------------------------
By default ``setup.py`` will attempt GNU compilers.
By default the setup script will attempt GNU compilers.
You can specify compilers manually like this::
$ python setup.py --fc=ifort --cc=icc --cxx=icpc
$ python setup --fc=ifort --cc=icc --cxx=icpc
How can I add compiler flags?
@ -29,7 +29,7 @@ How can I add compiler flags?
You can do this with ``--extra-fc-flags``, ``--extra-cc-flags``, or
``--extra-cxx-flags`` (depending on the set of enabled languages)::
$ python setup.py --fc=gfortran --extra-fc-flags='-some-exotic-flag'
$ python setup --fc=gfortran --extra-fc-flags='-some-exotic-flag'
How can I redefine compiler flags?
@ -42,9 +42,9 @@ these environment variables you have full control over the flags
without editing CMake files.
How can I select CMake options via the setup.py script?
-------------------------------------------------------
How can I select CMake options via the setup script?
----------------------------------------------------
Like this::
$ python setup.py --cmake-options="-DTHIS_OPTION=ON -DTHAT_OPTION=OFF"
$ python setup --cmake-options="-DTHIS_OPTION=ON -DTHAT_OPTION=OFF"

View File

@ -1,4 +1,4 @@
# CMakeLists.txt and setup.py will be generated from this file
# CMakeLists.txt and setup script will be generated from this file
# see: http://autocmake.readthedocs.org/en/latest/developers/configuration.html
# uncomment the following three lines and set the project name

View File

@ -1,5 +1,5 @@
# here we test setting -DENABLE_SOMETHING=OFF -DFOO=ON
# setup.py script
# in the setup script
option(ENABLE_SOMETHING "Enable something" ON)
option(ENABLE_FOO "Enable FOO" OFF)

View File

@ -94,93 +94,93 @@ def configure_build_and_exe(name, setup_command, launcher=None):
def test_extra_cmake_options():
configure_build_and_exe('extra_cmake_options', 'python setup.py --cxx=g++ --cmake-options="-DENABLE_SOMETHING=OFF -DENABLE_FOO=ON"')
configure_build_and_exe('extra_cmake_options', 'python setup --cxx=g++ --cmake-options="-DENABLE_SOMETHING=OFF -DENABLE_FOO=ON"')
def test_cxx():
configure_build_and_exe('cxx', 'python setup.py --cxx=g++')
configure_build_and_exe('cxx', 'python setup --cxx=g++')
def test_fc():
configure_build_and_exe('fc', 'python setup.py --fc=gfortran')
configure_build_and_exe('fc', 'python setup --fc=gfortran')
def test_fc_git_info():
configure_build_and_exe('fc_git_info', 'python setup.py --fc=gfortran')
configure_build_and_exe('fc_git_info', 'python setup --fc=gfortran')
def test_fc_int64():
configure_build_and_exe('fc_int64', 'python setup.py --fc=gfortran --int64')
configure_build_and_exe('fc_int64', 'python setup --fc=gfortran --int64')
def test_fc_mpi():
if sys.platform == 'win32':
setup_line = 'python setup.py --mpi --fc=gfortran --extra-fc-flags="-D_WIN64 -D INT_PTR_KIND()=8 -fno-range-check"'
setup_line = 'python setup --mpi --fc=gfortran --extra-fc-flags="-D_WIN64 -D INT_PTR_KIND()=8 -fno-range-check"'
else:
setup_line = 'python setup.py --mpi --fc=mpif90'
setup_line = 'python setup --mpi --fc=mpif90'
configure_build_and_exe('fc_mpi', setup_line, 'mpiexec -np 2')
@skip_on_osx
def test_fc_omp():
os.environ['OMP_NUM_THREADS'] = '2'
configure_build_and_exe('fc_omp', 'python setup.py --omp --fc=gfortran')
configure_build_and_exe('fc_omp', 'python setup --omp --fc=gfortran')
def test_fc_blas():
configure_build_and_exe('fc_blas', 'python setup.py --fc=gfortran --blas')
configure_build_and_exe('fc_blas', 'python setup --fc=gfortran --blas')
def test_fc_lapack():
configure_build_and_exe('fc_lapack', 'python setup.py --fc=gfortran --lapack')
configure_build_and_exe('fc_lapack', 'python setup --fc=gfortran --lapack')
@skip_on_osx
def test_cxx_cblas():
configure_build_and_exe('cxx_cblas', 'python setup.py --cxx=g++ --cblas')
configure_build_and_exe('cxx_cblas', 'python setup --cxx=g++ --cblas')
@skip_on_osx
@skip_on_linux
def test_cxx_lapacke():
configure_build_and_exe('cxx_lapacke', 'python setup.py --cxx=g++ --lapacke --cblas')
configure_build_and_exe('cxx_lapacke', 'python setup --cxx=g++ --lapacke --cblas')
@skip_on_linux
@skip_on_windows
def test_cxx_accelerate():
configure_build_and_exe('cxx_accelerate', 'python setup.py --cxx=g++ --accelerate')
configure_build_and_exe('cxx_accelerate', 'python setup --cxx=g++ --accelerate')
def test_python_interpreter():
configure_build_and_exe('python_interpreter', 'python setup.py --cxx=g++')
configure_build_and_exe('python_interpreter', 'python setup --cxx=g++')
def test_python_interpreter_custom():
setup = 'python setup.py --cxx=g++ --python=%s' % sys.executable
setup = 'python setup --cxx=g++ --python=%s' % sys.executable
configure_build_and_exe('python_interpreter_custom', setup)
def test_python_libs():
configure_build_and_exe('python_libs', 'python setup.py --cxx=g++')
configure_build_and_exe('python_libs', 'python setup --cxx=g++')
def test_python_libs_custom():
python_executable = sys.executable
configure_build_and_exe('python_libs_custom', 'python setup.py --cxx=g++ --python={}'.format(python_executable))
configure_build_and_exe('python_libs_custom', 'python setup --cxx=g++ --python={}'.format(python_executable))
def test_boost_header_only():
configure_build_and_exe('boost_header_only', 'python setup.py --cxx=g++')
configure_build_and_exe('boost_header_only', 'python setup --cxx=g++')
def test_boost_libs():
configure_build_and_exe('boost_libs', 'python setup.py --cxx=g++')
configure_build_and_exe('boost_libs', 'python setup --cxx=g++')
def test_boost_mpi_libs():
configure_build_and_exe('boost_mpi_libs', 'python setup.py --cxx=g++ --mpi')
configure_build_and_exe('boost_mpi_libs', 'python setup --cxx=g++ --mpi')
def test_boost_python_libs():
configure_build_and_exe('boost_python_libs', 'python setup.py --cxx=g++')
configure_build_and_exe('boost_python_libs', 'python setup --cxx=g++')

View File

@ -128,9 +128,9 @@ def autogenerated_notice():
# ------------------------------------------------------------------------------
def gen_setup(config, relative_path):
def gen_setup(config, relative_path, setup_script_name):
"""
Generate setup.py script.
Generate setup script.
"""
s = []
s.append('#!/usr/bin/env python')
@ -145,8 +145,8 @@ def gen_setup(config, relative_path):
s.append('\n\noptions = """')
s.append('Usage:')
s.append(' ./setup.py [options] [<builddir>]')
s.append(' ./setup.py (-h | --help)')
s.append(' ./{0} [options] [<builddir>]'.format(setup_script_name))
s.append(' ./{0} (-h | --help)'.format(setup_script_name))
s.append('\nOptions:')
options = []
@ -334,7 +334,7 @@ def main(argv):
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(" $ %s --self\n\n" % argv[0])
sys.stderr.write("Step 2: Create CMakeLists.txt and setup.py in PROJECT_ROOT:\n")
sys.stderr.write("Step 2: Create CMakeLists.txt and setup script in PROJECT_ROOT:\n")
sys.stderr.write(" $ %s <PROJECT_ROOT>\n" % argv[0])
sys.stderr.write(" example:\n")
sys.stderr.write(" $ %s ..\n" % argv[0])
@ -343,7 +343,7 @@ def main(argv):
if argv[1] in ['-h', '--help']:
print('Usage:')
print(' python update.py --self Update this script and fetch or update infrastructure files under lib/.')
print(' python update.py <builddir> (Re)generate CMakeLists.txt and setup.py and fetch or update CMake modules.')
print(' python update.py <builddir> (Re)generate CMakeLists.txt and setup script and fetch or update CMake modules.')
print(' python update.py (-h | --help) Show this help text.')
sys.exit(0)
@ -398,7 +398,12 @@ def main(argv):
sys.exit(-1)
min_cmake_version = config.get('project', 'min_cmake_version')
# get relative path from setup.py script to this directory
if config.has_option('project', 'setup_script'):
setup_script_name = config.get('project', 'setup_script')
else:
setup_script_name = 'setup'
# get relative path from setup script to this directory
relative_path = os.path.relpath(os.path.abspath('.'), project_root)
# fetch modules from the web or from relative paths
@ -410,10 +415,10 @@ def main(argv):
with open(os.path.join(project_root, 'CMakeLists.txt'), 'w') as f:
f.write('%s\n' % '\n'.join(s))
# create setup.py
print('- generating setup.py')
s = gen_setup(config, relative_path)
file_path = os.path.join(project_root, 'setup.py')
# 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('%s\n' % '\n'.join(s))
if sys.platform != 'win32':