Skip to content

Commit

Permalink
Merge pull request #221 from robertodr/bare-cmake
Browse files Browse the repository at this point in the history
Get setup to reproduce use of bare CMake
  • Loading branch information
bast authored Dec 8, 2017
2 parents 65df3ea + 0a8e7eb commit 2e587b5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 41 deletions.
19 changes: 19 additions & 0 deletions .default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
with import <nixpkgs> {}; {
autocmakeEnv = stdenv.mkDerivation {
name = "Autocmake";
buildInputs = [
atlas
ccache
clang
cmake
doxygen
gfortran
liblapack
openmpi
python35Packages.pep8
python35Packages.pytest
python35Packages.pyyaml
zlib
];
};
}
7 changes: 7 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use nix .default.nix
export SOURCE_DATE_EPOCH=$(date +%s)
dir_hash=autocmake-$(echo -n autocmake | shasum | cut -d ' ' -f 1)
direnv_layout_dir=$XDG_CACHE_HOME/direnv/layouts/$dir_hash
layout python `type -P python` --system-site-packages
pip install -r requirements.txt
export NINJA_STATUS="[Built edge %f of %t in %e sec]"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test/*/cmake/update.py
test/*/cmake/autocmake/
test/*/cmake/downloaded/
test/*/setup
test/*/cmake_output

# generated by doc/extract_rst.py
doc/module-reference.rst
32 changes: 1 addition & 31 deletions autocmake/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,6 @@ def setup_build_path(build_path):
os.makedirs(build_path, 0o755)


def test_adapt_cmake_command_to_platform():

cmake_command = "FC=foo CC=bar CXX=RABOOF cmake -DTHIS -DTHAT='this and that cmake' .."
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
assert res == cmake_command
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
assert res == "set FC=foo && set CC=bar && set CXX=RABOOF && cmake -DTHIS -DTHAT='this and that cmake' .."

cmake_command = "cmake -DTHIS -DTHAT='this and that cmake' .."
res = adapt_cmake_command_to_platform(cmake_command, 'linux')
assert res == cmake_command
res = adapt_cmake_command_to_platform(cmake_command, 'win32')
assert res == cmake_command


def adapt_cmake_command_to_platform(cmake_command, platform):
"""
Adapt CMake command to MS Windows platform.
"""
if platform == 'win32':
pos = cmake_command.find('cmake')
s = ['set {0} &&'.format(e) for e in cmake_command[:pos].split()]
s.append(cmake_command[pos:])
return ' '.join(s)
else:
return cmake_command


def run_cmake(command, build_path, default_build_path):
"""
Execute CMake command.
Expand All @@ -84,7 +56,6 @@ def run_cmake(command, build_path, default_build_path):
from shutil import rmtree

topdir = os.getcwd()
os.chdir(build_path)
p = Popen(command,
shell=True,
stdin=PIPE,
Expand Down Expand Up @@ -164,8 +135,7 @@ def configure(root_directory, build_path, cmake_command, only_show):
if not only_show:
setup_build_path(build_path)

cmake_command = adapt_cmake_command_to_platform(cmake_command, sys.platform)

cmake_command += ' -B' + build_path
print('{0}\n'.format(cmake_command))
if only_show:
sys.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions autocmake/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def gen_cmake_command(config):
s.append(' command.append({0})'.format(definition))

s.append(" command.append('-DCMAKE_BUILD_TYPE={0}'.format(arguments['--type']))")
s.append(" command.append('-G \"{0}\"'.format(arguments['--generator']))")
s.append(" command.append('-G\"{0}\"'.format(arguments['--generator']))")
s.append(" if arguments['--cmake-options'] != \"''\":")
s.append(" command.append(arguments['--cmake-options'])")
s.append(" if arguments['--prefix']:")
Expand Down Expand Up @@ -110,7 +110,7 @@ def gen_setup(config, default_build_type, relative_path, setup_script_name):
s.append("build_path = arguments['<builddir>']")
s.append("\n")
s.append("# create cmake command")
s.append("cmake_command = '{0} {1}'.format(gen_cmake_command(options, arguments), root_directory)")
s.append("cmake_command = '{0} -H{1}'.format(gen_cmake_command(options, arguments), root_directory)")
s.append("\n")
s.append("# run cmake")
s.append("configure.configure(root_directory, build_path, cmake_command, arguments['--show'])")
Expand Down
3 changes: 1 addition & 2 deletions modules/cc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
# docopt:
# - "--cc=<CC> C compiler [default: gcc]."
# - "--extra-cc-flags=<EXTRA_CFLAGS> Extra C compiler flags [default: '']."
# export: "'CC={0}'.format(arguments['--cc'])"
# define: "'-DEXTRA_CFLAGS=\"{0}\"'.format(arguments['--extra-cc-flags'])"
# define: "'-DCMAKE_C_COMPILER={0} -DEXTRA_CFLAGS=\"{1}\"'.format(arguments['--cc'], arguments['--extra-cc-flags'])"

if(NOT DEFINED CMAKE_C_COMPILER_ID)
message(FATAL_ERROR "CMAKE_C_COMPILER_ID variable is not defined!")
Expand Down
3 changes: 1 addition & 2 deletions modules/cxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
# docopt:
# - "--cxx=<CXX> C++ compiler [default: g++]."
# - "--extra-cxx-flags=<EXTRA_CXXFLAGS> Extra C++ compiler flags [default: '']."
# export: "'CXX={0}'.format(arguments['--cxx'])"
# define: "'-DEXTRA_CXXFLAGS=\"{0}\"'.format(arguments['--extra-cxx-flags'])"
# define: "'-DCMAKE_CXX_COMPILER={0} -DEXTRA_CXXFLAGS=\"{1}\"'.format(arguments['--cxx'], arguments['--extra-cxx-flags'])"

if(NOT DEFINED CMAKE_CXX_COMPILER_ID)
message(FATAL_ERROR "CMAKE_CXX_COMPILER_ID variable is not defined!")
Expand Down
3 changes: 1 addition & 2 deletions modules/fc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
# docopt:
# - "--fc=<FC> Fortran compiler [default: gfortran]."
# - "--extra-fc-flags=<EXTRA_FCFLAGS> Extra Fortran compiler flags [default: '']."
# export: "'FC={0}'.format(arguments['--fc'])"
# define: "'-DEXTRA_FCFLAGS=\"{0}\"'.format(arguments['--extra-fc-flags'])"
# define: "'-DCMAKE_Fortran_COMPILER={0} -DEXTRA_FCFLAGS=\"{1}\"'.format(arguments['--fc'], arguments['--extra-fc-flags'])"

set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modules)
include_directories(${PROJECT_BINARY_DIR}/modules)
Expand Down
3 changes: 1 addition & 2 deletions modules/fc_optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
# - "--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]."
# export: "'FC={0}'.format(arguments['--fc'])"
# define:
# - "'-DEXTRA_FCFLAGS=\"{0}\"'.format(arguments['--extra-fc-flags'])"
# - "'-DCMAKE_Fortran_COMPILER={0} -DEXTRA_FCFLAGS=\"{1}\"'.format(arguments['--fc'], arguments['--extra-fc-flags'])"
# - "'-DENABLE_FC_SUPPORT={0}'.format(arguments['--fc-support'])"

option(ENABLE_FC_SUPPORT "Enable Fortran language support" ON)
Expand Down

0 comments on commit 2e587b5

Please sign in to comment.